Commit c8e10e46 authored by Penny Leach's avatar Penny Leach
Browse files

lots of work on notification - all the subject message munging is

done now
parent 313b25ea
......@@ -66,4 +66,20 @@ $string['stopmonitoringfailed'] = 'Failed to stop monitoring';
$string['newwatchlistmessage'] = 'New activity on your watchlist';
$string['newviewmessage'] = 'New view you have access to';
$string['newcontactusfrom'] = 'New contact us from';
$string['newcontactus'] = 'New contact us';
$string['newfeedbackonview'] = 'New feedback on view';
$string['newfeedbackonartefact'] = 'New feedback on artefact';
$string['watchlistmessageview'] = 'Activity on watchlist (view)';
$string['watchlistmessageartefact'] = 'Activity on watchlist (artefact)';
$string['watchlistmessagecommunity'] = 'Activity on watchlist (community)';
$string['newviewmessage'] = 'New view called';
$string['newviewsubject'] = 'New view';
$string['onview'] = 'on view';
$string['onartefact'] = 'on artefact';
$string['oncommunity'] = 'on community';
$string['ownedby'] = 'owned by';
?>
......@@ -60,12 +60,13 @@ function activity_occurred($activitytype, $data) {
* @param mixed $data must contain message to save.
* it can also contain url.
* each activity type has different requirements of $data -
* <b>contactus</b> must contain $message, $subject, $fromname, $fromaddress, $userfrom (if a logged in user)
* <b>contactus</b> must contain $message, $subject (optional), $fromname, $fromaddress, $userfrom (if a logged in user)
* <b>objectionable</b> must contain $message,
* <b>maharamessage</b> must contain $users, an array of userids. $subject and $message (contents of message)
* <b>usermessage</b> must contain $userto, id of recipient user, $userfrom, id of user from
and $subject and $message (contents of message)
* <b>feedback (artefact)</b> must contain both $artefact (id) and $view (id) and $message and $subject
* <b>feedback (view)</b> must contain $view (id) and $message and $subject
* <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 (artefact)</b> must contain $artefact (id of artefact)
* and should also contain $subject (or a boring default will be used)
* <b>watchlist (view) </b> must contain $view (id of view)
......@@ -81,6 +82,7 @@ function handle_activity($activitytype, $data) {
$activitytype = get_record('activity_type', 'name', $activitytype);
}
if (!is_object($activitytype)) {
throw new InvalidArgumentException("Invalid activitytype $activitytype");
}
......@@ -96,7 +98,7 @@ function handle_activity($activitytype, $data) {
if (empty($data->message)) {
throw new InvalidArgumentException("Message was empty for activity type contactus");
}
$data->subject = get_string('newcontactusfrom', 'activity') . $data->fromname
$data->subject = get_string('newcontactusfrom', 'activity') . ' ' .$data->fromname
. '<' . $data->fromemail .'>' . (isset($data->subject) ? ': ' . $data->subject : '');
$data->message = $data->subject . "\n\n" . $data->message;
$data->subject = get_string('newcontactus', 'activity');
......@@ -144,9 +146,6 @@ function handle_activity($activitytype, $data) {
}
break;
case 'feedback':
if (empty($data->subject)) {
throw new InvalidArgumentException("Feedback activity type expects a subject");
}
if (empty($data->message)) {
throw new InvalidArgumentException("Feedbackactivity type expects a message");
}
......@@ -154,7 +153,10 @@ function handle_activity($activitytype, $data) {
throw new IllegalArgumentException("Feedback missing view id");
}
if (!empty($data->artefact)) { // feedback on artefact
$userid = get_field('artefact', 'owner', 'id', $data->artefact);
$data->subject = get_string('newfeedbackonartefact', 'activity');
$artefact = get_record('artefact', 'id', $data->artefact);
$userid = $artefact->owner;
$data->subject .= $artefact->title;
if (empty($data->url)) {
// @todo this might change later
$data->url = get_config('wwwroot') . 'view/artefact.php?id='
......@@ -162,7 +164,10 @@ function handle_activity($activitytype, $data) {
}
}
else { // feedback on view.
$userid = get_field('view', 'owner', 'id', $data->view);
$data->subject = get_string('newfeedbackonview', 'activity');
$view = get_record('view', 'id', $data->view);
$userid = $view->owner;
$data->subject .= $view->title;
if (empty($data->url)) {
// @todo this might change later
$data->url = get_config('wwwroot') . 'view/view.php?id=' . $data->view;
......@@ -173,69 +178,82 @@ function handle_activity($activitytype, $data) {
// and now the harder ones
case 'watchlist':
if (!empty($data->view)) {
$oldsubject = isset($data->subject) ? ': ' . $data->subject : '';
if (empty($data->subject)) {
throw new InvalidArgumentException("subject must be provided for watchlist view");
}
$oldsubject = isset($data->subject) ? $data->subject : '';
$data->subject = get_string('watchlistmessageview', 'activity');
$viewinfo = get_record_sql('SELECT u.*, v.title FROM ' . $prefix . 'mh_user u
$viewinfo = get_record_sql('SELECT u.*, v.title FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
WHERE v.id = ?', array($data->view));
$data->message = $oldsubject . get_string('onview', 'activity')
. $viewinfo->title . get_string('ownedby', 'activity');
$data->message = $oldsubject . ' ' . get_string('onview', 'activity')
. ' ' . $viewinfo->title . ' ' . get_string('ownedby', 'activity');
$sql = 'SELECT u.*, p.method, CAST(? AS TEXT) AS url
FROM ' . $prefix . 'usr_watchlist_view wv
JOIN ' . $prefix . 'usr u
ON wv.usr = u.id
JOIN ' . $prefix . 'usr_activity_preference p
LEFT JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE p.activity = ?
WHERE (p.activity = ? OR p.activity IS NULL)
AND wv.view = ?
';
$users = get_records_sql_array($sql,
array(get_config('wwwroot') . 'view/view.php?id='
. $data->view, 'watchlist', $data->view));
if (empty($users)) {
$users = array();
}
// ick
foreach ($users as $user) {
$user->message = $data->message . display_name($viewinfo, $user);
$user->message = $data->message . ' ' . display_name($viewinfo, $user);
}
}
else if (!empty($data->artefact)) {
$data->subject = get_string('watchlistmessageartefact', 'activity');
$ainfo = get_record_sql('SELECT u.*, a.title FROM ' . $prefix . 'mh_user u
$data->subject = get_string('watchlistmessageartefact', 'activity')
. (isset($data->subject) ? ': ' . $data->subject : '');
$ainfo = get_record_sql('SELECT u.*, a.title FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'artefact a ON a.owner = u.id
WHERE a.id = ?', array($data->artefact));
$data->message = get_string('onartefact', 'activity')
. $ainfo->title . get_string('ownedby', 'activity');
. ' ' . $ainfo->title . ' ' . get_string('ownedby', 'activity');
$sql = 'SELECT DISTINCT u.*, p.method, ?||wa.view as url
FROM ' . $prefix . 'usr_watchlist_artefact wa
LEFT JOIN ' . $prefix . 'artefact_parent_cache pc
ON (pc.parent = wa.artefact OR pc.artefact = wa.artefact)
JOIN ' . $prefix . 'usr u
ON wa.usr = u.id
JOIN ' . $prefix . 'usr_activity_preference p
LEFT JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE p.activity = ?
WHERE (p.activity = ? OR p.activity IS NULL)
AND (pc.parent = ? OR wa.artefact = ?)
';
$users = get_records_sql_array($sql,
array(get_config('wwwroot') . 'view/artefact.php?id='
. $data->artefact . '&view=', 'watchlist',
$data->artefact, $data->artefact));
if (empty($users)) {
$users = array();
}
// ick
foreach ($users as $user) {
$user->message = $data->message . display_name($ainfo, $user);
$user->message = $data->message . ' ' . display_name($ainfo, $user);
}
}
else if (!empty($data->community)) {
if (empty($data->subject)) {
throw new InvalidArgumentException("subject must be provided for watchlist community");
}
$oldsubject = $data->subject;
$data->subject = get_string('watchlistmessagecommunity', 'activity');
$data->message = $oldsubject . get_string('oncommunity', 'activity')
$data->message = $oldsubject . ' ' . get_string('oncommunity', 'activity')
. get_field('community', 'name', 'id', $data->community);
$sql = 'SELECT DISTINCT u.*, p.method, CAST(? AS TEXT) AS url
FROM ' . $prefix . 'usr_watchlist_community c
JOIN ' . $prefix . 'usr u
ON c.usr = u.id
JOIN ' . $prefix . 'usr_activity_preference p
LEFT JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE p.activity = ?
WHERE (p.activity = ? OR p.activity IS NULL)
AND c.community = ?
';
$users = get_records_sql_array($sql,
......@@ -250,12 +268,12 @@ function handle_activity($activitytype, $data) {
if (!is_numeric($data->owner) || !is_numeric($data->view)) {
throw new InvalidArgumentException("New view activity type requires view and owner to be set");
}
$viewinfo = get_record_sql('SELECT u.*, v.title FROM ' . $prefix . 'mh_user u
$viewinfo = get_record_sql('SELECT u.*, v.title FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
WHERE v.id = ?', array($data->view));
$data->message = get_string('newview', 'activity')
. $viewinfo->title . get_string('ownedby', 'activity');
$data->subject = get_string('messagenewview', 'activity');
$data->message = get_string('newviewmessage', 'activity')
. ' ' . $viewinfo->title . ' ' . get_string('ownedby', 'activity');
$data->subject = get_string('newviewsubject', 'activity');
// add users on friendslist, userlist or grouplist...
$sql = 'SELECT userid, u.*, p.method
FROM (
......@@ -271,12 +289,15 @@ function handle_activity($activitytype, $data) {
WHERE u.view = ?
) AS userlist
JOIN ' . $prefix . 'usr u ON u.id = userlist.userid
JOIN ' . $prefix . 'usr_activity_preference p ON p.usr = u.id';
LEFT JOIN ' . $prefix . 'usr_activity_preference p ON p.usr = u.id';
$users = get_records_sql_array($sql, array($data->owner, $data->owner, $data->owner,
$data->view, $data->view));
if (empty($users)) {
$users = array();
}
// ick
foreach ($users as $user) {
$user->message = $data->message . display_name($viewinfo, $user);
$user->message = $data->message . ' ' . display_name($viewinfo, $user);
}
break;
case 'contactus':
......@@ -302,6 +323,9 @@ function handle_activity($activitytype, $data) {
if (!empty($user->subject)) {
$userdata->subject = $user->subject;
}
if (empty($user->method)) {
$user->method = 'internal';
}
if ($user->method != 'internal') {
safe_require('notification', $method, 'lib.php', 'require_once');
call_static_method(generate_class_name('notification', $method), 'notify_user', $user, $userdata);
......@@ -327,9 +351,9 @@ function activity_get_users($activitytype, $userids=null, $userobjs=null, $admin
$values = array($activitytype);
$sql = 'SELECT u.*, p.method
FROM ' . get_config('dbprefix') .'usr u
JOIN ' . get_config('dbprefix') . 'usr_activity_preference p
LEFT JOIN ' . get_config('dbprefix') . 'usr_activity_preference p
ON p.usr = u.id
WHERE p.activity = ? ';
WHERE (p.activity = ? ' . (empty($adminonly) ? ' OR p.activity IS NULL' : '') . ')';
if (!empty($adminonly)) {
$sql .= ' AND u.admin = ? ';
$values[] = 1;
......
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