Commit 81a57af3 authored by Lisa Seeto's avatar Lisa Seeto Committed by Robert Lyon

Bug 922911: "Collections" email notification

- updated display rules to use the new subject and message body
for collection notifications
- only add record to activity_queue if a record does not exist

behatnotneeded

Change-Id: I0b8bcb9bd75c5c01af20c432614ac4491cc07a5d
Signed-off-by: default avatarLisa Seeto <lisaseeto@catalyst.net.nz>
parent 1e29ccee
......@@ -75,20 +75,18 @@ $string['newviewmessage'] = '%s has created a new page "%s"';
$string['newcontactusfrom'] = 'New contact us from';
$string['newcontactus'] = 'New contact us';
$string['newcollectionaccessmessage'] = 'You have been added to the access list for the collection "%s" by %s';
$string['newcollectionaccessmessageviews'] = 'You have been added to the access list for the pages "%s" in collection "%3$s" by %2$s';
$string['newviewaccessmessage'] = 'You have been added to the access list for the page "%s" by %s';
$string['newviewaccessmessageviews'] = 'You have been added to the access list for the pages "%s" by %s';
$string['newcollectionaccessmessagenoowner'] = 'You have been added to the access list for the collection "%s"';
$string['newcollectionaccessmessagenoownerviews'] = 'You have been added to the access list for the pages "%s" in collection "%s"';
$string['newviewaccessmessagenoowner'] = 'You have been added to the access list for the page "%s"';
$string['newviewaccessmessagenoownerviews'] = 'You have been added to the access list for the pages "%s"';
$string['newcollectionaccesssubject'] = 'New access to collection "%s"';
$string['newviewaccesssubject1'] = 'New access to page "%s"';
$string['newviewaccesssubjectviews'] = 'New access to pages "%s"';
$string['messageaccessfromto1'] = 'You can view this page between %s and %s.';
$string['messageaccessfrom1'] = 'You can view this page after %s.';
$string['messageaccessto1'] = 'You can view this page until %s.';
$string['newaccesssubject'] = array(
0 => 'You have been given access to %s portfolio',
1 => 'You have been given access to %s portfolios'
);
$string['newaccesssubjectname'] = array(
0 => 'You have been given access to %s portfolio by %s',
1 => 'You have been given access to %s portfolios by %s'
);
$string['newaccessubjectdefault'] = 'You have been given new access';
$string['messageaccessfromto1'] = 'You have access between %s and %s.';
$string['messageaccessfrom1'] = 'You will have access after %s.';
$string['messageaccessto1'] = 'You have access until %s.';
$string['viewmodified'] = 'has changed their page';
$string['ongroup'] = 'on group';
......
......@@ -38,7 +38,9 @@ function activity_occurred($activitytype, $data, $plugintype=null, $pluginname=n
$delayed->type = $at->id;
$delayed->data = serialize($data);
$delayed->ctime = db_format_timestamp(time());
insert_record('activity_queue', $delayed);
if (!record_exists('activity_queue', 'type', $delayed->type, 'data', $delayed->data)) {
insert_record('activity_queue', $delayed);
}
}
else {
handle_activity($at, $data);
......@@ -1392,7 +1394,6 @@ class ActivityTypeViewAccess extends ActivityType {
private $title, $ownername;
private $incollection = false;
/**
* @param array $data Parameters:
* - view (int)
......@@ -1406,43 +1407,39 @@ class ActivityTypeViewAccess extends ActivityType {
}
throw new ViewNotFoundException(get_string('viewnotfound', 'error', $this->view));
}
$this->url = $viewinfo->get_url(false);
$this->url = 'view/sharedviews.php';
$this->users = array_diff_key(
activity_get_viewaccess_users($this->view),
$this->oldusers
);
if ($viewinfo->get_collection()) {
$this->incollection = true;
$this->title = $viewinfo->get_collection()->get('name');
$this->add_urltext(array('key' => 'Collection', 'section' => 'collection'));
}
else {
if (!$viewinfo->get_collection()) {
$this->title = $viewinfo->get('title');
$this->add_urltext(array('key' => 'View', 'section' => 'view'));
}
$this->ownername = $viewinfo->formatted_owner();
$this->overridemessagecontents = true;
}
public function get_view_titles() {
$views = (!empty($this->views) && is_array($this->views) && sizeof($this->views) > 1) ? $this->views : false;
if (!$views) {
return false;
}
$titles = array();
foreach ($views as $view) {
$titles[$view['id']] = $view['title'];
}
return $titles;
}
public function get_subject($user) {
if ($titles = $this->get_view_titles()) {
// because we may be updating access rules on pages both in and not in a collection
// it is easiest just to return a list of the pages we have updated
return get_string('newviewaccesssubjectviews', 'activity', implode('", "', $titles));
$subject = get_string('newaccessubjectdefault', 'activity');
if ($titles = $this->get_view_titles_urls()) {
//covers collection(s), page(s) and combination of both
if ($this->ownername) {
$subject = get_string('newaccesssubjectname', 'activity', count($titles), $this->ownername);
}
else {
$subject = get_string('newaccesssubject', 'activity', count($titles));
}
}
else {
return $this->incollection ? get_string('newcollectionaccesssubject', 'activity', $this->title) : get_string('newviewaccesssubject1', 'activity', $this->title);
//dealing with a single page
if ($this->ownername) {
$subject = get_string('newaccesssubjectname', 'activity', 1, $this->ownername);
}
else {
$subject = get_string('newaccesssubject', 'activity', 1);
}
}
return $subject;
}
public function get_view_access_message($user) {
......@@ -1465,29 +1462,69 @@ class ActivityTypeViewAccess extends ActivityType {
return $accessdatemessage;
}
public function get_message($user) {
$title = $this->title;
$plural = '';
if ($titles = $this->get_view_titles()) {
$title = implode('", "', $titles);
$plural = 'views';
public function get_view_titles_urls() {
$items = array();
if (!empty($this->views)) {
//handle collection(s), page(s) and combination of both
$views = $this->views;
foreach ($views as $view) {
if ($view['collection_id']) {
//collections
$items[$view['collection_id']] = [
'name' => $view['collection_name'],
'url' => $view['collection_url'],
];
}
else {
//pages outside of collections
$items[$view['id']] = [
'name' => $view['title'],
'url' => get_config('wwwroot') . 'view/view.php?id=' . $view['id'],
];
}
}
return $items;
}
$accessdatemessage = ($this->view && $user->id) ? $this->get_view_access_message($user) : null;
return false;
}
$newaccessmessagestr = $this->incollection ? 'newcollectionaccessmessage' . $plural : 'newviewaccessmessage' . $plural;
if ($this->ownername) {
$message = get_string_from_language($user->lang, $newaccessmessagestr, 'activity',
$title, $this->ownername, $this->title);
public function _getmessage($user) {
$accessitems = array();
if ($items = $this->get_view_titles_urls()) {
$accessitems = $items;
}
else {
$newaccessmessagenoownerstr = $this->incollection ? 'newcollectionaccessmessagenoowner' : 'newviewaccessmessagenoowner' . $plural;
$message = get_string_from_language($user->lang, $newaccessmessagenoownerstr, 'activity', $title, $this->title);
//we are dealing with a single page
$accessitems[$this->view] = [
'name' => $this->title,
'url' => get_config('wwwroot') . 'view/view.php?id=' . $this->view,
];
}
$accessdatemessage = ($this->view && $user->id) ? $this->get_view_access_message($user) : null;
$prefurl = get_config('wwwroot') . 'account/activity/preferences/index.php';
$sitename = get_config('sitename');
if ($accessdatemessage) {
$message .= "\n\n" . $accessdatemessage;
}
return $message;
$smarty = smarty_core();
$smarty->assign('accessitems', $accessitems);
$smarty->assign('accessdatemsg', $accessdatemessage . "\n");
$smarty->assign('url', get_config('wwwroot') . $this->url);
$smarty->assign('sitename', $sitename);
$smarty->assign('prefurl', $prefurl);
$messagebody = $smarty->fetch('account/activity/access.tpl');
return $messagebody;
}
public function get_message($user) {
return strip_tags($this->_getmessage($user));
}
public function get_emailmessage($user) {
return strip_tags($this->_getmessage($user));
}
public function get_htmlmessage($user) {
return $this->_getmessage($user);
}
public function get_required_parameters() {
......
......@@ -1409,10 +1409,26 @@ class View {
$view = new View($viewid);
$views[] = array('id' => $view->get('id'),
'title' => $view->get('title'),
);
'collection_id' => $view->get_collection() ? $view->get_collection()->get('id') : null,
'collection_name' => $view->get_collection() ? $view->get_collection()->get('name') : null,
'collection_url' => $view->get_collection() ? $view->get_collection()->get_url() : null,
);
}
$data->views = $views;
}
else if (!empty($viewids) && sizeof($viewids) == 1) {
// dealing with a one page collection
$view = new View($viewids[0]);
if ($view->get_collection()) {
$views [] = array('id' => $view->get('id'),
'title' => $view->get('title'),
'collection_id' => $view->get_collection() ? $view->get_collection()->get('id') : null,
'collection_name' => $view->get_collection() ? $view->get_collection()->get('name') : null,
'collection_url' => $view->get_collection() ? $view->get_collection()->get_url() : null,
);
$data->views = $views;
}
}
activity_occurred('viewaccess', $data);
......
......@@ -210,6 +210,7 @@ function activitylistin_html($type='all', $limit=10, $offset=0) {
$section = empty($record->plugintype) ? 'activity' : "{$record->plugintype}.{$record->pluginname}";
$record->strtype = get_string('type' . $record->type, $section);
$record->message = format_notification_whitespace($record->message);
$record->message = clean_html($record->message);
// used to identify notification as internal for json-calls
$record->table = 'notification_internal_activity';
$record->url = preg_replace('|^' . get_config('wwwroot') . '|', '', $record->url); // Remove the wwwroot form url as it will ba added again in template
......@@ -278,6 +279,7 @@ function activitylistin_html($type='all', $limit=10, $offset=0) {
$record->fromusr = 0;
}
$record->message = format_notification_whitespace($record->message);
$record->message = clean_html($record->message);
// used to identify notification as from this plugin for json-calls
$record->table = 'module_multirecipient_notification';
$records[] = $record;
......
......@@ -28,7 +28,7 @@
{/if}
<div class="collapse" id="message_content_{$i->type}_{$i->id}">
{if $i->message}
<p class="content-text">{$i->message|safe}</p>
<p class="content-text">{$i->message|clean_html|safe}</p>
{if $i->url}
<a href="{$WWWROOT}{$i->url}" class="text-small">
{if $i->urltext}{$i->urltext}{else}{str tag="more..."}{/if} <span class="icon icon-arrow-right mls icon-sm" role="presentation" aria-hidden="true"></span>
......
<p>{str tag=emailheader section=notification.email arg1=$sitename}</p>
------------------------------------------------------------------------
<p>You have been given access to the following:</p>
<ul class="list-unstyled">
{foreach from=$accessitems item=item}
<li style='padding: 0.5em'>{$item.name|clean_html|safe} <a href={$item.url}>{$item.url}</a></li>
{/foreach}
</ul>
{strip}
{if accessdatemsg}
<p>{$accessdatemsg}</p>
{/if}
{/strip}
<p>{str (tag=referurl section=notification.email arg1=$url)|clean_html|safe}</p>
------------------------------------------------------------------------
<p>{str tag=emailfooter section=notification.email arg1=$sitename, arg2=$prefurl|clean_html|safe}</p>
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