Пример #1
0
 /**
  * Get a count for the specified key
  *
  * @param   string   $what  Key name [following, followers, collectios, posts]
  * @return  integer
  */
 public function count($what = 'following')
 {
     $what = strtolower(trim($what));
     $value = $this->get($what);
     switch ($what) {
         case 'following':
             if ($value === null) {
                 $value = $this->_tbl->count(array('follower_type' => $this->get('following_type'), 'follower_id' => $this->get('following_id')));
                 $this->set($what, $value);
             }
             break;
         case 'followers':
             if ($value === null) {
                 $value = $this->_tbl->count(array('following_type' => $this->get('following_type'), 'following_id' => $this->get('following_id')));
                 $this->set($what, $value);
             }
             break;
         case 'collections':
             if ($value === null && $this->get('following_type') != 'collection') {
                 $model = Collections::getInstance($this->get('following_type'), $this->get('following_id'));
                 $value = $model->collections(array('count'));
                 $this->set($what, $value);
             }
             break;
         case 'posts':
             if ($value === null) {
                 if ($this->get('following_type') != 'collection') {
                     $model = Archive::getInstance($this->get('following_type'), $this->get('following_id'));
                     $value = $model->posts(array('count'));
                     $this->set($what, $value);
                 } else {
                     $model = Collection::getInstance($this->get('following_id'));
                     $value = $model->posts(array('count'));
                     $this->set($what, $value);
                 }
             }
             break;
     }
     if ($value === null) {
         $value = 0;
     }
     return $value;
 }