/** * 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; }
/** * Action - tag * displays messages which are marked this tag for all authors * * Access to the action is possible in the following paths: * router pattern - user/all/tag/:tag/* * - /user/all/tag/reports * * @return void */ public function tagAction() { $request = $this->getRequest(); $params = $request->getParams(); $itemCountPerPage = isset($params['itemCountPerPage']) ? $params['itemCountPerPage'] : 0; $page = isset($params['page']) ? $params['page'] : 0; //Получим параметр метки $tag = trim($request->getUserParam('tag')); if (strlen($tag) == 0) { $this->_redirect('/index/index'); } $options = array('tag' => $tag, 'status' => Default_Model_DbTable_BlogPost::STATUS_LIVE, 'order' => 'p.ts_created desc'); // Будем проверять признак публикации сообщений, только у гостей if (!$this->_authenticated) { $options['public_only'] = TRUE; } // Установим в параметры данные для Paginator if ($page) { $options['page'] = (int) $page; } if ($itemCountPerPage) { $options['itemCountPerPage'] = (int) $itemCountPerPage; } $arrData = Default_Model_DbTable_BlogPost::GetPaginatorPosts($this->db, $options); $posts = $arrData['items']; $pages = $arrData['pages']; if (count($posts) == 0) { $this->view->class_message = 'information'; $label = Default_Model_DbTable_BlogPost::getLabelForTag($this->db, $tag); $this->view->message = $this->Translate('Ни одной записи в блоге не было найдено для метки') . " - <em>{$label}</em>"; } else { // determine which users' posts were retrieved $user_ids = array(); foreach ($posts as $post) { $user_ids[$post->user_id] = $post->user_id; } // load the user records if (count($user_ids) > 0) { $options = array('user_id' => $user_ids); $users = Default_Model_DbTable_User::GetUsers($this->db, $options); } else { $users = array(); } } $tagLabel = Default_Model_DbTable_BlogPost::getLabelForTag($this->db, $tag); $this->_breadcrumbs->addStep($this->Translate('Сообщения для метки')); $this->view->tag = $tag; $this->view->tagLabel = $tagLabel; $this->view->posts = $posts; $this->view->users = $users; $this->view->pages = $pages; }
/** * Action - tag * operations with tags * * Access to the action is possible in the following paths: * router pattern - user/:username/tag/:tag/* * - /user/user1/tag/reports * * @return void */ public function tagAction() { $request = $this->getRequest(); $params = $request->getParams(); $itemCountPerPage = isset($params['itemCountPerPage']) ? $params['itemCountPerPage'] : 0; $page = isset($params['page']) ? $params['page'] : 0; //Получим параметр метки $tag = trim($request->getUserParam('tag')); if (strlen($tag) == 0) { $urlCustom = $this->getCustomUrl(array('username' => $this->user->username, 'action' => 'index'), 'user'); $this->_redirector->gotoUrl($urlCustom, array('prependBase' => FALSE)); } $options = array('user_id' => $this->user->getId(), 'tag' => $tag, 'status' => Default_Model_DbTable_BlogPost::STATUS_LIVE, 'order' => 'p.ts_created desc', 'actuals' => array(1)); // Установим в параметры данные для Paginator if ($page) { $options['page'] = (int) $page; } if ($itemCountPerPage) { $options['itemCountPerPage'] = (int) $itemCountPerPage; } $arrData = Default_Model_DbTable_BlogPost::GetPaginatorPosts($this->db, $options); $posts = $arrData['items']; $pages = $arrData['pages']; if (count($posts) == 0) { $this->view->class_message = 'information'; $this->view->message = $this->Translate('Ни одной записи в блоге не было найдено для метки') . " - <em>{$tag}</em>"; } $tagLabel = Default_Model_DbTable_BlogPost::getLabelForTag($this->db, $tag); $this->_breadcrumbs->addStep($this->Translate('Сообщения для метки')); $this->view->tag = $tag; $this->view->tagLabel = $tagLabel; $this->view->posts = $posts; $this->view->pages = $pages; }