/** * 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 - index * * A list of all posts of the author by month and labels and posts in the current month * * Access to the action is possible in the following paths: * - /blogmanager/index * - /blogmanager/ * @return void */ public function indexAction() { $request = $this->getRequest(); $params = $request->getParams(); $itemCountPerPage = isset($params['itemCountPerPage']) ? $params['itemCountPerPage'] : 0; $page = isset($params['page']) ? $params['page'] : 0; // Получим url MVC $urlMVC = $this->_url_mvc; // initialize the tag $tag = isset($params['tag']) ? $params['tag'] : ''; if ($tag) { $options = array('user_id' => $this->_identity->user_id, 'tag' => $tag, 'order' => 'p.ts_created desc'); // Скорректируем url MVC $addTag = '/index/tag/' . $tag; $urlMVC = str_replace($addTag, '', $urlMVC); $urlMVC .= $addTag; $tagLabel = Default_Model_DbTable_BlogPost::getLabelForTag($this->db, $tag); $this->view->tag = $tag; $this->view->tagLabel = $tagLabel; } else { // initialize the month $month = isset($params['month']) ? $params['month'] : ''; if ($month && preg_match('/^(\\d{4})-(\\d{2})$/', $month, $matches)) { $y = $matches[1]; $m = max(1, min(12, $matches[2])); // Скорректируем url MVC $addMonth = '/index/month/' . $month; $urlMVC = str_replace($addMonth, '', $urlMVC); $urlMVC .= $addMonth; } else { $y = date('Y'); // current year $m = date('n'); // current month } $from = mktime(0, 0, 0, $m, 1, $y); $to = mktime(0, 0, 0, $m + 1, 1, $y) - 1; $options = array('user_id' => $this->_identity->user_id, 'from' => date('Y-m-d H:i:s', $from), 'to' => date('Y-m-d H:i:s', $to), 'order' => 'p.ts_created desc'); $this->view->month = $from; } // Установим в параметры данные для Paginator if ($page) { $options['page'] = (int) $page; } if ($itemCountPerPage) { $options['itemCountPerPage'] = (int) $itemCountPerPage; } // retrieve the blog posts $arrData = Default_Model_DbTable_BlogPost::GetPaginatorPosts($this->db, $options); $recentPosts = isset($arrData['items']) ? $arrData['items'] : array(); $pages = isset($arrData['pages']) ? $arrData['pages'] : 0; // get the total number of posts for this user $totalPosts = Default_Model_DbTable_BlogPost::GetPostsCount($this->db, array('user_id' => $this->_identity->user_id)); $this->view->recentPosts = $recentPosts; $this->view->totalPosts = $totalPosts; $this->view->pages = $pages; $this->view->url_mvc = $urlMVC; }