Commit 2fdc5b1b authored by Richard Mansfield's avatar Richard Mansfield

Initial group views page

parent ad08bee0
......@@ -494,8 +494,9 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" />
<FIELD NAME="title" TYPE="text" NOTNULL="true" />
<FIELD NAME="description" TYPE="text" NOTNULL="false" />
<FIELD NAME="owner" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="owner" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="ownerformat" TYPE="text" NOTNULL="true" />
<FIELD NAME="group" TYPE="int" LENGTH="10" NOTNULL="false" />
<FIELD NAME="startdate" TYPE="datetime" />
<FIELD NAME="stopdate" TYPE="datetime" />
<FIELD NAME="ctime" TYPE="datetime" NOTNULL="true" />
......@@ -510,6 +511,7 @@
<KEY NAME="ownerfk" TYPE="foreign" FIELDS="owner" REFTABLE="usr" REFFIELDS="id" />
<KEY NAME="submittedtofk" TYPE="foreign" FIELDS="submittedto" REFTABLE="group" REFFIELDS="id" />
<KEY NAME="layoutfk" TYPE="foreign" FIELDS="layout" REFTABLE="view_layout" REFFIELDS="id"/>
<KEY NAME="groupfk" TYPE="foreign" FIELDS="group" REFTABLE="group" REFFIELDS="id" />
</KEYS>
</TABLE>
<TABLE NAME="view_tag">
......@@ -602,7 +604,7 @@
<FIELDS>
<FIELD NAME="view" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="group" TYPE="int" LENGTH="10" NOTNULL="true" />
<FIELD NAME="tutoronly" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" />
<FIELD NAME="role" TYPE="text" NOTNULL="false" />
<FIELD NAME="startdate" TYPE="datetime" NOTNULL="false" />
<FIELD NAME="stopdate" TYPE="datetime" NOTNULL="false" />
</FIELDS>
......
......@@ -1108,6 +1108,15 @@ function xmldb_core_upgrade($oldversion=0) {
add_key($table, $key);
}
if ($oldversion < 2008062303) {
execute_sql('ALTER TABLE {view} ADD COLUMN "group" BIGINT');
execute_sql('ALTER TABLE {view} ADD CONSTRAINT {view_gro_fk} FOREIGN KEY ("group") REFERENCES {group}(id)');
execute_sql('ALTER TABLE {view} ALTER COLUMN owner DROP NOT NULL');
execute_sql('ALTER TABLE {view_access_group} ADD COLUMN role TEXT');
execute_sql("UPDATE {view_access_group} SET role = 'tutor' WHERE tutoronly = 1");
execute_sql('ALTER TABLE {view_access_group} DROP COLUMN tutoronly');
}
return $status;
}
......
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2008062302;
$config->version = 2008062303;
$config->release = '1.1.0alpha';
$config->minupgradefrom = 2007080700;
$config->minupgraderelease = '0.8.0 (release tag 0.8.0_RELEASE)';
......
......@@ -1244,6 +1244,121 @@ class View {
return array($result, $pagination, $totalartefacts, $offset);
}
public static function get_myviews_data($limit=5, $offset=0, $groupid=null) {
global $USER;
$userid = $USER->get('id');
if ($groupid) {
require_once(get_config('docroot') . 'lib/group.php');
if (!group_user_access($groupid)) {
throw new AccessDeniedException();
}
$count = count_records('view', 'group', $groupid);
$viewdata = get_records_sql_array('SELECT v.id,v.title,v.startdate,v.stopdate,v.description
FROM {view} v
WHERE v.group = ' . $groupid . '
ORDER BY v.title, v.id', '', $offset, $limit);
}
else {
$count = count_records('view', 'owner', $userid);
$viewdata = get_records_sql_array('SELECT v.id,v.title,v.startdate,v.stopdate,v.description, g.id AS groupid, g.name
FROM {view} v
LEFT OUTER JOIN {group} g ON (v.submittedto = g.id AND g.deleted = 0)
WHERE v.owner = ' . $userid . '
ORDER BY v.title, v.id', '', $offset, $limit);
}
if ($viewdata) {
$viewidlist = implode(', ', array_map(create_function('$a', 'return $a->id;'), $viewdata));
$artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin
FROM {view_artefact} va
INNER JOIN {artefact} a ON va.artefact = a.id
INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name
WHERE va.view IN (' . $viewidlist . ')
GROUP BY va.view, va.artefact, a.title, a.artefacttype, t.plugin
ORDER BY a.title, va.artefact', '');
$accessgroups = get_records_sql_array('SELECT view, accesstype, id, name, startdate, stopdate
FROM (
SELECT view, \'group\' AS accesstype, vg.role, g.id, g.name, startdate, stopdate
FROM {view_access_group} vg
INNER JOIN {group} g ON g.id = vg.group AND g.deleted = 0
UNION SELECT view, \'user\' AS accesstype, NULL AS role, usr AS id, \'\' AS name, startdate, stopdate
FROM {view_access_usr} vu
UNION SELECT view, accesstype, NULL AS role, 0 AS id, \'\' AS name, startdate, stopdate
FROM {view_access} va
) AS a
WHERE view in (' . $viewidlist . ')
ORDER BY view, accesstype, role, name, id
', array());
}
$data = array();
if ($viewdata) {
for ($i = 0; $i < count($viewdata); $i++) {
$index[$viewdata[$i]->id] = $i;
$data[$i]['id'] = $viewdata[$i]->id;
$data[$i]['title'] = $viewdata[$i]->title;
$data[$i]['description'] = $viewdata[$i]->description;
if ($viewdata[$i]->name) {
$data[$i]['submittedto'] = array('name' => $viewdata[$i]->name, 'id' => $viewdata[$i]->groupid);
}
$data[$i]['artefacts'] = array();
$data[$i]['accessgroups'] = array();
if ($viewdata[$i]->startdate && $viewdata[$i]->stopdate) {
$data[$i]['access'] = get_string('accessbetweendates', 'view', format_date(strtotime($viewdata[$i]->startdate), 'strftimedate'),
format_date(strtotime($viewdata[$i]->stopdate), 'strftimedate'));
}
else if ($viewdata[$i]->startdate) {
$data[$i]['access'] = get_string('accessfromdate', 'view', format_date(strtotime($viewdata[$i]->startdate), 'strftimedate'));
}
else if ($viewdata[$i]->stopdate) {
$data[$i]['access'] = get_string('accessuntildate', 'view', format_date(strtotime($viewdata[$i]->stopdate), 'strftimedate'));
}
}
// Go through all the artefact records and put them in with the
// views they belong to.
if ($artefacts) {
foreach ($artefacts as $artefactrec) {
safe_require('artefact', $artefactrec->plugin);
// Perhaps I shouldn't have to construct the entire
// artefact object to render the name properly.
$classname = generate_artefact_class_name($artefactrec->artefacttype);
$artefactobj = new $classname(0, array('title' => $artefactrec->title));
$artefactobj->set('dirty', false);
if (!$artefactobj->in_view_list()) {
continue;
}
$artname = $artefactobj->display_title(30);
if (strlen($artname)) {
$data[$index[$artefactrec->view]]['artefacts'][] = array('id' => $artefactrec->artefact,
'title' => $artname);
}
}
}
if ($accessgroups) {
foreach ($accessgroups as $access) {
$data[$index[$access->view]]['accessgroups'][] = array(
'accesstype' => $access->accesstype, // friends, group, loggedin, public, tutorsgroup, user
'role' => $access->role,
'id' => $access->id,
'name' => $access->name,
'startdate' => $access->startdate,
'stopdate' => $access->stopdate
);
}
}
}
return (object) array(
'data' => $data,
'count' => $count,
);
}
}
/**
......
<?php
/**
* Mahara: Electronic portfolio, weblog, resume builder and social networking
* Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
*
* 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 core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
define('MENUITEM', 'groups/mygroups');
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'groupviews');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('docroot') . 'lib/view.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('groupviews', 'view'));
//@todo: group menu; group sideblock
$limit = param_integer('limit', 5);
$offset = param_integer('offset', 0);
$group = param_integer('group');
$data = View::get_myviews_data($limit, $offset, $group);
$userid = $USER->get('id');
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'view/?',
'count' => $data->count,
'limit' => $limit,
'offset' => $offset,
'resultcounttextsingular' => get_string('view', 'view'),
'resultcounttextplural' => get_string('views', 'view')
));
$smarty = smarty();
$smarty->assign('views', $data->data);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('heading', get_string('groupviews'));
$smarty->display('view/index.tpl');
?>
......@@ -32,127 +32,27 @@ define('SECTION_PLUGINNAME', 'view');
define('SECTION_PAGE', 'index');
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('docroot') . 'lib/view.php');
require_once('pieforms/pieform.php');
define('TITLE', get_string('myviews', 'view'));
$limit = param_integer('limit', 5);
$offset = param_integer('offset', 0);
$userid = $USER->get('id');
$count = count_records('view', 'owner', $userid);
/* Get $limit views from the view table, then get all these views'
associated artefacts */
/* Do this in one query sometime */
$viewdata = get_records_sql_array('SELECT v.id,v.title,v.startdate,v.stopdate,v.description, g.id AS groupid, g.name
FROM {view} v
LEFT OUTER JOIN {group} g ON (v.submittedto = g.id AND g.deleted = 0)
WHERE v.owner = ' . $userid . '
ORDER BY v.title, v.id', '', $offset, $limit);
if ($viewdata) {
$viewidlist = implode(', ', array_map(create_function('$a', 'return $a->id;'), $viewdata));
$artefacts = get_records_sql_array('SELECT va.view, va.artefact, a.title, a.artefacttype, t.plugin
FROM {view_artefact} va
INNER JOIN {artefact} a ON va.artefact = a.id
INNER JOIN {artefact_installed_type} t ON a.artefacttype = t.name
WHERE va.view IN (' . $viewidlist . ')
GROUP BY 1, 2, 3, 4, 5
ORDER BY a.title, va.artefact', '');
$accessgroups = get_records_sql_array('SELECT view, accesstype, id, name, startdate, stopdate
FROM (
SELECT view, \'group\' AS accesstype, g.id, g.name, startdate, stopdate
FROM {view_access_group} vg
INNER JOIN {group} g ON g.id = vg.group AND g.deleted = 0
WHERE vg.tutoronly = 0
UNION SELECT view, \'tutorgroup\' AS accesstype, g.id, g.name, startdate, stopdate
FROM {view_access_group} vg
INNER JOIN {group} g ON g.id = vg.group AND g.deleted = 0
WHERE vg.tutoronly = 1
UNION SELECT view, \'user\' AS accesstype, usr AS id, \'\' AS name, startdate, stopdate
FROM {view_access_usr} vu
UNION SELECT view, accesstype, 0 AS id, \'\' AS name, startdate, stopdate
FROM {view_access} va
) AS a
WHERE view in (' . $viewidlist . ')
ORDER BY view, accesstype, name, id
', array());
}
$data = array();
if ($viewdata) {
for ($i = 0; $i < count($viewdata); $i++) {
$index[$viewdata[$i]->id] = $i;
$data[$i]['id'] = $viewdata[$i]->id;
$data[$i]['title'] = $viewdata[$i]->title;
$data[$i]['description'] = $viewdata[$i]->description;
if ($viewdata[$i]->name) {
$data[$i]['submittedto'] = array('name' => $viewdata[$i]->name, 'id' => $viewdata[$i]->groupid);
}
$data[$i]['artefacts'] = array();
$data[$i]['accessgroups'] = array();
if ($viewdata[$i]->startdate && $viewdata[$i]->stopdate) {
$data[$i]['access'] = get_string('accessbetweendates', 'view', format_date(strtotime($viewdata[$i]->startdate), 'strftimedate'),
format_date(strtotime($viewdata[$i]->stopdate), 'strftimedate'));
}
else if ($viewdata[$i]->startdate) {
$data[$i]['access'] = get_string('accessfromdate', 'view', format_date(strtotime($viewdata[$i]->startdate), 'strftimedate'));
}
else if ($viewdata[$i]->stopdate) {
$data[$i]['access'] = get_string('accessuntildate', 'view', format_date(strtotime($viewdata[$i]->stopdate), 'strftimedate'));
}
}
// Go through all the artefact records and put them in with the
// views they belong to.
if ($artefacts) {
foreach ($artefacts as $artefactrec) {
safe_require('artefact', $artefactrec->plugin);
// Perhaps I shouldn't have to construct the entire
// artefact object to render the name properly.
$classname = generate_artefact_class_name($artefactrec->artefacttype);
$artefactobj = new $classname(0, array('title' => $artefactrec->title));
$artefactobj->set('dirty', false);
if (!$artefactobj->in_view_list()) {
continue;
}
$artname = $artefactobj->display_title(30);
if (strlen($artname)) {
$data[$index[$artefactrec->view]]['artefacts'][] = array('id' => $artefactrec->artefact,
'title' => $artname);
}
}
}
if ($accessgroups) {
foreach ($accessgroups as $access) {
$data[$index[$access->view]]['accessgroups'][] = array(
'accesstype' => $access->accesstype, // friends, group, loggedin, public, tutorsgroup, user
'id' => $access->id,
'name' => $access->name,
'startdate' => $access->startdate,
'stopdate' => $access->stopdate
);
}
}
}
$data = View::get_myviews_data($limit, $offset);
$userid = $USER->get('id');
/* Get a list of groups that the user belongs to which also have
a tutor member. This is the list of groups that the user is
able to submit views to. */
/* Get a list of groups that the user belongs to which views can
be sumitted. */
if (!$tutorgroupdata = @get_records_sql_array('SELECT g.id, g.name
FROM {group_member} u
INNER JOIN {group} g ON (u.group = g.id AND g.deleted = 0)
INNER JOIN {group_member} t ON t.group = g.id
INNER JOIN {grouptype} t ON t.name = g.grouptype
WHERE u.member = ?
AND t.tutor = 1
AND t.member != ?
GROUP BY g.id, g.name
ORDER BY g.name', array($userid, $userid))) {
AND t.submittableto = 1
ORDER BY g.name', array($userid))) {
$tutorgroupdata = array();
}
else {
......@@ -161,7 +61,7 @@ else {
$options[$group->id] = $group->name;
}
$i = 0;
foreach ($data as &$view) {
foreach ($data->data as &$view) {
if (empty($view['submittedto'])) {
// This form sucks from a language string point of view. It should
// use pieforms' form template feature
......@@ -204,7 +104,7 @@ else {
$pagination = build_pagination(array(
'url' => get_config('wwwroot') . 'view/?',
'count' => $count,
'count' => $data->count,
'limit' => $limit,
'offset' => $offset,
'resultcounttextsingular' => get_string('view', 'view'),
......@@ -216,7 +116,7 @@ function submitto_submit(Pieform $form, $values) {
}
$smarty = smarty();
$smarty->assign('views', $data);
$smarty->assign('views', $data->data);
$smarty->assign('pagination', $pagination['html']);
$smarty->assign('heading', get_string('myviews'));
$smarty->display('view/index.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