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

Bug 1722861: Display tag prefix on tagged journal search

Change-Id: I833caaa90b2640c3902c81d96ffaf451489abbcb
parent 0704eccb
......@@ -282,6 +282,15 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
if ($key > 0) {
$tagstr .= ', ';
}
if (strpos($tag, 'tagid_') !== false) {
$tags = get_records_sql_array("
SELECT CONCAT(i.displayname, ': ', t.tag) AS tag, t.resourceid
FROM {tag} t
LEFT JOIN {institution} i ON i.name = t.ownerid
WHERE t.id = ?", array(substr($tag, 6, 5))
);
$tag = $tags[0]->tag;
}
$tagstr .= ($USER->id != $owner) ? '"<a href="' . get_config('wwwroot') . 'relatedtags.php?tag=' . urlencode($tag) . '&view=' . $view . '">' . hsc($tag) . '</a>"' : '"<a href="' . get_config('wwwroot') . 'tags.php?tag=' . urlencode($tag) . '&sort=name&type=text">' . hsc($tag) . '</a>"';
}
if (!empty($tagsout)) {
......@@ -345,7 +354,18 @@ class PluginBlocktypeTaggedposts extends MaharaCoreBlocktype {
$elements = array();
if (!empty($tags)) {
$tagselect = array();
$tagrecords = get_records_array('blocktype_taggedposts_tags', 'block_instance', $instance->get('id'), 'tagtype desc, tag', 'tag, tagtype');
$typecast = is_postgres() ? '::varchar' : '';
$tagrecords = get_records_sql_array("
SELECT
(CASE
WHEN bt.tag LIKE 'tagid_%' THEN CONCAT(i.displayname, ': ', t.tag)
ELSE bt.tag
END) AS tag, bt.tagtype
FROM {blocktype_taggedposts_tags} bt
LEFT JOIN {tag} t ON t.id" . $typecast . " = SUBSTRING(bt.tag, 7)
LEFT JOIN {institution} i ON i.name = t.ownerid
WHERE bt.block_instance = ?
ORDER BY tagtype DESC", array($instance->get('id')));
if ($tagrecords) {
foreach ($tagrecords as $tag) {
if ($tag->tagtype == PluginBlocktypeTaggedposts::TAGTYPE_INCLUDE) {
......@@ -459,6 +479,16 @@ EOF;
$value = PluginBlocktypeTaggedposts::TAGTYPE_EXCLUDE;
$tag = substr($tag, 1);
}
// If tag is institution tag, save it's correct form.
if (strpos($tag, ':')) {
$tagarray = explode(': ', $tag);
$sql = "SELECT t.id
FROM {tag} t
JOIN {institution} i ON i.name = t.ownerid
WHERE t.tag = ? AND t.resourcetype = 'institution' AND i.displayname = ?";
$insttagid = get_field_sql($sql, array($tagarray[1], $tagarray[0]));
$tag = 'tagid_' . $insttagid;
}
$todb = new stdClass();
$todb->block_instance = $instance->get('id');
$todb->tag = htmlspecialchars_decode($tag);
......
......@@ -29,18 +29,27 @@ if ($page < 1) {
$tagsperpage = 5;
$values = array($USER->id);
$typecast = is_postgres() ? '::varchar' : '';
$sql = "SELECT at.tag FROM {tag} at
$sql = "SELECT
(CASE
WHEN at.tag LIKE 'tagid_%' THEN CONCAT(i.displayname, ': ', t2.tag)
ELSE at.tag
END) AS tag
FROM {tag} at
LEFT JOIN {tag} t2 ON t2.id" . $typecast . " = SUBSTRING(at.tag, 7)
LEFT JOIN {institution} i ON i.name = t2.ownerid
JOIN {artefact} a ON (at.resourcetype = 'artefact' AND at.resourceid = a.id" . $typecast . ")
WHERE a.owner = ?
AND at.resourcetype = 'artefact'
AND at.resourceid = a.id" . $typecast . "
AND a.artefacttype = 'blogpost'";
if ($request !== '') {
$sql .= " AND at.tag LIKE '%' || ? || '%'";
$sql .= " AND (at.tag LIKE '%' || ? || '%' OR t2.tag LIKE '%' || ? || '%')";
$values[] = $request;
$values[] = $request;
}
$sql .= " GROUP BY at.tag
ORDER BY at.tag ASC";
// We need to do group/order by alias of first column (tag) so we use column positioning
$sql .= " GROUP BY 1, i.displayname
ORDER BY 1 ASC";
$more = true;
$tmptags = array();
$alltags = get_records_sql_array($sql, $values);
......
......@@ -17,6 +17,14 @@ Background:
| title | description | ownertype | ownername |
| Page UserA_01 | Page 01| user | UserA |
And the following "journals" exist:
| owner | ownertype | title | description | tags |
| UserA | user | Mars journal | My Mars Mission | Mars |
And the following "journalposts" exist:
| owner | ownertype | title | entry | blog | tags | draft |
| UserA | user | Mars party | I just landed on Mars, mission success | Mars journal | Mars | 0 |
Scenario: Creating institution tags
# Log in as "Admin" user
Given I log in as "admin" with password "Kupuh1pa!"
......@@ -30,19 +38,32 @@ Scenario: Creating institution tags
And I log out
Given I log in as "UserA" with password "Kupuh1pa!"
And I choose "Pages and collections" in "Portfolio" from main menu
And I choose "Journals" in "Content" from main menu
And I click on "Mars journal"
And I click on "Edit" in "Mars party" row
And I fill in select2 input "editpost_tags" with "One tag" and select "Institution One: One tag (0)"
And I press "Save entry"
Given I choose "Pages and collections" in "Portfolio" from main menu
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 "One tag" and select "Institution One: One tag (1)"
And I fill in select2 input "settings_tags" with "Test" and select "Test"
And I press "Save"
And I expand "Journals" node in the "blocktype sidebar" property
And I follow "Tagged journal entries"
And I press "Add"
And I fill in select2 input "instconf_tagselect" with "One tag" and select "Institution One: One tag"
And I press "Save"
Then I should see "Journal entries with tag \"Institution One: One tag\""
And I follow "Display page"
Then I should see "Institution One: One tag"
Given I choose "Files" in "Content" from main menu
And I attach the file "Image2.png" to "files_filebrowser_userfile"
And I click on "Edit" in "Image2.png" row
And I fill in select2 input "files_filebrowser_edit_tags" with "One tag" and select "Institution One: One tag (1)"
And I fill in select2 input "files_filebrowser_edit_tags" with "One tag" and select "Institution One: One tag (2)"
And I fill in select2 input "files_filebrowser_edit_tags" with "Image" and select "Image"
And I press "Save changes"
......
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