コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
ファイル: IndexController.php プロジェクト: bsa-git/zf-myblog
 /**
  * Action - feed 
  * actions with news user tape 
  * you can get all the news 
  * and the user can receive news only on a separate tag
  *
  * Access to the action is possible in the following paths:
  * router pattern - user/all/feed/:tag/* or controller/:action/*
  *
  * - /user/all/feed/reports
  * or
  * - /index/feed
  *
  * @return void
  */
 public function feedAction()
 {
     //Получим параметр метки
     $tag = trim($this->_request->getUserParam('tag'));
     // first retrieve all recent posts
     $options = array('status' => Default_Model_DbTable_BlogPost::STATUS_LIVE, 'limit' => 10, 'order' => 'p.ts_created desc', 'public_only' => true);
     if ($tag) {
         $options['tag'] = $tag;
     }
     $recentPosts = Default_Model_DbTable_BlogPost::GetPosts($this->db, $options);
     // base URL for generated links
     if ($this->getRequest()->getServer('HTTPS') == 'on') {
         $domain = 'https://';
     } else {
         $domain = 'http://';
     }
     $domain .= $this->getRequest()->getServer('HTTP_HOST');
     // url for web feed
     if ($tag) {
         $url = $this->getCustomUrl(array('tag' => $tag), 'feed_tag_all');
     } else {
         $url = $this->getUrl('feed');
     }
     $feedData = array('link' => $domain . $url, 'charset' => 'UTF-8', 'entries' => array());
     if ($tag) {
         $tagLabel = Default_Model_DbTable_BlogPost::getLabelForTag($this->db, $tag);
         $title = $this->Translate('Сообщения авторов') . ' ' . $this->Translate('для метки') . ' - ' . $tagLabel;
     } else {
         $title = $this->Translate('Сообщения всех авторов');
     }
     $feedData['title'] = $title;
     // determine which users' posts were retrieved
     $user_ids = array();
     foreach ($recentPosts 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();
     }
     // build feed entries based on returned posts
     foreach ($recentPosts as $post) {
         $user = $users[$post->user_id];
         $url = $this->getCustomUrl(array('username' => $user->username, 'url' => $post->url), 'post');
         $entry = array('title' => $post->profile->title, 'link' => $domain . $url, 'description' => $post->getTeaser(200), 'lastUpdate' => $post->ts_created, 'category' => array());
         // attach tags to each entry
         foreach ($post->getTags() as $tag) {
             $entry['category'][] = array('term' => $tag);
         }
         $feedData['entries'][] = $entry;
     }
     // create feed based on created data
     $feed = Zend_Feed::importArray($feedData, 'atom');
     // disable auto-rendering since we're outputting an image
     $this->_helper->viewRenderer->setNoRender();
     // output the feed to the browser
     $feed->send();
 }