Exemple #1
0
 /**
  * fetchRecentComments
  * Fetch recent comments
  *
  * @param int $limit limit (default 10)
  * @return array result set
  */
 public function fetchRecentComments($limit = null)
 {
     if (is_null($limit)) {
         $limit = 10;
     }
     $limit = (int) $limit;
     $results = $this->fetchAllAsArray(array('where' => array('type = ?' => array(0)), 'eager' => array('commentinfo', 'posts'), 'order' => array('id DESC'), 'limit' => array($limit)));
     Foresmo::dateFilter($results);
     Foresmo::sanitize($results);
     return $results;
 }
Exemple #2
0
 /**
  * fetchPostsByTag
  * Fetch all posts with status of 1 (published) with specific tag(s)
  * with all it's pertitent associated data (tags, comments,
  * postinfo) as an array
  *
  * @param array $tags list of tags
  *
  * @param string $oper AND / OR
  *
  * @return array
  */
 public function fetchPostsByTag($tags, $oper = 'AND')
 {
     if (!$tags || empty($tags) || $oper != 'AND' && $oper != 'OR') {
         return array();
     }
     $where_stmt = 'status = ? AND content_type = ?';
     $where_values = array(1, 1);
     $join = array();
     $count = count($tags);
     for ($i = 0; $i < $count; $i++) {
         $where_values[] = $tags[$i];
         if ($oper == 'AND') {
             $tc = $i + 1;
             $where_stmt .= " AND tags{$tc}.tag_slug = ?";
             if ($tc == 1) {
                 $join[] = array('type' => "inner", 'name' => "{$this->_config['prefix']}posts_tags AS posts_tags{$tc}", 'cond' => "posts_tags{$tc}.post_id = {$this->_config['prefix']}posts.id");
             } else {
                 $join[] = array('type' => "inner", 'name' => "{$this->_config['prefix']}posts_tags AS posts_tags{$tc}", 'cond' => "posts_tags{$tc}.post_id = posts_tags{$i}.post_id");
             }
             $join[] = array('type' => "inner", 'name' => "{$this->_config['prefix']}tags AS tags{$tc}", 'cond' => "posts_tags{$tc}.tag_id = tags{$tc}.id");
         }
     }
     if ($oper == 'OR') {
         $join[] = array('type' => "inner", 'name' => "{$this->_config['prefix']}posts_tags AS posts_tags1", 'cond' => "posts_tags1.post_id = {$this->_config['prefix']}posts.id");
         $join[] = array('type' => "inner", 'name' => "{$this->_config['prefix']}tags AS tags1", 'cond' => "posts_tags1.tag_id = tags1.id");
         $where_stmt .= ' AND tags1.tag_slug IN (' . rtrim(str_repeat('?,', $count), ',') . ')';
     }
     $where = array($where_stmt => $where_values);
     $results = $this->fetchAllAsArray(array('distinct' => true, 'where' => $where, 'order' => array('id DESC'), 'join' => $join, 'eager' => array('comments' => array('eager' => array('commentinfo')), 'tags', 'postinfo', 'users')));
     Foresmo::dateFilter($results);
     Foresmo::sanitize($results);
     return $results;
 }