Example #1
0
 /**
  * Get a count of data associated with this collection
  *
  * @param   string $what What to count
  * @return  integer
  */
 public function count($what = '')
 {
     if (!isset($this->_counts) || !is_array($this->_counts)) {
         $this->_counts = array();
     }
     $what = strtolower(trim($what));
     switch ($what) {
         case 'collection':
         case 'image':
         case 'text':
         case 'file':
         case 'link':
             if (isset($this->_counts[$what])) {
                 return (int) $this->_counts[$what];
             } else {
                 return 0;
             }
             break;
         case 'followers':
             if (!isset($this->_counts[$what])) {
                 $tbl = new Tables\Following($this->_db);
                 $this->_counts[$what] = $tbl->count(array('following_type' => 'collection', 'following_id' => $this->get('id')));
             }
             return $this->_counts[$what];
             break;
         case 'likes':
         case 'like':
         case 'votes':
         case 'vote':
             if ($this->get('likes', null) == null) {
                 $tbl = new Tables\Item($this->_db);
                 $this->set('likes', $tbl->getLikes(array('object_type' => 'collection', 'object_id' => $this->get('id'))));
             }
             return (int) $this->get('likes', 0);
             break;
         case 'reposts':
         case 'repost':
             if ($this->get('reposts', null) == null) {
                 $tbl = new Tables\Item($this->_db);
                 $this->set('reposts', $tbl->getReposts(array('object_type' => 'collection', 'object_id' => $this->get('id'))));
             }
             return (int) $this->get('reposts', 0);
             break;
         case 'posts':
         case 'post':
             if ($this->get('posts', null) == null) {
                 $this->set('posts', $this->posts(array('count' => true)));
             }
             return (int) $this->get('posts', 0);
             break;
         default:
             return 0;
             break;
     }
 }