Commit fc40db28 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Allow searching and filtering by tag in view_search



Previously, the search term passed in the $query parameter would only
match in the view title and description.  Results are now returned
when this search term matches one of the view's tags.

Additionally, a new $tag parameter will act as a filter on views, so
that only views with the given tag are returned.

Change-Id: I352f31b6adb088072c8bcf45ae8b237b61f71a6f
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent 92fef0df
......@@ -2790,15 +2790,22 @@ class View {
* @param array $types List of view types to filter by
* @param bool $collection Use query against collection names and descriptions
* @param array $accesstypes Only return views visible due to the given access types
* @param array $tag Only return views with this tag
*
*/
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) {
$extra=true, $sort=null, $types=null, $collection=false, $accesstypes=null, $tag=null) {
global $USER;
$admin = $USER->get('admin');
$loggedin = $USER->is_logged_in();
$viewerid = $USER->get('id');
$from = '
FROM {view} v
LEFT OUTER JOIN {collection_view} cv ON cv.view = v.id
LEFT OUTER JOIN {collection} c ON cv.collection = c.id
';
$where = '
WHERE (v.owner IS NULL OR v.owner > 0)
AND (v.group IS NULL OR v.group NOT IN (SELECT id FROM {group} WHERE deleted = 1))';
......@@ -2827,10 +2834,13 @@ class View {
}
$like = db_ilike();
if ($query) {
if ($query) { // Include matches on the title, description or tag
$from .= "
LEFT JOIN {view_tag} vt ON (vt.view = v.id AND vt.tag = ?)";
$where .= "
AND (v.title $like '%' || ? || '%' OR v.description $like '%' || ? || '%' ";
$ph = array($query, $query);
AND (v.title $like '%' || ? || '%' OR v.description $like '%' || ? || '%' OR vt.tag = ?";
$ph = array($query, $query, $query, $query);
if ($collection) {
$where .= "
OR c.name $like '%' || ? || '%' OR c.description $like '%' || ? || '%' ";
......@@ -2838,6 +2848,11 @@ class View {
}
$where .= ")";
}
else if ($tag) { // Filter by the tag
$from .= "
INNER JOIN {view_tag} vt ON (vt.view = v.id AND vt.tag = ?)";
$ph = array($tag);
}
else {
$ph = array();
}
......@@ -2854,12 +2869,6 @@ class View {
$accesstypes = array('public');
}
$from = '
FROM {view} v
LEFT OUTER JOIN {collection_view} cv ON cv.view = v.id
LEFT OUTER JOIN {collection} c ON cv.collection = c.id
';
if ($editableviews) {
$editablesql = "v.owner = ? -- user owns the view
OR v.group IN ( -- group view, editable by the user
......
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