Tag relations don't suggest tags already used
This commit is contained in:
parent
fba6a50251
commit
73fc1830ff
4 changed files with 10 additions and 5 deletions
|
@ -32,6 +32,7 @@ usersPerPage=8
|
||||||
postsPerPage=20
|
postsPerPage=20
|
||||||
logsPerPage=250
|
logsPerPage=250
|
||||||
tagsPerPage=100
|
tagsPerPage=100
|
||||||
|
tagsRelated=15
|
||||||
thumbWidth=150
|
thumbWidth=150
|
||||||
thumbHeight=150
|
thumbHeight=150
|
||||||
thumbStyle=outside
|
thumbStyle=outside
|
||||||
|
|
|
@ -276,7 +276,8 @@ function attachTagIt(target)
|
||||||
onTagClicked: function(e, ui)
|
onTagClicked: function(e, ui)
|
||||||
{
|
{
|
||||||
var targetTagit = ui.tag.parents('.tagit');
|
var targetTagit = ui.tag.parents('.tagit');
|
||||||
options = { tag: ui.tagLabel };
|
var context = target.tagit('assignedTags');
|
||||||
|
options = { context: context, tag: ui.tagLabel };
|
||||||
if (targetTagit.siblings('.related-tags:eq(0)').data('for') == options.tag)
|
if (targetTagit.siblings('.related-tags:eq(0)').data('for') == options.tag)
|
||||||
{
|
{
|
||||||
targetTagit.siblings('.related-tags').slideUp(function()
|
targetTagit.siblings('.related-tags').slideUp(function()
|
||||||
|
@ -289,7 +290,7 @@ function attachTagIt(target)
|
||||||
$.getJSON('/tags-related?json', options, function(data)
|
$.getJSON('/tags-related?json', options, function(data)
|
||||||
{
|
{
|
||||||
var list = $('<ul>');
|
var list = $('<ul>');
|
||||||
$.each(data.tags.slice(0, 10), function(i, tag)
|
$.each(data.tags, function(i, tag)
|
||||||
{
|
{
|
||||||
var link = $('<a>');
|
var link = $('<a>');
|
||||||
link.attr('href', '/posts/' + tag.name + '/');
|
link.attr('href', '/posts/' + tag.name + '/');
|
||||||
|
|
|
@ -73,9 +73,11 @@ class TagController
|
||||||
{
|
{
|
||||||
PrivilegesHelper::confirmWithException(Privilege::ListTags);
|
PrivilegesHelper::confirmWithException(Privilege::ListTags);
|
||||||
|
|
||||||
|
$suppliedContext = (array) InputHelper::get('context');
|
||||||
$suppliedTag = InputHelper::get('tag');
|
$suppliedTag = InputHelper::get('tag');
|
||||||
|
|
||||||
$tags = TagSearchService::getRelatedTagRows($suppliedTag, 10, 1);
|
$limit = intval($this->config->browsing->tagsRelated);
|
||||||
|
$tags = TagSearchService::getRelatedTagRows($suppliedTag, $suppliedContext, $limit);
|
||||||
|
|
||||||
$this->context->transport->tags =
|
$this->context->transport->tags =
|
||||||
array_values(array_map(
|
array_values(array_map(
|
||||||
|
|
|
@ -9,7 +9,7 @@ class TagSearchService extends AbstractSearchService
|
||||||
$stmt->addColumn(new Sql\AliasFunctor(new Sql\CountFunctor('post_tag.post_id'), 'post_count'));
|
$stmt->addColumn(new Sql\AliasFunctor(new Sql\CountFunctor('post_tag.post_id'), 'post_count'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRelatedTagRows($parentTagName, $limit)
|
public static function getRelatedTagRows($parentTagName, $context, $limit)
|
||||||
{
|
{
|
||||||
$parentTagEntity = TagModel::findByName($parentTagName, false);
|
$parentTagEntity = TagModel::findByName($parentTagName, false);
|
||||||
if (empty($parentTagEntity))
|
if (empty($parentTagEntity))
|
||||||
|
@ -24,7 +24,6 @@ class TagSearchService extends AbstractSearchService
|
||||||
->addInnerJoin('post_tag', new Sql\EqualsFunctor('post_tag.tag_id', 'tag.id'))
|
->addInnerJoin('post_tag', new Sql\EqualsFunctor('post_tag.tag_id', 'tag.id'))
|
||||||
->setGroupBy('tag.id')
|
->setGroupBy('tag.id')
|
||||||
->setOrderBy('post_count', Sql\SelectStatement::ORDER_DESC)
|
->setOrderBy('post_count', Sql\SelectStatement::ORDER_DESC)
|
||||||
->setLimit($limit + 1, 0)
|
|
||||||
->setCriterion(new Sql\ExistsFunctor((new Sql\SelectStatement)
|
->setCriterion(new Sql\ExistsFunctor((new Sql\SelectStatement)
|
||||||
->setTable('post_tag pt2')
|
->setTable('post_tag pt2')
|
||||||
->setCriterion((new Sql\ConjunctionFunctor)
|
->setCriterion((new Sql\ConjunctionFunctor)
|
||||||
|
@ -62,6 +61,8 @@ class TagSearchService extends AbstractSearchService
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($rows, function($a, $b) { return intval($b['sort']) - intval($a['sort']); });
|
usort($rows, function($a, $b) { return intval($b['sort']) - intval($a['sort']); });
|
||||||
|
$rows = array_filter($rows, function($row) use ($context) { return !in_array($row['name'], $context); });
|
||||||
|
$rows = array_slice($rows, 0, $limit);
|
||||||
|
|
||||||
return $rows;
|
return $rows;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue