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) {
// normal processing
$type = param_alphanum('type', 'all');
$type = param_variable('type', 'all');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
......@@ -107,12 +107,18 @@ if ($type == 'all') {
$records = get_records_sql_array($sql, array($userid, 1), $offset, $limit);
}
else {
$count = count_records_select('notification_internal_activity', 'usr = ? AND type = ?',
array($userid,$type));
$sql = 'SELECT a.*, at.name AS type,at.plugintype, at.pluginname FROM {notification_internal_activity} a
$types = split(',', preg_replace('/[^a-z,]+/', '', $type));
if ($types) {
$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
WHERE a.usr = ? AND a.type = ?';
$records = get_records_sql_array($sql, array($userid, $type), $offset, $limit);
WHERE a.usr = ? $typesql";
$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)) {
......
......@@ -35,25 +35,36 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('inbox'));
$types = get_records_assoc('activity_type', 'admin', 0, 'plugintype,pluginname,name', 'id,name,plugintype,pluginname');
$types = array_map(create_function('$a', '
if (!empty($a->plugintype)) {
$section = "{$a->plugintype}.{$a->pluginname}";
}
else {
$section = "activity";
$installedtypes = get_records_assoc(
'activity_type', '', '',
'plugintype,pluginname,name',
'name,admin,plugintype,pluginname'
);
$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')) {
$types['adminmessages'] = get_string('typeadminmessages', 'activity');
$options['adminmessages'] = get_string('typeadminmessages', 'activity');
}
$type = param_alphanum('type', 'all');
if (!isset($types[$type])) {
$type = 'all';
$type = param_variable('type', 'all');
if (!isset($options[$type])) {
// 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);
$morestr = get_string('more...');
......@@ -214,7 +225,8 @@ $smarty->assign('selectalldel', 'toggleChecked(\'tocheckdel\'); return false;');
$smarty->assign('markread', 'markread(this, \'read\'); 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('types', $types);
$smarty->assign('options', $options);
$smarty->assign('type', $type);
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->assign('PAGEHEADING', hsc(get_string('inbox')));
$smarty->assign('deleteall', $deleteall);
......
......@@ -4,8 +4,7 @@
<form method="post">
<label>{str section='activity' tag='type'}:</label>
<select name="type" onChange="{$typechange}">
<option value="all">{str section='activity' tag='alltypes'}</option>
{foreach from=$types item=name key=type}
{foreach from=$options item=name key=type}
<option value="{$type}">{$name}</option>
{/foreach}
</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