예제 #1
0
파일: Tags.php 프로젝트: nosch/phpMyFAQ
 /**
  * Returns all tags
  *
  * @param  string  $search Move the returned result set to be the result of a start-with search
  * @param  boolean $limit  Limit the returned result set
  * @return array
  */
 public function getAllTags($search = null, $limit = false)
 {
     global $DB;
     $tags = $allTags = array();
     // Hack: LIKE is case sensitive under PostgreSQL
     switch ($DB['type']) {
         case 'pgsql':
             $like = 'ILIKE';
             break;
         default:
             $like = 'LIKE';
             break;
     }
     $query = sprintf("\n            SELECT\n                tagging_id, tagging_name\n            FROM\n                %sfaqtags\n                %s\n            ORDER BY tagging_name", SQLPREFIX, isset($search) && $search != '' ? "WHERE tagging_name " . $like . " '" . $search . "%'" : '');
     $result = $this->db->query($query);
     if ($result) {
         while ($row = $this->db->fetchObject($result)) {
             $allTags[$row->tagging_id] = $row->tagging_name;
         }
     }
     $numberOfItems = $limit ? PMF_TAGS_CLOUD_RESULT_SET_SIZE : $this->db->numRows($result);
     if (isset($allTags) && $numberOfItems < count($allTags)) {
         $keys = array_keys($allTags);
         shuffle($keys);
         foreach ($keys as $current_key) {
             $tags[$current_key] = $allTags[$current_key];
         }
         $tags = array_slice($tags, 0, $numberOfItems);
     } else {
         $tags = PMF_Utils::shuffleData($allTags);
     }
     return $tags;
 }
예제 #2
0
파일: Tags.php 프로젝트: atlcurling/tkt
 /**
  * Returns all tags
  *
  * @param  string  $search Move the returned result set to be the result of a start-with search
  * @param  boolean $limit  Limit the returned result set
  * @return array
  */
 public function getAllTags($search = null, $limit = false, $showInactive = false)
 {
     global $DB;
     $tags = $allTags = array();
     // Hack: LIKE is case sensitive under PostgreSQL
     switch ($DB['type']) {
         case 'pgsql':
             $like = 'ILIKE';
             break;
         default:
             $like = 'LIKE';
             break;
     }
     $query = sprintf("\n            SELECT\n                t.tagging_id AS tagging_id, t.tagging_name AS tagging_name\n            FROM\n                %sfaqtags t\n            LEFT JOIN\n                %sfaqdata_tags dt\n            ON\n                dt.tagging_id = t.tagging_id\n            LEFT JOIN\n                %sfaqdata d\n            ON\n                d.id = dt.record_id\n            WHERE\n                1=1\n                %s\n                %s\n            ORDER BY tagging_name", SQLPREFIX, SQLPREFIX, SQLPREFIX, $showInactive ? '' : "AND d.active = 'yes'", isset($search) && $search != '' ? "AND tagging_name " . $like . " '" . $search . "%'" : '');
     $result = $this->db->query($query);
     if ($result) {
         while ($row = $this->db->fetch_object($result)) {
             $allTags[$row->tagging_id] = $row->tagging_name;
         }
     }
     $numberOfItems = $limit ? PMF_TAGS_CLOUD_RESULT_SET_SIZE : $this->db->num_rows($result);
     if (isset($allTags) && $numberOfItems < count($allTags)) {
         $keys = array_keys($allTags);
         shuffle($keys);
         foreach ($keys as $current_key) {
             $tags[$current_key] = $allTags[$current_key];
         }
         $tags = array_slice($tags, 0, $numberOfItems, true);
     } else {
         $tags = PMF_Utils::shuffleData($allTags);
     }
     return $tags;
 }