Commit 4d4db06c authored by Penny Leach's avatar Penny Leach
Browse files

beginnings of watchlist page

parent f9ef02a7
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
json_headers();
$stopmonitoring = param_integer('stopmonitoring', 0);
$getartefacts = param_integer('getartefacts', 0);
if ($stopmonitoring) {
$count = 0;
db_begin();
try {
foreach ($_GET as $k => $v) {
if (preg_match('/^stopview\-(\d+)$/',$k,$m)) {
// @todo
$count++;
}
else if (preg_match('/^stopartefact\-(\d+)$/',$k,$m)) {
// @todo
$count++;
}
else if (preg_match('/^stopcommunity\-(\d+)$/',$k,$m)) {
// @todo
$count++;
}
}
}
catch (Exception $e) {
db_rollback();
$data = array('error' => $e->getMessage);
echo json_encode($data);
}
db_commit();
$data = array('success' => 1, 'count' => $count);
echo json_encode($data);
exit;
}
// normal processing
$type = param_alpha('type', 'views');
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$userid = $SESSION->get('id');
$prefix = get_config('dbprefix');
if ($type == 'views') {
$count = count_records('usr_watchlist_view', 'usr', $userid);
$sql = 'SELECT v.*
FROM ' . $prefix . 'view v
JOIN ' . $prefix . 'usr_watchlist_view w ON w.view = v.id
WHERE w.usr = ?';
if ($records = get_rows_sql($sql, array($userid), 'v.mtime DESC', '*', $offset, $limit)) {
foreach ($records as &$r) {
// @todo session expandey stuff
}
}
}
else if ($type == 'communities') {
$count = count_records('usr_watchlist_community', 'usr', $userid);
$sql = 'SELECT c.*
FROM ' . $prefix . 'community c
JOIN ' . $prefix . 'usr_watchlist_community w ON w.community = c.id
WHERE w.usr = ?';
$records = get_rows_sql($sql, array($userid), 'c.mtime DESC', '*', $offset, $limit);
}
if (empty($records)) {
$records = array();
}
$activity = array(
'count' => $count,
'offset' => $offset,
'limit' => $limit,
'data' => $records,
'type' => $type,
'minusicon' => theme_get_image_path('minus.gif'),
'plusicon' => theme_get_image_path('plus.gif'),
'minusalt' => get_string('collapse'),
'plusalt' => get_string('expand'),
);
echo json_encode($activity);
?>
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'account');
define('SUBMENUITEM', 'watchlist');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
$viewstring = get_string('viewsandartefacts', 'activity');
$communitystring = get_string('communities', 'activity');
$monitoredstring = get_string('monitored', 'activity');
$javascript = <<<JAVASCRIPT
var watchlist = new TableRenderer(
'watchlist',
'index.json.php',
[
function(r, d) {
if (r.type == 'community') {
return TD(null, '');
}
if (r.expanded) {
return TD(null, A({'href': '', 'onClick' : 'collapse(' + r.id | ')'}),
IMG({'src' : d.minusicon, 'alt' : d.minusalt}));
}
else {
return TD(null, A({'href': '', 'onClick' : 'collapse(' + r.id | ')'}),
IMG({'src' : d.plusicon, 'alt' : d.plusalt}));
}
},
function(r) {
if (r.url) {
return TD(null,A({'href': r.url}, r.name));
}
return TD(null,r.name);
},
function (r) {
return TD(null, INPUT({'type' : 'checkbox', 'class' : 'viewcheck', 'name' : 'view-' + r.id}));
}
]
);
watchlist.type = 'views';
watchlist.statevars.push('type');
watchlist.updateOnLoad();
function changeTitle(title) {
var titles = { 'views' : '{$viewstring}', 'communities' : '{$communitystring}' };
$('typeheader').innerHTML = '{$monitoredstring} ' + titles[title];
}
JAVASCRIPT;
$typechange = 'watchlist.doupdate({\'type\':this.options[this.selectedIndex].value}); changeTitle(this.options[this.selectedIndex].value);';
$smarty = smarty(array('tablerenderer'));
$smarty->assign('site_menu', site_menu());
$smarty->assign('typechange', $typechange);
$smarty->assign('typestr', get_string('viewsandartefacts', 'activity'));
$smarty->assign('INLINEJAVASCRIPT', $javascript);
$smarty->display('account/watchlist/index.tpl');
?>
\ No newline at end of file
......@@ -51,5 +51,9 @@ $string['alltypes'] = 'All types';
$string['markedasread'] = 'Marked your notifications as read';
$string['failedtomarkasread'] = 'Failed to mark your notifications as read';
$string['stopmonitoring'] = 'Stop monitoring';
$string['viewsandartefacts'] = 'Views and artefacts';
$string['communities'] = 'Communities';
$string['monitored'] = 'Monitored';
?>
......@@ -191,6 +191,7 @@ $string['membercount'] = 'Member count';
$string['account'] = 'My account';
$string['accountprefs'] = 'Account preferences';
$string['activityprefs'] = 'Activity preferences';
$string['watchlist'] = 'My watchlist';
$string['changepassword'] = 'Change password';
$string['activity'] = 'Recent activity';
......@@ -210,6 +211,7 @@ $string['width'] = 'Width';
$string['height'] = 'Height';
$string['widthshort'] = 'w';
$string['heightshort'] = 'h';
$string['filter'] = 'Filter';
$string['nohelpfound'] = 'There was no help found for this item';
......
{include file="header.tpl"}
{include file="adminmenu.tpl"}
<h2>{str tag="watchlist"}</h2>
<div class="content">
<form method="post">
{str tag='filter'}:
<select name="type" onChange="{$typechange}">
<option value="views">{str section='activity' tag='viewsandartefacts'}</option>
<option value="communities">{str section='activity' tag='communities'}</option>
</select>
</form>
<div id="typeheader">{str section='activity' tag='monitored'} {$typestr}</div>
<form method="post" onSubmit="{$stopmonitoring}">
<table id="watchlist">
<thead>
<tr>
<th></th>
<th></th>
<th>{str section='activity' tag='stopmonitoring'} [<a href="" onClick="{$selectall}">{str section='activity' tag='selectall'}</a>]</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td align="right" colspan="4"><div id="messagediv"></div></td>
<td align="right"><input type="submit" value="{str tag='update'}" /></td>
</tr>
</tfoot>
</table>
</form>
</div>
{include file="footer.tpl"}
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