[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/mod/glossary/ -> showentry.php (source)

   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      print_error('invalidelementid');
  40  }
  41  
  42  $PAGE->set_pagelayout('incourse');
  43  
  44  if ($entries) {
  45      foreach ($entries as $key => $entry) {
  46          // Need to get the course where the entry is,
  47          // in order to check for visibility/approve permissions there
  48          $entrycourse = $DB->get_record('course', array('id' => $entry->courseid), '*', MUST_EXIST);
  49          $modinfo = get_fast_modinfo($entrycourse);
  50          // make sure the entry is visible
  51          if (empty($modinfo->cms[$entry->cmid]->uservisible)) {
  52              unset($entries[$key]);
  53              continue;
  54          }
  55          // make sure the entry is approved (or approvable by current user)
  56          if (!$entry->approved and ($USER->id != $entry->userid)) {
  57              $context = context_module::instance($entry->cmid);
  58              if (!has_capability('mod/glossary:approve', $context)) {
  59                  unset($entries[$key]);
  60                  continue;
  61              }
  62          }
  63          $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>";
  64          $event = \mod_glossary\event\entry_viewed::create(array(
  65              'objectid' => $entry->id,
  66              'context' => $modinfo->cms[$entry->cmid]->context
  67          ));
  68          $event->add_record_snapshot('glossary_entries', $entry);
  69          $event->trigger();
  70      }
  71  }
  72  
  73  if (!empty($courseid)) {
  74      $strglossaries = get_string('modulenameplural', 'glossary');
  75      $strsearch = get_string('search');
  76  
  77      $PAGE->navbar->add($strglossaries);
  78      $PAGE->navbar->add($strsearch);
  79      $PAGE->set_title(strip_tags("$course->shortname: $strglossaries $strsearch"));
  80      $PAGE->set_heading($course->fullname);
  81      echo $OUTPUT->header();
  82  } else {
  83      echo $OUTPUT->header();    // Needs to be something here to allow linking back to the whole glossary
  84  }
  85  
  86  if ($entries) {
  87      glossary_print_dynaentry($courseid, $entries, $displayformat);
  88  }
  89  
  90  /// Show one reduced footer
  91  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1