mirror of
https://github.com/moodle/moodle.git
synced 2025-01-17 21:49:15 +01:00
MDL-40053 events: Replace add_to_log() with new events in core_notes
This commit is contained in:
parent
1b486fc501
commit
c4f9401ce4
@ -42,7 +42,7 @@ class note_updated extends \core\event\base {
|
||||
*/
|
||||
protected function init() {
|
||||
$this->data['objecttable'] = 'post';
|
||||
$this->data['crud'] = 'c';
|
||||
$this->data['crud'] = 'u';
|
||||
$this->data['level'] = self::LEVEL_OTHER;
|
||||
}
|
||||
|
||||
|
@ -61,12 +61,6 @@ if ($userid) {
|
||||
|
||||
/// require login to access notes
|
||||
require_login($course);
|
||||
add_to_log($courseid, 'notes', 'view', 'index.php?course='.$courseid.'&user='.$userid, 'view notes');
|
||||
|
||||
if (empty($CFG->enablenotes)) {
|
||||
print_error('notesdisabled', 'notes');
|
||||
}
|
||||
|
||||
/// output HTML
|
||||
if ($course->id == SITEID) {
|
||||
$coursecontext = context_system::instance(); // SYSTEM context
|
||||
@ -75,6 +69,19 @@ if ($course->id == SITEID) {
|
||||
}
|
||||
$systemcontext = context_system::instance(); // SYSTEM context
|
||||
|
||||
// Trigger event.
|
||||
$event = \core\event\notes_viewed::create(array(
|
||||
'courseid' => $courseid,
|
||||
'relateduserid' => $userid,
|
||||
'context' => $coursecontext,
|
||||
'other' => array('content' => 'notes')
|
||||
));
|
||||
$event->trigger();
|
||||
|
||||
if (empty($CFG->enablenotes)) {
|
||||
print_error('notesdisabled', 'notes');
|
||||
}
|
||||
|
||||
$strnotes = get_string('notes', 'notes');
|
||||
if ($userid) {
|
||||
$PAGE->set_context(context_user::instance($user->id));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user