Skip to content

Commit

Permalink
MDL-45890 Blog: add additional events
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourget committed Sep 25, 2016
1 parent 26162ef commit 02ce2e4
Show file tree
Hide file tree
Showing 12 changed files with 1,115 additions and 328 deletions.
15 changes: 15 additions & 0 deletions blog/external_blog_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@
context_user::instance($newexternal->userid), $data->autotags);
blog_sync_external_entries($newexternal);

// Log this action.
$eventparms = array('context' => $context,
'objectid' => $newexternal->id,
'other' => array('url' => $newexternal->url));
$event = \core\event\blog_external_added::create($eventparms);
$event->trigger();

break;

case 'edit':
Expand All @@ -104,6 +111,14 @@
$external->timemodified = time();

$DB->update_record('blog_external', $external);

// Log this action.
$eventparms = array('context' => $context,
'objectid' => $external->id,
'other' => array('url' => $external->url));
$event = \core\event\blog_external_updated::create($eventparms);
$event->trigger();

core_tag_tag::set_item_tags('core', 'blog_external', $external->id,
context_user::instance($external->userid), $data->autotags);
} else {
Expand Down
13 changes: 11 additions & 2 deletions blog/external_blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
$message = null;

if ($delete && confirm_sesskey()) {
$externalbloguserid = $DB->get_field('blog_external', 'userid', array('id' => $delete));
if ($externalbloguserid == $USER->id) {
$externalblog = $DB->get_record('blog_external', array('id' => $delete));
if ($externalblog->userid == $USER->id) {
// Delete the external blog.
$DB->delete_records('blog_external', array('id' => $delete));

Expand All @@ -55,6 +55,11 @@
'userid' => $USER->id,
'delete' => $delete));

// Log this action.
$eventparms = array('context' => $context, 'objectid' => $delete);
$event = \core\event\blog_external_removed::create($eventparms);
$event->add_record_snapshot('blog_external', $externalblog);
$event->trigger();
$message = get_string('externalblogdeleted', 'blog');
}
}
Expand Down Expand Up @@ -111,4 +116,8 @@
$newexternalurl = new moodle_url('/blog/external_blog_edit.php');
echo html_writer::link($newexternalurl, $straddnewexternalblog);
echo $OUTPUT->box_end();

// Log this page.
$event = \core\event\blog_external_viewed::create(array('context' => $context));
$event->trigger();
echo $OUTPUT->footer();
22 changes: 20 additions & 2 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,29 @@ public function add_association($contextid, $unused = null) {

/**
* remove all associations for a blog entry
* @return voic
*
* @return void
*/
public function remove_associations() {
global $DB;
$DB->delete_records('blog_association', array('blogid' => $this->id));

$associations = $DB->get_records('blog_association', array('blogid' => $this->id));
foreach ($associations as $association) {

// Trigger an association deleted event.
$context = context::instance_by_id($association->contextid);
$eventparam = array(
'objectid' => $this->id,
'other' => array('subject' => $this->subject, 'blogid' => $this->id),
'relateduserid' => $this->userid
);
$event = \core\event\blog_association_deleted::create($eventparam);
$event->add_record_snapshot('blog_association', $association);
$event->trigger();

// Now remove the association.
$DB->delete_records('blog_association', array('id' => $association->id));
}
}

/**
Expand Down
Loading

0 comments on commit 02ce2e4

Please sign in to comment.