/** * Get an array objects of tags to posts * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array Default_Model_DbTable_BlogPostTag */ public static function GetTags($db, $options = array()) { // initialize the options $defaults = array('post_id' => array()); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = $db->select(); $select->from(array('t' => 'blog_posts_tags'), 't.*'); // filter results on specified post ids (if any) if (count($options['post_id']) > 0) { $select->where('t.post_id in (?)', $options['post_id']); } // fetch post data from database $data = $db->fetchAll($select); // turn data into array of DatabaseObject_BlogPostLocation objects $tags = parent::BuildMultiple($db, __CLASS__, $data); return $tags; }
/** * Get an array of audio objects for post * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array Default_Model_DbTable_BlogPostImage */ public static function GetAudio($db, $options = array()) { // initialize the options $defaults = array('post_id' => array()); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = $db->select(); $select->from(array('au' => 'blog_posts_audio'), array('au.*')); // filter results on specified post ids (if any) if (count($options['post_id']) > 0) { $select->where('au.post_id in (?)', $options['post_id']); } $select->order('au.ranking'); // fetch post data from database $data = $db->fetchAll($select); // turn data into array of BlogPostAudio objects $audio = parent::BuildMultiple($db, __CLASS__, $data); return $audio; }
/** * Get an array objects of comments for post * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array Default_Model_DbTable_BlogPostComment */ public static function GetComments($db, $options = array()) { // initialize the options $defaults = array('user_id' => array(), 'post_id' => array(), 'reply_id' => array()); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = $db->select(); $select->from(array('c' => 'blog_posts_comments'), array('c.*')); // filter results on specified user ids (if any) if (count($options['user_id']) > 0) { $select->where('c.user_id in (?)', $options['user_id']); } // filter results on specified post ids (if any) if (count($options['post_id']) > 0) { $select->where('c.post_id in (?)', $options['post_id']); } // filter results on specified reply ids (if any) if (count($options['reply_id']) > 0) { $select->where('c.reply_id in (?)', $options['reply_id']); } $select->order('c.id'); // fetch post data from database $data = $db->fetchAll($select); // turn data into array of BlogPostComment objects $comments = parent::BuildMultiple($db, __CLASS__, $data); return $comments; }
/** * Get the array objects of users satisfying the criteria specified in the parameter $options * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array массив обьектов типа - Default_Model_DbTable_User */ public static function GetUsers($db, $options = array()) { $users = FALSE; //---------------------- // initialize the options $defaults = array('offset' => 0, 'limit' => 0, 'order' => 'u.username'); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = self::_GetBaseQuery($db, $options); // set the fields to select $select->from(null, 'u.*'); // set the offset, limit, and ordering of results if ($options['limit'] > 0) { $select->limit($options['limit'], $options['offset']); } // Установим параметры сортировки для таблицы $select = self::GetSelectForSort($select, $options); $strSelect = $select->__toString(); //------ Применить кеширование ------- $dbCache = Default_Plugin_SysBox::getCache('db'); if ($dbCache->getOption('caching')) { // Получим TAG для кеширования $arrItems = array($select, $options); $strSerialize = serialize($arrItems); $tagCache = md5($strSerialize); // Очистим кеш if (Default_Plugin_SysBox::isCleanCache()) { $dbCache->clean(Zend_Cache::CLEANING_MODE_ALL); } // Получим данные из кеша по тегу $tagCache $users = $dbCache->load($tagCache); } // проверка, есть ли уже данные в кэше: if ($users === FALSE) { // fetch user data from database $data = $db->fetchAll($select); // turn data into array of DatabaseObject_User objects $users = parent::BuildMultiple($db, __CLASS__, $data); if (count($users) == 0) { return $users; } $user_ids = array_keys($users); // load the profile data for loaded posts $profiles = Default_Model_Profile::BuildMultiple($db, 'Default_Model_DbTable_UserProfile', array($user_ids)); foreach ($users as $user_id => $user) { if (array_key_exists($user_id, $profiles) && $profiles[$user_id] instanceof Default_Model_DbTable_UserProfile) { $users[$user_id]->profile = $profiles[$user_id]; } else { $users[$user_id]->profile->setUserId($user_id); } //!!!!------ Начало установки признака сортировки -----!!!!! if (isset($options['sortColumn'])) { $users[$user_id]->sortColumn = $options['sortColumn']; } if (isset($options['ascDescFlg'])) { $users[$user_id]->ascDescFlg = $options['ascDescFlg']; } //!!!!------ Начало установки признака сортировки -----!!!!! } // Если разрешено кеширование, то сохраним данные в кеше if ($dbCache->getOption('caching')) { $dbCache->save($users, $tagCache); } } else { $result = $users; } return $users; }