Пример #1
0
 /**
  * Get the data to build a tree Comments
  *
  * @param Zend_Db_Adapter_Abstract $db
  * @param int $post_id
  * @return array
  */
 public static function getTreeComments($db, $user_id, $params)
 {
     $sortcomm = array();
     $newComments = array();
     //-----------------------------------------
     // Получим комментарии
     $comments = self::GetComments_Array($db, $params);
     // Получим не повторяющийся массив Ids пользователей
     $arrBox = new Default_Plugin_ArrayBox($comments);
     if ($arrBox->count() == 0) {
         return $sortcomm;
     }
     $arrUser_ids = $arrBox->slice('user_id', TRUE);
     // Добавим в массив Ids пользователей id автора, если его там нет
     if (!$arrUser_ids->isValue($user_id)) {
         $arrUser_ids = $arrUser_ids->push($user_id);
     }
     $arrUser_ids = $arrUser_ids->get();
     // Получим массив пользователей из их Ids
     $options = array('user_id' => $arrUser_ids);
     $users = Default_Model_DbTable_User::GetUsers($db, $options);
     foreach ($comments as $comment) {
         if (isset($comment['user_id']) && isset($users[$comment['user_id']])) {
             $user = $users[$comment['user_id']];
             // Установим имя пользователя
             $comment['username'] = $user->username;
             // Установим дату создания комментария
             $date = new Zend_Date($comment['ts'], 'U');
             $dtFormat = $date->get('dd MMMM YYYY, HH:mm');
             $comment['date'] = $dtFormat;
             // Установим признак авторства
             $isAutor = $user_id == $comment['user_id'];
             $comment['is_autor'] = $isAutor;
             // Установим изображение пользователя
             if ($user->profile->user_img) {
                 $user_img = $user->profile->user_img;
             } else {
                 if ($comment['is_autor']) {
                     $user_img = "/images/system/user_new.png";
                 } else {
                     if ($user->profile->sex) {
                         if ($user->profile->sex == 'male') {
                             $user_img = "/images/system/user_male.png";
                         } else {
                             $user_img = "/images/system/user_female.png";
                         }
                     } else {
                         $user_img = "/images/system/user_message.png";
                     }
                 }
             }
             $comment['user_img'] = $user_img;
             // Установим URL пользователя
             $comment['user_url'] = "/user/{$user->username}";
             // Добавим в новый массив
             $newComments[] = $comment;
         }
     }
     //------ Создадим дерево комментариев ------
     if (count($newComments) > 0) {
         // subcomments
         foreach ($newComments as $item) {
             if ($item['reply_id'] == 0) {
                 $sortcomm[$item['id']]['parent'] = $item;
             }
             if ($item['reply_id'] > 0) {
                 if (isset($path[$item['reply_id']])) {
                     $str = '$sortcomm';
                     foreach ($path[$item['reply_id']] as $pitem) {
                         $rep = $item['reply_id'];
                         $str .= "[{$pitem}][sub]";
                     }
                     $str .= "[{$item['reply_id']}][sub]";
                     $str .= "[{$item['id']}]['parent']";
                     $str .= '=$item;';
                     eval($str);
                     foreach ($path[$item['reply_id']] as $pitem) {
                         $path[$item['id']][] = $pitem;
                     }
                     $path[$item['id']][] = $item['reply_id'];
                 } else {
                     $sortcomm[$item['reply_id']]['sub'][$item['id']]['parent'] = $item;
                     $path[$item['id']][] = $item['reply_id'];
                 }
             }
         }
     }
     return $sortcomm;
 }
Пример #2
0
 /**
  * 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();
 }
Пример #3
0
 /**
  * Action - index
  * search posts for request
  * 
  * Access to the action is possible in the following paths:
  * - /search/index
  * - /search/
  * @return void
  */
 public function indexAction()
 {
     $searchZendAuth = $this->_sessZendAuth->search;
     //------------------
     $request = $this->getRequest();
     $params = $request->getParams();
     $itemCountPerPage = isset($params['itemCountPerPage']) ? $params['itemCountPerPage'] : 0;
     $page = isset($params['page']) ? $params['page'] : 0;
     // Получим запрос для поиска
     $query = trim($params['q']);
     // Получим  url MVC
     $urlMVC = $this->_url_mvc;
     // Скорректируем  url MVC
     $addQuery = '/q/' . $query;
     $arrMVC = explode('/q/', $urlMVC);
     $urlMVC = $arrMVC[0] . $addQuery;
     // Подготовка запроса для поиска
     $q = Zend_Search_Lucene_Search_QueryParser::parse($query, 'utf-8');
     // Параметры поиска
     $search = array('performed' => false, 'limit' => $this->_config['paginator']['itemCountPerPage'], 'total' => 0, 'start' => 0, 'finish' => 0, 'page' => 1, 'pages' => 1, 'results' => array());
     // Установим параметры для Paginator
     if ($itemCountPerPage) {
         $search['limit'] = (int) $itemCountPerPage;
     }
     if ($page) {
         $search['page'] = (int) $page;
     }
     // Поиск по запросу
     try {
         if (strlen($q) == 0) {
             throw new Exception('No search term specified');
         }
         // Преобразуем строку запроса через translit();
         $search_query = new Default_Plugin_String($query);
         $search_query = (string) $search_query->translit()->Strip('-');
         // Проверим если результаты запроса в сессии пользователя
         // если есть, то берем их из сессии и отсылаем пользователю
         if (isset($searchZendAuth[$search_query])) {
             $post_ids = $searchZendAuth[$search_query];
             $post_ids = explode(';', $post_ids);
         } else {
             $path = Default_Model_DbTable_BlogPost::getIndexFullpath();
             $index = Zend_Search_Lucene::open($path);
             $hits = $index->find($q);
             $post_ids = array();
             foreach ($hits as $hit) {
                 $post_ids[] = (int) $hit->post_id;
             }
             // ВАЖНО!!! привильно запоминать
             $this->_sessZendAuth->search[$search_query] = implode(";", $post_ids);
             // НЕ ПРАВИЛЬНО!!!
         }
         // $searchZendAuth[$search_query] = implode(";", $post_ids);
         //------ Создадим обьект Zend_Paginator
         $paginator = Zend_Paginator::factory($post_ids);
         // Установим максимальное количество отображаемых на странице элементов
         $paginator->setItemCountPerPage($search['limit']);
         // Установим текущую страницу
         $paginator->setCurrentPageNumber($search['page']);
         // Получим массив "ids" для заданной страницы
         $post_ids = array();
         foreach ($paginator as $post_id) {
             $post_ids[] = $post_id;
         }
         // Получим обьект управления страницами
         $pages = $paginator->getPages();
         $search['performed'] = true;
         $search['total'] = $pages->totalItemCount;
         $search['pages'] = $pages->pageCount;
         $search['start'] = $pages->firstItemNumber;
         $search['finish'] = $pages->lastItemNumber;
         // Получим найденные сообщения для текущей страницы
         $options = array('status' => Default_Model_DbTable_BlogPost::STATUS_LIVE, 'post_id' => $post_ids);
         $posts = Default_Model_DbTable_BlogPost::GetPosts($this->db, $options);
         foreach ($post_ids as $post_id) {
             if (array_key_exists($post_id, $posts)) {
                 $search['results'][$post_id] = $posts[$post_id];
             }
         }
         // 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();
         }
     } catch (Exception $ex) {
         // no search performed or an error occurred
     }
     if ($search['performed']) {
         $this->_breadcrumbs->addStep($this->Translate('Поиск'));
     } else {
         $this->_breadcrumbs->addStep($this->Translate('Поиск'));
     }
     $this->view->q = $query;
     $this->view->search = $search;
     $this->view->users = $users;
     $this->view->pages = $pages;
     $this->view->url_mvc = $urlMVC;
 }