diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2011-03-23 18:52:01 +0100 | 
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2011-03-23 18:52:01 +0100 | 
| commit | 5c480c9babcd20c8701fc5e3f651a1e9082d4e8f (patch) | |
| tree | d5dcad71694df33beb7aa1239fbe71e369ae5478 /src/SemanticScuttle | |
| parent | 9f46e9f3ff2454318f50ead7790e3bf46bb868f2 (diff) | |
| download | semanticscuttle-5c480c9babcd20c8701fc5e3f651a1e9082d4e8f.tar.gz semanticscuttle-5c480c9babcd20c8701fc5e3f651a1e9082d4e8f.tar.bz2 | |
format getPopularTags and add docblock
Diffstat (limited to 'src/SemanticScuttle')
| -rw-r--r-- | src/SemanticScuttle/Service/Bookmark2Tag.php | 75 | 
1 files changed, 56 insertions, 19 deletions
| diff --git a/src/SemanticScuttle/Service/Bookmark2Tag.php b/src/SemanticScuttle/Service/Bookmark2Tag.php index 4d2c969..e3997dd 100644 --- a/src/SemanticScuttle/Service/Bookmark2Tag.php +++ b/src/SemanticScuttle/Service/Bookmark2Tag.php @@ -477,35 +477,70 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService          return $this->getPopularTags($contacts, $limit, $logged_on_user, $days);      } -    // $users can be {NULL, an id, an array of id} -    function &getPopularTags($user = NULL, $limit = 30, $logged_on_user = NULL, $days = NULL) { +    /** +     * The the most popular tags and their usage count +     * +     * @param mixed   $user           Integer user ID or array of user IDs to limit tag +     *                                finding to +     * @param integer $limit          Number of tags to return +     * @param integer $logged_on_user ID of the user that's currently logged in. +     *                                If the logged in user equals the $user to find +     *                                tags for, tags of private bookmarks are +     *                                returned. +     * @param integer $days           Bookmarks have to be changed in the last X days +     *                                if their tags shall count* +     * +     * @return array Array of found tags. Each tag entry is an array with two keys, +     *               'tag' (tag name) and 'bCount'. +     */ +    public function getPopularTags( +        $user = null, $limit = 30, $logged_on_user = null, $days = null +    ) {          // Only count the tags that are visible to the current user. -        if (($user != $logged_on_user) || is_null($user) || ($user === false)) -        $privacy = ' AND B.bStatus = 0'; -        else -        $privacy = ''; +        if (($user != $logged_on_user) || is_null($user) || ($user === false)) { +            $privacy = ' AND B.bStatus = 0'; +        } else { +            $privacy = ''; +        } -        if (is_null($days) || !is_int($days)) -        $span = ''; -        else -        $span = ' AND B.bDatetime > "'. date('Y-m-d H:i:s', time() - (86400 * $days)) .'"'; +        if (is_null($days) || !is_int($days)) { +            $span = ''; +        } else { +            $span = ' AND B.bDatetime > "' +                . date('Y-m-d H:i:s', time() - (86400 * $days)) +                . '"'; +        } + +        $query = 'SELECT' +            . ' T.tag, COUNT(T.bId) AS bCount' +            . ' FROM ' +            . $this->getTableName() . ' AS T' +            . ', ' . $GLOBALS['tableprefix'] . 'bookmarks AS B' +            . ' WHERE'; -        $query = 'SELECT T.tag, COUNT(T.bId) AS bCount FROM '. $this->getTableName() .' AS T, '. $GLOBALS['tableprefix'] .'bookmarks AS B WHERE ';          if (is_null($user) || ($user === false)) { -            $query .= 'B.bId = T.bId AND B.bStatus = 0'; -        } elseif(is_array($user)) { +            $query .= ' B.bId = T.bId AND B.bStatus = 0'; +        } else if (is_array($user)) {              $query .= ' (1 = 0';  //tricks -            foreach($user as $u) { -                $query .= ' OR B.uId = '. $this->db->sql_escape($u) .' AND B.bId = T.bId'; +            foreach ($user as $u) { +                $query .= ' OR B.uId = ' . $this->db->sql_escape($u) +                    . ' AND B.bId = T.bId';              }              $query .= ' )';          } else { -            $query .= 'B.uId = '. $this->db->sql_escape($user) .' AND B.bId = T.bId'. $privacy; +            $query .= ' B.uId = ' . $this->db->sql_escape($user) +                . ' AND B.bId = T.bId' . $privacy;          } -        $query .= $span .' AND LEFT(T.tag, 7) <> "system:" GROUP BY T.tag ORDER BY bCount DESC, tag'; -        if (!($dbresult =& $this->db->sql_query_limit($query, $limit))) { -            message_die(GENERAL_ERROR, 'Could not get popular tags', '', __LINE__, __FILE__, $query, $this->db); +        $query .= $span . ' AND LEFT(T.tag, 7) <> "system:"' +            . ' GROUP BY T.tag' +            . ' ORDER BY bCount DESC, tag'; + +        if (!($dbresult = $this->db->sql_query_limit($query, $limit))) { +            message_die( +                GENERAL_ERROR, 'Could not get popular tags', +                '', __LINE__, __FILE__, $query, $this->db +            );              return false;          } @@ -514,6 +549,8 @@ class SemanticScuttle_Service_Bookmark2Tag extends SemanticScuttle_DbService          return $output;      } + +      function hasTag($bookmarkid, $tag) {          $query = 'SELECT COUNT(*) AS tCount FROM '. $this->getTableName() .' WHERE bId = '. intval($bookmarkid) .' AND tag ="'. $this->db->sql_escape($tag) .'"'; | 
