Commit 57be77ac authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add share page to display access lists; remove them from My Views


Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 87a2c5f2
......@@ -51,7 +51,7 @@ class PluginArtefactBlog extends PluginArtefact {
global $USER;
$tab = array(
'path' => 'myportfolio/blogs',
'weight' => 30,
'weight' => 50,
);
if ($USER->get_account_preference('multipleblogs')) {
$tab['url'] = 'artefact/blog/';
......
......@@ -53,7 +53,7 @@ class PluginArtefactFile extends PluginArtefact {
'path' => 'myportfolio/files',
'url' => 'artefact/file/',
'title' => get_string('myfiles', 'artefact.file'),
'weight' => 20,
'weight' => 40,
),
array(
'path' => 'profile/icons',
......
......@@ -49,7 +49,7 @@ class PluginArtefactPlans extends PluginArtefact {
'path' => 'myportfolio/plans',
'url' => 'artefact/plans/',
'title' => get_string('myplans', 'artefact.plans'),
'weight' => 40,
'weight' => 60,
),
);
}
......
......@@ -92,11 +92,7 @@ $string['loggedin'] = 'Logged In Users';
$string['friends'] = 'Friends';
$string['groups'] = 'Groups';
$string['users'] = 'Users';
$string['friendslower'] = 'friends';
$string['grouplower'] = 'group';
$string['tutors'] = 'tutors';
$string['loggedinlower'] = 'logged in users';
$string['publiclower'] = 'public';
$string['everyoneingroup'] = 'Everyone in Group';
$string['token'] = 'Secret URL';
$string['showfullurl'] = 'Show full URL';
......@@ -135,7 +131,9 @@ $string['profileicon'] = 'Profile Icon';
// general views stuff
$string['Added'] = 'Added';
$string['share'] = 'Share';
$string['sharewith'] = 'Share with';
$string['accessibleby'] = 'Accessible by';
$string['sharewithmygroups'] = 'Share with My Groups';
$string['otherusersandgroups'] = 'Share with other users and groups';
$string['moreoptions'] = 'Advanced Options';
......
......@@ -2283,13 +2283,6 @@ class View {
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 va.*, g.grouptype, g.name
FROM {view_access} va LEFT OUTER JOIN {group} g ON (g.id = va.group AND g.deleted = 0)
WHERE va.view IN (' . $viewidlist . ')
ORDER BY va.view, va.accesstype, g.grouptype, va.role, g.name, va.group, va.usr',
array()
);
$tags = get_records_select_array('view_tag', '"view" IN (' . $viewidlist . ')');
$collections = get_records_sql_array('
SELECT c.name, c.id, cv.view
......@@ -2340,17 +2333,6 @@ class View {
}
}
$data[$i]['artefacts'] = array();
$data[$i]['accessgroups'] = array();
if ($viewdata[$i]->startdate && $viewdata[$i]->stopdate) {
$data[$i]['access'] = get_string('accessbetweendates2', '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('accessfromdate2', 'view', format_date(strtotime($viewdata[$i]->startdate), 'strftimedate'));
}
else if ($viewdata[$i]->stopdate) {
$data[$i]['access'] = get_string('accessuntildate2', 'view', format_date(strtotime($viewdata[$i]->stopdate), 'strftimedate'));
}
$data[$i]['template'] = $viewdata[$i]->template;
}
......@@ -2374,37 +2356,6 @@ class View {
}
}
}
if ($accessgroups) {
foreach ($accessgroups as $access) {
$key = null;
if ($access->usr) {
$access->accesstype = 'user';
$access->id = $access->usr;
}
else if ($access->group) {
$access->accesstype = 'group';
$access->id = $access->group;
if ($access->role) {
$access->roledisplay = get_string($access->role, 'grouptype.' . $access->grouptype);
}
}
else if ($access->token) {
$access->accesstype = 'secreturl';
$key = 'secreturl';
}
else {
$key = $access->accesstype;
}
if ($key) {
if (!isset($data[$index[$access->view]]['accessgroups'][$key])) {
$data[$index[$access->view]]['accessgroups'][$key] = (array) $access;
}
}
else {
$data[$index[$access->view]]['accessgroups'][] = (array) $access;
}
}
}
if ($tags) {
foreach ($tags as $tag) {
$data[$index[$tag->view]]['tags'][] = $tag->tag;
......@@ -3337,6 +3288,145 @@ class View {
return array($collections, $views);
}
/**
* Get all views & collections for a (user,group), grouped
* by their accesslists as defined by the accessconf column
*
* @param integer $owner
* @param integer $group
*
* @return array
*/
public static function get_accesslists($owner=null, $group=null, $institution=null) {
$ownersql = self::owner_sql((object) array('owner' => $owner, 'group' => $group, 'institution' => $institution));
$records = get_records_sql_assoc("
SELECT
v.id AS vid, v.title AS vname, v.accessconf,
v.startdate, v.stopdate, v.description, v.template, v.type,
c.id AS cid, c.name AS cname
FROM {view} v
LEFT JOIN {collection_view} cv ON v.id = cv.view
LEFT JOIN {collection} c ON cv.collection = c.id
WHERE v.$ownersql AND v.type = 'portfolio'",
array()
);
if (!$records) {
return array();
}
// First group all views & collections by their access sets. If no accessconf
// field exists on a view, put it (or its collection) in a group of one.
$data = array();
$viewindex = array(); // Remember one viewid for each access set
foreach ($records as &$r) {
$newkey = null;
if (empty($r->accessconf) && empty($r->cid)) {
// Singleton view
$newkey = 'v:' . $r->vid;
$data[$newkey] = array(
'views' => array($r->vid => array('id' => $r->vid, 'name' => $r->vname)),
'viewid' => $r->vid,
);
$viewindex[$r->vid] = $newkey;
}
else if (empty($r->accessconf) && !empty($r->cid)) {
// Singleton collection; throw view data away
if (!isset($data['c:'.$r->cid])) {
$newkey = 'c:'.$r->cid;
$data[$newkey] = array(
'collections' => array($r->cid => array('id' => $r->cid, 'name' => $r->cname)),
'viewid' => $r->vid,
);
$viewindex[$r->vid] = $newkey;
}
}
else if (!empty($r->accessconf)) {
if (!isset($data[$r->accessconf])) {
$newkey = $r->accessconf;
$data[$newkey] = array(
'collections' => array(),
'views' => array(),
'viewid' => $r->vid,
);
$viewindex[$r->vid] = $newkey;
}
if (!empty($r->cid) && !isset($data[$r->accessconf]['collections'][$r->cid])) {
$data[$r->accessconf]['collections'][$r->cid] = array('id' => $r->cid, 'name' => $r->cname);
}
else {
$data[$r->accessconf]['views'][$r->vid] = array('id' => $r->vid, 'name' => $r->vname);
}
}
if ($newkey) {
if ($r->startdate && $r->stopdate) {
$data[$newkey]['access'] = get_string(
'accessbetweendates2', 'view',
format_date(strtotime($viewdata[$i]->startdate), 'strftimedate'),
format_date(strtotime($viewdata[$i]->stopdate), 'strftimedate')
);
}
else if ($r->startdate) {
$data[$newkey] = get_string(
'accessfromdate2', 'view',
format_date(strtotime($viewdata[$i]->startdate), 'strftimedate')
);
}
else if ($r->stopdate) {
$data[$newkey]['access'] = get_string(
'accessuntildate2', 'view',
format_date(strtotime($viewdata[$i]->stopdate), 'strftimedate')
);
}
}
}
$accessgroups = get_records_sql_array('
SELECT va.*, g.grouptype, g.name
FROM {view_access} va LEFT OUTER JOIN {group} g ON (g.id = va.group AND g.deleted = 0)
WHERE va.view IN (' . join(',', array_keys($viewindex)) . ')
ORDER BY va.view, va.accesstype, g.grouptype, va.role, g.name, va.group, va.usr',
array()
);
if ($accessgroups) {
foreach ($accessgroups as $access) {
$key = null;
if ($access->usr) {
$access->accesstype = 'user';
$access->id = $access->usr;
}
else if ($access->group) {
$access->accesstype = 'group';
$access->id = $access->group;
if ($access->role) {
$access->roledisplay = get_string($access->role, 'grouptype.' . $access->grouptype);
}
}
else if ($access->token) {
$access->accesstype = 'secreturl';
$key = 'secreturl';
}
else {
$key = $access->accesstype;
}
if ($key) {
if (!isset($data[$viewindex[$access->view]]['accessgroups'][$key])) {
$data[$viewindex[$access->view]]['accessgroups'][$key] = (array) $access;
}
}
else {
$data[$viewindex[$access->view]]['accessgroups'][] = (array) $access;
}
}
}
return $data;
}
}
......
......@@ -1951,18 +1951,24 @@ function mahara_standard_nav() {
'title' => get_string('myviews'),
'weight' => 10,
),
array(
'path' => 'myportfolio/share',
'url' => 'view/share.php',
'title' => get_string('share', 'view'),
'weight' => 30,
),
array(
'path' => 'myportfolio/export',
'url' => 'export/',
'title' => get_string('Export', 'export'),
'weight' => 50,
'weight' => 70,
'ignore' => !$exportenabled,
),
array(
'path' => 'myportfolio/collection',
'url' => 'collection/',
'title' => get_string('mycollections', 'collection'),
'weight' => 10,
'weight' => 20,
),
array(
'path' => 'groups',
......
......@@ -66,33 +66,6 @@
<div class="collection"><label>{str tag=Collection section=collection}:</label> <a href="{$WWWROOT}collection/views.php?id={$view.collection->id}">{$view.collection->name}</a></div>
{elseif $view.type != 'profile' && $view.type != 'dashboard' && $view.type != 'grouphomepage'}
<h4><a href="{$WWWROOT}view/access.php?id={$view.id}" id="editviewaccess">{str tag="editaccess" section="view"}</a></h4>
{/if}
{if $view.access}
<div class="videsc">{$view.access}</div>
{/if}
{if !$view.collection}
{if $view.accessgroups}
<div class="viewaccess"><label>{str tag="whocanseethisview" section="view"}:</label>
{foreach from=$view.accessgroups item=accessgroup name=artefacts}{strip}
{if $accessgroup.accesstype == 'loggedin'}
{str tag="loggedinlower" section="view"}
{elseif $accessgroup.accesstype == 'public'}
{str tag="publiclower" section="view"}
{elseif $accessgroup.accesstype == 'friends'}
<a href="{$WWWROOT}user/myfriends.php" id="link-myfriends">{str tag="friendslower" section="view"}</a>
{elseif $accessgroup.accesstype == 'group'}
<a href="{$WWWROOT}group/view.php?id={$accessgroup.id}">{$accessgroup.name}</a>{if $accessgroup.role} ({$accessgroup.roledisplay}){/if}
{elseif $accessgroup.accesstype == 'user'}
<a href="{$WWWROOT}user/view.php?id={$accessgroup.id}">{$accessgroup.id|display_name|escape}</a>
{elseif $accessgroup.accesstype == 'secreturl'}
{str tag="peoplewiththesecreturl" section="view"}
{/if}{/strip}{if !$.foreach.artefacts.last}, {/if}
{/foreach}
{if $view.template}<br>{str tag=thisviewmaybecopied section=view}{/if}
</div>
{else}
<div class="videsc">{str tag="nobodycanseethisview2" section="view"}</div>
{/if}
{/if}
</div>
{if $view.submitto && $view.type != 'profile' && $view.type != 'dashboard'}
......
{include file="header.tpl"}
<table>
<thead>
<tr>
<th>{str tag=Views section=view}/{str tag=collections section=collection}</th>
<th>{str tag=accessibleby section=view}</th>
<th></th>
</tr>
</thead>
<tbody>
{foreach from=$accesslists item=accesslist}
<tr class="{cycle values='r0,r1'}">
<td>
{if $accesslist.collections}
<div><strong>{str tag=collections section=collection}:</strong>
{foreach from=$accesslist.collections item=collection name=c}{strip}
<a href="">{$collection.name|str_shorten_text:30:true}</a>{if !$.foreach.c.last}, {/if}
{/strip}{/foreach}
</div>
{/if}
{if $accesslist.views}
<div><strong>{str tag=Views section=view}:</strong>
{foreach from=$accesslist.views item=view name=v}{strip}
<a href="">{$view.name|str_shorten_text:30:true}</a>{if !$.foreach.v.last}, {/if}
{/strip}{/foreach}
</div>
{/if}
</td>
<td>
{if $accesslist.access}
<div class="videsc">{$accesslist.access}</div>
{/if}
{if $accesslist.accessgroups}
{foreach from=$accesslist.accessgroups item=accessgroup}
<div>
{if $accessgroup.accesstype == 'loggedin'}
{str tag="loggedin" section="view"}
{elseif $accessgroup.accesstype == 'public'}
{str tag="public" section="view"}
{elseif $accessgroup.accesstype == 'friends'}
<a href="{$WWWROOT}user/myfriends.php" id="link-myfriends">{str tag="friends" section="view"}</a>
{elseif $accessgroup.accesstype == 'group'}
<a href="{$WWWROOT}group/view.php?id={$accessgroup.id}">{$accessgroup.name}</a>{if $accessgroup.role} ({$accessgroup.roledisplay}){/if}
{elseif $accessgroup.accesstype == 'user'}
<a href="{$WWWROOT}user/view.php?id={$accessgroup.id}">{$accessgroup.id|display_name|escape}</a>
{elseif $accessgroup.accesstype == 'secreturl'}
{str tag="peoplewiththesecreturl" section="view"}
{/if}
</div>
{/foreach}
{if $view.template}<div>{str tag=thisviewmaybecopied section=view}</div>{/if}
</div>
{else}
<div class="videsc">{str tag="nobodycanseethisview2" section="view"}</div>
{/if}
</td>
<td>
<a href="{$WWWROOT}view/access.php?id={$accesslist.viewid}">{str tag=edit}</a>
</td>
</tr>
{/foreach}
</tbody>
</table>
{include file="footer.tpl"}
......@@ -492,7 +492,7 @@ function editaccess_submit(Pieform $form, $values) {
$SESSION->add_ok_msg(get_string('updatedaccessfornumviews', 'view', count($toupdate)));
if ($view->get('owner')) {
redirect(); // @todo redirect to new share tab
redirect('/view/share.php');
}
$view->post_edit_redirect();
}
......
<?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 core
* @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
*
*/
define('INTERNAL', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
require_once(get_config('libroot') . 'view.php');
define('TITLE', get_string('share', 'view'));
define('MENUITEM', 'myportfolio/share');
$accesslists = View::get_accesslists($USER->get('id'));
$smarty = smarty();
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('accesslists', $accesslists);
$smarty->display('view/share.tpl');
Supports Markdown
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