Commit 72d23ba1 authored by Penny Leach's avatar Penny Leach
Browse files

watchlist now has user filtering

parent b7d1ac8b
......@@ -31,12 +31,13 @@ require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$stopmonitoring = param_integer('stopmonitoring', 0);
$userlist = param_alpha('userlist', null);
$getartefacts = param_integer('getartefacts', 0);
$prefix = get_config('dbprefix');
$userid = $USER->get('id');
if ($stopmonitoring) {
$userid = $USER->get('id');
$count = 0;
db_begin();
try {
......@@ -82,11 +83,44 @@ if ($stopmonitoring) {
echo json_encode($data);
exit;
}
if (!empty($userlist)) {
if ($userlist == 'views') {
$sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?';
if (!$users = get_records_sql_array($sql, array($userid))) {
$users = array();
}
}
else if ($userlist == 'artefacts') {
$sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'artefact a ON a.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id
WHERE w.usr = ?';
if (!$users = get_records_sql_array($sql, array($userid))) {
$users = array();
}
}
else {
$users = array();
}
$data = array();
foreach ($users as $u) {
$data[] = array('id' => $u->id, 'name' => display_name($u, $USER));
}
json_reply(false, array('users' => $data));
}
// normal processing
// normal processing (fetching tablerenderer results)
$type = param_alpha('type', 'views');
$owner = param_integer('user', null);
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
......@@ -101,9 +135,15 @@ if ($type == 'views') {
$sql = 'SELECT v.*, v.title AS name
FROM ' . $prefix . 'view v
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?
WHERE w.usr = ?';
$values = array($userid);
if (isset($owner)) {
$sql .= ' AND v.owner = ?';
$values[] = $owner;
}
$sql .= '
ORDER BY v.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
$records = get_records_sql_array($sql, $values, $offset, $limit);
}
else if ($type == 'communities') {
$count = count_records('usr_watchlist_community', 'usr', $userid);
......@@ -119,9 +159,15 @@ else if ($type == 'artefacts') {
$sql = 'SELECT a.* , a.title AS name
FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id
WHERE w.usr = ?
WHERE w.usr = ?';
$values = array($userid);
if (isset($owner)) {
$sql .= ' AND a.owner = ?';
$values[] = $owner;
}
$sql .= '
ORDER BY a.mtime DESC';
$records = get_records_sql_array($sql, array($userid), $offset, $limit);
$records = get_records_sql_array($sql, $values, $offset, $limit);
}
if (empty($records)) {
......
......@@ -34,6 +34,7 @@ $viewstring = get_string('views', 'activity');
$communitystring = get_string('communities', 'activity');
$artefactstring = get_string('artefacts', 'activity');
$monitoredstring = get_string('monitored', 'activity');
$allusersstring = get_string('allusers');
$savefailed = get_string('stopmonitoringfailed', 'activity');
$savesuccess = get_string('stopmonitoringsuccess', 'activity');
......@@ -116,24 +117,71 @@ function stopmonitoring(form) {
)
}
function typeChange(element) {
watchlist.doupdate({'type': element.options[element.selectedIndex].value});
changeTitle(element.options[element.selectedIndex].value);
function statusChange() {
var typevalue = $('type').options[$('type').selectedIndex].value;
var uservalue;
if ($('user').disabled == true) {
uservalue = undefined;
}
else {
uservalue = getNodeAttribute($('user').options[$('user').selectedIndex], 'value');
}
if (uservalue) {
watchlist.doupdate({'type': typevalue, 'user': uservalue});
}
else {
watchlist.doupdate({'type': typevalue});
}
changeTitle(typevalue);
$('messagediv').innerHTML = '';
if (element.options[element.selectedIndex].value == 'communities') {
if (typevalue == 'communities') {
$('recurseheader').innerHTML = '';
$('user').options.length = 0;
$('user').disabled = true;
}
else {
$('recurseheader').innerHTML = '{$recursestrjs}';
var pd = {'userlist': typevalue};
var d = loadJSONDoc('index.json.php', pd);
d.addCallbacks(function (data) {
var userSelect = $('user');
var newOptions = new Array()
var opt = OPTION(null, '{$allusersstring}');
if (!uservalue) {
opt.selected = true;
}
newOptions.push(opt);
forEach (data.message.users, function (u) {
var opt = OPTION({'value': u.id}, u.name);
if (uservalue == u.id) {
opt.selected = true;
}
newOptions.push(opt);
});
userSelect.disabled = false;
replaceChildNodes(userSelect, newOptions);
});
}
}
JAVASCRIPT;
$prefix = get_config('prefix');
$sql = 'SELECT DISTINCT u.*
FROM ' . $prefix . 'usr u
JOIN ' . $prefix . 'view v ON v.owner = u.id
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?';
if (!$viewusers = get_records_sql_array($sql, array($USER->get('id')))) {
$viewusers = array();
}
$smarty = smarty(array('tablerenderer'));
$smarty->assign('site_menu', site_menu());
$smarty->assign('typechange', 'typeChange(this);');
$smarty->assign('viewusers', $viewusers);
$smarty->assign('typestr', get_string('views', 'activity'));
$smarty->assign('selectall', 'toggleChecked(\'tocheck\'); return false;');
$smarty->assign('recursestr', $recursestr);
......
......@@ -257,4 +257,6 @@ $string['noresultsfound'] = 'No results found';
// artefact
$string['artefactnotfound'] = 'Artefact with id %s not found';
$string['belongingto'] = 'Belonging to';
$string['allusers'] = 'All users';
?>
......@@ -7,11 +7,18 @@
<div class="content">
<form method="post">
{str tag='filter'}:
<select name="type" onChange="{$typechange}">
<select id="type" name="type" onChange="statusChange(); return false;">
<option value="views">{str section='activity' tag='views'}</option>
<option value="artefacts">{str section='activity' tag='artefacts'}</option>
<option value="communities">{str section='activity' tag='communities'}</option>
</select>
{str tag='belongingto'}:
<select id="user" name="user" onChange="statusChange(); return false;">
<option>{str tag='allusers'}</option>
{foreach from=$viewusers item='user}
<option value="{$user->id}">{display_name user=$user}</option>
{/foreach}
</select>
</form>
<p><b><div id="typeheader">{str section='activity' tag='monitored'} {$typestr}</div></b></p>
<form method="post" onSubmit="{$stopmonitoring}">
......
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