Skip to content

Commit

Permalink
MDL-49499 user: Move events triggering to new API function
Browse files Browse the repository at this point in the history
New function in profile/lib: profile_viewed()
  • Loading branch information
jleyva committed Apr 2, 2015
1 parent 1d3fd63 commit d1b2383
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
8 changes: 1 addition & 7 deletions user/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,7 @@
}

// Trigger a user profile viewed event.
$event = \core\event\user_profile_viewed::create(array(
'objectid' => $user->id,
'relateduserid' => $user->id,
'context' => $usercontext
));
$event->add_record_snapshot('user', $user);
$event->trigger();
profile_view($user, $usercontext);

// TODO WORK OUT WHERE THE NAV BAR IS!
echo $OUTPUT->header();
Expand Down
29 changes: 29 additions & 0 deletions user/profile/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,33 @@ function profile_load_custom_fields($user) {
$user->profile = (array)profile_user_record($user->id);
}

/**
* Trigger a user profile viewed event.
*
* @param stdClass $user user object
* @param stdClass $context context object (course or user)
* @param stdClass $course course object
* @since Moodle 2.9
*/
function profile_view($user, $context, $course = null) {

$eventdata = array(
'objectid' => $user->id,
'relateduserid' => $user->id,
'context' => $context
);

if (!empty($course)) {
$eventdata['courseid'] = $course->id;
$eventdata['other'] = array(
'courseid' => $course->id,
'courseshortname' => $course->shortname,
'coursefullname' => $course->fullname
);
}

$event = \core\event\user_profile_viewed::create($eventdata);
$event->add_record_snapshot('user', $user);
$event->trigger();
}

14 changes: 1 addition & 13 deletions user/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,7 @@

// OK, security out the way, now we are showing the user.
// Trigger a user profile viewed event.
$event = \core\event\user_profile_viewed::create(array(
'objectid' => $user->id,
'relateduserid' => $user->id,
'courseid' => $course->id,
'context' => $coursecontext,
'other' => array(
'courseid' => $course->id,
'courseshortname' => $course->shortname,
'coursefullname' => $course->fullname
)
));
$event->add_record_snapshot('user', $user);
$event->trigger();
profile_view($user, $coursecontext, $course);

// Get the hidden field list.
if (has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
Expand Down

0 comments on commit d1b2383

Please sign in to comment.