[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

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

   1  <?php
   2  define('AJAX_SCRIPT', true);
   3  
   4  require_once('../../config.php');
   5  require_once ('lib.php');
   6  require_once($CFG->libdir . '/filelib.php');
   7  
   8  $concept  = optional_param('concept', '', PARAM_CLEAN);
   9  $courseid = optional_param('courseid', 0, PARAM_INT);
  10  $eid      = optional_param('eid', 0, PARAM_INT); // glossary entry id
  11  $displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR);
  12  
  13  $url = new moodle_url('/mod/glossary/showentry.php');
  14  $url->param('concept', $concept);
  15  $url->param('courseid', $courseid);
  16  $url->param('eid', $eid);
  17  $url->param('displayformat', $displayformat);
  18  $PAGE->set_url($url);
  19  
  20  if ($CFG->forcelogin) {
  21      require_login();
  22  }
  23  
  24  if ($eid) {
  25      $entry = $DB->get_record('glossary_entries', array('id'=>$eid), '*', MUST_EXIST);
  26      $glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid), '*', MUST_EXIST);
  27      $cm = get_coursemodule_from_instance('glossary', $glossary->id, 0, false, MUST_EXIST);
  28      $course = $DB->get_record('course', array('id'=>$cm->course), '*', MUST_EXIST);
  29      require_course_login($course, true, $cm);
  30      $entry->glossaryname = $glossary->name;
  31      $entry->cmid = $cm->id;
  32      $entry->courseid = $cm->course;
  33      $entries = array($entry);
  34  
  35  } else if ($concept) {
  36      $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
  37      require_course_login($course);
  38      $entries = glossary_get_entries_search($concept, $courseid);
  39  
  40  } else {
  41      print_error('invalidelementid');
  42  }
  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  
  64          $context = context_module::instance($entry->cmid);
  65          $definition = file_rewrite_pluginfile_urls($entry->definition, 'pluginfile.php', $context->id, 'mod_glossary', 'entry', $entry->id);
  66  
  67          $options = new stdClass();
  68          $options->para = false;
  69          $options->trusted = $entry->definitiontrust;
  70          $options->context = $context;
  71          $entries[$key]->definition = format_text($definition, $entry->definitionformat, $options);
  72  
  73          $entries[$key]->attachments = '';
  74          if (!empty($entries[$key]->attachment)) {
  75              $attachments = glossary_print_attachments($entry, $cm, 'html');
  76              $entries[$key]->attachments = html_writer::tag('p', $attachments);
  77          }
  78  
  79          $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>";
  80          $event = \mod_glossary\event\entry_viewed::create(array(
  81              'objectid' => $entry->id,
  82              'context' => $modinfo->cms[$entry->cmid]->context
  83          ));
  84          $event->add_record_snapshot('glossary_entries', $entry);
  85          $event->trigger();
  86      }
  87  }
  88  
  89  echo $OUTPUT->header();
  90  
  91  $result = new stdClass;
  92  $result->success = true;
  93  $result->entries = $entries;
  94  echo json_encode($result);
  95  
  96  echo $OUTPUT->footer();
  97  


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