1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-08-26 18:21:02 +00:00

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;

View file

@ -488,25 +488,33 @@ class Poche
Tools::logm('error : article not found');
Tools::redirect();
}
//get all already set tags to preven duplicates
$already_set_tags = array();
$entry_tags = $this->store->retrieveTagsByEntry($entry_id);
foreach ($entry_tags as $tag) {
$already_set_tags[] = $tag['value'];
}
foreach($tags as $key => $tag_value) {
$value = trim($tag_value);
$tag = $this->store->retrieveTagByValue($value);
if ($value && !in_array($value, $already_set_tags)) {
$tag = $this->store->retrieveTagByValue($value);
if (is_null($tag)) {
# we create the tag
$tag = $this->store->createTag($value);
$sequence = '';
if (STORAGE == 'postgres') {
$sequence = 'tags_id_seq';
}
$tag_id = $this->store->getLastId($sequence);
}
else {
$tag_id = $tag['id'];
}
if (is_null($tag)) {
# we create the tag
$tag = $this->store->createTag($value);
$sequence = '';
if (STORAGE == 'postgres') {
$sequence = 'tags_id_seq';
}
$tag_id = $this->store->getLastId($sequence);
}
else {
$tag_id = $tag['id'];
}
# we assign the tag to the article
$this->store->setTagToEntry($tag_id, $entry_id);
# we assign the tag to the article
$this->store->setTagToEntry($tag_id, $entry_id);
}
}
if(!$import) {
Tools::redirect();
@ -579,7 +587,17 @@ class Poche
break;
case 'tags':
$token = $this->user->getConfigValue('token');
$tags = $this->store->retrieveAllTags($this->user->getId());
//if term is set - search tags for this term
$term = Tools::checkVar('term');
$tags = $this->store->retrieveAllTags($this->user->getId(), $term);
if (Tools::isAjaxRequest()) {
$result = array();
foreach ($tags as $tag) {
$result[] = $tag['value'];
}
echo json_encode($result);
exit;
}
$tpl_vars = array(
'token' => $token,
'user_id' => $this->user->getId(),

10
inc/poche/Tools.class.php Normal file → Executable file
View file

@ -311,4 +311,14 @@ class Tools
return json_decode($json, true);
}
/**
* Returns whether we handle an AJAX (XMLHttpRequest) request.
* @return boolean whether we handle an AJAX (XMLHttpRequest) request.
*/
public static function isAjaxRequest()
{
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest';
}
}