Commit 6f5acb95 authored by Son Nguyen's avatar Son Nguyen Committed by Gerrit Code Review

Merge changes I0ee53499,Iceba8f96

* changes:
  Show collections in "Latest pages" block (Bug 1476491)
  Support for collections & views in View::view_search()
parents c8634ebf 1d31928b
......@@ -36,7 +36,23 @@ class PluginBlocktypeNewViews extends SystemBlocktype {
$nviews = isset($configdata['limit']) ? intval($configdata['limit']) : 5;
$sort = array(array('column' => 'mtime', 'desc' => true));
$views = View::view_search(null, null, null, null, $nviews, 0, true, $sort, array('portfolio'));
$views = View::view_search(
null, // $query
null, // $ownerquery
null, // $ownedby
null, // $copyableby
$nviews, // $limit
0, // $offset
true, // $extra
$sort, // $sort
array('portfolio'), // $types
null, // $collection
null, // $accesstypes
null, // $tag
null, // $viewid
null, // $excludeowner
true // $groupbycollection
);
$smarty = smarty_core();
$smarty->assign('loggedin', $USER->is_logged_in());
$smarty->assign('views', $views->data);
......
......@@ -3949,11 +3949,12 @@ class View {
* @param array $tag Only return views with this tag
* @param integer $viewid Only return a particular view (find by view id)
* @param integer $excludeowner Only return views not owned by this owner id
*
* @param boolean $groupbycollection Return one record for each collection, and one record for each view that's not in a collection
* @return array
*/
public static function view_search($query=null, $ownerquery=null, $ownedby=null, $copyableby=null, $limit=null, $offset=0,
$extra=true, $sort=null, $types=null, $collection=false, $accesstypes=null, $tag=null,
$viewid=null, $excludeowner=null) {
$viewid=null, $excludeowner=null, $groupbycollection=null) {
global $USER;
$admin = $USER->get('admin');
$loggedin = $USER->is_logged_in();
......@@ -4058,6 +4059,12 @@ class View {
$fromparams[] = $tag;
}
if ($groupbycollection) {
$where .= '
AND (cv.displayorder = 0 OR cv.displayorder IS NULL)
';
}
if (is_array($accesstypes)) {
$editableviews = in_array('editable', $accesstypes);
}
......@@ -4240,19 +4247,82 @@ class View {
$ph = array_merge($fromparams, $whereparams);
$count = count_records_sql('SELECT COUNT(*) ' . $from . $where, $ph);
$viewdata = get_records_sql_assoc('
SELECT
v.id, v.title, v.description, v.owner, v.ownerformat, v.group, v.institution,
v.template, v.mtime, v.ctime,
c.id AS collid, c.name, v.type, v.urlid, v.submittedtime, v.submittedgroup, v.submittedhost
' . $from . $where . '
if ($groupbycollection) {
$select = '
v.id AS viewid,
-- generic id column needed by get_extra___info methods
(CASE
WHEN c.id IS NOT NULL
THEN c.id
ELSE v.id
END) AS id,
(CASE
WHEN c.id IS NOT NULL
THEN c.name
ELSE v.title
END) AS title,
(CASE
WHEN c.id IS NOT NULL
THEN c.description
ELSE v.description
END) AS description,
(CASE
WHEN c.id IS NOT NULL
THEN (SELECT COUNT(*) FROM {collection_view} cv2 WHERE cv2.collection=c.id)
ELSE 0
END) AS numpages,
';
}
else {
$select = '
v.id, v.title, v.description,
';
}
$select .= '
v.owner, v.ownerformat, v.group, v.institution, v.template, v.mtime, v.ctime,
c.id as collid, c.name, v.type, v.urlid, v.submittedtime, v.submittedgroup, v.submittedhost
';
$viewdata = get_records_sql_assoc(
'SELECT ' . $select . $from . $where . '
ORDER BY ' . $orderby . ', v.id ASC',
$ph, $offset, $limit
);
if ($viewdata) {
if ($extra) {
View::get_extra_view_info($viewdata, false);
if (!$groupbycollection) {
View::get_extra_view_info($viewdata, false);
}
else {
// Split the collections and views into separate lists so
// we can send each to its bulk data-gathering method
$viewlist = array();
$collectionlist = array();
foreach ($viewdata as $k=>$v) {
if ($v->collid) {
$collectionlist[$v->collid] = $v;
}
else {
$viewlist[$v->viewid] = $v;
}
}
View::get_extra_collection_info($collectionlist);
View::get_extra_view_info($viewlist, false);
// Now update the data in $viewdata (we do this instead
// of using array_merge, in order to preserve the sortorder
// in $viewdata
foreach ($viewdata as $k=>$v) {
if ($v->collid) {
$viewdata[$k] = $collectionlist[$v->collid];
}
else {
$viewdata[$k] = $viewlist[$k];
}
}
}
}
}
else {
......
......@@ -10,6 +10,7 @@
<div class="list-group-item">
<h4 class="list-group-item-heading">
<a href="{$view.fullurl}">{$view.title}</a>
{if $view.collid}({str tag=nviews section=view arg1=$view.numpages}){/if}
</h4>
{if $view.description}
......
@javascript @core @blocktype @blocktype_newviews
Feature: Looking at the "Latest Pages" (newviews) block on my dashboard
In order to see new pages across the site
So I can know what people are up to
Background:
Given the following "users" exist:
| username | password | email | firstname | lastname | institution | authname | role |
| userA | Password1 | test01@example.com | Pete | Mc | mahara | internal | member |
| userB | Password1 | test02@example.com | Son | Nguyen | mahara | internal | member |
And the following "pages" exist:
| title | description| ownertype | ownername |
| Shared page | This is a page that is shared with me| user | userA |
| Private page | This is a page shared with no one | user | userA |
| C1P1 | Page 1 in Collection 1 | user | userA |
| C1P2 | Page 2 in Collection 1 | user | userA |
| C2P1 | Page 1 in Collection 2 | user | userA |
| C2P2 | Page 2 in Collection 2 | user | userA |
And the following "collections" exist:
| title | description| ownertype | ownername | pages |
| Shared Collection 01 | This is the collection 01 | user | userA | C1P1, C1P2 |
| Private Collection 02 | This is the collection 02 | user | userA | C2P1, C2P2 |
And the following "permissions" exist:
| title | accesstype |
| Shared page | public |
| Shared Collection 01 | public |
Scenario: Share pages and collections to a group.
The list of shared pages must take into account of access date (Bug 1374163)
And I log in as "userB" with password "Password1"
Then I should see "Shared page" in the "div.bt-newviews" "css_element"
And I should see "Shared Collection 01" in the "div.bt-newviews" "css_element"
# I shouldn't see the pages I didn't share
And I should not see "Private page" in the "div.bt-newviews" "css_element"
And I should not see "Private Collection 02" in the "div.bt-newviews" "css_element"
# I shouldn't see the individual pages in a collection
And I should not see "C1P1" in the "div.bt-newviews" "css_element"
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