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/url/ -> index.php (source)

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

   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 urls in course
  20   *
  21   * @package    mod_url
  22   * @copyright  2009 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  $params = array(
  36      'context' => context_course::instance($course->id)
  37  );
  38  $event = \mod_url\event\course_module_instance_list_viewed::create($params);
  39  $event->add_record_snapshot('course', $course);
  40  $event->trigger();
  41  
  42  $strurl       = get_string('modulename', 'url');
  43  $strurls      = get_string('modulenameplural', 'url');
  44  $strname         = get_string('name');
  45  $strintro        = get_string('moduleintro');
  46  $strlastmodified = get_string('lastmodified');
  47  
  48  $PAGE->set_url('/mod/url/index.php', array('id' => $course->id));
  49  $PAGE->set_title($course->shortname.': '.$strurls);
  50  $PAGE->set_heading($course->fullname);
  51  $PAGE->navbar->add($strurls);
  52  echo $OUTPUT->header();
  53  echo $OUTPUT->heading($strurls);
  54  
  55  if (!$urls = get_all_instances_in_course('url', $course)) {
  56      notice(get_string('thereareno', 'moodle', $strurls), "$CFG->wwwroot/course/view.php?id=$course->id");
  57      exit;
  58  }
  59  
  60  $usesections = course_format_uses_sections($course->format);
  61  
  62  $table = new html_table();
  63  $table->attributes['class'] = 'generaltable mod_index';
  64  
  65  if ($usesections) {
  66      $strsectionname = get_string('sectionname', 'format_'.$course->format);
  67      $table->head  = array ($strsectionname, $strname, $strintro);
  68      $table->align = array ('center', 'left', 'left');
  69  } else {
  70      $table->head  = array ($strlastmodified, $strname, $strintro);
  71      $table->align = array ('left', 'left', 'left');
  72  }
  73  
  74  $modinfo = get_fast_modinfo($course);
  75  $currentsection = '';
  76  foreach ($urls as $url) {
  77      $cm = $modinfo->cms[$url->coursemodule];
  78      if ($usesections) {
  79          $printsection = '';
  80          if ($url->section !== $currentsection) {
  81              if ($url->section) {
  82                  $printsection = get_section_name($course, $url->section);
  83              }
  84              if ($currentsection !== '') {
  85                  $table->data[] = 'hr';
  86              }
  87              $currentsection = $url->section;
  88          }
  89      } else {
  90          $printsection = '<span class="smallinfo">'.userdate($url->timemodified)."</span>";
  91      }
  92  
  93      $extra = empty($cm->extra) ? '' : $cm->extra;
  94      $icon = '';
  95      if (!empty($cm->icon)) {
  96          // each url has an icon in 2.0
  97          $icon = $OUTPUT->pix_icon($cm->icon, get_string('modulename', $cm->modname)) . ' ';
  98      }
  99  
 100      $class = $url->visible ? '' : 'class="dimmed"'; // hidden modules are dimmed
 101      $table->data[] = array (
 102          $printsection,
 103          "<a $class $extra href=\"view.php?id=$cm->id\">".$icon.format_string($url->name)."</a>",
 104          format_module_intro('url', $url, $cm->id));
 105  }
 106  
 107  echo html_writer::table($table);
 108  
 109  echo $OUTPUT->footer();