a lot of enhancements related to tags: tags list is now sorted, shows number of articles, autocomplete added according to #477, #542

This commit is contained in:
Maryana Rozhankivska
2014-03-10 16:28:47 +02:00
parent 17b2afefad
commit fb26cc9375
27 changed files with 3225 additions and 25 deletions

View File

@ -389,12 +389,15 @@ class Database {
return $this->getHandle()->lastInsertId($column);
}
public function retrieveAllTags($user_id) {
$sql = "SELECT DISTINCT tags.* FROM tags
public function retrieveAllTags($user_id, $term = null) {
$sql = "SELECT DISTINCT tags.*, count(entries.id) AS entriescount FROM tags
LEFT JOIN tags_entries ON tags_entries.tag_id=tags.id
LEFT JOIN entries ON tags_entries.entry_id=entries.id
WHERE entries.content <> '' AND entries.user_id=?";
$query = $this->executeQuery($sql, array($user_id));
WHERE entries.content <> '' AND entries.user_id=?
". (($term) ? "AND lower(tags.value) LIKE ?" : '') ."
GROUP BY tags.id, tags.value
ORDER BY tags.value";
$query = $this->executeQuery($sql, (($term)? array($user_id, strtolower('%'.$term.'%')) : array($user_id) ));
$tags = $query->fetchAll();
return $tags;