Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
/mod/page/ -> index.php (source)
   1  <?php
   2  
   3  // This file is part of Moodle - http://moodle.org/
   4  //
   5  // Moodle is free software: you can redistribute it and/or modify
   6  // it under the terms of the GNU General Public License as published by
   7  // the Free Software Foundation, either version 3 of the License, or
   8  // (at your option) any later version.
   9  //
  10  // Moodle is distributed in the hope that it will be useful,
  11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13  // GNU General Public License for more details.
  14  //
  15  // You should have received a copy of the GNU General Public License
  16  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  17  
  18  /**
  19   * List of all pages in course
  20   *
  21   * @package mod_page
  22   * @copyright  1999 onwards Martin Dougiamas (http://dougiamas.com)
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require('../../config.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  require_course_login($course, true);
  33  $PAGE->set_pagelayout('incourse');
  34  
  35  // Trigger instances list viewed event.
  36  $event = \mod_page\event\course_module_instance_list_viewed::create(array('context' => context_course::instance($course->id)));
  37  $event->add_record_snapshot('course', $course);
  38  $event->trigger();
  39  
  40  $strpage         = get_string('modulename', 'page');
  41  $strpages        = get_string('modulenameplural', 'page');
  42  $strname         = get_string('name');
  43  $strintro        = get_string('moduleintro');
  44  $strlastmodified = get_string('lastmodified');
  45  
  46  $PAGE->set_url('/mod/page/index.php', array('id' => $course->id));
  47  $PAGE->set_title($course->shortname.': '.$strpages);
  48  $PAGE->set_heading($course->fullname);
  49  $PAGE->navbar->add($strpages);
  50  echo $OUTPUT->header();
  51  echo $OUTPUT->heading($strpages);
  52  if (!$pages = get_all_instances_in_course('page', $course)) {
  53      notice(get_string('thereareno', 'moodle', $strpages), "$CFG->wwwroot/course/view.php?id=$course->id");
  54      exit;
  55  }
  56  
  57  $usesections = course_format_uses_sections($course->format);
  58  
  59  $table = new html_table();
  60  $table->attributes['class'] = 'generaltable mod_index';
  61  
  62  if ($usesections) {
  63      $strsectionname = get_string('sectionname', 'format_'.$course->format);
  64      $table->head  = array ($strsectionname, $strname, $strintro);
  65      $table->align = array ('center', 'left', 'left');
  66  } else {
  67      $table->head  = array ($strlastmodified, $strname, $strintro);
  68      $table->align = array ('left', 'left', 'left');
  69  }
  70  
  71  $modinfo = get_fast_modinfo($course);
  72  $currentsection = '';
  73  foreach ($pages as $page) {
  74      $cm = $modinfo->cms[$page->coursemodule];
  75      if ($usesections) {
  76          $printsection = '';
  77          if ($page->section !== $currentsection) {
  78              if ($page->section) {
  79                  $printsection = get_section_name($course, $page->section);
  80              }
  81              if ($currentsection !== '') {
  82                  $table->data[] = 'hr';
  83              }
  84              $currentsection = $page->section;
  85          }
  86      } else {
  87          $printsection = '<span class="smallinfo">'.userdate($page->timemodified)."</span>";
  88      }
  89  
  90      $class = $page->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
  91  
  92      $table->data[] = array (
  93          $printsection,
  94          "<a $class href=\"view.php?id=$cm->id\">".format_string($page->name)."</a>",
  95          format_module_intro('page', $page, $cm->id));
  96  }
  97  
  98  echo html_writer::table($table);
  99  
 100  echo $OUTPUT->footer();