/** * Get the array of posts satisfying the criteria specified in the parameter $options * * @param Zend_Db_Adapter_Abstract $db * @param array $options * @return array */ public static function GetPosts_Array($db, $options = array()) { $arrPosts = FALSE; $user_ids = array(); //---------------------- // 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 $arrPosts = $dbCache->load($tagCache); } // проверка, есть ли уже данные в кэше: if ($arrPosts === 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) { return $posts; } $post_ids = array_keys($posts); // load the profile data for loaded posts $profiles = Default_Model_Profile::BuildMultiple_Array($db, 'Default_Model_DbTable_BlogPostProfile', array($post_ids)); $arrPosts = array(); foreach ($posts as $post_id => $post) { if (array_key_exists($post_id, $profiles)) { $arrPosts[$post_id] = $posts[$post_id] + $profiles[$post_id]; } else { $arrPosts[$post_id] = $posts[$post_id]; } // Получим ids пользователей для всех сообщениий $user_ids[] = $post['user_id']; } // Уберем повторяющиеся значения из массива $user_ids = array_unique($user_ids); // Получим всех пользователей $options = array('user_id' => $user_ids); $users = Default_Model_DbTable_User::GetUsers_Array($db, $options); // Добавим пользователя для каждого сообщения foreach ($posts as $post_id => $post) { $postuser_id = $post['user_id']; foreach ($users as $user) { $user_id = $user['id']; if ($user_id == $postuser_id) { $arrPosts[$post_id]['_user_'] = $user; break; } } } // Загрузим изображения для каждого сообщения $options = array('post_id' => $post_ids); $images = Default_Model_DbTable_BlogPostImage::GetImages_Array($db, $options); foreach ($images as $image) { $post_id = $image['post_id']; $image_id = $image['id']; $arrPosts[$post_id]['_images_'][$image_id] = $image; } // Загрузим координаты для каждого сообщения $locations = Default_Model_DbTable_BlogPostLocation::GetLocations_Array($db, $options); foreach ($locations as $location) { $post_id = $location['post_id']; $location_id = $location['id']; $arrPosts[$post_id]['_locations_'][$location_id] = $location; } // Загрузим метки для каждого сообщения $tags = Default_Model_DbTable_BlogPostTag::GetTags_Array($db, $options); foreach ($tags as $tag) { $post_id = $tag['post_id']; $tag_id = $tag['id']; $arrPosts[$post_id]['_tags_'][$tag_id] = $tag; } // Загрузим audio для каждого сообщения $audios = Default_Model_DbTable_BlogPostAudio::GetAudio_Array($db, $options); foreach ($audios as $audio) { $post_id = $audio['post_id']; $audio_id = $audio['id']; $arrPosts[$post_id]['_audio_'][$audio_id] = $audio; } // Загрузим video для каждого сообщения $videos = Default_Model_DbTable_BlogPostVideo::GetVideo_Array($db, $options); foreach ($videos as $video) { $post_id = $video['post_id']; $video_id = $video['id']; $arrPosts[$post_id]['_video_'][$video_id] = $video; } // Загрузим comments для каждого сообщения $comments = Default_Model_DbTable_BlogPostComment::GetComments_Array($db, $options); foreach ($comments as $comment) { $post_id = $comment['post_id']; $comment_id = $comment['id']; $arrPosts[$post_id]['_comments_'][$comment_id] = $comment; } // Если разрешено кеширование, то сохраним данные в кеше if ($dbCache->getOption('caching')) { $dbCache->save($arrPosts, $tagCache); } } else { $result = $arrPosts; } return $arrPosts; }
/** * Get the number of rows in the table * * @param array $options * * @return int */ public function getCountRowsTable($options = NULL) { $request = $this->getRequest(); $params = $request->getParams(); $table = $params['table']; //--------------------------- if ($table == 'admin.blog_posts') { return Default_Model_DbTable_BlogPost::GetPostsCount($this->db, $options); } if ($table == 'admin.blog_posts_tags') { $post_ids = Default_Model_DbTable_BlogPost::GetPostsIds_Array($this->db, $options); return Default_Model_DbTable_BlogPostTag::GetPostsTags_Count($this->db, array('post_id' => $post_ids)); } if ($table == 'admin.blog_posts_images') { $post_ids = Default_Model_DbTable_BlogPost::GetPostsIds_Array($this->db, $options); return Default_Model_DbTable_BlogPostImage::GetPostsImages_Count($this->db, array('post_id' => $post_ids)); } if ($table == 'admin.blog_posts_audio') { $post_ids = Default_Model_DbTable_BlogPost::GetPostsIds_Array($this->db, $options); return Default_Model_DbTable_BlogPostAudio::GetPostsAudio_Count($this->db, array('post_id' => $post_ids)); } if ($table == 'admin.blog_posts_video') { $post_ids = Default_Model_DbTable_BlogPost::GetPostsIds_Array($this->db, $options); return Default_Model_DbTable_BlogPostVideo::GetPostsVideo_Count($this->db, array('post_id' => $post_ids)); } if ($table == 'admin.blog_posts_locations') { $post_ids = Default_Model_DbTable_BlogPost::GetPostsIds_Array($this->db, $options); return Default_Model_DbTable_BlogPostLocation::GetPostsLocations_Count($this->db, array('post_id' => $post_ids)); } }
/** * Action - details * get detailed information for geographical coordinate * * Access to the action is possible in the following paths: * - /blogmanager/details?post_id=2345&location_id=1234 * * @return void */ public function detailsAction() { $request = $this->getRequest(); $post_id = $request->getParam('post_id'); $location_id = $request->getParam('location_id'); $location = new Default_Model_DbTable_BlogPostLocation($this->db); if ($location->loadForPost($post_id, $location_id)) { $details = $location->details; } else { $details = $this->Translate('Ошибка получения подробной информации по географической координате'); $details = '<div class="error">' . $details . '</div>'; } $this->view->details = $details; }