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

Show search results for all the user's tagged items when no tag is selected

parent 6e1e24f5
...@@ -30,7 +30,7 @@ define('JSON', 1); ...@@ -30,7 +30,7 @@ define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php'); require(dirname(dirname(__FILE__)) . '/init.php');
require('searchlib.php'); require('searchlib.php');
$tag = param_variable('tag'); $tag = param_variable('tag', null);
$limit = param_integer('limit', 10); $limit = param_integer('limit', 10);
$offset = param_integer('offset', 0); $offset = param_integer('offset', 0);
$sort = param_alpha('sort', 'name'); $sort = param_alpha('sort', 'name');
...@@ -39,7 +39,7 @@ $owner = (object) array('type' => 'user', 'id' => $USER->get('id')); ...@@ -39,7 +39,7 @@ $owner = (object) array('type' => 'user', 'id' => $USER->get('id'));
$data = get_portfolio_items_by_tag($tag, $owner, $limit, $offset, $sort, $type); $data = get_portfolio_items_by_tag($tag, $owner, $limit, $offset, $sort, $type);
build_portfolio_search_html($data); build_portfolio_search_html($data);
$data->tagdisplay = hsc(str_shorten_text($tag, 50)); $data->tagdisplay = is_null($tag) ? get_string('alltags') : hsc(str_shorten_text($tag, 50));
$data->tagurl = urlencode($tag); $data->tagurl = urlencode($tag);
json_reply(false, array('data' => $data)); json_reply(false, array('data' => $data));
......
...@@ -90,6 +90,7 @@ $string['Tag'] = 'Tag'; ...@@ -90,6 +90,7 @@ $string['Tag'] = 'Tag';
$string['itemstaggedwith'] = 'Items tagged with "%s"'; $string['itemstaggedwith'] = 'Items tagged with "%s"';
$string['numitems'] = '%s items'; $string['numitems'] = '%s items';
$string['searchresultsfor'] = 'Search results for'; $string['searchresultsfor'] = 'Search results for';
$string['alltags'] = 'All Tags';
$string['sortalpha'] = 'Sort tags alphabetically'; $string['sortalpha'] = 'Sort tags alphabetically';
$string['sortfreq'] = 'Sort tags by frequency'; $string['sortfreq'] = 'Sort tags by frequency';
$string['sortresultsby'] = 'Sort results by:'; $string['sortresultsby'] = 'Sort results by:';
......
...@@ -2179,7 +2179,7 @@ function build_portfolio_search_html(&$data) { ...@@ -2179,7 +2179,7 @@ function build_portfolio_search_html(&$data) {
} }
} }
$data->baseurl = get_config('wwwroot') . 'tags.php?tag=' . urlencode($data->tag); $data->baseurl = get_config('wwwroot') . 'tags.php' . (is_null($data->tag) ? '' : '?tag=' . urlencode($data->tag));
$data->sortcols = array('name', 'date'); $data->sortcols = array('name', 'date');
$data->filtercols = array( $data->filtercols = array(
'all' => get_string('tagfilter_all'), 'all' => get_string('tagfilter_all'),
......
...@@ -849,7 +849,8 @@ class PluginSearchInternal extends PluginSearch { ...@@ -849,7 +849,8 @@ class PluginSearchInternal extends PluginSearch {
* @param boolean $returntags Return all the tags that have been attached to each result * @param boolean $returntags Return all the tags that have been attached to each result
*/ */
public static function portfolio_search_by_tag($tag, $owner, $limit, $offset, $sort, $types, $returntags) { public static function portfolio_search_by_tag($tag, $owner, $limit, $offset, $sort, $types, $returntags) {
$viewfilter = is_null($types) || $types['view'] == true ? 'TRUE' : 'FALSE'; $viewfilter = is_null($types) || $types['view'] == true ? 'AND TRUE' : 'AND FALSE';
if (is_null($types)) { if (is_null($types)) {
$artefacttypefilter = ''; $artefacttypefilter = '';
} }
...@@ -860,18 +861,25 @@ class PluginSearchInternal extends PluginSearch { ...@@ -860,18 +861,25 @@ class PluginSearchInternal extends PluginSearch {
$artefacttypefilter = ' AND FALSE'; $artefacttypefilter = ' AND FALSE';
} }
if (!is_null($tag)) {
$artefacttypefilter .= ' AND at.tag = ?';
$viewfilter .= ' AND vt.tag = ?';
$values = array($owner->id, $tag, $owner->id, $tag);
}
else {
$values = array($owner->id, $owner->id);
}
$from = "FROM ( $from = "FROM (
(SELECT a.id, a.title, a.description, 'artefact' AS type, a.artefacttype, " . db_format_tsfield('a.ctime', 'ctime') . " (SELECT a.id, a.title, a.description, 'artefact' AS type, a.artefacttype, " . db_format_tsfield('a.ctime', 'ctime') . "
FROM {artefact} a JOIN {artefact_tag} at ON (a.id = at.artefact AND at.tag = ?) FROM {artefact} a JOIN {artefact_tag} at ON (a.id = at.artefact)
WHERE a.owner = ?" . $artefacttypefilter . ") WHERE a.owner = ?" . $artefacttypefilter . ")
UNION UNION
(SELECT v.id, v.title, v.description, 'view' AS type, NULL AS artefacttype, " . db_format_tsfield('v.ctime', 'ctime') . " (SELECT v.id, v.title, v.description, 'view' AS type, NULL AS artefacttype, " . db_format_tsfield('v.ctime', 'ctime') . "
FROM {view} v JOIN {view_tag} vt ON (v.id = vt.view AND vt.tag = ?) FROM {view} v JOIN {view_tag} vt ON (v.id = vt.view)
WHERE v.owner = ? AND " . $viewfilter . ") WHERE v.owner = ? " . $viewfilter . ")
) p"; ) p";
$values = array($tag, $owner->id, $tag, $owner->id);
$result = (object) array( $result = (object) array(
'tag' => $tag, 'tag' => $tag,
'owner' => $owner, 'owner' => $owner,
......
...@@ -49,7 +49,7 @@ $str = array(); ...@@ -49,7 +49,7 @@ $str = array();
foreach (array('tags', 'tag', 'sort', 'type') as $v) { foreach (array('tags', 'tag', 'sort', 'type') as $v) {
$str[$v] = json_encode($$v); $str[$v] = json_encode($$v);
} }
$hidepagination = $tag ? '' : "addElementClass('results_pagination', 'hidden');";
$js = <<<EOF $js = <<<EOF
var p = null; var p = null;
var mytags_container = null; var mytags_container = null;
...@@ -113,10 +113,6 @@ function rewriteTagLink(elem, keep, replace) { ...@@ -113,10 +113,6 @@ function rewriteTagLink(elem, keep, replace) {
} }
} }
for (var i in reqparams) {
log(i + ' ' + reqparams[i]);
}
sendjsonrequest(config.wwwroot + 'json/tagsearch.php', reqparams, 'POST', function(data) { sendjsonrequest(config.wwwroot + 'json/tagsearch.php', reqparams, 'POST', function(data) {
p.updateResults(data); p.updateResults(data);
...@@ -128,7 +124,9 @@ function rewriteTagLink(elem, keep, replace) { ...@@ -128,7 +124,9 @@ function rewriteTagLink(elem, keep, replace) {
}); });
// Mark the selected tag in the My Tags list: // Mark the selected tag in the My Tags list:
addElementClass('tag:' + data.data.tag, 'selected'); if (data.data.tag) {
addElementClass('tag:' + data.data.tag, 'selected');
}
// Replace the tag in the Search Results heading // Replace the tag in the Search Results heading
var heading_tag = getFirstElementByTagAndClassName('a', 'tag', 'results_heading'); var heading_tag = getFirstElementByTagAndClassName('a', 'tag', 'results_heading');
...@@ -138,11 +136,18 @@ function rewriteTagLink(elem, keep, replace) { ...@@ -138,11 +136,18 @@ function rewriteTagLink(elem, keep, replace) {
} }
var edit_tag_link = getFirstElementByTagAndClassName('a', 'edit-tag', 'results_container'); var edit_tag_link = getFirstElementByTagAndClassName('a', 'edit-tag', 'results_container');
if (edit_tag_link) { if (edit_tag_link) {
setNodeAttribute(edit_tag_link, 'href', config.wwwroot + 'edittags.php?tag=' + data.data.tagurl); if (data.data.tag) {
setNodeAttribute(edit_tag_link, 'href', config.wwwroot + 'edittags.php?tag=' + data.data.tagurl);
removeElementClass(edit_tag_link, 'hidden');
}
else {
addElementClass(edit_tag_link, 'hidden');
}
} }
removeElementClass('results_container', 'hidden'); if (data.data.tag) {
params.tag = data.data.tag; params.tag = data.data.tag;
}
} }
// Rewrite tag links in the results list: // Rewrite tag links in the results list:
...@@ -196,7 +201,6 @@ addLoadEvent(function() { ...@@ -196,7 +201,6 @@ addLoadEvent(function() {
forEach(getElementsByTagAndClassName('a', 'tag', 'results'), function (elem) {rewriteTagLink(elem, [], 'tag')}); forEach(getElementsByTagAndClassName('a', 'tag', 'results'), function (elem) {rewriteTagLink(elem, [], 'tag')});
forEach(getElementsByTagAndClassName('a', null, 'results_sort'), function (elem) {rewriteTagLink(elem, ['tag', 'type'], 'sort')}); forEach(getElementsByTagAndClassName('a', null, 'results_sort'), function (elem) {rewriteTagLink(elem, ['tag', 'type'], 'sort')});
forEach(getElementsByTagAndClassName('a', null, 'results_filter'), function (elem) {rewriteTagLink(elem, ['tag', 'sort'], 'type')}); forEach(getElementsByTagAndClassName('a', null, 'results_filter'), function (elem) {rewriteTagLink(elem, ['tag', 'sort'], 'type')});
{$hidepagination}
}); });
EOF; EOF;
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
<div>{str tag=youhavenottaggedanythingyet}</div> <div>{str tag=youhavenottaggedanythingyet}</div>
{/if} {/if}
<div id="results_container" class="rel tag-results{if !$tag} hidden{/if}"> <div id="results_container" class="rel tag-results">
<h2 id="results_heading">{str tag=searchresultsfor} <a class="tag" href="{$WWWROOT}tags.php?tag={$tag|urlencode}">{$tag|str_shorten_text:50|escape}</a></h2> <h2 id="results_heading">{str tag=searchresultsfor} <a class="tag" href="{$WWWROOT}tags.php{if $tag}?tag={$tag|urlencode}{/if}">{if $tag}{$tag|str_shorten_text:50|escape}{else}{str tag=alltags}{/if}</a></h2>
<div class="rbuttons"><a class="edit-tag" href="{$WWWROOT}edittags.php?tag={$tag|urlencode}">{str tag=editthistag}</a></div> <div class="rbuttons"><a class="edit-tag{if !$tag} hidden{/if}" href="{$WWWROOT}edittags.php?tag={$tag|urlencode}">{str tag=editthistag}</a></div>
<div id="results_sort">{str tag=sortresultsby} <div id="results_sort">{str tag=sortresultsby}
{foreach from=$results->sortcols item=sortfield name=sortcols} {foreach from=$results->sortcols item=sortfield name=sortcols}
<a href="{$results->baseurl}&type={$results->filter}&sort={$sortfield}"{if $results->sort == $sortfield} class="selected"{/if}>{str tag=$sortfield}</a>{if !$smarty.foreach.sortcols.last} | {/if} <a href="{$results->baseurl}&type={$results->filter}&sort={$sortfield}"{if $results->sort == $sortfield} class="selected"{/if}>{str tag=$sortfield}</a>{if !$smarty.foreach.sortcols.last} | {/if}
......
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