-
- public function retrieveAllTags() {
- $sql = "SELECT * FROM tags";
- $query = $this->executeQuery($sql, array());
+
+ public function search($term, $user_id, $limit = '') {
+ $search = '%'.$term.'%';
+ $sql_action = "SELECT * FROM entries WHERE user_id=? AND (content LIKE ? OR title LIKE ? OR url LIKE ?) "; //searches in content, title and URL
+ $sql_action .= $this->getEntriesOrder().' ' . $limit;
+ $params_action = array($user_id, $search, $search, $search);
+ $query = $this->executeQuery($sql_action, $params_action);
+ return $query->fetchAll();
+ }
+
+ 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.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) ));