Commit 9a46dd09 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Use a new row for each view & each collection on the share page (bug #710292)



Grouping views and collections with the same access lists saves space, but
is confusing for users because secret urls must remain per-view and per-
collection and cannot be grouped together.

This change displays a single row for each view & each collection, and just
repeats the access list for view/collection with the same access list.

This allows the get_accesslists function to be simplified; most of its work
can now be done by the existing get_views_and_collections function instead.

Change-Id: Ie3f21919f1d20cd4ea67afdfd385ce5f34eaa7fc
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent fbc45f73
......@@ -3568,7 +3568,9 @@ class View {
function get_views_and_collections($owner=null, $group=null, $institution=null, $matchconfig=null) {
$ownersql = self::owner_sql((object) array('owner' => $owner, 'group' => $group, 'institution' => $institution));
$records = get_records_sql_array("
SELECT v.id AS vid, v.title AS vname, v.accessconf, c.id AS cid, c.name AS cname
SELECT v.id AS vid, v.title AS vname, v.accessconf,
v.startdate, v.stopdate, v.template,
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
......@@ -3585,7 +3587,13 @@ class View {
}
foreach ($records as &$r) {
$v = array('id' => $r->vid, 'name' => $r->vname);
$v = array(
'id' => $r->vid,
'name' => $r->vname,
'startdate' => $r->startdate,
'stopdate' => $r->stopdate,
'template' => $r->template,
);
if ($r->cid) {
if (!isset($collections[$r->cid])) {
$collections[$r->cid] = array('id' => $r->cid, 'name' => $r->cname, 'views' => array());
......@@ -3607,6 +3615,30 @@ class View {
}
// Returns a string describing the override access for a view record
public static function access_override_description($v) {
if ($v['startdate'] && $v['stopdate']) {
return get_string(
'accessbetweendates2', 'view',
format_date(strtotime($v['startdate']), 'strftimedate'),
format_date(strtotime($v['stopdate']), 'strftimedate')
);
}
if ($v['startdate']) {
return get_string(
'accessfromdate2', 'view',
format_date(strtotime($v['startdate']), 'strftimedate')
);
}
if ($v['stopdate']) {
return get_string(
'accessuntildate2', 'view',
format_date(strtotime($v['stopdate']), 'strftimedate')
);
}
}
/**
* Get all views & collections for a (user,group), grouped
* by their accesslists as defined by the accessconf column
......@@ -3617,159 +3649,77 @@ class View {
* @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'
ORDER BY cv.displayorder, v.title",
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
$viewaccesslist = array(); // Remember access set for every view
list($data['collections'], $data['views']) = self::get_views_and_collections($owner, $group, $institution);
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;
$viewaccesslist[$r->vid] = $newkey;
}
else if (empty($r->accessconf) && !empty($r->cid)) {
// Singleton collection; throw view data away
$key = 'c:'.$r->cid;
if (!isset($data[$key])) {
$newkey = $key;
$data[$newkey] = array(
'collections' => array($r->cid => array('id' => $r->cid, 'name' => $r->cname, 'viewid' => $r->vid)),
'viewid' => $r->vid,
);
$viewindex[$r->vid] = $newkey;
}
$viewaccesslist[$r->vid] = $key;
}
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, 'viewid' => $r->vid);
}
else if (empty($r->cid)) {
$data[$r->accessconf]['views'][$r->vid] = array('id' => $r->vid, 'name' => $r->vname);
}
$viewaccesslist[$r->vid] = $r->accessconf;
}
if ($newkey) {
if ($r->startdate && $r->stopdate) {
$data[$newkey]['access'] = get_string(
'accessbetweendates2', 'view',
format_date(strtotime($r->startdate), 'strftimedate'),
format_date(strtotime($r->stopdate), 'strftimedate')
);
}
else if ($r->startdate) {
$data[$newkey]['access'] = get_string(
'accessfromdate2', 'view',
format_date(strtotime($r->startdate), 'strftimedate')
);
}
else if ($r->stopdate) {
$data[$newkey]['access'] = get_string(
'accessuntildate2', 'view',
format_date(strtotime($r->stopdate), 'strftimedate')
);
}
}
// Remember one representative viewid in each collection
$viewindex = array();
// Add strings to describe startdate/stopdate access overrides
foreach ($data['collections'] as &$c) {
$view = current($c['views']);
$viewindex[$view['id']] = array('type' => 'collections', 'id' => $c['id']);
$c['access'] = self::access_override_description($view);
$c['viewid'] = $view['id'];
}
foreach ($data['views'] as &$v) {
$viewindex[$v['id']] = array('type' => 'views', 'id' => $v['id']);
$v['access'] = self::access_override_description($v);
$v['viewid'] = $v['id'];
}
// Get view_access records, apart from those with visible = 0 (system access records),
// and token (secret url) records which go with individual views or collections.
if (empty($viewindex)) {
return $data;
}
// Get view_access records, apart from those with visible = 0 (system access records)
$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)) . ') AND va.visible = 1 AND va.token IS NULL
WHERE va.view IN (' . join(',', array_keys($viewindex)) . ') AND va.visible = 1
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 {
$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;
}
}
if (!$accessgroups) {
return $data;
}
$tokenaccess = get_records_sql_array('
SELECT va.*, cv.collection
FROM {view_access} va LEFT JOIN {collection_view} cv ON va.view = cv.view
WHERE va.view IN (' . join(',', array_keys($viewaccesslist)) . ') AND va.visible = 1 AND NOT va.token IS NULL
ORDER BY va.view',
array()
);
foreach ($accessgroups as $access) {
$vi = $viewindex[$access->view];
if ($tokenaccess) {
foreach ($tokenaccess as &$access) {
$accesslist =& $data[$viewaccesslist[$access->view]];
if (isset($accesslist['views'][$access->view])) {
unset($access->collection);
$accesslist['views'][$access->view]['secreturls'][$access->token] = (array) $access;
// Just count secret urls.
if ($access->token) {
if (!isset($data[$vi['type']][$vi['id']]['secreturls'])) {
$data[$vi['type']][$vi['id']]['secreturls'] = 0;
}
else if (isset($accesslist['collections'][(int)$access->collection])) {
$collection = (int)$access->collection;
unset($access->collection);
if (!isset($accesslist['collections'][$collection]['secreturls'][$access->token])) {
$accesslist['collections'][$collection]['secreturls'][$access->token] = (array) $access;
}
$data[$vi['type']][$vi['id']]['secreturls']++;
continue;
}
$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 {
$key = $access->accesstype;
}
if ($key) {
if (!isset($data[$vi['type']][$vi['id']]['accessgroups'][$key])) {
$data[$vi['type']][$vi['id']]['accessgroups'][$key] = (array) $access;
}
}
else {
$data[$vi['type']][$vi['id']]['accessgroups'][] = (array) $access;
}
}
return $data;
......
......@@ -1733,33 +1733,26 @@ table.attachments td {
}
/* Publish page */
.accesslists .cv {
width: 50%;
padding-left: 0;
padding-bottom: 0;
}
.accesslist .al-num {
width: 5%;
width: 30%;
font-weight: bold;
}
.accesslists .al-edit {
padding-top: 5px;
text-align: center;
width: 15%;
text-align: center;
vertical-align: middle;
}
.accesslists .al {
font-size: .9167em;
padding-top: 5px;
}
.accesslists .cv-listitem {
clear: both;
padding: 3px 5px;
border-bottom: 1px solid #FFF;
}
.accesslists .cv-listitem .viewname {
font-weight: bold;
width: 35%;
}
.accesslists .secreturls {
float: right;
text-align: center;
width: 20%;
width: 15%;
text-align: center;
vertical-align: middle;
}
.accesslists .secreturls div {
text-align: right;
width: 2.25em;
margin: 0 auto;
}
/* Secret url */
table.secreturls {
......
<tr class="{cycle values='r0,r1'}">
<td class="cv"><a href="{$WWWROOT}view/view.php?id={$item.viewid}">{$item.name|str_shorten_text:50:true}</a></td>
<td class="al">
{if $item.access}<div>{$item.access}</div>{/if}
{if $item.accessgroups}
<div>
{foreach from=$item.accessgroups item=accessgroup name=ags}{strip}
{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>
{/if}
{if $accessgroup.startdate}
{if $accessgroup.stopdate}
<span class="date"> {$accessgroup.startdate|strtotime|format_date:'strfdaymonthyearshort'}&rarr;{$accessgroup.stopdate|strtotime|format_date:'strfdaymonthyearshort'}</span>
{else}
<span class="date"> {str tag=after} {$accessgroup.startdate|strtotime|format_date:'strfdaymonthyearshort'}</span>
{/if}
{elseif $accessgroup.stopdate}
<span class="date"> {str tag=before} {$accessgroup.stopdate|strtotime|format_date:'strfdaymonthyearshort'}</span>
{/if}{if !$dwoo.foreach.ags.last}, {/if}
{/strip}{/foreach}
</div>
{if $view.template}<div>{str tag=thisviewmaybecopied section=view}</div>{/if}
{/if}
</td>
<td class="al-edit">
<a href="{$WWWROOT}view/access.php?id={$item.viewid}" title="{str tag=editaccess section=view}"><img src="{theme_url filename='images/edit_access.gif'}" alt="{str tag=editaccess}"></a>
</td>
<td class="secreturls">
<div>
{$item.secreturls} <a title="{str tag=editsecreturlaccess section=view}" href="{$WWWROOT}view/urls.php?id={$item.viewid}"><img src="{theme_url filename='images/edit.gif'}" alt="{str tag=edit}"></a>
</div>
</td>
</tr>
......@@ -2,90 +2,50 @@
{if $institution} {$institutionselector|safe}{/if}
{if !$accesslists}
{if !$accesslists.views && !$accesslists.collections}
<p>{str tag=youhaventcreatedanyviewsyet section=view}</p>
{else}
{if $accesslists.collections}
<table class="fullwidth accesslists">
<thead>
<tr>
<th>
<span class="fl">{str tag=Views section=view} &amp; {str tag=collections section=collection}</span>
<span class="fr secreturl">{str tag=secreturls section=view}</span>
</th>
<th>{str tag=accesslist section=view}</th>
<th class="center">{str tag=editaccess section=view}</th>
<th class="cv">{str tag=collections section=collection}</th>
<th class="al">{str tag=accesslist section=view}</th>
<th class="al-edit">{str tag=editaccess section=view}</th>
<th class="secreturls">{str tag=secreturls section=view}</th>
</tr>
</thead>
<tbody>
{foreach from=$accesslists item=accesslist name=als}
<tr class="{cycle values='r0,r1'}">
<td class="cv">
{if $accesslist.views}
<div class="cb cv-listitem">{str tag=Views section=view}:</div>
{foreach from=$accesslist.views item=view name=v}
<div class="cv-listitem">
<div class="fr secreturls">
<span class="secreturlcount">{count($view.secreturls)}</span> <span class="cv-listitem-edit"><a title="{str tag=editsecreturlaccess section=view}" href="{$WWWROOT}view/urls.php?id={$view.id}"><img src="{theme_url filename='images/edit.gif'}" alt="{str tag=edit}"></a></span>
</div>
<div class="viewname">
<a href="{$WWWROOT}view/view.php?id={$view.id}">{$view.name|str_shorten_text:60:true}</a>
</div>
</div>
{/foreach}
{/if}
{if $accesslist.collections}
<div class="cb cv-listitem">{str tag=Collections section=collection}:</div>
{foreach from=$accesslist.collections item=collection name=c}
<div class="cb cv-listitem">
<div class="fr secreturls">
<span class="secreturlcount">{count($collection.secreturls)}</span> <span class="cv-listitem-edit"><a title="{str tag=editsecreturlaccess section=view}" href="{$WWWROOT}view/urls.php?id={$collection.viewid}"><img src="{theme_url filename='images/edit.gif'}" alt="{str tag=edit}"></a></span>
</div>
<div>
<strong><a href="{$WWWROOT}view/view.php?id={$collection.viewid}">{$collection.name|str_shorten_text:60:true}</a></strong>
</div>
</div>
{/foreach}
{/if}
</td>
<td class="al">
{if $accesslist.access}
<div class="videsc">{$accesslist.access}</div>
{/if}
{if $accesslist.accessgroups}
<div class="accesslistitem">
{foreach from=$accesslist.accessgroups item=accessgroup name=ags}{strip}
{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>
{/if}
{if $accessgroup.startdate}
{if $accessgroup.stopdate}
<span class="date"> {$accessgroup.startdate|strtotime|format_date:'strfdaymonthyearshort'}&rarr;{$accessgroup.stopdate|strtotime|format_date:'strfdaymonthyearshort'}</span>
{else}
<span class="date"> {str tag=after} {$accessgroup.startdate|strtotime|format_date:'strfdaymonthyearshort'}</span>
{/if}
{elseif $accessgroup.stopdate}
<span class="date"> {str tag=before} {$accessgroup.stopdate|strtotime|format_date:'strfdaymonthyearshort'}</span>
{/if}{if !$dwoo.foreach.ags.last}, {/if}
{/strip}{/foreach}
</div>
{if $view.template}<div>{str tag=thisviewmaybecopied section=view}</div>{/if}
</div>
{/if}
</td>
<td class="al-edit">
<a href="{$WWWROOT}view/access.php?id={$accesslist.viewid}" title="{str tag=editaccess section=view}"><img src="{theme_url filename='images/edit_access.gif'}" alt="{str tag=editaccess}"></a>
</td>
{foreach from=$accesslists.collections item=collection}
{include file="view/accesslistrow.tpl" item=$collection}
{/foreach}
</tbody>
</table>
{/if}
{if $accesslists.views}
<table class="fullwidth accesslists">
<thead>
<tr>
<th class="cv">{str tag=Views section=view}</th>
{if $accesslists.collections}
<th></th>
<th></th>
<th></th>
{else}
<th class="al">{str tag=accesslist section=view}</th>
<th class="al-edit">{str tag=editaccess section=view}</th>
<th class="secreturls">{str tag=secreturls section=view}</th>
{/if}
</tr>
{/foreach}
</thead>
<tbody>
{foreach from=$accesslists.views item=view}
{include file="view/accesslistrow.tpl" item=$view}
{/foreach}
</tbody>
</table>
{/if}
{/if}
{include file="footer.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