Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  
   3  require_once("../../config.php");
   4  require_once ("lib.php");
   5  
   6  $eid = required_param('eid', PARAM_INT);    // Entry ID
   7  
   8  $newstate = optional_param('newstate', 1, PARAM_BOOL);
   9  $mode = optional_param('mode', 'approval', PARAM_ALPHA);
  10  $hook = optional_param('hook', 'ALL', PARAM_CLEAN);
  11  
  12  $url = new moodle_url('/mod/glossary/approve.php', array('eid' => $eid, 'mode' => $mode, 'hook' => $hook, 'newstate' => $newstate));
  13  $PAGE->set_url($url);
  14  
  15  $entry = $DB->get_record('glossary_entries', array('id'=> $eid), '*', MUST_EXIST);
  16  $glossary = $DB->get_record('glossary', array('id'=> $entry->glossaryid), '*', MUST_EXIST);
  17  $cm = get_coursemodule_from_instance('glossary', $glossary->id, 0, false, MUST_EXIST);
  18  $course = $DB->get_record('course', array('id'=> $cm->course), '*', MUST_EXIST);
  19  
  20  require_login($course, false, $cm);
  21  
  22  $context = context_module::instance($cm->id);
  23  require_capability('mod/glossary:approve', $context);
  24  
  25  if (($newstate != $entry->approved) && confirm_sesskey()) {
  26      $newentry = new stdClass();
  27      $newentry->id           = $entry->id;
  28      $newentry->approved     = $newstate;
  29      $newentry->timemodified = time(); // wee need this date here to speed up recent activity, TODO: use timestamp in approved field instead in 2.0
  30      $DB->update_record("glossary_entries", $newentry);
  31  
  32      // Trigger event about entry approval/disapproval.
  33      $params = array(
  34          'context' => $context,
  35          'objectid' => $entry->id
  36      );
  37      if ($newstate) {
  38          $event = \mod_glossary\event\entry_approved::create($params);
  39      } else {
  40          $event = \mod_glossary\event\entry_disapproved::create($params);
  41      }
  42      $entry->approved = $newstate ? 1 : 0;
  43      $entry->timemodified = $newentry->timemodified;
  44      $event->add_record_snapshot('glossary_entries', $entry);
  45      $event->trigger();
  46  
  47      // Update completion state
  48      $completion = new completion_info($course);
  49      if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries) {
  50          $completion->update_state($cm, COMPLETION_COMPLETE, $entry->userid);
  51      }
  52  
  53      // Reset caches.
  54      if ($entry->usedynalink) {
  55          \mod_glossary\local\concept_cache::reset_glossary($glossary);
  56      }
  57  }
  58  
  59  redirect("view.php?id=$cm->id&amp;mode=$mode&amp;hook=$hook");