Exemplo n.º 1
0
 /**
  * Store attachments
  *
  * @param   boolean  $updateNulls
  * @return  void
  */
 public function store($updateNulls = false)
 {
     $result = parent::store($updateNulls);
     if (!$result) {
         return false;
     }
     if (isset($this->attachmentNames) && count($this->attachmentNames) > 0) {
         // save the attachments
         foreach ($this->attachmentNames as $nm) {
             // delete old attachment
             // find old file and remove it from file system
             $file = new File($this->_db);
             $file->loadByComment($this->id);
             if ($file->id) {
                 if (!$file->deleteFile()) {
                     $this->setError($file->getError());
                     continue;
                 }
             }
             $file->filename = $nm;
             $file->comment_id = $this->id;
             if (!$file->store()) {
                 $this->setError($file->getError());
                 continue;
             }
         }
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * Get a list of attachments on this comment
  *
  * @param      string  $rtrn    What data to return
  * @param      array   $filters Filters to build query from
  * @param      boolean $clear   Clear cached data or not?
  * @return     object  \Hubzero\Base\ItemList
  */
 public function attachments($rtrn = 'list', $filters = array(), $clear = false)
 {
     if (!isset($filters['comment_id'])) {
         $filters['comment_id'] = $this->get('id');
     }
     switch (strtolower($rtrn)) {
         case 'count':
             return $this->attachments('list')->total();
             break;
         case 'first':
             return $this->attachments('list')->first();
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_cache['attachments'] instanceof ItemList || $clear) {
                 $tbl = new File($this->_db);
                 if ($results = $tbl->find($filters)) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Attachment($result);
                     }
                 } else {
                     $results = array();
                 }
                 $this->_cache['attachments'] = new ItemList($results);
             }
             return $this->_cache['attachments'];
             break;
     }
 }