Commit 3b0382ef authored by Robert Lyon's avatar Robert Lyon
Browse files

Allowing feedback notifications on group pages (Bug #1307247)



In this patch:
- Changed the Group Edit 'General' section and added the 'Feedback
notifications' options.
- Changed the Group Edit 'General' section and altered the 'Shared
page' option from tickbox to select options.
- Changed the CommentFeedback to be able to notify multiple users in a
group
- Changed the CommentFeedback to be able to send message in the
institution lang if needed.
- Adjusted group_get_editroles_options() to allow it to return a non
associative array
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>

Change-Id: Ia2e995c51aa08610945788e55c809b3c650dcd17
parent a789090c
......@@ -1252,6 +1252,7 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
$artefactinstance = artefact_instance_from_id($onartefact);
if ($artefactinstance->feedback_notify_owner()) {
$userid = $artefactinstance->get('owner');
$groupid = $artefactinstance->get('group');
}
if (empty($this->url)) {
$this->url = 'artefact/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
......@@ -1263,24 +1264,43 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
throw new ViewNotFoundException(get_string('viewnotfound', 'error', $onview));
}
$userid = $viewrecord->owner;
$groupid = $viewrecord->group;
if (empty($this->url)) {
$this->url = 'view/view.php?id=' . $onview;
}
}
if (empty($userid)) {
if (!empty($userid)) {
$this->users = activity_get_users($this->get_id(), array($userid));
}
else if (!empty($groupid)) {
require_once(get_config('docroot') . 'lib/group.php');
$this->users = get_records_sql_array("SELECT u.* from {usr} u, {group_member} m, {group} g
WHERE g.id = m.group AND m.member = u.id AND m.group = ?
AND (g.feedbacknotify = " . GROUP_ROLES_ALL . "
OR (g.feedbacknotify = " . GROUP_ROLES_NONMEMBER . " AND (m.role = 'tutor' OR m.role = 'admin'))
OR (g.feedbacknotify = " . GROUP_ROLES_ADMIN . " AND m.role = 'admin')
)", array($groupid));
}
if (empty($userid) && empty($groupid)) {
return;
}
if (empty($this->users)) {
// no one to notify - possibe if group 'feedbacknotify' is set to 0
return;
}
$this->users = activity_get_users($this->get_id(), array($userid));
$title = $onartefact ? $artefactinstance->get('title') : $viewrecord->title;
$this->urltext = $title;
$body = $comment->get('description');
$posttime = strftime(get_string('strftimedaydatetime'), $comment->get('ctime'));
$user = $this->users[0];
$lang = (empty($user->lang) || $user->lang == 'default') ? get_config('lang') : $user->lang;
// Internal
$this->message = strip_tags(str_shorten_html($body, 200, true));
// Seen as things like emaildigest base the message on $this->message
// we need to set the language for the $removedbyline here based on first user.
$user = $this->users[0];
$lang = (empty($user->lang) || $user->lang == 'default') ? get_config('lang') : $user->lang;
// Comment deleted notification
if ($deletedby = $comment->get('deletedby')) {
......@@ -1295,15 +1315,26 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
$removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.comment');
$this->message = $removedbyline . ":\n" . $this->message;
// Email
$this->users[0]->htmlmessage = get_string_from_language(
$lang, 'feedbackdeletedhtml', 'artefact.comment',
hsc($title), $removedbyline, clean_html($body), get_config('wwwroot') . $this->url, hsc($title)
);
$this->users[0]->emailmessage = get_string_from_language(
$lang, 'feedbackdeletedtext', 'artefact.comment',
$title, $removedbyline, trim(html2text($body)), $title, get_config('wwwroot') . $this->url
);
foreach ($this->users as $key => $user) {
if (empty($user->lang) || $user->lang == 'default') {
// check to see if we need to show institution language
$instlang = get_user_institution_language($user->id);
$lang = (empty($instlang) || $instlang == 'default') ? get_config('lang') : $instlang;
}
else {
$lang = $user->lang;
}
// For email we can send the message in the user's preferred language
$removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.comment');
$this->users[$key]->htmlmessage = get_string_from_language(
$lang, 'feedbackdeletedhtml', 'artefact.comment',
hsc($title), $removedbyline, clean_html($body), get_config('wwwroot') . $this->url, hsc($title)
);
$this->users[$key]->emailmessage = get_string_from_language(
$lang, 'feedbackdeletedtext', 'artefact.comment',
$title, $removedbyline, trim(html2text($body)), $title, get_config('wwwroot') . $this->url
);
}
return;
}
......@@ -1319,16 +1350,25 @@ class ActivityTypeArtefactCommentFeedback extends ActivityTypePlugin {
// Email
$author = $comment->get('author');
$authorname = empty($author) ? $comment->get('authorname') : display_name($author, $user);
$this->users[0]->htmlmessage = get_string_from_language(
$lang, 'feedbacknotificationhtml', 'artefact.comment',
hsc($authorname), hsc($title), $posttime, clean_html($body), get_config('wwwroot') . $this->url
);
$this->users[0]->emailmessage = get_string_from_language(
$lang, 'feedbacknotificationtext', 'artefact.comment',
$authorname, $title, $posttime, trim(html2text($body)), get_config('wwwroot') . $this->url
);
foreach ($this->users as $key => $user) {
$authorname = empty($author) ? $comment->get('authorname') : display_name($author, $user);
if (empty($user->lang) || $user->lang == 'default') {
// check to see if we need to show institution language
$instlang = get_user_institution_language($user->id);
$lang = (empty($instlang) || $instlang == 'default') ? get_config('lang') : $instlang;
}
else {
$lang = $user->lang;
}
$this->users[$key]->htmlmessage = get_string_from_language(
$lang, 'feedbacknotificationhtml', 'artefact.comment',
hsc($authorname), hsc($title), $posttime, clean_html($body), get_config('wwwroot') . $this->url
);
$this->users[$key]->emailmessage = get_string_from_language(
$lang, 'feedbacknotificationtext', 'artefact.comment',
$authorname, $title, $posttime, trim(html2text($body)), get_config('wwwroot') . $this->url
);
}
}
public function get_plugintype(){
......
......@@ -54,7 +54,7 @@ else {
'category' => 0,
'public' => 0,
'usersautoadded' => 0,
'viewnotify' => 1,
'viewnotify' => GROUP_ROLES_ALL,
'submittableto' => 0,
'editroles' => 'all',
'hidden' => 0,
......@@ -66,7 +66,8 @@ else {
'urlid' => null,
'editwindowstart' => null,
'editwindowend' => null,
'sendnow' => 0
'sendnow' => 0,
'feedbacknotify' => GROUP_ROLES_ALL,
);
}
......@@ -366,12 +367,21 @@ $elements['usersautoadded'] = array(
'defaultvalue' => $group_data->usersautoadded,
'help' => true,
'ignore' => !$USER->get('admin'));
$notifyroles = array(get_string('none', 'admin')) + group_get_editroles_options(true);
$elements['viewnotify'] = array(
'type' => 'checkbox',
'type' => 'select',
'title' => get_string('viewnotify', 'group'),
'description' => get_string('viewnotifydescription1', 'group'),
'options' => $notifyroles,
'description' => get_string('viewnotifydescription2', 'group'),
'defaultvalue' => $group_data->viewnotify
);
$elements['feedbacknotify'] = array(
'type' => 'select',
'title' => get_string('feedbacknotify', 'group'),
'options' => $notifyroles,
'description' => get_string('feedbacknotifydescription', 'group'),
'defaultvalue' => $group_data->feedbacknotify
);
if ($cancreatecontrolled) {
$elements['sendnow'] = array(
'type' => 'checkbox',
......@@ -468,7 +478,8 @@ function editgroup_submit(Pieform $form, $values) {
'suggestfriends' => intval($values['suggestfriends']),
'editwindowstart' => db_format_timestamp($values['editwindowstart']),
'editwindowend' => db_format_timestamp($values['editwindowend']),
'sendnow' => intval($values['sendnow'])
'sendnow' => intval($values['sendnow']),
'feedbacknotify' => intval($values['feedbacknotify']),
);
if (
......
......@@ -91,7 +91,9 @@ $string['hasbeeninvitedtojoin'] = 'has been invited to join this group';
$string['groupinvitesfrom'] = 'Invited to join:';
$string['requestedmembershipin'] = 'Requested membership in:';
$string['viewnotify'] = 'Shared page notifications';
$string['viewnotifydescription1'] = 'If checked, a notification will be sent to every group member whenever a new group page is created, and whenever a group member shares one of their pages with the group (the group member sharing the page will not receive this notification). Enabling this setting in very large groups can produce a lot of notifications.';
$string['viewnotifydescription2'] = 'Select which group members should receive a notification whenever a new group page is created, and whenever a group member shares one of their pages with the group (the group member sharing the page will not receive this notification). For very large groups it would be best to limit to non ordinary members as it can produce a lot of notifications.';
$string['feedbacknotify'] = 'Feedback notifications';
$string['feedbacknotifydescription'] = 'Select which group members should receive a notification when feedback is submitted to a group page.';
$string['allowsendnow'] = 'Send forum posts immediately';
$string['allowsendnowdescription'] = 'If checked, any group member will be able to choose to send forum posts immediately. If unchecked, only group administrators, tutors and moderators can do so.';
$string['hiddengroup'] = 'Hide group';
......
......@@ -452,6 +452,7 @@ function watchlist_process_notifications() {
}
function activity_get_viewaccess_users($view) {
require_once(get_config('docroot') . 'lib/group.php');
$sql = "SELECT userlist.userid, usr.*, actpref.method, accpref.value AS lang
FROM (
SELECT friend.usr1 AS userid
......@@ -470,9 +471,13 @@ function activity_get_viewaccess_users($view) {
UNION
SELECT members.member AS userid
FROM {view_access} access
JOIN {group} grp ON (access.group = grp.id AND grp.deleted = 0 AND grp.viewnotify = 1 AND access.view = ?)
JOIN {group_member} members ON (grp.id = members.group AND members.member <> access.usr)
WHERE (access.role IS NULL OR access.role = members.role)
JOIN {group} grp ON (access.group = grp.id AND grp.deleted = 0 AND access.view = ?)
JOIN {group_member} members ON (grp.id = members.group AND members.member <> CASE WHEN access.usr IS NULL THEN -1 ELSE access.usr END)
WHERE (access.role IS NULL OR access.role = members.role) AND
(grp.viewnotify = " . GROUP_ROLES_ALL . "
OR (grp.viewnotify = " . GROUP_ROLES_NONMEMBER . " AND (members.role = 'admin' OR members.role = 'tutor'))
OR (grp.viewnotify = " . GROUP_ROLES_ADMIN . " AND members.role = 'admin')
)
) AS userlist
JOIN {usr} usr ON usr.id = userlist.userid
LEFT JOIN {usr_activity_preference} actpref ON actpref.usr = usr.id
......@@ -701,14 +706,19 @@ abstract class ActivityType {
}
if (empty($user->method)) {
// If method is not set then either the user has selected 'none' or their setting has not been set (so use default).
if (record_exists('usr_activity_preference', 'usr', $user->id, 'activity', $this->get_id())) {
// The user specified 'none' as their notification type.
return;
if ($record = get_record('usr_activity_preference', 'usr', $user->id, 'activity', $this->get_id())) {
$user->method = $record->method;
if (empty($user->method)) {
// The user specified 'none' as their notification type.
return;
}
}
$user->method = $this->get_default_method();
if (empty($user->method)) {
// The default notification type is 'none' for this activity type.
return;
else {
$user->method = $this->get_default_method();
if (empty($user->method)) {
// The default notification type is 'none' for this activity type.
return;
}
}
}
......
......@@ -399,6 +399,7 @@
<FIELD NAME="editwindowstart" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="editwindowend" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="sendnow" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="feedbacknotify" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="1" />
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" />
......
......@@ -3433,5 +3433,16 @@ function xmldb_core_upgrade($oldversion=0) {
ensure_record_exists('cron', (object)$data, (object)$data);
}
// Add feedbacknotify option to group table
if ($oldversion < 2014062500) {
require_once(get_config('libroot') . 'group.php');
$table = new XMLDBTable('group');
$field = new XMLDBField('feedbacknotify');
$field->setAttributes(XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, null, null, GROUP_ROLES_ALL);
if (!field_exists($table, $field)) {
add_field($table, $field);
}
}
return $status;
}
......@@ -11,6 +11,11 @@
defined('INTERNAL') || die();
// Constants for the different group roles
define('GROUP_ROLES_ALL', 1);
define('GROUP_ROLES_NONMEMBER', 2);
define('GROUP_ROLES_ADMIN', 3);
// Role related functions
/**
......@@ -439,6 +444,8 @@ function group_create($data) {
'editwindowstart' => $data['editwindowstart'],
'editwindowend' => $data['editwindowend'],
'sendnow' => isset($data['sendnow']) ? $data['sendnow'] : null,
'viewnotify' => isset($data['viewnotify']) ? $data['viewnotify'] : null,
'feedbacknotify' => isset($data['feedbacknotify']) ? $data['feedbacknotify'] : null,
),
'id',
true
......@@ -1684,12 +1691,20 @@ function group_get_grouptype_options($currentgrouptype=null) {
return $groupoptions;
}
function group_get_editroles_options() {
return array(
function group_get_editroles_options($intkeys = false) {
if ($intkeys) {
return array(GROUP_ROLES_ALL => get_string('allgroupmembers', 'group'),
GROUP_ROLES_NONMEMBER => get_string('allexceptmember', 'group'),
GROUP_ROLES_ADMIN => get_string('groupadmins', 'group'),
);
}
$options = array(
'all' => get_string('allgroupmembers', 'group'),
'notmember' => get_string('allexceptmember', 'group'),
'admin' => get_string('groupadmins', 'group'),
);
return $options;
}
function group_can_list_members($group, $role) {
......
......@@ -16,7 +16,7 @@ $config = new stdClass();
// See https://wiki.mahara.org/index.php/Developer_Area/Version_Numbering_Policy
// For upgrades on stable branches, increment the version by one. On master, use the date.
$config->version = 2014062000;
$config->version = 2014062500;
$config->release = '1.10.0dev';
$config->minupgradefrom = 2009022600;
$config->minupgraderelease = '1.1.0 (release tag 1.1.0_RELEASE)';
......
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