Exemplo n.º 1
0
 /**
  * Get a count of or list of attachments on this model
  *
  * @param   string   $rtrn     Data to return state in [count, list]
  * @param   array    $filters  Filters to apply to the query
  * @param   boolean  $clear    Clear data cache?
  * @return  mixed
  */
 public function attachments($rtrn = 'list', $filters = array(), $clear = false)
 {
     $filters['comment_id'] = 0;
     if (!isset($filters['ticket'])) {
         $filters['ticket'] = $this->get('id');
     }
     switch (strtolower($rtrn)) {
         case 'count':
             if (!is_numeric($this->_data->get('attachments.count')) || $clear) {
                 $tbl = new Tables\Attachment($this->_db);
                 $this->_data->set('attachments.count', $tbl->find('count', $filters));
             }
             return $this->_data->get('attachments.count');
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_data->get('attachments') instanceof ItemList || $clear) {
                 $tbl = new Tables\Attachment($this->_db);
                 if ($results = $tbl->find('list', $filters)) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Attachment($result);
                     }
                 } else {
                     $results = array();
                 }
                 $this->_data->set('attachments', new ItemList($results));
             }
             return $this->_data->get('attachments');
             break;
     }
 }