Esempio n. 1
0
 /**
  * Get a list of posts in this thread
  *
  * @param   string  $rtrn    What data to return?
  * @param   array   $filters Filters to apply to data fetch
  * @param   boolean $clear   Clear cached data?
  * @return  mixed
  */
 public function posts($rtrn = 'list', $filters = array(), $clear = false)
 {
     $filters['thread'] = isset($filters['thread']) ? $filters['thread'] : $this->get('thread');
     $filters['state'] = isset($filters['state']) ? $filters['state'] : array(self::APP_STATE_PUBLISHED, self::APP_STATE_FLAGGED);
     switch (strtolower($rtrn)) {
         case 'count':
             if (!isset($this->_cache['posts_count']) || $clear) {
                 $this->_cache['posts_count'] = $this->_tbl->getCount($filters);
             }
             return $this->_cache['posts_count'];
             break;
         case 'first':
             return $this->posts('list', $filters)->first();
             break;
         case 'tree':
             if (!$this->_cache['tree'] instanceof ItemList || $clear) {
                 if ($rows = $this->_tbl->getTree($filters['thread'])) {
                     $children = array(0 => array());
                     $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit'];
                     foreach ($rows as $row) {
                         $v = new Post($row);
                         $v->set('category', $this->get('category'));
                         $v->set('section', $this->get('section'));
                         $pt = $v->get('parent');
                         $list = @$children[$pt] ? $children[$pt] : array();
                         array_push($list, $v);
                         $children[$pt] = $list;
                     }
                     $results = $this->_treeRecurse($children[$this->get('parent')], $children);
                 }
                 $this->_cache['tree'] = new ItemList($results);
             }
             return $this->_cache['tree'];
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_cache['posts'] instanceof ItemList || $clear) {
                 if ($results = $this->_tbl->getRecords($filters)) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Post($result);
                         $results[$key]->set('category', $this->get('category'));
                         $results[$key]->set('section', $this->get('section'));
                     }
                 } else {
                     $results = array();
                 }
                 $this->_cache['posts'] = new ItemList($results);
             }
             return $this->_cache['posts'];
             break;
     }
 }