Commit 4ae687a0 authored by Robert Lyon's avatar Robert Lyon
Browse files

Allowing all interested parties to get notified of feedback (Bug 1374674)



On personal pages / artefacts

- while ignoring the user that left the feedback from the list of users to email
- but still including the owner of the view/artefact if needed
- but then ignoring owner if the owner is the user leaving feed back

Also when a user adds a public comment to a view/artefact they automatically
become a watcher of the view - to allow them to receive notifications
about future comments left on the artefact/view

Change-Id: I0fc7109c74581266024c52ee40edbaff6dbb99d2
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 7d832726
......@@ -903,6 +903,41 @@ class ArtefactTypeComment extends ArtefactType {
set_config_plugin('artefact', 'comment', $settingname, $values[$settingname]);
}
}
/**
* Fetch all users that are currently watching the view the comment is being added to,
* in case of comment on artefact it will be the view the artefact sits on,
* so we can use this array to email affected parties.
*
* @param int $posterid If set, the poster's id is ignored from resulting array
* @param int $ownerid If set, we make sure the owner is emailed even if they don't have a comment
* @return array $users An array of user objects of the users that have comments on this view/artefact
*/
public function get_comments_users($posterid = null, $ownerid = null) {
$ontype = ($onview = $this->get('onview')) ? 'onview' : 'onartefact';
$values = array();
$sql = "SELECT DISTINCT u.* FROM {usr} u";
if ($ontype == 'onview') {
$sql .= " JOIN {usr_watchlist_view} uwv ON uwv.view = ? AND uwv.usr = u.id";
$values[] = $this->get($ontype);
}
else if ($ontype == 'onartefact') {
$sql .= " JOIN {view_artefact} va ON va.artefact = ?
JOIN {usr_watchlist_view} uwv ON uwv.view = va.view AND uwv.usr = u.id";
$values[] = $this->get($ontype);
}
if ($posterid) {
$sql .= " WHERE u.id != ?";
$values[] = $posterid;
}
if (!empty($ownerid) && $ownerid != $posterid) {
$sql .= " UNION SELECT * FROM {usr} WHERE id = ?";
$values[] = $ownerid;
}
$users = get_records_sql_assoc($sql, $values);
return $users;
}
}
/* To make private comments public, both the author and the owner must agree. */
......@@ -1148,6 +1183,8 @@ function add_feedback_form_submit(Pieform $form, $values) {
$data->institution = $view->get('institution');
}
$owner = $data->owner;
$author = null;
if ($author = $USER->get('id')) {
$anonymous = false;
$data->author = $author;
......@@ -1284,6 +1321,23 @@ function add_feedback_form_submit(Pieform $form, $values) {
'commentid' => $comment->get('id'),
'viewid' => $view->get('id')
);
// We want to add the user placing the comment to the watchlist so they
// can get notified about future comments to the page.
// @TODO Add a site/institution preference to override this.
if (!get_field('usr_watchlist_view', 'ctime', 'usr', $author, 'view', $view->get('id'))) {
insert_record('usr_watchlist_view', (object) array('usr' => $author,
'view' => $view->get('id'),
'ctime' => db_format_timestamp(time())));
}
if (!$private) {
// We want to alert all interested parties that a new public comment was added
if ($users = $comment->get_comments_users($author, $owner)) {
$data->users = $users;
}
}
activity_occurred('feedback', $data, 'artefact', 'comment');
if (isset($moderatemsg)) {
......@@ -1370,7 +1424,13 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
// Now fetch the users that will need to get notified about this event
// depending on whether the page has an owner, group, or institution id set.
if (!empty($userid)) {
$this->users = activity_get_users($this->get_id(), array($userid));
$users = $this->users;
if (empty($users)) {
$this->users = activity_get_users($this->get_id(), array($userid));
}
else {
$this->users = array_values($users);
}
}
else if (!empty($groupid)) {
require_once(get_config('docroot') . 'lib/group.php');
......@@ -1469,7 +1529,7 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
);
$this->users[$key]->emailmessage = get_string_from_language(
$lang, 'feedbacknotificationtext', 'artefact.comment',
$authorname, $title, $posttime, trim(html2text($body)), get_config('wwwroot') . $this->url
$authorname, $title, $posttime, trim(html2text(htmlspecialchars($body))), get_config('wwwroot') . $this->url
);
}
}
......
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