/** * Get the array of ids satisfying the criteria specified in the parameter $options * * @param Zend_Db_Adapter_Abstract $db * @param string $nameTable * @param array $options * @return array */ public static function GetLogIds_Array($db, $nameTable, $options = array()) { //---------------------- // initialize the options $defaults = array('offset' => 0, 'limit' => 0, 'order' => 'l.ts', 'sort' => true); foreach ($defaults as $k => $v) { $options[$k] = array_key_exists($k, $options) ? $options[$k] : $v; } $select = self::_GetBaseQuery($db, $nameTable, $options); // set the fields to select $select->from(null, 'l.*'); // set the offset, limit, and ordering of results if ($options['limit'] > 0) { $select->limit($options['limit'], $options['offset']); } // Установим параметры сортировки для таблицы if ($options['sort']) { $select = self::GetSelectForSort($select, $options); } $strSelect = $select->__toString(); // fetch user data from database $data = $db->fetchAll($select); // turn data into array of DatabaseObject_User objects $logs = parent::BuildMultiple_Array($db, __CLASS__, $data, $nameTable); $log_ids = array_keys($logs); return $log_ids; }
/** * Get an array of audio for post * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array Default_Model_DbTable_BlogPostAudio */ public static function GetAudio_Array($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'); $strSelect = $select->__toString(); // fetch post data from database $data = $db->fetchAll($select); // turn data into array of BlogPostAudio objects $audio = parent::BuildMultiple_Array($db, __CLASS__, $data); return $audio; }
/** * Get an array of comments for post * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array Default_Model_DbTable_BlogPostComment */ public static function GetComments_Array($db, $options = array()) { // initialize the options $defaults = array('user_id' => array(), 'post_id' => array(), 'reply_id' => array(), 'comment_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']); } // filter results on specified id ids (if any) if (count($options['comment_id']) > 0) { $select->where('c.id in (?)', $options['comment_id']); } $select->order('c.id'); $strSelect = $select->__toString(); // fetch post data from database $data = $db->fetchAll($select); // turn data into array of BlogPostComment objects $comments = parent::BuildMultiple_Array($db, __CLASS__, $data); return $comments; }
/** * Get the array of ids satisfying the criteria specified in the parameter $options * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array */ public static function GetPostsIds_Array($db, $options = array()) { $post_ids = FALSE; //---------------------- // initialize the options $defaults = array('offset' => 0, 'limit' => 0, 'order' => 'p.ts_created', 'sort' => true); 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, 'p.*'); // set the offset, limit, and ordering of results if ($options['limit'] > 0) { $select->limit($options['limit'], $options['offset']); } // Установим параметры сортировки для таблицы if ($options['sort']) { $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 $post_ids = $dbCache->load($tagCache); } // проверка, есть ли уже данные в кэше: if ($post_ids === FALSE) { // fetch user data from database $data = $db->fetchAll($select); // turn data into array of DatabaseObject_User objects $posts = parent::BuildMultiple_Array($db, __CLASS__, $data); if (count($posts) == 0) { $post_ids = array(); } else { $post_ids = array_keys($posts); } // Если разрешено кеширование, то сохраним данные в кеше if ($dbCache->getOption('caching')) { $dbCache->save($post_ids, $tagCache); } } else { $result = $post_ids; } return $post_ids; }
/** * Get an array of tags to posts * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array */ public static function GetTags_Array($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_Array($db, __CLASS__, $data); return $tags; }
/** * Get the array of users satisfying the criteria specified in the parameter $options * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array */ public static function GetUsers_Array($db, $options = array()) { $arrUsers = 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->order($options['order']); // Установим параметры сортировки для таблицы $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); // $cache->clean(Zend_Cache::CLEANING_MODE_OLD); // $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, array($tagCache)); } // Получим данные из кеша по тегу $tagCache $arrUsers = $dbCache->load($tagCache); } // проверка, есть ли уже данные в кэше: if ($arrUsers === FALSE) { // fetch user data from database $data = $db->fetchAll($select); // turn data into array of DatabaseObject_User objects $users = parent::BuildMultiple_Array($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_Array($db, 'Default_Model_DbTable_UserProfile', array($user_ids)); $arrUsers = array(); foreach ($users as $user_id => $user) { if (array_key_exists($user_id, $profiles)) { $arrUsers[$user_id] = $users[$user_id] + $profiles[$user_id]; } else { $arrUsers[$user_id] = $users[$user_id]; } } // Если разрешено кеширование, то сохраним данные в кеше if ($dbCache->getOption('caching')) { $dbCache->save($arrUsers, $tagCache); } } else { $result = $arrUsers; } return $arrUsers; }