Commit 057900f9 authored by Maria Sorica's avatar Maria Sorica Committed by Robert Lyon
Browse files

Bug 1722861: Fix the institution tags display on tags.php

1. On the tags.php page the institution tags
shoud be displayed with the institution
name as prefix.
2. The institution tags should not be available
for editing.
3. Fixed the side block display as well.

Change-Id: I4383f3ec6c6976a40897c406887c49c2a219c644
parent fe026d2f
......@@ -15,7 +15,7 @@ require('init.php');
define('TITLE', get_string('edittags'));
$tags = get_my_tags();
$tags = get_my_tags(null, true, 'freq', true);
if ($tag = param_variable('tag', null)) {
$edittagform = pieform(array(
......
......@@ -29,6 +29,14 @@ $owner = (object) array('type' => 'user', 'id' => $USER->get('id'));
$data = get_portfolio_items_by_tag($tag, $owner, $limit, $offset, $sort, $type);
build_portfolio_search_html($data);
$data->tagdisplay = is_null($tag) ? get_string('alltags') : hsc(str_shorten_text($tag, 50));
$data->is_institution_tag = false;
if ($tag) {
$tagname = strpos($tag, ':') ? explode(': ', $tag)[1] : $tag;
if ($institution = get_field('tag', 'ownerid', 'tag', $tagname)) {
$data->is_institution_tag = get_field('institution', 'displayname', 'name', $institution);
}
}
$data->tagurl = urlencode($tag);
json_reply(false, array('data' => $data));
......@@ -3853,22 +3853,30 @@ function tag_weight($freq) {
// return log10($freq);
}
function get_my_tags($limit=null, $cloud=true, $sort='freq') {
function get_my_tags($limit=null, $cloud=true, $sort='freq', $excludeinstitutiontags=false) {
global $USER;
$id = $USER->get('id');
if ($limit || $sort != 'alpha') {
$sort = 'COUNT(t.tag) DESC';
$sort = 'COUNT(1) DESC'; // In this instance '1' is not a number but the column reference to 'tag' column
}
else {
$sort = 't.tag ASC';
$sort = '1 ASC';
}
$excludeinstitutiontagssql = $excludeinstitutiontags ? " AND t.tag NOT LIKE 'tagid_%'" : '';
$typecast = is_postgres() ? '::varchar' : '';
$tagrecords = get_records_sql_array("
SELECT t.tag, COUNT(t.tag) AS count
SELECT
(CASE
WHEN t.tag LIKE 'tagid_%' THEN CONCAT(i.displayname, ': ', t2.tag)
ELSE t.tag
END) AS tag, COUNT(t.tag) AS count
FROM {tag} t
LEFT JOIN {tag} t2 ON t2.id" . $typecast . " = SUBSTRING(t.tag, 7)
LEFT JOIN {institution} i ON i.name = t2.ownerid
WHERE t.resourcetype IN ('artefact', 'view', 'collection')
AND t.ownertype = 'user'
AND t.ownerid = ?
GROUP BY t.tag
AND t.ownerid = ?" . $excludeinstitutiontagssql . "
GROUP BY 1
ORDER BY " . $sort . (is_null($limit) ? '' : " LIMIT $limit"),
array($id)
);
......@@ -3892,10 +3900,8 @@ function get_my_tags($limit=null, $cloud=true, $sort='freq') {
}
usort($tagrecords, create_function('$a,$b', 'return strnatcasecmp($a->tag, $b->tag);'));
}
else {
foreach ($tagrecords as &$t) {
$t->tagurl = urlencode($t->tag);
}
foreach ($tagrecords as &$t) {
$t->tagurl = urlencode($t->tag);
}
return $tagrecords;
}
......
......@@ -1025,8 +1025,21 @@ class PluginSearchInternal extends PluginSearch {
if (!is_null($tag)) {
$artefacttypefilter .= ' AND at.tag = ?';
$viewfilter .= ' AND vt.tag = ?';
$collectionfilter .= ' AND (ct.tag = ? OR vt.tag = ?)';
$viewfilter .= ' AND vt.tag = ?';
$collectionfilter .= ' AND (ct.tag = ? OR vt.tag = ?)';
// Test if this is an institutionally defined
// tag and strip the displayname prefix out.
// $tagid = null;
$split = explode(':', $tag);
if (count($split) == 2) {
$prefix = trim($split[0]);
$tag = trim($split[1]);
$tag = get_field_sql("SELECT CONCAT('tagid_', t.id)
FROM {tag} t
JOIN {institution} i ON i.name = t.ownerid
WHERE i.displayname = ? AND t.tag = ?", array($prefix, $tag));
}
$values = array($owner->id, $tag, $owner->id, $tag, $owner->id, $tag, $tag);
}
else {
......@@ -1136,23 +1149,49 @@ class PluginSearchInternal extends PluginSearch {
}
}
if (!empty($ids['view'])) {
if ($viewtags = get_records_select_array('tag', "resourcetype = 'view' AND resourceid IN ('" . join("','", array_keys($ids['view'])) . "')")) {
$viewtags = get_records_sql_array("
SELECT
(CASE
WHEN t.tag LIKE 'tagid_%' THEN CONCAT(i.displayname, ': ', t2.tag)
ELSE t.tag
END) AS tag, t.resourceid
FROM {tag} t
LEFT JOIN {tag} t2 ON t2.id" . $typecast . " = SUBSTRING(t.tag, 7)
LEFT JOIN {institution} i ON i.name = t2.ownerid
WHERE t.resourcetype = 'view' AND t.resourceid IN ('" . join("','", array_keys($ids['view'])) . "')");
if ($viewtags) {
foreach ($viewtags as &$vt) {
$data['view:' . $vt->resourceid]->tags[] = $vt->tag;
}
}
}
if (!empty($ids['collection'])) {
if ($collectiontags = get_records_select_array('tag', "resourcetype = 'collection' AND resourceid IN ('" . join("','", array_keys($ids['collection'])) . "')")) {
$collectiontags = get_records_sql_array("
SELECT
(CASE
WHEN t.tag LIKE 'tagid_%' THEN CONCAT(i.displayname, ': ', t2.tag)
ELSE t.tag
END) AS tag, t.resourceid
FROM {tag} t
LEFT JOIN {tag} t2 ON t2.id" . $typecast . " = SUBSTRING(t.tag, 7)
LEFT JOIN {institution} i ON i.name = t2.ownerid
WHERE t.resourcetype = 'collection' AND t.resourceid IN ('" . join("','", array_keys($ids['collection'])) . "')");
if ($collectiontags) {
foreach ($collectiontags as &$ct) {
$data['collection:' . $ct->resourceid]->tags[] = $ct->tag;
}
}
if ($collectionviewtags = get_records_sql_array("
SELECT vt.tag, c.id, cv.view
SELECT c.id, cv.view,
(CASE
WHEN vt.tag LIKE 'tagid_%' THEN CONCAT(i.displayname, ': ', t2.tag)
ELSE vt.tag
END) AS tag
FROM {collection} c
JOIN {collection_view} cv ON cv.collection = c.id
LEFT JOIN {tag} vt ON (vt.resourcetype = 'view' AND vt.resourceid = cv.view" . $typecast . ")
LEFT JOIN {tag} t2 ON t2.id" . $typecast . " = SUBSTRING(vt.tag, 7)
LEFT JOIN {institution} i ON i.name = t2.ownerid
WHERE c.id IN (" . join(',', array_keys($ids['collection'])) . ")
AND vt.tag IS NOT NULL")) {
foreach ($collectionviewtags as &$cvt) {
......@@ -1163,16 +1202,32 @@ class PluginSearchInternal extends PluginSearch {
}
}
if (!empty($ids['artefact'])) {
if ($artefacttags = get_records_select_array('tag', "resourcetype = 'artefact' AND resourceid IN ('" . join("','", array_keys($ids['artefact'])) . "')", NULL, 'tag')) {
$artefacttags = get_records_sql_array("
SELECT
(CASE
WHEN t.tag LIKE 'tagid_%' THEN CONCAT(i.displayname, ': ', t2.tag)
ELSE t.tag
END) AS tag, t.resourceid
FROM {tag} t
LEFT JOIN {tag} t2 ON t2.id" . $typecast . " = SUBSTRING(t.tag, 7)
LEFT JOIN {institution} i ON i.name = t2.ownerid
WHERE t.resourcetype = 'artefact' AND t.resourceid IN ('" . join("','", array_keys($ids['artefact'])) . "')");
if ($artefacttags) {
foreach ($artefacttags as &$at) {
$data['artefact:' . $at->resourceid]->tags[] = $at->tag;
}
}
if (!empty($viewids) && $artefactviewtags = get_records_sql_array("
SELECT vt.tag, a.id, va.view
SELECT a.id, va.view,
(CASE
WHEN vt.tag LIKE 'tagid_%' THEN CONCAT(i.displayname, ': ', t2.tag)
ELSE vt.tag
END) AS tag
FROM {artefact} a
JOIN {view_artefact} va ON va.artefact = a.id
LEFT JOIN {tag} vt ON (vt.resourcetype = 'view' AND vt.resourceid = va.view" . $typecast . ")
LEFT JOIN {tag} t2 ON t2.id" . $typecast . " = SUBSTRING(vt.tag, 7)
LEFT JOIN {institution} i ON i.name = t2.ownerid
WHERE a.id IN ('" . join("','", array_keys($ids['artefact'])) . "')
AND va.view IN ('" . join("','", $viewids) . "')")) {
foreach ($artefactviewtags as &$avt) {
......
......@@ -133,7 +133,7 @@ jQuery(function($) {
}
var edit_tag_link = $('#results_container a.edit-tag').first();
if (edit_tag_link.length) {
if (data.data.tag) {
if (data.data.tag && !data.data.is_institution_tag) {
edit_tag_link.prop('href', config.wwwroot + 'edittags.php?tag=' + data.data.tagurl);
edit_tag_link.removeClass('hidden');
}
......@@ -207,10 +207,18 @@ foreach (array('alpha', 'freq') as $option) {
$data->queryprefix = (strpos($data->baseurl, '?') === false ? '?' : '&');
$notinstitutiontag = true;
if ($tag) {
$tagname = strpos($tag, ':') ? explode(': ', $tag)[1] : $tag;
if (get_field('tag', 'ownertype', 'tag', $tagname) == 'institution') {
$notinstitutiontag = false;
}
}
$smarty = smarty(array('paginator'));
$smarty->assign('tags', $tags);
$smarty->assign('tagsortoptions', $tagsortoptions);
$smarty->assign('tag', $tag);
$smarty->assign('not_institution_tag', $notinstitutiontag);
$smarty->assign('results', $data);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->display('tags.tpl');
......@@ -43,6 +43,7 @@ define ("LOCATOR_CONSTANTS", json_encode(array(
'Submissions to this group' => array("#allsubmissionlist", "css_element"),
'Blocktype sidebar' => array("#content-editor-foldable", "css_element"),
'Tags section' => array("#edit_tags_container", "css_element"),
'My tags list' => array(".mytags", "css_element"),
'Upload dialog' => array("#editgoalsandskills_filebrowser_upload_browse", "css_element"),
'Filter by first name' => array("#firstnamelist", "css_element"),
'Find people results' => array("#friendslist_pagination", "css_element"),
......
......@@ -5,7 +5,7 @@
<div class="tagblock panel-body">
{if $sbdata.tags}
{foreach from=$sbdata.tags item=tag}
<a class="tag"{if $tag->size} style="font-size: {$tag->size}em;"{/if} href="{$WWWROOT}tags.php?tag={$tag->tag|urlencode|safe}" title="{str tag=nitems arg1=$tag->count}">{$tag->tag|str_shorten_text:20}</a> &nbsp;
<a class="tag"{if $tag->size} style="font-size: {$tag->size}em;"{/if} href="{$WWWROOT}tags.php?tag={$tag->tagurl|safe}" title="{str tag=nitems arg1=$tag->count}">{$tag->tag|str_shorten_text:30}</a> &nbsp;
{/foreach}
{else}
<div class="no-results-small text-small">{str tag=youhavenottaggedanythingyet}</div>
......
......@@ -11,17 +11,19 @@
<div class="mytags">
<ul class="list-unstyled">
{foreach from=$tags item=t}
<li class="text-inline"><a id="tag:{$t->tag|urlencode|safe}" class="tag {if $t->tag == $tag}selected{/if}" href="{$WWWROOT}tags.php?tag={$t->tag|urlencode|safe}">{$t->tag|str_shorten_text:30}&nbsp;<span class="tagfreq badge">{$t->count}</span></a></li>
<li class="text-inline"><a id="tag:{$t->tag|urlencode|safe}" class="tag {if $t->tag == $tag}selected{/if}" href="{$WWWROOT}tags.php?tag={$t->tag|urlencode|safe}">{$t->tag|str_shorten_text:30}&nbsp;{if $t->owner}({$t->owner}){/if}<span class="tagfreq badge">{$t->count}</span></a></li>
{/foreach}
</ul>
</div>
<div id="results_container" class="panel panel-default tag-results">
<h2 id="results_heading" class="panel-heading">{str tag=searchresultsfor}
<a class="tag secondary-link" href="{$results->baseurl}">{if $tag}{$tag|str_shorten_text:50}{else}{str tag=alltags}{/if}</a>
<a class="tag secondary-link" href="{$results->baseurl}{if $tag}{$results->queryprefix}tag={$tag|urlencode|safe}{/if}">{if $tag}{$tag|str_shorten_text:50}{else}{str tag=alltags}{/if}</a>
</h2>
<div class="btn-top-right btn-group btn-group-top">
<a class="btn btn-default edit-tag{if !$tag} hidden{/if}" href="{$WWWROOT}edittags.php?tag={$tag|urlencode|safe}"><span class="icon icon-pencil left" role="presentation" aria-hidden="true"></span>{str tag=editthistag}</a>
</div>
{if $not_institution_tag}
<div class="btn-top-right btn-group btn-group-top">
<a class="btn btn-default edit-tag{if !$tag} hidden{/if}" href="{$WWWROOT}edittags.php?tag={$tag|urlencode|safe}"><span class="icon icon-pencil left" role="presentation" aria-hidden="true"></span>{str tag=editthistag}</a>
</div>
{/if}
<div class="tag-filters">
<div id="results_sort" class="pull-right">
<strong>{str tag=sortresultsby}</strong>
......
......@@ -34,6 +34,13 @@ Scenario: Creating institution tags
And I click on "Edit" in "Page UserA_01" panel menu
And I follow "Settings" in the "Toolbar buttons" property
And I fill in select2 input "settings_tags" with "One tag" and select "Institution One: One tag (0)"
And I fill in select2 input "settings_tags" with "Test" and select "Test"
And I press "Save"
And I follow "Display page"
Then I should see "Institution One: One tag"
Given I choose "Pages and collections" in "Portfolio" from main menu
And I follow "Tags"
And I follow "Edit tags"
Then I should see "Test" in the "My tags list" property
Then I should not see "Institution One: One tag" in the "My tags list" property
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