MDL-40059 glossary: events for add/delete/update entries
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* mod_glossary entry created event.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_glossary\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_glossary entry created event.
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* @type string concept the concept of created entry.
|
||||
* }
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class entry_created extends \core\event\base {
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'glossary_entries';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('evententrycreated', 'mod_glossary');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "User {$this->userid} has created a glossary entry with id {$this->objectid}.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url("/mod/glossary/view.php",
|
||||
array('id' => $this->contextinstanceid,
|
||||
'mode' => 'entry',
|
||||
'hook' => $this->objectid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function get_legacy_logdata() {
|
||||
return array($this->courseid, 'glossary', 'add entry',
|
||||
"view.php?id={$this->contextinstanceid}&mode=entry&hook={$this->objectid}",
|
||||
$this->objectid, $this->contextinstanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
// Make sure this class is never used without proper object details.
|
||||
if (!$this->contextlevel === CONTEXT_MODULE) {
|
||||
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* mod_glossary entry deleted event.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_glossary\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_glossary entry deleted event.
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* @type string concept the concept of deleted entry.
|
||||
* @type string mode (optional) view mode user was in before deleting entry.
|
||||
* @type int|string hook (optional) hook parameter in the previous view mode.
|
||||
* }
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class entry_deleted extends \core\event\base {
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'd';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'glossary_entries';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('evententrydeleted', 'mod_glossary');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "User {$this->userid} has deleted a glossary entry with id {$this->objectid}.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
// Entry does not exist any more, returning link to the module view page in the mode it was before deleting entry.
|
||||
$params = array('id' => $this->contextinstanceid);
|
||||
if (isset($this->other['hook'])) {
|
||||
$params['hook'] = $this->other['hook'];
|
||||
}
|
||||
if (isset($this->other['mode'])) {
|
||||
$params['mode'] = $this->other['mode'];
|
||||
}
|
||||
return new \moodle_url("/mod/glossary/view.php", $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function get_legacy_logdata() {
|
||||
$hook = $mode = '';
|
||||
if (isset($this->other['hook'])) {
|
||||
$hook = $this->other['hook'];
|
||||
}
|
||||
if (isset($this->other['mode'])) {
|
||||
$mode = $this->other['mode'];
|
||||
}
|
||||
return array($this->courseid, 'glossary', 'delete entry',
|
||||
"view.php?id={$this->contextinstanceid}&mode={$mode}&hook={$hook}",
|
||||
$this->objectid, $this->contextinstanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
// Make sure this class is never used without proper object details.
|
||||
if (!$this->contextlevel === CONTEXT_MODULE) {
|
||||
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* mod_glossary entry updated event.
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace mod_glossary\event;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* mod_glossary entry updated event.
|
||||
*
|
||||
* @property-read array $other {
|
||||
* Extra information about event.
|
||||
*
|
||||
* @type string concept the concept of updated entry (after update).
|
||||
* }
|
||||
*
|
||||
* @package mod_glossary
|
||||
* @copyright 2014 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class entry_updated extends \core\event\base {
|
||||
/**
|
||||
* Init method
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
|
||||
$this->data['objecttable'] = 'glossary_entries';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns localised general event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('evententryupdated', 'mod_glossary');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "User {$this->userid} has updated a glossary entry with id {$this->objectid}.";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get URL related to the action.
|
||||
*
|
||||
* @return \moodle_url
|
||||
*/
|
||||
public function get_url() {
|
||||
return new \moodle_url("/mod/glossary/view.php",
|
||||
array('id' => $this->contextinstanceid,
|
||||
'mode' => 'entry',
|
||||
'hook' => $this->objectid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the legacy event log data.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function get_legacy_logdata() {
|
||||
return array($this->courseid, 'glossary', 'update entry',
|
||||
"view.php?id={$this->contextinstanceid}&mode=entry&hook={$this->objectid}",
|
||||
$this->objectid, $this->contextinstanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom validation.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return void
|
||||
*/
|
||||
protected function validate_data() {
|
||||
// Make sure this class is never used without proper object details.
|
||||
if (!$this->contextlevel === CONTEXT_MODULE) {
|
||||
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ if (!$ineditperiod and !$manageentries) {
|
||||
if ($confirm and confirm_sesskey()) { // the operation was confirmed.
|
||||
// if it is an imported entry, just delete the relation
|
||||
|
||||
$origentry = fullclone($entry);
|
||||
if ($entry->sourceglossaryid) {
|
||||
if (!$newcm = get_coursemodule_from_instance('glossary', $entry->sourceglossaryid)) {
|
||||
print_error('invalidcoursemodule');
|
||||
@@ -113,7 +114,17 @@ if ($confirm and confirm_sesskey()) { // the operation was confirmed.
|
||||
$rm->delete_ratings($delopt);
|
||||
}
|
||||
|
||||
add_to_log($course->id, "glossary", "delete entry", "view.php?id=$cm->id&mode=$prevmode&hook=$hook", $entry->id,$cm->id);
|
||||
$event = \mod_glossary\event\entry_deleted::create(array(
|
||||
'context' => $context,
|
||||
'objectid' => $origentry->id,
|
||||
'other' => array(
|
||||
'mode' => $prevmode,
|
||||
'hook' => $hook,
|
||||
'concept' => $origentry->concept
|
||||
)
|
||||
));
|
||||
$event->add_record_snapshot('glossary_entries', $origentry);
|
||||
$event->trigger();
|
||||
redirect("view.php?id=$cm->id&mode=$prevmode&hook=$hook");
|
||||
|
||||
} else { // the operation has not been confirmed yet so ask the user to do so
|
||||
|
||||
+27
-16
@@ -101,6 +101,9 @@ if ($mform->is_cancelled()){
|
||||
$entry->timecreated = $timenow;
|
||||
$entry->sourceglossaryid = 0;
|
||||
$entry->teacherentry = has_capability('mod/glossary:manageentries', $context);
|
||||
$isnewentry = true;
|
||||
} else {
|
||||
$isnewentry = false;
|
||||
}
|
||||
|
||||
$entry->concept = trim($entry->concept);
|
||||
@@ -117,25 +120,12 @@ if ($mform->is_cancelled()){
|
||||
$entry->approved = 1;
|
||||
}
|
||||
|
||||
if (empty($entry->id)) {
|
||||
//new entry
|
||||
if ($isnewentry) {
|
||||
// Add new entry.
|
||||
$entry->id = $DB->insert_record('glossary_entries', $entry);
|
||||
|
||||
// Update completion state
|
||||
$completion = new completion_info($course);
|
||||
if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries && $entry->approved) {
|
||||
$completion->update_state($cm, COMPLETION_COMPLETE);
|
||||
}
|
||||
|
||||
add_to_log($course->id, "glossary", "add entry",
|
||||
"view.php?id=$cm->id&mode=entry&hook=$entry->id", $entry->id, $cm->id);
|
||||
|
||||
} else {
|
||||
//existing entry
|
||||
// Update existing entry.
|
||||
$DB->update_record('glossary_entries', $entry);
|
||||
add_to_log($course->id, "glossary", "update entry",
|
||||
"view.php?id=$cm->id&mode=entry&hook=$entry->id",
|
||||
$entry->id, $cm->id);
|
||||
}
|
||||
|
||||
// save and relink embedded images and save attachments
|
||||
@@ -175,6 +165,27 @@ if ($mform->is_cancelled()){
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger event and update completion (if entry was created).
|
||||
$eventparams = array(
|
||||
'context' => $context,
|
||||
'objectid' => $entry->id,
|
||||
'other' => array('concept' => $entry->concept)
|
||||
);
|
||||
if ($isnewentry) {
|
||||
$event = \mod_glossary\event\entry_created::create($eventparams);
|
||||
} else {
|
||||
$event = \mod_glossary\event\entry_updated::create($eventparams);
|
||||
}
|
||||
$event->add_record_snapshot('glossary_entries', $entry);
|
||||
$event->trigger();
|
||||
if ($isnewentry) {
|
||||
// Update completion state
|
||||
$completion = new completion_info($course);
|
||||
if ($completion->is_enabled($cm) == COMPLETION_TRACKING_AUTOMATIC && $glossary->completionentries && $entry->approved) {
|
||||
$completion->update_state($cm, COMPLETION_COMPLETE);
|
||||
}
|
||||
}
|
||||
|
||||
redirect("view.php?id=$cm->id&mode=entry&hook=$entry->id");
|
||||
}
|
||||
|
||||
|
||||
@@ -155,6 +155,9 @@ $string['errconceptalreadyexists'] = 'This concept already exists. No duplicates
|
||||
$string['errdeltimeexpired'] = 'You can\'t delete this. Time expired!';
|
||||
$string['erredittimeexpired'] = 'The editing time for this entry has expired.';
|
||||
$string['errorparsingxml'] = 'Errors occurred while parsing the file. Make sure it is valid XML syntax.';
|
||||
$string['evententrycreated'] = 'Entry has been created';
|
||||
$string['evententrydeleted'] = 'Entry has been deleted';
|
||||
$string['evententryupdated'] = 'Entry has been updated';
|
||||
$string['explainaddentry'] = 'Add a new entry to the current glossary.<br />Concept and definition are mandatory fields.';
|
||||
$string['explainall'] = 'Shows ALL entries on one page';
|
||||
$string['explainalphabet'] = 'Browse the glossary using this index';
|
||||
|
||||
Reference in New Issue
Block a user