Commit 1e51bab6 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add "shared with" option to shared pages (part of bug #857793)



Adds a set of checkboxes to Shared Pages which allows the user to
filter by the various access types.  The default remains unchanged
(pages shared with you, friends, or your groups).  Additional options
are public, logged-in, and institutions, and any combination of these
can be searched.

This allows users to find all public pages on the site, for example.

Change-Id: I7b123f2088756cea04d2685e2e35ef578252991a
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 67f2fe2b
......@@ -61,7 +61,24 @@ if ($sort !== 'lastchanged') {
}
$sortdir = ($sort == 'lastchanged' || $sort == 'mtime') ? 'desc' : 'asc';
$data = View::shared_to_user($query, $tag, $limit, $offset, $sort, $sortdir);
$shareoptions = array(
'user',
'friend',
'group',
'institution',
'loggedin',
'public',
);
$share = param_variable('share', array());
if (is_array($share)) {
$share = $queryparams['share'] = array_intersect($share, $shareoptions);
}
else {
$share = null;
}
$data = View::shared_to_user($query, $tag, $limit, $offset, $sort, $sortdir, $share);
$pagination = build_pagination(array(
'id' => 'sharedviews_pagination',
......
......@@ -347,3 +347,5 @@ $string['sharedviews'] = 'Shared pages';
$string['titleanddescription'] = 'Title, description, tags';
$string['tagsonly'] = 'Tags only';
$string['sharedviewsdescription'] = 'This page lists the most recently modified or commented on pages that have been shared with you. They may have been shared with you directly, shared with friends of the owner, or shared with one of your groups.';
$string['sharedwith'] = 'Shared with';
$string['Me'] = 'Me';
......@@ -3082,9 +3082,8 @@ class View {
}
/**
* Get views that have been actively shared with a user, either
* shared with the user individually, shared as a friend of the
* view owner, or shared with one of the user's groups.
* Get views that have been shared with a user using the given
* access types.
*
* @param string $query Search string for title/description
* @param string $tag Return only views with this tag
......@@ -3092,9 +3091,11 @@ class View {
* @param integer $offset
* @param string $sort Either 'lastchanged', 'ownername', or a column of the view table
* @param string $sortdir Ascending/descending
* @param array $accesstypes Types of view access
*
*/
public static function shared_to_user($query=null, $tag=null, $limit=null, $offset=0, $sort='lastchanged', $sortdir='desc') {
public static function shared_to_user($query=null, $tag=null, $limit=null, $offset=0, $sort='lastchanged', $sortdir='desc',
$accesstypes=null) {
$sort = array(
array(
......@@ -3104,8 +3105,7 @@ class View {
);
$result = self::view_search(
$query, null, null, null, $limit, $offset, true, $sort, array('portfolio'), false,
array('user', 'group', 'friend'), $tag
$query, null, null, null, $limit, $offset, true, $sort, array('portfolio'), false, $accesstypes, $tag
);
if (!$result->count) {
......
......@@ -73,6 +73,25 @@ if ($sort !== 'lastchanged') {
}
$sortdir = ($sort == 'lastchanged' || $sort == 'mtime') ? 'desc' : 'asc';
$share = $queryparams['share'] = $sharedefault = array('user', 'friend', 'group');
$shareoptions = array(
'user' => get_string('Me', 'view'),
'friend' => get_string('friends', 'view'),
'group' => get_string('mygroups'),
);
if ($USER->get('institutions')) {
$shareoptions['institution'] = get_string('myinstitutions', 'group');
}
$shareoptions['loggedin'] = get_string('loggedin', 'view');
if (get_config('allowpublicviews')) {
$shareoptions['public'] = get_string('public', 'view');
}
foreach ($shareoptions as $k => &$v) {
$v = array('title' => $v, 'value' => $k, 'defaultvalue' => in_array($k, $sharedefault));
}
$searchform = pieform(array(
'name' => 'search',
'dieaftersubmit' => false,
......@@ -94,6 +113,12 @@ $searchform = pieform(array(
'options' => $sortoptions,
'defaultvalue' => $sort,
),
'share' => array(
'type' => 'checkboxes',
'title' => get_string('sharedwith', 'view') . ': ',
'elements' => $shareoptions,
'labelwidth' => 0,
),
'search' => array(
'type' => 'submit',
'value' => get_string('search')
......@@ -101,7 +126,7 @@ $searchform = pieform(array(
)
));
$data = View::shared_to_user($query, $tag, $limit, $offset, $sort, $sortdir);
$data = View::shared_to_user($query, $tag, $limit, $offset, $sort, $sortdir, $share);
$pagination = build_pagination(array(
'id' => 'sharedviews_pagination',
......@@ -124,7 +149,7 @@ exit;
function search_submit(Pieform $form, $values) {
// Convert (query,type) parameters from form to (query,tag)
global $queryparams, $tag, $query;
global $queryparams, $tag, $query, $share;
if (isset($queryparams['query'])) {
unset($queryparams['query']);
......@@ -144,4 +169,6 @@ function search_submit(Pieform $form, $values) {
$queryparams['query'] = $query = $values['query'];
}
}
$share = $queryparams['share'] = param_variable('share', array());
}
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