Commit bd3c9f41 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Link from inbox block to inbox with appropriate activitytype filter


Only show the link if there are more notifications to see in the inbox
Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 3e7e5ef0
......@@ -32,5 +32,6 @@ $string['description'] = 'Display a selection of your recent inbox messages';
$string['messagetypes'] = 'Message types to display';
$string['maxitems'] = 'Maximum number of items to display';
$string['maxitemsdescription'] = 'Between 1 and 100';
$string['More'] = 'More';
?>
......@@ -49,50 +49,57 @@ class PluginBlocktypeInbox extends SystemBlocktype {
global $USER;
$configdata = $instance->get('configdata');
$types = get_records_assoc('activity_type', 'admin', 0, '', 'id,name,plugintype,pluginname');
$desiredtypes = array();
foreach($types as $type) {
if (!empty($configdata[$type->name])) {
$desiredtypes[] = $type->id;
foreach($configdata as $k => $v) {
if (!empty($v) && $k != 'maxitems') {
$type = preg_replace('/[^a-z]+/', '', $k);
$desiredtypes[$type] = $type;
}
}
if ($USER->get('admin') && !empty($configdata['adminmessages'])) {
$admintypes = get_records_assoc('activity_type', 'admin', 1, '', 'id,name,plugintype,pluginname');
$types += $admintypes;
foreach($admintypes as $type) {
$desiredtypes[] = $type->id;
}
if ($USER->get('admin') && !empty($desiredtypes['adminmessages'])) {
unset($desiredtypes['adminmessages']);
$desiredtypes += get_column('activity_type', 'name', 'admin', 1);
}
$sql = "
SELECT *
FROM {notification_internal_activity} n
WHERE n.usr = ?
AND n.type IN (" . implode(',', $desiredtypes) . ")
ORDER BY n.ctime DESC
LIMIT ?;";
$maxitems = $configdata['maxitems'] ? $configdata['maxitems'] : 5;
$records = array();
if ($desiredtypes) {
$sql = "
SELECT n.*, t.name
FROM {notification_internal_activity} n JOIN {activity_type} t ON n.type = t.id
WHERE n.usr = ?
AND t.name IN (" . join(',', array_map('db_quote', $desiredtypes)) . ")
ORDER BY n.ctime DESC
LIMIT ?;";
$records = get_records_sql_array($sql, array(
$USER->get('id'),
$configdata['maxitems'] ? $configdata['maxitems'] : 5,
$maxitems + 1 // Hack to decide whether to show the More... link
));
}
// Hack to decide whether to show the More... link
if ($showmore = count($records) > $maxitems) {
unset($records[$maxitems]);
}
$items = array();
if ($records) {
foreach($records as $record) {
$items[] = array(
'subject' => $record->subject,
'url' => $record->url,
'type' => $types[$record->type]->name,
'type' => $record->name,
);
}
}
$smarty = smarty_core();
if ($showmore) {
$smarty->assign('desiredtypes', implode(',', $desiredtypes));
}
$smarty->assign('items', $items);
return $smarty->fetch('blocktype:inbox:inbox.tpl');
}
......
......@@ -12,4 +12,6 @@
</tr>
{/foreach}
</table>
<a href="{$WWWROOT}account/activity" target="_blank">{str tag=gotoinbox section=mahara} &raquo;</a>
{if $desiredtypes}
<a href="{$WWWROOT}account/activity?type={$desiredtypes|escape}">{str tag=More section=blocktype.inbox} &raquo;</a>
{/if}
\ No newline at end of file
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