Esempio n. 1
0
 /**
  * STATIC Get the number of faved items per model
  * @return string $archived {true, false, both}
  * @return array $favorites
  */
 static function getAllCount($archives = true)
 {
     $_this = Common::getModel('Favorite');
     // Get potential models from list
     $models = @array_keys(Configure::read('App.favorites.models'), true);
     // default condition
     $conditions = array('conditions' => array('model' => $models, 'user_id' => User::get('id')), 'fields' => array('model', 'COUNT(model) as count'), 'group' => array('Favorite.model'));
     // Bind the models if the search depends on record's status
     if ($archives != 'both' && is_bool($archives)) {
         Favorite::__bindArchivableModels(&$_this, &$models, &$conditions, $archives);
     }
     // Search for faved records
     $favorites = $_this->find('all', $conditions);
     //pr($favorites);
     //tidy up
     foreach ($favorites as $i => $fav) {
         $favorites[$i]['Favorite']['count'] = $fav[0]['count'];
         unset($favorites[$i][0]);
     }
     return $favorites;
 }