Commit 7712593a authored by Penny Leach's avatar Penny Leach
Browse files

added recursive delete to watchlist

parent a4b9cf24
...@@ -33,6 +33,8 @@ json_headers(); ...@@ -33,6 +33,8 @@ json_headers();
$stopmonitoring = param_integer('stopmonitoring', 0); $stopmonitoring = param_integer('stopmonitoring', 0);
$getartefacts = param_integer('getartefacts', 0); $getartefacts = param_integer('getartefacts', 0);
$prefix = get_config('dbprefix');
if ($stopmonitoring) { if ($stopmonitoring) {
$userid = $USER->get('id'); $userid = $USER->get('id');
$count = 0; $count = 0;
...@@ -40,10 +42,27 @@ if ($stopmonitoring) { ...@@ -40,10 +42,27 @@ if ($stopmonitoring) {
try { try {
foreach ($_GET as $k => $v) { foreach ($_GET as $k => $v) {
if (preg_match('/^stopviews\-(\d+)$/',$k,$m)) { 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]); delete_records('usr_watchlist_view', 'usr', $userid, 'view', $m[1]);
$count++; $count++;
} }
else if (preg_match('/^stopartefacts\-(\d+)$/',$k,$m)) { 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]); delete_records('usr_watchlist_artefact', 'usr', $userid, 'artefact', $m[1]);
$count++; $count++;
} }
......
...@@ -40,6 +40,12 @@ $savesuccess = get_string('stopmonitoringsuccess', 'activity'); ...@@ -40,6 +40,12 @@ $savesuccess = get_string('stopmonitoringsuccess', 'activity');
$getartefactsjson = get_config('wwwroot') . 'json/getartefacts.php'; $getartefactsjson = get_config('wwwroot') . 'json/getartefacts.php';
$recursestr = '[<a href="" onClick="toggleChecked(\'tocheck-r\'); return false;">'
. get_string('recurseall', 'activity')
. '</a>]';
$recursestrjs = str_replace("'", "\'", $recursestr);
$javascript = <<<JAVASCRIPT $javascript = <<<JAVASCRIPT
var watchlist = new TableRenderer( var watchlist = new TableRenderer(
'watchlist', 'watchlist',
...@@ -53,6 +59,14 @@ var watchlist = new TableRenderer( ...@@ -53,6 +59,14 @@ var watchlist = new TableRenderer(
}, },
function (r, d) { function (r, d) {
return TD(null, INPUT({'type' : 'checkbox', 'class': 'tocheck', 'name': 'stop' + d.type + '-' + r.id})); 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 '';
}
} }
] ]
); );
...@@ -70,8 +84,9 @@ function changeTitle(title) { ...@@ -70,8 +84,9 @@ function changeTitle(title) {
} }
function stopmonitoring(form) { function stopmonitoring(form) {
var c = 'tocheck'; var e1 = getElementsByTagAndClassName(null,'tocheck',form);
var e = getElementsByTagAndClassName(null,'tocheck',form); var e2 = getElementsByTagAndClassName(null,'tocheck-r',form);
var e = concat(e1, e2);
var pd = {}; var pd = {};
for (cb in e) { for (cb in e) {
...@@ -101,16 +116,27 @@ function stopmonitoring(form) { ...@@ -101,16 +116,27 @@ function stopmonitoring(form) {
) )
} }
function typeChange(element) {
watchlist.doupdate({'type': element.options[element.selectedIndex].value});
changeTitle(element.options[element.selectedIndex].value);
$('messagediv').innerHTML = '';
if (element.options[element.selectedIndex].value == 'communities') {
$('recurseheader').innerHTML = '';
}
else {
$('recurseheader').innerHTML = '{$recursestrjs}';
}
JAVASCRIPT; }
$typechange = 'watchlist.doupdate({\'type\':this.options[this.selectedIndex].value}); changeTitle(this.options[this.selectedIndex].value); $(\'messagediv\').innerHTML = \'\';'; JAVASCRIPT;
$smarty = smarty(array('tablerenderer')); $smarty = smarty(array('tablerenderer'));
$smarty->assign('site_menu', site_menu()); $smarty->assign('site_menu', site_menu());
$smarty->assign('typechange', $typechange); $smarty->assign('typechange', 'typeChange(this);');
$smarty->assign('typestr', get_string('views', 'activity')); $smarty->assign('typestr', get_string('views', 'activity'));
$smarty->assign('selectall', 'toggleChecked(\'tocheck\'); return false;'); $smarty->assign('selectall', 'toggleChecked(\'tocheck\'); return false;');
$smarty->assign('recursestr', $recursestr);
$smarty->assign('stopmonitoring', 'stopmonitoring(this); return false;'); $smarty->assign('stopmonitoring', 'stopmonitoring(this); return false;');
$smarty->assign('INLINEJAVASCRIPT', $javascript); $smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('account/watchlist/index.tpl'); $smarty->display('account/watchlist/index.tpl');
......
...@@ -46,6 +46,7 @@ $string['unread'] = 'Unread'; ...@@ -46,6 +46,7 @@ $string['unread'] = 'Unread';
$string['markasread'] = 'Mark as read'; $string['markasread'] = 'Mark as read';
$string['selectall'] = 'Select all'; $string['selectall'] = 'Select all';
$string['recurseall'] = 'Recurse all';
$string['alltypes'] = 'All types'; $string['alltypes'] = 'All types';
$string['markedasread'] = 'Marked your notifications as read'; $string['markedasread'] = 'Marked your notifications as read';
......
...@@ -18,9 +18,9 @@ ...@@ -18,9 +18,9 @@
<table id="watchlist"> <table id="watchlist">
<thead> <thead>
<tr> <tr>
<th></th>
<th></th> <th></th>
<th>[<a href="" onClick="{$selectall}">{str section='activity' tag='selectall'}</a>]</th> <th>[<a href="" onClick="{$selectall}">{str section='activity' tag='selectall'}</a>]</th>
<th id="recurseheader">{$recursestr}</th>
</tr> </tr>
</thead> </thead>
<tbody> <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