Пример #1
0
 /**
  * Get a count or list of the comments on an item
  *
  * @param   string  $rtrn    Data format to return
  * @param   array   $filters Filters to apply to data fetch
  * @param   boolean $clear   Clear cached data?
  * @return  mixed
  */
 public function comments($what = 'list', $filters = array(), $clear = false)
 {
     if (!isset($filters['item_id'])) {
         $filters['item_id'] = $this->get('id');
     }
     if (!isset($filters['item_type'])) {
         $filters['item_type'] = 'collection';
     }
     if (!isset($filters['state'])) {
         $filters['state'] = array(1, 3);
     }
     switch (strtolower(trim($what))) {
         case 'count':
             if ($this->_cache['comments.count'] === null) {
                 $tbl = new Comment($this->_db);
                 $this->_cache['comments.count'] = $tbl->count($filters);
             }
             return $this->_cache['comments.count'];
             break;
         case 'list':
         case 'results':
         default:
             if (!is_array($this->_cache['comments.list'])) {
                 $tbl = new Comment($this->_db);
                 if (!($results = $tbl->getComments('collection', $this->get('id')))) {
                     $results = array();
                 }
                 $this->_cache['comments.list'] = $results;
             }
             return $this->_cache['comments.list'];
             break;
     }
 }