Commit 89f4e1c5 authored by Robert Lyon's avatar Robert Lyon

Allowing users to see more notification types (Bug #1382899)

Adding a get_special_notifications function to allow for the adding of
special case notification options to non admin user's notifications list

Allowing the 'Objectionable content in forum' notification type to be
seen/set by forum moderators/admins

Change-Id: I69ab8b9de850345868346a85342f48d1f0b0f2aa
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 8ddf3295
<!-- @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later -->
<!-- @copyright For copyright information on Mahara, please see the README file distributed with this software. -->
<h3>Objectionable content in forum topics and posts</h3>
<p>Messages to administrators that contain complaints by users about objectionable forum content. Forum topics and posts can be flagged as containing objectionable content.</p>
\ No newline at end of file
<p>Messages to administrators that contain complaints by users about objectionable forum content. Forum topics and posts can be flagged as containing objectionable content.</p>
<p>Administrators include site admins, group admins, and forum moderators.</p>
\ No newline at end of file
......@@ -1474,6 +1474,7 @@ function get_notification_settings_elements($user = null, $sitedefaults = false)
}
else {
$activitytypes = get_records_array('activity_type', 'admin', 0, 'id');
$activitytypes = get_special_notifications($user, $activitytypes);
}
$notifications = plugins_installed('notification');
......@@ -1570,6 +1571,7 @@ function save_notification_settings($values, $user = null, $sitedefaults = false
}
else {
$activitytypes = get_records_array('activity_type', 'admin', 0);
$activitytypes = get_special_notifications($user, $activitytypes);
}
foreach ($activitytypes as $type) {
......@@ -1588,3 +1590,41 @@ function save_notification_settings($values, $user = null, $sitedefaults = false
}
}
}
/**
* Get special case activity types.
* Currently checks if a non admin is an admin/moderator of a group and
* adds that notification type to the array.
*
* @param object $user whose settings are being displayed
* @param array $activitytypes array of elements
* @return array $activitytypes amended array of elements
*/
function get_special_notifications($user, $activitytypes) {
if (empty($user)) {
return $activitytypes;
}
// Check if the non-admin is a group admin/moderator in any of their groups
if ($user->get('grouproles') !== null) {
$groups = $user->get('grouproles');
$allowreportpost = false;
foreach ($groups as $group => $role) {
if ($role == 'admin') {
$allowreportpost = true;
break;
}
else if ($moderator = get_record_sql("SELECT i.id
FROM {interaction_forum_moderator} m, {interaction_instance} i
WHERE i.id = m.forum AND i.group = ? AND i.deleted = 0 and m.user = ?", array($group, $user->get('id')))) {
$allowreportpost = true;
break;
}
}
if ($allowreportpost) {
// Add the reportpost option to the $activitytypes
$reportpost = get_records_array('activity_type', 'name', 'reportpost', 'id');
$activitytypes = array_merge($activitytypes, $reportpost);
}
}
return $activitytypes;
}
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