Commit d3713154 authored by Evan Goldenberg's avatar Evan Goldenberg Committed by Richard Mansfield
Browse files

add a dashboard view to the index page for logged in users

Also included is an inbox blocktype for dashboard views which shows the
user's most recent notifications. Multiple instances of this block can
be present in a dashboard view, and the message types displayed in each
can be configured.

A default dashboard view is installed for each user the next time they
log in. Additionally, since the profile view is now shown in the view
list, it is installed on login, rather than when the profile is first
requested.

Conflicts:

	htdocs/lib/version.php
	htdocs/view/blocks.php
parent 83ccf40e
......@@ -423,7 +423,7 @@ class User {
*
* @return View
*/
private function install_profile_view() {
protected function install_profile_view() {
static $systemprofileviewid = null;
db_begin();
......@@ -471,6 +471,50 @@ class User {
return $view;
}
/**
* Return the dashboard view object for this user.
*
* If the user does not yet have a dashboard view, one is created for them.
*
* @return View
*/
public function get_dashboard_view() {
$viewid = get_field('view', 'id', 'type', 'dashboard', 'owner', $this->get('id'));
log_debug($viewid);
if (!$viewid) {
global $USER;
if (!$USER->get('id')) {
return null;
}
return $this->install_dashboard_view();
}
return new View($viewid);
}
/**
* Installs a user's dashboard view.
*
* @return View
*/
protected function install_dashboard_view() {
static $systemdashboardviewid = null;
db_begin();
if (is_null($systemdashboardviewid)) {
$systemdashboardviewid = get_field('view', 'id', 'owner', 0, 'type', 'dashboard');
}
require_once(get_config('libroot') . 'view.php');
list($view) = View::create_from_template(array(
'owner' => $this->get('id'),
'title' => get_field('view', 'title', 'id', $systemdashboardviewid),
'type' => 'dashboard',
), $systemdashboardviewid, $this->get('id'));
db_commit();
return $view;
}
/**
......@@ -888,9 +932,21 @@ class LiveUser extends User {
throw new AccessTotallyDeniedException(get_string('accesstotallydenied_institutionsuspended', 'mahara', $authinstance->displayname, $sitename));
return false;
}
// install the profile and dashboard views if they don't already exist
$userobj = new User();
$userobj->find_by_id($user->id);
if (!get_field('view', 'id', 'type', 'profile', 'owner', $this->get('id'))) {
$userobj->install_profile_view();
}
if (!get_field('view', 'id', 'type', 'dashboard', 'owner', $this->get('id'))) {
$userobj->install_dashboard_view();
}
return true;
}
} catch (AuthInstanceException $e) {
}
catch (AuthInstanceException $e) {
return false;
}
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 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-inbox
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$string['title'] = 'My Inbox';
$string['description'] = 'Display a selection of your recent inbox messages';
$string['messagetypes'] = 'Message types to display';
$string['maxitems'] = 'Maximum number of items to display';
$string['maxitemsdescription'] = 'Between 1 and 100';
?>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 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-inbox
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
class PluginBlocktypeInbox extends SystemBlocktype {
public static function get_title() {
return get_string('title', 'blocktype.inbox');
}
public static function get_description() {
return get_string('description', 'blocktype.inbox');
}
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');
$types = get_records_assoc('activity_type', 'admin', 0, '', 'id,name,plugintype,pluginname');
$desiredtypes = array();
foreach($types as $type) {
if ($configdata[$type->name]) {
$desiredtypes[] = $type->id;
}
}
if ($USER->get('admin') && $configdata['adminmessages']) {
$admintypes = get_records_assoc('activity_type', 'admin', 1, '', 'id,name,plugintype,pluginname');
$types += $admintypes;
foreach($admintypes as $type) {
$desiredtypes[] = $type->id;
}
}
$sql = "
SELECT *
FROM {notification_internal_activity} n
WHERE n.usr = ?
AND n.type IN (" . implode(',', $desiredtypes) . ")
ORDER BY n.ctime DESC
LIMIT ?;";
$records = array();
if ($desiredtypes) {
$records = get_records_sql_array($sql, array(
$USER->get('id'),
$configdata['maxitems']
));
}
$items = array();
foreach($records as $record) {
$items[] = array(
'subject' => $record->subject,
'url' => $record->url,
'type' => $types[$record->type]->name,
);
}
$smarty = smarty_core();
$smarty->assign('items', $items);
return $smarty->fetch('blocktype:inbox:inbox.tpl');
}
public static function has_instance_config() {
return true;
}
public static function instance_config_form($instance) {
global $USER;
$configdata = $instance->get('configdata');
$types = get_records_array('activity_type', 'admin', 0, 'plugintype,pluginname,name', 'name,plugintype,pluginname');
if ($USER->get('admin')) {
$types[] = (object)array('name' => 'adminmessages');
}
$elements = array();
$elements['types'] = array(
'type' => 'fieldset',
'legend' => get_string('messagetypes', 'blocktype.inbox'),
'elements' => array(),
);
foreach($types as $type) {
if (!empty($type->plugintype)) {
$title = get_string('type' . $type->name, $type->plugintype . '.' . $type->pluginname);
}
else {
$title = get_string('type' . $type->name, 'activity');
}
$elements['types']['elements'][$type->name] = array(
'type' => 'checkbox',
'title' => $title,
'defaultvalue' => $configdata[$type->name] ? $configdata[$type->name] : 0,
);
}
$elements['maxitems'] = array(
'type' => 'text',
'title' => get_string('maxitems', 'blocktype.inbox'),
'description' => get_string('maxitemsdescription', 'blocktype.inbox'),
'defaultvalue' => $configdata['maxitems'] ? $configdata['maxitems'] : 5,
);
return $elements;
}
public static function default_copy_type() {
return 'shallow';
}
/**
* Inbox only makes sense for personal views
*/
public static function allowed_in_view(View $view) {
return $view->get('owner') != null;
}
}
?>
<table>
{foreach from=$items item=i}
<tr>
<td>
<img src="{theme_url filename=cat('images/' $i.type '.gif')}" />
</td>
<td>
{if $i.url}<a href="{$i.url}">{/if}
{$i.subject}
{if $i.url}</a>{/if}
</td>
</tr>
{/foreach}
</table>
<a href="{$WWWROOT}account/activity" target="_blank">{str tag=gotoinbox section=mahara} &raquo;</a>
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2009 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-inbox
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2010031800;
$config->release = '1.0.0';
?>
......@@ -48,7 +48,7 @@ class PluginBlocktypeMyfriends extends SystemBlocktype {
}
public static function get_viewtypes() {
return array('profile');
return array('profile', 'dashboard');
}
public static function build_myfriends_html(&$friends, $userid) {
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009021800;
$config->version = 2010031800;
$config->release = '1.0.0';
?>
......@@ -46,7 +46,7 @@ class PluginBlocktypeMyGroups extends SystemBlocktype {
}
public static function get_viewtypes() {
return array('profile');
return array('profile', 'dashboard');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009021800;
$config->version = 2010031800;
$config->release = '1.0.0';
?>
......@@ -46,7 +46,7 @@ class PluginBlocktypeMyviews extends SystemBlocktype {
}
public static function get_viewtypes() {
return array('profile');
return array('profile', 'dashboard');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
......@@ -59,7 +59,7 @@ class PluginBlocktypeMyviews extends SystemBlocktype {
// Get viewable views
$views = array();
if ($allviews = get_records_select_array('view', 'owner = ? AND type != ?', array($userid, 'profile'), 'title')) {
if ($allviews = get_records_select_array('view', "owner = ? AND type NOT IN ('profile', 'dashboard')", array($userid))) {
foreach ($allviews as $view) {
if (can_view_view($view->id)) {
$views[$view->id] = $view;
......
......@@ -28,7 +28,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009021800;
$config->version = 2010031800;
$config->release = '1.0.0';
?>
......@@ -41,7 +41,7 @@ class PluginBlocktypeRecentForumPosts extends SystemBlocktype {
}
public static function get_viewtypes() {
return array('profile', 'portfolio');
return array('profile', 'portfolio', 'dashboard');
}
public static function render_instance(BlockInstance $instance, $editing=false) {
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2009120700;
$config->version = 2010031800;
$config->release = '1.0.0';
?>
......@@ -45,15 +45,32 @@ else {
$pagename = 'home';
}
$smarty = smarty();
$smarty->assign('page_content', get_site_page_content($pagename));
if ($USER->is_logged_in()) {
// get the user's dashboard view
require_once(get_config('libroot') . 'view.php');
$viewid = get_field('view', 'id', 'owner', $USER->get('id'), 'type', 'dashboard');
$view = new View($viewid);
$stylesheets = array('<link rel="stylesheet" type="text/css" href="' . get_config('wwwroot') . 'theme/views.css">');
$smarty = smarty(
array(),
$stylesheets,
array(),
array(
'stylesheets' => array('style/views.css'),
)
);
if ($nviews = get_config('homepageviewlist')) {
require_once('view.php');
$views = View::view_search(null, null, null, null, $nviews, 0, true, 'mtime DESC');
$smarty->assign('views', $views->data);
$smarty->assign('dashboardview', true);
$smarty->assign('maintitle', get_string('mydashboard'));
$smarty->assign('viewcontent', $view->build_columns());
$smarty->assign('viewid', $view->get('id'));
}
else {
$smarty = smarty();
}
$smarty->assign('page_content', get_site_page_content($pagename));
$smarty->display('index.tpl');
?>
......@@ -496,6 +496,7 @@ $string['activityprefs'] = 'Activity preferences';
$string['changepassword'] = 'Change password';
$string['notifications'] = 'Notifications';
$string['inbox'] = 'Inbox';
$string['gotoinbox'] = 'Go to inbox';
$string['institutionmembership'] = 'Institution Membership';
$string['institutionmembershipdescription'] = 'If you are a member of any institutions, they will be listed here. You may also request membership of an institution, and if any institutions have invited you to join, you can accept or decline the invitation.';
$string['youareamemberof'] = 'You are a member of %s';
......@@ -891,6 +892,15 @@ $string['viewmyprofilepage'] = 'View profile page';
$string['editmyprofilepage'] = 'Edit profile page';
$string['usersprofile'] = "%s's Profile";
// Dashboard views
$string['mydashboard'] = 'My Dashboard';
$string['editdashboard'] = 'Edit';
$string['usersdashboard'] = "%s's Dashboard";
$string['dashboarddescription'] = 'Your dashboard view is what you see on the homepage when you first log in. Only you have access to it';
$string['topicsimfollowing'] = "Topics I'm Following";
$string['recentactivity'] = 'Recent Activity';
$string['mymessages'] = 'My Messages';
$string['pleasedonotreplytothismessage'] = "Please do not reply to this message.";
$string['deleteduser'] = 'Deleted user';
......
......@@ -45,7 +45,8 @@ $string['unrecogniseddateformat'] = 'Unrecognised date format';
$string['allowcommentsonview'] = 'If checked, users who can see your View will be allowed to leave comments.';
$string['ownerformat'] = 'Name display format';
$string['ownerformatdescription'] = 'How do you want people who look at your View to see your name?';
$string['profileviewtitle'] = 'Profile view';
$string['profileviewtitle'] = 'Profile View';
$string['dashboardviewtitle'] = 'Dashboard View';
$string['editprofileview'] = 'Edit profile view';
// my views
......
......@@ -1643,5 +1643,118 @@ function xmldb_core_upgrade($oldversion=0) {
}
}
if ($oldversion < 2010042602) {
insert_record('view_type', (object)array(
'type' => 'dashboard',
));
if ($data = check_upgrades('blocktype.inbox')) {
upgrade_plugin($data);
}
// Install system dashboard view
require_once(get_config('libroot') . 'view.php');
$dbtime = db_format_timestamp(time());
$viewdata = (object) array(
'type' => 'dashboard',
'owner' => 0,
'numcolumns' => 3,
'ownerformat' => FORMAT_NAME_PREFERREDNAME,
'title' => get_string('dashboardviewtitle', 'view'),
'description' => '',
'template' => 1,
'ctime' => $dbtime,
'atime' => $dbtime,
'mtime' => $dbtime,
);
$id = insert_record('view', $viewdata, 'id', true);
$accessdata = (object) array('view' => $id, 'accesstype' => 'loggedin');
insert_record('view_access', $accessdata);
$blocktypes = array(
0 => array(
'blocktype' => 'inbox',
'title' => get_string('mymessages'),
'column' => 1,
'config' => array(
'newpost' => false,
'feedback' => false,
'groupmessage' => true,
'institutionmessage' => true,
'maharamessage' => false,
'usermessage' => true,
'viewaccess' => false,
'watchlist' => false,
'adminmessages' => false,
'maxitems' => '5',
),
),
1 => array(
'blocktype' => 'inbox',
'title' => get_string('recentactivity'),
'column' => 2,
'config' => array(
'newpost' => false,
'feedback' => true,
'groupmessage' => false,
'institutionmessage' => false,
'maharamessage' => true,
'usermessage' => false,
'viewaccess' => true,
'watchlist' => true,
'adminmessages' => false,
'maxitems' => '5',
),
),
2 => array(
'blocktype' => 'inbox',
'title' => get_string('topicsimfollowing'),
'column' => 3,
'config' => array(
'newpost' => true,
'feedback' => false,
'groupmessage' => false,
'institutionmessage' => false,
'maharamessage' => false,
'usermessage' => false,
'viewaccess' => false,
'watchlist' => false,
'adminmessages' => false,
'maxitems' => '5',
),
),
3 => array(
'blocktype' => 'myviews',
'title' => get_string('title', 'blocktype.myviews'),
'column' => 1,
'config' => null,
),
4 => array(
'blocktype' => 'mygroups',
'title' => get_string('title', 'blocktype.mygroups'),
'column' => 2,
'config' => null,
),
5 => array(
'blocktype' => 'myfriends',
'title' => get_string('title', 'blocktype.myfriends'),
'column' => 3,
'config' => null,
),
);
$installed = get_column_sql('SELECT name FROM {blocktype_installed}');
$weights = array(1 => 0, 2 => 0, 3 => 0);
foreach ($blocktypes as $blocktype) {
if (in_array($blocktype['blocktype'], $installed)) {
$weights[$blocktype['column']]++;
insert_record('block_instance', (object) array(
'blocktype' => $blocktype['blocktype'],
'title' => $blocktype['title'],
'view' => $id,
'column' => $blocktype['column'],
'order' => $weights[$blocktype['column']],
'configdata' => serialize($blocktype['config']),
));
}
}
}
return $status;