Commit 67f2fe2b authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Add sorting options to Shared Pages (part of bug #857793)



Adds a second drop-down to Shared pages to allow sorting of results by
owner, title, and last modification time.

Change-Id: I760eec99a6d187b72389b017a55bc7fd7a544e05
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 97deb459
......@@ -46,7 +46,22 @@ else if (!empty($query)) {
$queryparams['query'] = $query;
}
$data = View::shared_to_user($query, $tag, $limit, $offset);
$sortoptions = array(
'lastchanged',
'mtime',
'ownername',
'title',
);
if (!in_array($sort = param_alpha('sort', 'lastchanged'), $sortoptions)) {
$sort = 'lastchanged';
}
if ($sort !== 'lastchanged') {
$queryparams['sort'] = $sort;
}
$sortdir = ($sort == 'lastchanged' || $sort == 'mtime') ? 'desc' : 'asc';
$data = View::shared_to_user($query, $tag, $limit, $offset, $sort, $sortdir);
$pagination = build_pagination(array(
'id' => 'sharedviews_pagination',
......
......@@ -632,6 +632,7 @@ $string['results'] = 'results';
$string['Results'] = 'Results';
$string['noresultsfound'] = 'No results found';
$string['users'] = 'Users';
$string['searchwithin'] = 'Search within';
// artefact
$string['artefact'] = 'artefact';
......@@ -958,6 +959,9 @@ $string['nusers'] = array(
'%s users',
);
$string['hidden'] = 'hidden';
$string['lastupdate'] = 'Last update';
$string['lastupdateorcomment'] = 'Last update or comment';
$string['Title'] = 'Title';
// import related strings (maybe separated later)
$string['importedfrom'] = 'Imported from %s';
......
......@@ -3090,14 +3090,22 @@ class View {
* @param string $tag Return only views with this tag
* @param integer $limit
* @param integer $offset
* @param string $sort Either 'lastchanged', 'ownername', or a column of the view table
* @param string $sortdir Ascending/descending
*
*/
public static function shared_to_user($query=null, $tag=null, $limit=null, $offset=0) {
public static function shared_to_user($query=null, $tag=null, $limit=null, $offset=0, $sort='lastchanged', $sortdir='desc') {
$sort = array(
array(
'column' => $sort,
'desc' => $sortdir == 'desc',
)
);
$result = self::view_search(
$query, null, null, null, $limit, $offset, true,
array(array('column' => 'lastchanged', 'desc' => true)),
array('portfolio'), false, array('user', 'group', 'friend'), $tag
$query, null, null, null, $limit, $offset, true, $sort, array('portfolio'), false,
array('user', 'group', 'friend'), $tag
);
if (!$result->count) {
......
......@@ -58,29 +58,50 @@ else {
}
}
$sortoptions = array(
'lastchanged' => get_string('lastupdateorcomment'),
'mtime' => get_string('lastupdate'),
'ownername' => get_string('Owner', 'view'),
'title' => get_string('Title'),
);
if (!in_array($sort = param_alpha('sort', 'lastchanged'), array_keys($sortoptions))) {
$sort = 'lastchanged';
}
if ($sort !== 'lastchanged') {
$queryparams['sort'] = $sort;
}
$sortdir = ($sort == 'lastchanged' || $sort == 'mtime') ? 'desc' : 'asc';
$searchform = pieform(array(
'name' => 'search',
'renderer' => 'oneline',
'dieaftersubmit' => false,
'elements' => array(
'query' => array(
'type' => 'text',
'title' => get_string('search') . ': ',
'title' => get_string('Query') . ': ',
'defaultvalue' => $searchdefault,
),
'type' => array(
'type' => 'select',
'title' => get_string('searchwithin') . ': ',
'options' => $searchoptions,
'defaultvalue' => $searchtype,
),
'submit' => array(
'sort' => array(
'type' => 'select',
'title' => get_string('sortresultsby') . ' ',
'options' => $sortoptions,
'defaultvalue' => $sort,
),
'search' => array(
'type' => 'submit',
'value' => get_string('search')
)
),
)
));
$data = View::shared_to_user($query, $tag, $limit, $offset);
$data = View::shared_to_user($query, $tag, $limit, $offset, $sort, $sortdir);
$pagination = build_pagination(array(
'id' => 'sharedviews_pagination',
......
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