| 1 | efrain | 1 | <?php
 | 
        
           |  |  | 2 | // This file is part of Moodle - http://moodle.org/
 | 
        
           |  |  | 3 | //
 | 
        
           |  |  | 4 | // Moodle is free software: you can redistribute it and/or modify
 | 
        
           |  |  | 5 | // it under the terms of the GNU General Public License as published by
 | 
        
           |  |  | 6 | // the Free Software Foundation, either version 3 of the License, or
 | 
        
           |  |  | 7 | // (at your option) any later version.
 | 
        
           |  |  | 8 | //
 | 
        
           |  |  | 9 | // Moodle is distributed in the hope that it will be useful,
 | 
        
           |  |  | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
        
           |  |  | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
        
           |  |  | 12 | // GNU General Public License for more details.
 | 
        
           |  |  | 13 | //
 | 
        
           |  |  | 14 | // You should have received a copy of the GNU General Public License
 | 
        
           |  |  | 15 | // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 | 
        
           |  |  | 16 |   | 
        
           |  |  | 17 | /**
 | 
        
           |  |  | 18 |  * This page lists all the instances of book in a particular course
 | 
        
           |  |  | 19 |  *
 | 
        
           |  |  | 20 |  * @package    mod_book
 | 
        
           |  |  | 21 |  * @copyright  2004-2011 Petr Skoda {@link http://skodak.org}
 | 
        
           |  |  | 22 |  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 | 
        
           |  |  | 23 |  */
 | 
        
           |  |  | 24 |   | 
        
           |  |  | 25 | require(__DIR__.'/../../config.php');
 | 
        
           |  |  | 26 | require_once(__DIR__.'/locallib.php');
 | 
        
           |  |  | 27 |   | 
        
           |  |  | 28 | $id = required_param('id', PARAM_INT); // Course ID.
 | 
        
           |  |  | 29 |   | 
        
           |  |  | 30 | $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST);
 | 
        
           |  |  | 31 |   | 
        
           |  |  | 32 | unset($id);
 | 
        
           |  |  | 33 |   | 
        
           |  |  | 34 | require_course_login($course, true);
 | 
        
           |  |  | 35 | $PAGE->set_pagelayout('incourse');
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 | // Get all required strings
 | 
        
           |  |  | 38 | $strbooks        = get_string('modulenameplural', 'mod_book');
 | 
        
           |  |  | 39 | $strbook         = get_string('modulename', 'mod_book');
 | 
        
           |  |  | 40 | $strname         = get_string('name');
 | 
        
           |  |  | 41 | $strintro        = get_string('moduleintro');
 | 
        
           |  |  | 42 | $strlastmodified = get_string('lastmodified');
 | 
        
           |  |  | 43 |   | 
        
           |  |  | 44 | $PAGE->set_url('/mod/book/index.php', array('id' => $course->id));
 | 
        
           |  |  | 45 | $PAGE->set_title($course->shortname.': '.$strbooks);
 | 
        
           |  |  | 46 | $PAGE->set_heading($course->fullname);
 | 
        
           |  |  | 47 | $PAGE->navbar->add($strbooks);
 | 
        
           |  |  | 48 | echo $OUTPUT->header();
 | 
        
           |  |  | 49 |   | 
        
           |  |  | 50 | \mod_book\event\course_module_instance_list_viewed::create_from_course($course)->trigger();
 | 
        
           |  |  | 51 |   | 
        
           |  |  | 52 | // Get all the appropriate data
 | 
        
           |  |  | 53 | if (!$books = get_all_instances_in_course('book', $course)) {
 | 
        
           |  |  | 54 |     notice(get_string('thereareno', 'moodle', $strbooks), "$CFG->wwwroot/course/view.php?id=$course->id");
 | 
        
           |  |  | 55 |     die;
 | 
        
           |  |  | 56 | }
 | 
        
           |  |  | 57 |   | 
        
           |  |  | 58 | $usesections = course_format_uses_sections($course->format);
 | 
        
           |  |  | 59 |   | 
        
           |  |  | 60 | $table = new html_table();
 | 
        
           |  |  | 61 | $table->attributes['class'] = 'generaltable mod_index';
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 | if ($usesections) {
 | 
        
           | 1441 | ariadna | 64 |     $strsectionname = course_get_format($course)->get_generic_section_name();
 | 
        
           | 1 | efrain | 65 |     $table->head  = array ($strsectionname, $strname, $strintro);
 | 
        
           |  |  | 66 |     $table->align = array ('center', 'left', 'left');
 | 
        
           |  |  | 67 | } else {
 | 
        
           |  |  | 68 |     $table->head  = array ($strlastmodified, $strname, $strintro);
 | 
        
           |  |  | 69 |     $table->align = array ('left', 'left', 'left');
 | 
        
           |  |  | 70 | }
 | 
        
           |  |  | 71 |   | 
        
           |  |  | 72 | $modinfo = get_fast_modinfo($course);
 | 
        
           |  |  | 73 | $currentsection = '';
 | 
        
           |  |  | 74 | foreach ($books as $book) {
 | 
        
           |  |  | 75 |     $cm = $modinfo->get_cm($book->coursemodule);
 | 
        
           |  |  | 76 |     if ($usesections) {
 | 
        
           |  |  | 77 |         $printsection = '';
 | 
        
           |  |  | 78 |         if ($book->section !== $currentsection) {
 | 
        
           |  |  | 79 |             if ($book->section) {
 | 
        
           |  |  | 80 |                 $printsection = get_section_name($course, $book->section);
 | 
        
           |  |  | 81 |             }
 | 
        
           |  |  | 82 |             if ($currentsection !== '') {
 | 
        
           |  |  | 83 |                 $table->data[] = 'hr';
 | 
        
           |  |  | 84 |             }
 | 
        
           |  |  | 85 |             $currentsection = $book->section;
 | 
        
           |  |  | 86 |         }
 | 
        
           |  |  | 87 |     } else {
 | 
        
           |  |  | 88 |         $printsection = html_writer::tag('span', userdate($book->timemodified), array('class' => 'smallinfo'));
 | 
        
           |  |  | 89 |     }
 | 
        
           |  |  | 90 |   | 
        
           |  |  | 91 |     $class = $book->visible ? null : array('class' => 'dimmed'); // hidden modules are dimmed
 | 
        
           |  |  | 92 |   | 
        
           |  |  | 93 |     $table->data[] = array (
 | 
        
           |  |  | 94 |         $printsection,
 | 
        
           |  |  | 95 |         html_writer::link(new moodle_url('view.php', array('id' => $cm->id)), format_string($book->name), $class),
 | 
        
           |  |  | 96 |         format_module_intro('book', $book, $cm->id));
 | 
        
           |  |  | 97 | }
 | 
        
           |  |  | 98 |   | 
        
           |  |  | 99 | echo html_writer::table($table);
 | 
        
           |  |  | 100 |   | 
        
           |  |  | 101 | echo $OUTPUT->footer();
 |