Пример #1
0
 /**
  *	resultAction
  *
  *	Gets search results.
  *
  */
 function resultAction()
 {
     // assuming that the CleanQuery plugin has already stripped empty parameters
     // regenerate URI
     if (isset($_GET) && is_array($_GET) && !empty($_GET)) {
         $path = '';
         array_walk($_GET, array('SearchController', 'encodeParam'));
         foreach ($_GET as $key => $value) {
             if ($key != 'submit' && $key != 'submitsearch') {
                 $path .= '/' . $key . '/' . $value;
             }
         }
         $uri = $_SERVER['REQUEST_URI'];
         $path = substr($uri, 0, strpos($uri, '?')) . $path;
         $this->getResponse()->setRedirect($path, $this->_permanent ? 301 : 302);
         $this->getResponse()->sendResponse();
         return;
     }
     $params = $this->getRequest()->getParams();
     $data = array();
     // Get page number and items per page
     $page = isset($params['page']) ? $params['page'] : 1;
     $count = isset($params['count']) ? $params['count'] : 10;
     // Get list order value
     $order = isset($params['order']) ? $params['order'] : 'created';
     // disabled for now...
     // Search params
     //$search = isset($params['q']) ? $params['q'] : null;
     // quick fix enables the search string to last to the next page as well
     /****************************************************/
     $search_space = new Zend_Session_Namespace('search');
     if (isset($params['q'])) {
         $search_space->query = $params['q'];
     }
     $search = $search_space->query;
     /****************************************************/
     // Get data and content result count
     $contentModel = new Default_Model_Content();
     $data = $contentModel->getSearchResult($search, $page, $count, $order);
     $contentCount = $contentModel->getContentCountBySearch($search);
     $results = array();
     // gather other content data and insert to results array
     if (isset($data[0])) {
         $contentHasTagModel = new Default_Model_ContentHasTag();
         $contentRatingsModel = new Default_Model_ContentRatings();
         $i = 0;
         foreach ($data as $content) {
             $results[$i] = $content;
             $results[$i]['tags'] = $contentHasTagModel->getContentTags($content['id_cnt']);
             $results[$i]['ratingdata'] = $contentRatingsModel->getPercentagesById($content['id_cnt']);
             $i++;
         }
     }
     // Calculate total page count
     $pageCount = ceil($contentCount / $count);
     // Custom pagination to fix memory error on large amount of data
     $paginator = new Zend_View();
     $paginator->setScriptPath('../application/views/scripts');
     $paginator->pageCount = $pageCount;
     $paginator->currentPage = $page;
     $paginator->pagesInRange = 10;
     $this->view->search = $search;
     $this->view->page = $page;
     $this->view->contentPaginator = $paginator;
     $this->view->contentData = $results;
 }