Commit ec223afd authored by Nigel McNie's avatar Nigel McNie
Browse files

Make views send notifications to the watchlist when they change. Fixes #1753.

A related bug, #1758, has been opened for artefacts sending notifications.

Also changed the activity code for watchlist to look for $data->message rather than $data->subject, which makes the code in there a bit more readable.
parent 6d3ec579
......@@ -65,7 +65,8 @@ $string['stopmonitoring'] = 'Stop monitoring';
$string['stopmonitoringsuccess'] = 'Stopped monitoring successfully';
$string['stopmonitoringfailed'] = 'Failed to stop monitoring';
$string['newwatchlistmessage'] = 'New activity on your watchlist';
$string['newwatchlistmessagesubject'] = 'New activity on your watchlist';
$string['newwatchlistmessageview'] = 'has changed their view "%s"';
$string['newcontactusfrom'] = 'New contact us from';
$string['newcontactus'] = 'New contact us';
......
......@@ -67,8 +67,7 @@ function activity_occurred($activitytype, $data) {
- and $subject and $message (contents of message)
* - <b>feedback (artefact)</b> must contain both $artefact (id) and $view (id) and $message
* - <b>feedback (view)</b> must contain $view (id) and $message
* - <b>watchlist (view) </b> must contain $view (id of view)
- and should also contain $subject (or a boring default will be used)
* - <b>watchlist (view) </b> must contain $view (id of view) as $message
* - <b>viewaccess</b> must contain $owner userid of view owner AND $view (id of view) and $oldusers array of userids before access change was committed.
*/
function handle_activity($activitytype, $data, $cron=false) {
......@@ -217,11 +216,10 @@ function handle_activity($activitytype, $data, $cron=false) {
// and now the harder ones
case 'watchlist':
if (!empty($data->view)) {
if (empty($data->subject)) {
throw new InvalidArgumentException("subject must be provided for watchlist view");
if (empty($data->message)) {
throw new InvalidArgumentException("message must be provided for watchlist view");
}
$oldsubject = isset($data->subject) ? $data->subject : '';
$data->subject = get_string('newwatchlistmessage', 'activity');
$data->subject = get_string('newwatchlistmessagesubject', 'activity');
if (!$viewinfo = get_record_sql('SELECT u.*, v.title FROM {usr} u
JOIN {view} v ON v.owner = u.id
WHERE v.id = ?', array($data->view))) {
......@@ -230,7 +228,6 @@ function handle_activity($activitytype, $data, $cron=false) {
}
throw new InvalidArgumentException("Couldn't find view with id " . $data->view);
}
$data->message = $oldsubject . ' ' . $viewinfo->title;
$sql = 'SELECT u.*, p.method, ' . $casturl . ' AS url
FROM {usr_watchlist_view} wv
JOIN {usr} u
......
......@@ -595,6 +595,14 @@ class View {
try {
$values['returndata'] = defined('JSON');
$returndata = $this->$action($values);
// Tell the watchlist that the view changed
$data = (object)array(
'view' => $this->get('id'),
'message' => get_string('newwatchlistmessageview', 'activity', $this->get('title')),
);
activity_occurred('watchlist', $data);
if (!defined('JSON')) {
$message = $this->get_viewcontrol_ok_string($action);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment