Merge branch 'MDL-74815-400' of https://github.com/junpataleta/moodle into MOODLE_400...
[moodle.git] / mod / glossary / approve.php
blobc2a0ea23d32eca91a89215bd2a350213ab7c0724
1 <?php
3 require_once("../../config.php");
4 require_once("lib.php");
6 $eid = required_param('eid', PARAM_INT); // Entry ID
8 $newstate = optional_param('newstate', 1, PARAM_BOOL);
9 $mode = optional_param('mode', 'approval', PARAM_ALPHA);
10 $hook = optional_param('hook', 'ALL', PARAM_CLEAN);
12 $url = new moodle_url('/mod/glossary/approve.php', array('eid' => $eid, 'mode' => $mode, 'hook' => $hook, 'newstate' => $newstate));
13 $PAGE->set_url($url);
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);
20 require_login($course, false, $cm);
22 $context = context_module::instance($cm->id);
23 require_capability('mod/glossary:approve', $context);
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);
32 // Trigger event about entry approval/disapproval.
33 $params = array(
34 'context' => $context,
35 'objectid' => $entry->id
37 if ($newstate) {
38 $event = \mod_glossary\event\entry_approved::create($params);
39 } else {
40 $event = \mod_glossary\event\entry_disapproved::create($params);
42 $entry->approved = $newstate ? 1 : 0;
43 $entry->timemodified = $newentry->timemodified;
44 $event->add_record_snapshot('glossary_entries', $entry);
45 $event->trigger();
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);
53 // Reset caches.
54 if ($entry->usedynalink) {
55 \mod_glossary\local\concept_cache::reset_glossary($glossary);
59 redirect("view.php?id=$cm->id&amp;mode=$mode&amp;hook=$hook");