Commit 85062711 authored by Chris Wharton's avatar Chris Wharton
Browse files

Display a list of views on a users watchlist



Bug #794460

A basic block that shows a list of views currently on a users watchlist.
Allows click-through to the view itself, where the user can remove the
view from their watchlist.

This block could be extended with a "Remove from Watchlist" button on
the block itself, and/or an inbox style paginated list.

Change-Id: Iec98314c1c22daec919290cfaaf0f02cced7100a
Signed-off-by: default avatarChris Wharton <chrisw@catalyst.net.nz>
parent bc46889d
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2011 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-watchlist
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2011 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$string['title'] = 'My Watched Pages';
$string['description'] = 'Display pages on your watchlist';
$string['nopages'] = 'There are no pages on your watchlist';
$string['itemstoshow'] = 'Items to show';
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2011 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-watchlist
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2011 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
class PluginBlocktypeWatchlist extends SystemBlocktype {
public static function single_only() {
return true;
}
public static function get_title() {
return get_string('title', 'blocktype.watchlist');
}
public static function get_description() {
return get_string('description', 'blocktype.watchlist');
}
public static function get_categories() {
return array('general');
}
public static function get_viewtypes() {
return array('dashboard');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
global $USER;
$configdata = $instance->get('configdata');
$limit = isset($configdata['count']) ? (int) $configdata['count'] : 10;
$userid = $USER->get('id');
$smarty = smarty_core();
$sql =
'SELECT v.title, v.id
FROM {view} v
JOIN {usr_watchlist_view} wv ON wv.view = v.id
WHERE wv.usr = ?
ORDER BY v.title
LIMIT ?';
$results = get_records_sql_array($sql, array($userid, $limit));
// if there are no watched views, notify the user
if (!$results) {
$smarty->assign('watchlistempty', true);
return $smarty->fetch('blocktype:watchlist:watchlist.tpl');
}
$smarty->assign('blockid', 'blockinstance_' . $instance->get('id'));
$smarty->assign('views', $results);
return $smarty->fetch('blocktype:watchlist:watchlist.tpl');
}
public static function has_instance_config() {
return true;
}
public static function instance_config_form($instance) {
$configdata = $instance->get('configdata');
return array(
'count' => array(
'type' => 'text',
'title' => get_string('itemstoshow', 'blocktype.watchlist'),
'defaultvalue' => isset($configdata['count']) ? $configdata['count'] : 10,
'size' => 3,
'rules' => array('integer' => true, 'minvalue' => 1, 'maxvalue' => 999),
),
);
}
public static function default_copy_type() {
return 'shallow';
}
/**
* watchlist only makes sense for personal views
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
}
}
{if $watchlistempty}
{str tag=nopages section=blocktype.watchlist}
{else}
<table id="watchlistblock" class="viewlist">
{foreach $views as item=view}
<tr>
<td class="{cycle values='r0,r1'}">
<h4><a href="{$WWWROOT}view/view.php?id={$view->id}" class="watchlist-showview">{$view->title}</a></h4>
</td>
</tr>
{/foreach}
</table>
<div class="cb"></div>
{/if}
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2011 Catalyst IT Ltd and others; see:
* http://wiki.mahara.org/Contributors
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
* @package mahara
* @subpackage blocktype-watchlist
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2011 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2011090700;
$config->release = '1.0.0';
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