Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402]

   1  <?php
   2  
   3  require_once('../../config.php');
   4  require_once ('lib.php');
   5  
   6  $concept  = optional_param('concept', '', PARAM_CLEAN);
   7  $courseid = optional_param('courseid', 0, PARAM_INT);
   8  $eid      = optional_param('eid', 0, PARAM_INT); // glossary entry id
   9  $displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR);
  10  
  11  $url = new moodle_url('/mod/glossary/showentry.php');
  12  $url->param('concept', $concept);
  13  $url->param('courseid', $courseid);
  14  $url->param('eid', $eid);
  15  $url->param('displayformat', $displayformat);
  16  $PAGE->set_url($url);
  17  
  18  if ($CFG->forcelogin) {
  19      require_login();
  20  }
  21  
  22  if ($eid) {
  23      $entry = $DB->get_record('glossary_entries', array('id'=>$eid), '*', MUST_EXIST);
  24      $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid), '*', MUST_EXIST);
  25      $cm = get_coursemodule_from_instance('glossary', $glossary->id, 0, false, MUST_EXIST);
  26      $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
  27      require_course_login($course, true, $cm);
  28      $entry->glossaryname = $glossary->name;
  29      $entry->cmid = $cm->id;
  30      $entry->courseid = $cm->course;
  31      $entries = array($entry);
  32  
  33  } else if ($concept) {
  34      $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
  35      require_course_login($course);
  36      $entries = glossary_get_entries_search($concept, $courseid);
  37  
  38  } else {
  39      throw new \moodle_exception('invalidelementid');
  40  }
  41  
  42  $PAGE->set_pagelayout('incourse');
  43  $PAGE->activityheader->disable();
  44  
  45  if ($entries) {
  46      foreach ($entries as $key => $entry) {
  47          // Need to get the course where the entry is,
  48          // in order to check for visibility/approve permissions there
  49          $entrycourse = $DB->get_record('course', array('id' => $entry->courseid), '*', MUST_EXIST);
  50          $modinfo = get_fast_modinfo($entrycourse);
  51          // make sure the entry is visible
  52          if (empty($modinfo->cms[$entry->cmid]->uservisible)) {
  53              unset($entries[$key]);
  54              continue;
  55          }
  56          // make sure the entry is approved (or approvable by current user)
  57          if (!$entry->approved and ($USER->id != $entry->userid)) {
  58              $context = context_module::instance($entry->cmid);
  59              if (!has_capability('mod/glossary:approve', $context)) {
  60                  unset($entries[$key]);
  61                  continue;
  62              }
  63          }
  64          $entries[$key]->footer = "<p style=\"text-align:right\">&raquo;&nbsp;<a href=\"$CFG->wwwroot/mod/glossary/view.php?g=$entry->glossaryid\">".format_string($entry->glossaryname,true)."</a></p>";
  65          glossary_entry_view($entry, $modinfo->cms[$entry->cmid]->context);
  66      }
  67  }
  68  
  69  if (!empty($courseid)) {
  70      $strglossaries = get_string('modulenameplural', 'glossary');
  71      $strsearch = get_string('search');
  72  
  73      $PAGE->navbar->add($strglossaries);
  74      $PAGE->navbar->add($strsearch);
  75      $PAGE->set_title(strip_tags("$course->shortname: $strglossaries $strsearch"));
  76      $PAGE->set_heading($course->fullname);
  77      echo $OUTPUT->header();
  78  } else {
  79      echo $OUTPUT->header();    // Needs to be something here to allow linking back to the whole glossary
  80  }
  81  
  82  if ($glossary) {
  83      $url = new moodle_url('view.php', ['id' => $cm->id]);
  84      $backlink = html_writer::link($url, get_string('back'), ['class' => 'btn btn-secondary']);
  85      echo html_writer::tag('div', $backlink, ['class' => 'tertiary-navigation']);
  86  }
  87  
  88  if ($entries) {
  89      glossary_print_dynaentry($courseid, $entries, $displayformat);
  90  }
  91  
  92  /// Show one reduced footer
  93  echo $OUTPUT->footer();