Commit 9504c632 authored by Penny Leach's avatar Penny Leach
Browse files

rework of the watchlist/activity/view/recursion mess [#437]

parent 0271a6d7
......@@ -44,27 +44,10 @@ if ($stopmonitoring) {
try {
foreach ($_GET as $k => $v) {
if (preg_match('/^stopviews\-(\d+)$/',$k,$m)) {
$recurse = param_boolean($k . '-recurse', null);
if (!empty($recurse)) {
$sql = 'DELETE FROM ' . $prefix . 'usr_watchlist_artefact
WHERE usr = ? AND (artefact IN (
SELECT artefact FROM ' . $prefix . 'artefact_parent_cache WHERE parent IN (
SELECT artefact FROM ' . $prefix . 'view_artefact WHERE view = ? ) )
OR artefact IN (
SELECT artefact FROM ' . $prefix . 'view_artefact WHERE view = ?))';
delete_records_sql($sql, array($userid, $m[1], $m[1]));
}
delete_records('usr_watchlist_view', 'usr', $userid, 'view', $m[1]);
$count++;
}
else if (preg_match('/^stopartefacts\-(\d+)$/',$k,$m)) {
$recurse = param_boolean($k . '-recurse', null);
if (!empty($recurse)) {
$sql = 'DELETE FROM ' . $prefix . 'usr_watchlist_artefact
WHERE usr = ? AND artefact IN (
SELECT artefact FROM ' . $prefix . 'artefact_parent_cache WHERE parent = ?)';
delete_records_sql($sql, array($userid, $m[1]));
}
delete_records('usr_watchlist_artefact', 'usr', $userid, 'artefact', $m[1]);
$count++;
}
......@@ -133,7 +116,7 @@ $records = array();
if ($type == 'views') {
$count = count_records('usr_watchlist_view', 'usr', $userid);
$sql = 'SELECT v.*, v.title AS name
$sql = 'SELECT v.*, v.title AS name, w.recurse
FROM ' . $prefix . 'view v
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?';
......@@ -157,7 +140,7 @@ else if ($type == 'communities') {
}
else if ($type == 'artefacts') {
$count = count_records('usr_watchlist_artefact', 'usr', $userid);
$sql = 'SELECT a.* , a.title AS name
$sql = 'SELECT a.* , a.title AS name, w.view, w.recurse
FROM ' . $prefix . 'artefact a
JOIN ' . $prefix . 'usr_watchlist_artefact w ON w.artefact = a.id
WHERE w.usr = ?';
......
......@@ -36,36 +36,38 @@ $artefactstring = get_string('artefacts', 'activity');
$monitoredstring = get_string('monitored', 'activity');
$allusersstring = get_string('allusers');
$andchildren = ' * ' . get_string('andchildren', 'activity');
$savefailed = get_string('stopmonitoringfailed', 'activity');
$savesuccess = get_string('stopmonitoringsuccess', 'activity');
$recursestr = '[<a href="" onClick="toggleChecked(\'tocheck-r\'); return false;">'
. get_string('recurseall', 'activity')
. '</a>]';
$recursestrjs = str_replace("'", "\'", $recursestr);
$wwwroot = get_config('wwwroot');
$javascript = <<<JAVASCRIPT
var watchlist = new TableRenderer(
'watchlist',
'index.json.php',
[
function(r) {
if (r.url) {
return TD(null,A({'href': r.url}, r.name));
}
return TD(null, r.name);
function(r, d) {
var url = '';
if (d.type == 'communities') {
url = '{$wwwroot}/contacts/communities/view.php?id=' + r.id;
}
else if (d.type == 'views') {
url = '{$wwwroot}/view/view.php?view=' + r.id;
}
else {
url = '{$wwwroot}/view/view.php?view=' + r.view + '&artefact=' + r.id;
}
var star = '';
if (r.recurse) {
star = ' *';
}
return TD(null, A({'href': url}, r.name), star);
},
function (r, d) {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stop' + d.type + '-' + r.id}));
},
function (r, d) {
if (d.type != 'communities') {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck-r', 'name': 'stop' + d.type + '-' + r.id + '-recurse'}));
}
else {
return '';
}
}
]
);
......@@ -79,6 +81,12 @@ watchlist.rowfunction = function(r, n) { return TR({'id': r.id, 'class': 'view r
function changeTitle(title) {
var titles = { 'views': '{$viewstring}', 'communities': '{$communitystring}', 'artefacts': '{$artefactstring}' };
$('typeheader').innerHTML = '{$monitoredstring} ' + titles[title];
if (title != 'communities') {
$('typeandchildren').innerHTML = '{$andchildren}';
}
else {
$('typeandchildren').innerHTML = '';
}
}
function stopmonitoring(form) {
......@@ -133,12 +141,10 @@ function statusChange() {
changeTitle(typevalue);
$('messagediv').innerHTML = '';
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) {
......@@ -180,7 +186,6 @@ $smarty = smarty(array('tablerenderer'));
$smarty->assign('viewusers', $viewusers);
$smarty->assign('typestr', get_string('views', 'activity'));
$smarty->assign('selectall', 'toggleChecked(\'tocheck\'); return false;');
$smarty->assign('recursestr', $recursestr);
$smarty->assign('stopmonitoring', 'stopmonitoring(this); return false;');
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('account/watchlist/index.tpl');
......
......@@ -98,4 +98,6 @@ $string['removefromwatchlist'] = 'Remove from watchlist';
$string['removedcommunityfromwatchlist'] = 'The community has been removed from your watchlist';
$string['addedcommunitytowatchlist'] = 'The community was added to your watchlist';
$string['andchildren'] = 'Children are also being monitored'
?>
......@@ -262,21 +262,36 @@ function handle_activity($activitytype, $data, $cron=false) {
}
$data->message = get_string('onartefact', 'activity')
. ' ' . $ainfo->title . ' ' . get_string('ownedby', 'activity');
$sql = 'SELECT DISTINCT u.*, p.method, ?||wa.view as url
FROM ' . $prefix . 'usr_watchlist_artefact wa
LEFT JOIN ' . $prefix . 'artefact_parent_cache pc
ON (pc.parent = wa.artefact OR pc.artefact = wa.artefact)
JOIN ' . $prefix . 'usr u
ON wa.usr = u.id
LEFT JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
WHERE (p.activity = ? OR p.activity IS NULL)
AND (pc.parent = ? OR wa.artefact = ?)
';
$users = get_records_sql_array($sql,
array(get_config('wwwroot') . 'view/view.php?view='
. $data->artefact . '&view=', 'watchlist',
$data->artefact, $data->artefact));
$sql = '
SELECT DISTINCT u.*, p.method, ?||wa.view AS url
FROM ' . $prefix . 'usr u
LEFT JOIN ' . $prefix . 'usr_activity_preference p
ON p.usr = u.id
JOIN (
SELECT wa.usr AS uid, wa.view AS view
FROM ' . $prefix . 'usr_watchlist_artefact wa
WHERE wa.artefact = ?
UNION SELECT wa.usr AS uid, wa.view AS view
FROM ' . $prefix . 'artefact_parent_cache pc
JOIN ' . $prefix . 'usr_watchlist_artefact wa
ON wa.artefact = pc.parent
WHERE pc.artefact = ? AND wa.recurse = 1
UNION SELECT wv.usr AS uid, wv.view AS view
FROM ' . $prefix . 'artefact_parent_cache pc
JOIN ' . $prefix . 'view_artefact va
ON va.artefact = pc.parent
JOIN ' . $prefix . 'usr_watchlist_view wv
ON va.view = wv.view
WHERE pc.artefact = ? AND wv.recurse = 1
) wa ON wa.uid = u.id
WHERE p.activity = ? OR p.activity IS NULL';
$values = array(get_config('wwwroot') . 'view/view.php?artefact='
. $data->artefact . '&view=',
$data->artefact, $data->artefact, $data->artefact,
'watchlist');
log_debug($sql);
log_debug($values);
$users = get_records_sql_array($sql, $values);
if (empty($users)) {
$users = array();
}
......
......@@ -23,13 +23,13 @@
</select>
</form>
<div id="typeheader">{str section='activity' tag='monitored'} {$typestr}</div>
<div id="typeandchildren">* {str section='activity' tag='andchildren}</div>
<form method="post" onSubmit="{$stopmonitoring}">
<table id="watchlist" class="tablerenderer">
<thead>
<tr>
<th></th>
<th>[<a href="" onClick="{$selectall}">{str section='activity' tag='selectall'}</a>]</th>
<th id="recurseheader">{$recursestr}</th>
</tr>
</thead>
<tbody>
......
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