MDL-40053 events: Replace add_to_log() with new events in core_notes
This commit is contained in:
+45
-17
@@ -66,7 +66,7 @@ function note_list($courseid=0, $userid=0, $state = '', $author = 0, $order='las
|
||||
* Retrieves a note object based on its id.
|
||||
*
|
||||
* @param int $note_id id of the note to retrieve
|
||||
* @return note object
|
||||
* @return stdClass object
|
||||
*/
|
||||
function note_load($note_id) {
|
||||
global $DB;
|
||||
@@ -79,13 +79,13 @@ function note_load($note_id) {
|
||||
* Saves a note object. The note object is passed by reference and its fields (i.e. id)
|
||||
* might change during the save.
|
||||
*
|
||||
* @param note $note object to save
|
||||
* @param stdClass $note object to save
|
||||
* @return boolean true if the object was saved; false otherwise
|
||||
*/
|
||||
function note_save(&$note) {
|
||||
global $USER, $DB;
|
||||
|
||||
// setup & clean fields
|
||||
// Setup & clean fields.
|
||||
$note->module = 'notes';
|
||||
$note->lastmodified = time();
|
||||
$note->usermodified = $USER->id;
|
||||
@@ -95,23 +95,40 @@ function note_save(&$note) {
|
||||
if (empty($note->publishstate)) {
|
||||
$note->publishstate = NOTES_STATE_PUBLIC;
|
||||
}
|
||||
// save data
|
||||
// Save data.
|
||||
if (empty($note->id)) {
|
||||
// insert new note
|
||||
// Insert new note.
|
||||
$note->created = $note->lastmodified;
|
||||
$id = $DB->insert_record('post', $note);
|
||||
$note = note_load($id);
|
||||
$logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid));
|
||||
$logurl->set_anchor('note-' . $id);
|
||||
|
||||
add_to_log($note->courseid, 'notes', 'add', $logurl, 'add note');
|
||||
// Trigger event.
|
||||
$event = \core\event\note_created::create(array(
|
||||
'objectid' => $note->id,
|
||||
'courseid' => $note->courseid,
|
||||
'relateduserid' => $note->userid,
|
||||
'userid' => $note->usermodified,
|
||||
'context' => context_course::instance($note->courseid),
|
||||
'other' => array('publishstate' => $note->publishstate)
|
||||
));
|
||||
$event->add_record_snapshot('post', $note);
|
||||
$event->trigger();
|
||||
} else {
|
||||
// update old note
|
||||
// Update old note.
|
||||
$DB->update_record('post', $note);
|
||||
$note = note_load($note->id);
|
||||
$logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid));
|
||||
$logurl->set_anchor('note-' . $note->id);
|
||||
add_to_log($note->courseid, 'notes', 'update', $logurl , 'update note');
|
||||
|
||||
// Trigger event.
|
||||
$event = \core\event\note_updated::create(array(
|
||||
'objectid' => $note->id,
|
||||
'courseid' => $note->courseid,
|
||||
'relateduserid' => $note->userid,
|
||||
'userid' => $note->usermodified,
|
||||
'context' => context_course::instance($note->courseid),
|
||||
'other' => array('publishstate' => $note->publishstate)
|
||||
));
|
||||
$event->add_record_snapshot('post', $note);
|
||||
$event->trigger();
|
||||
}
|
||||
unset($note->module);
|
||||
return true;
|
||||
@@ -127,12 +144,23 @@ function note_delete($note) {
|
||||
global $DB;
|
||||
if (is_int($note)) {
|
||||
$note = note_load($note);
|
||||
debugging('Warning: providing note_delete with a note object would improve performance.',DEBUG_DEVELOPER);
|
||||
debugging('Warning: providing note_delete with a note object would improve performance.', DEBUG_DEVELOPER);
|
||||
}
|
||||
$logurl = new moodle_url('index.php', array('course'=> $note->courseid, 'user'=>$note->userid));
|
||||
$logurl->set_anchor('note-' . $note->id);
|
||||
add_to_log($note->courseid, 'notes', 'delete', $logurl, 'delete note');
|
||||
return $DB->delete_records('post', array('id'=>$note->id, 'module'=>'notes'));
|
||||
$return = $DB->delete_records('post', array('id' => $note->id, 'module' => 'notes'));
|
||||
|
||||
// Trigger event.
|
||||
$event = \core\event\note_deleted::create(array(
|
||||
'objectid' => $note->id,
|
||||
'courseid' => $note->courseid,
|
||||
'relateduserid' => $note->userid,
|
||||
'userid' => $note->usermodified,
|
||||
'context' => context_course::instance($note->courseid),
|
||||
'other' => array('publishstate' => $note->publishstate)
|
||||
));
|
||||
$event->add_record_snapshot('post', $note);
|
||||
$event->trigger();
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user