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

Select activity types by name & allow multiple types to be selected


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 94f6d74b
...@@ -85,7 +85,7 @@ else if ($delete) { ...@@ -85,7 +85,7 @@ else if ($delete) {
// normal processing // normal processing
$type = param_alphanum('type', 'all'); $type = param_variable('type', 'all');
$limit = param_integer('limit', 10); $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
...@@ -107,12 +107,18 @@ if ($type == 'all') { ...@@ -107,12 +107,18 @@ if ($type == 'all') {
$records = get_records_sql_array($sql, array($userid, 1), $offset, $limit); $records = get_records_sql_array($sql, array($userid, 1), $offset, $limit);
} }
else { else {
$count = count_records_select('notification_internal_activity', 'usr = ? AND type = ?', $types = split(',', preg_replace('/[^a-z,]+/', '', $type));
array($userid,$type)); if ($types) {
$sql = 'SELECT a.*, at.name AS type,at.plugintype, at.pluginname FROM {notification_internal_activity} a $typesql = ' AND at.name IN (' . join(',', array_map('db_quote', $types)) . ')';
}
$from = "
FROM {notification_internal_activity} a
JOIN {activity_type} at ON a.type = at.id JOIN {activity_type} at ON a.type = at.id
WHERE a.usr = ? AND a.type = ?'; WHERE a.usr = ? $typesql";
$records = get_records_sql_array($sql, array($userid, $type), $offset, $limit); $values = array($userid);
$count = count_records_sql('SELECT COUNT(*)' . $from, $values);
$records = get_records_sql_array('
SELECT a.*, at.name AS type,at.plugintype, at.pluginname' . $from, $values, $offset, $limit);
} }
if (empty($records)) { if (empty($records)) {
......
...@@ -35,25 +35,36 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php'); ...@@ -35,25 +35,36 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php'); require_once('pieforms/pieform.php');
define('TITLE', get_string('inbox')); define('TITLE', get_string('inbox'));
$types = get_records_assoc('activity_type', 'admin', 0, 'plugintype,pluginname,name', 'id,name,plugintype,pluginname'); $installedtypes = get_records_assoc(
$types = array_map(create_function('$a', ' 'activity_type', '', '',
if (!empty($a->plugintype)) { 'plugintype,pluginname,name',
$section = "{$a->plugintype}.{$a->pluginname}"; 'name,admin,plugintype,pluginname'
} );
else {
$section = "activity"; $options = array(
'all' => get_string('alltypes', 'activity'),
);
foreach ($installedtypes as &$t) {
if (!$t->admin) {
$section = $t->pluginname ? "{$t->plugintype}.{$t->pluginname}" : 'activity';
$options[$t->name] = get_string('type' . $t->name, $section);
} }
return get_string("type" . $a->name, $section); }
'), $types);
if ($USER->get('admin')) { if ($USER->get('admin')) {
$types['adminmessages'] = get_string('typeadminmessages', 'activity'); $options['adminmessages'] = get_string('typeadminmessages', 'activity');
} }
$type = param_alphanum('type', 'all'); $type = param_variable('type', 'all');
if (!isset($types[$type])) { if (!isset($options[$type])) {
$type = 'all'; // Comma-separated list; filter out anything that's not an installed type
$types = join(',', array_unique(array_filter(
split(',', $type),
create_function('$a', 'global $installedtypes; return isset($installedtypes[$a]);')
)));
} }
$strtype = json_encode($type); $strtype = json_encode($type);
$morestr = get_string('more...'); $morestr = get_string('more...');
...@@ -214,7 +225,8 @@ $smarty->assign('selectalldel', 'toggleChecked(\'tocheckdel\'); return false;'); ...@@ -214,7 +225,8 @@ $smarty->assign('selectalldel', 'toggleChecked(\'tocheckdel\'); return false;');
$smarty->assign('markread', 'markread(this, \'read\'); return false;'); $smarty->assign('markread', 'markread(this, \'read\'); return false;');
$smarty->assign('markdel', 'markread(document.notificationlist, \'del\'); return false;'); $smarty->assign('markdel', 'markread(document.notificationlist, \'del\'); return false;');
$smarty->assign('typechange', 'activitylist.type = this.options[this.selectedIndex].value; activitylist.doupdate();'); $smarty->assign('typechange', 'activitylist.type = this.options[this.selectedIndex].value; activitylist.doupdate();');
$smarty->assign('types', $types); $smarty->assign('options', $options);
$smarty->assign('type', $type);
$smarty->assign('INLINEJAVASCRIPT', $javascript); $smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('PAGEHEADING', hsc(get_string('inbox'))); $smarty->assign('PAGEHEADING', hsc(get_string('inbox')));
$smarty->assign('deleteall', $deleteall); $smarty->assign('deleteall', $deleteall);
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
<form method="post"> <form method="post">
<label>{str section='activity' tag='type'}:</label> <label>{str section='activity' tag='type'}:</label>
<select name="type" onChange="{$typechange}"> <select name="type" onChange="{$typechange}">
<option value="all">{str section='activity' tag='alltypes'}</option> {foreach from=$options item=name key=type}
{foreach from=$types item=name key=type}
<option value="{$type}">{$name}</option> <option value="{$type}">{$name}</option>
{/foreach} {/foreach}
</select>{contextualhelp plugintype='core' pluginname='activity' section='activitytypeselect'} </select>{contextualhelp plugintype='core' pluginname='activity' section='activitytypeselect'}
......
Supports Markdown
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