Improved sibling tag order

This commit is contained in:
Marcin Kurczewski 2014-10-15 21:05:38 +02:00
parent 15c9061562
commit d30fd1a9de

View file

@ -51,12 +51,13 @@ class TagDao extends AbstractDao implements ICrudDao
return []; return [];
$tagId = $tag->getId(); $tagId = $tag->getId();
$query = $this->fpdo->from($this->tableName) $query = $this->fpdo->from($this->tableName)
->select('COUNT(pt2.postId) AS postCount')
->disableSmartJoin() ->disableSmartJoin()
->innerJoin('postTags pt1 ON pt1.tagId = tags.id') ->innerJoin('postTags pt1 ON pt1.tagId = tags.id')
->innerJoin('postTags pt2 ON pt2.postId = pt1.postId') ->innerJoin('postTags pt2 ON pt2.postId = pt1.postId')
->where('pt2.tagId', $tagId) ->where('pt2.tagId', $tagId)
->groupBy('tags.id') ->groupBy('tags.id')
->orderBy('tags.usages DESC, name ASC'); ->orderBy('postCount DESC, name ASC');
$arrayEntities = iterator_to_array($query); $arrayEntities = iterator_to_array($query);
return $this->arrayToEntities($arrayEntities); return $this->arrayToEntities($arrayEntities);
} }