public function updateAction()
 {
     Zend_Search_Lucene_Analysis_Analyzer::setDefault(new Zend_Search_Lucene_Analysis_Analyzer_Common_Utf8_CaseInsensitive());
     // Создание индекса
     $index = Zend_Search_Lucene::create(APPLICATION_ROOT . '/data/my-index');
     $mediaMapper = new Media_Model_Mapper_Media();
     $select = $mediaMapper->getDbTable()->select();
     $select->where('deleted != ?', 1)->where('active != ?', 0)->where('category_id IN(?)', array(2, 3, 4))->order('timestamp DESC');
     $mediaItems = $mediaMapper->fetchAll($select);
     if (!empty($mediaItems)) {
         foreach ($mediaItems as $mediaItem) {
             $doc = new Zend_Search_Lucene_Document();
             // Сохранение Name документа для того, чтобы идентифицировать его
             // в результатах поиска
             $doc->addField(Zend_Search_Lucene_Field::Text('title', strtolower($mediaItem->getName()), 'UTF-8'));
             // Сохранение URL документа для того, чтобы идентифицировать его
             // в результатах поиска
             $doc->addField(Zend_Search_Lucene_Field::Text('url', '/media/' . $mediaItem->getFullPath(), 'UTF-8'));
             // Сохранение Description документа для того, чтобы идентифицировать его
             // в результатах поиска
             // $doc->addField(Zend_Search_Lucene_Field::Text('description', strtolower($mediaItem->getSContent()),'UTF-8'));
             // Индексирование keyWords содержимого документа
             $doc->addField(Zend_Search_Lucene_Field::UnStored('keyword', strtolower($mediaItem->getMetaKeywords()), 'UTF-8'));
             // Индексирование содержимого документа
             $doc->addField(Zend_Search_Lucene_Field::UnStored('contents', strtolower($mediaItem->getContent()), 'UTF-8'));
             // Добавление документа в индекс
             $index->addDocument($doc);
         }
     }
 }
 function getBlockNews()
 {
     $mediaMapper = new Media_Model_Mapper_Media();
     $select = $mediaMapper->getDbTable()->select();
     //News
     $select->where('deleted != ?', 1)->where('active != ?', 0)->where('category_id = ?', 2)->order('timestamp DESC')->limit(1, 0);
     $newsItem = $mediaMapper->fetchAll($select);
     if (!empty($newsItem)) {
         $this->view->assign('newsItem', array_shift($newsItem));
     }
 }
 public function indexAction()
 {
     $request = $this->getRequest();
     $mediaCategoryMapper = new Media_Model_Mapper_MediaCategories();
     if ($request->getParam('fullPath')) {
         $mediaCategory = $mediaCategoryMapper->findByPath($request->getParam('fullPath'), new Media_Model_MediaCategories());
         if (is_null($mediaCategory)) {
             //throw new Zend_Controller_Action_Exception("Страница не найдена", 404);
             $this->forward('view');
             return;
         }
         $this->setCategoriesDefaultId($mediaCategory->getId());
     }
     $mediaCategoryId = $this->getCategoriesDefaultId();
     if (!is_null($this->getRequest()->getParam('json')) && Zend_Auth::getInstance()->hasIdentity()) {
         $this->forward('json', 'media-categories', 'admin', array('id' => $mediaCategoryId));
         return;
     }
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $pageItem = $mediaCategoryMapper->find($mediaCategoryId, new Media_Model_MediaCategories());
         $this->_request->setParams(array('dataItem' => array('controller' => 'media-categories', 'id' => $pageItem->getId(), 'active' => $pageItem->getActive(), 'deleted' => $pageItem->getDeleted())));
     }
     $mediaMapper = new Media_Model_Mapper_Media();
     $select = $mediaMapper->getDbTable()->select();
     $select->where('deleted != ?', 1)->where('active != ?', 0)->where('category_id = ?', $mediaCategoryId)->order('timestamp DESC');
     $mediaItems = $mediaMapper->fetchAll($select);
     if (!empty($mediaItems)) {
         if (count($mediaItems) > $this->getCountItemOnPage()) {
             $mediaPages = array_chunk($mediaItems, $this->getCountItemOnPage());
             $currentPage = 0;
             if ($request->getParam('page') && $request->getParam('page') > 0) {
                 $currentPage = $request->getParam('page') - 1;
             }
             if ($request->getParam('page') && $request->getParam('page') > count($mediaPages)) {
                 $currentPage = count($mediaPages) - 1;
             }
             $mediaItems = $mediaPages[$currentPage];
             $this->view->assign(array('countPage' => count($mediaPages), 'currentPage' => $currentPage + 1));
         }
         if (!isset($mediaCategory)) {
             $mediaCategory = $mediaCategoryMapper->find($this->getCategoriesDefaultId(), new Media_Model_MediaCategories());
         }
         if (isset($mediaCategory)) {
             $this->view->assign('currentCategory', $mediaCategory);
         }
         $this->view->assign(array('title' => $mediaCategory->getName(), 'mediaItems' => $mediaItems));
     }
     $categoryName = '';
     if (isset($mediaCategory)) {
         $categoryName = $mediaCategory->getName();
     }
     $this->view->assign(array('meta_description' => 'Альфа-Гидро - Пресса. ' . $categoryName, 'meta_keywords' => 'пресса, новости, акции, статьи', 'adminPath' => 'media-categories/list/' . $mediaCategoryId));
 }
 function getPageArticles()
 {
     $frontController = Zend_Controller_Front::getInstance();
     $request = $frontController->getRequest();
     $moduleName = $request->getModuleName();
     $actionName = $request->getActionName();
     //Zend_Debug::dump($request->getParams());
     $this->view->moduleName = $moduleName;
     $this->view->actionName = $actionName;
     $pagesMapper = new Pages_Model_Mapper_Pages();
     $page = $pagesMapper->findByPath($moduleName, new Pages_Model_Pages());
     if (!$page) {
         return null;
     }
     $this->view->sectionName = $page->getTitle();
     $this->view->sectionId = $page->getId();
     $mediaModelMapper = new Media_Model_Mapper_Media();
     $selectMedia = $mediaModelMapper->getDbTable()->select();
     $selectMedia->where('active != ?', 0)->where('deleted != ?', 1)->where('section_site_id = ?', $page->getId())->order('timestamp DESC');
     $mediaItems = $mediaModelMapper->fetchAll($selectMedia);
     if (!empty($mediaItems)) {
         if (count($mediaItems) > $this->getCountItemOnPage()) {
             $mediaPages = array_chunk($mediaItems, $this->getCountItemOnPage());
             $currentPage = 0;
             if ($request->getParam('page') && $request->getParam('page') > 0) {
                 $currentPage = $request->getParam('page') - 1;
             }
             if ($request->getParam('page') && $request->getParam('page') > count($mediaPages)) {
                 $currentPage = count($mediaPages) - 1;
             }
             $mediaItems = $mediaPages[$currentPage];
             $this->view->countPage = count($mediaPages);
             $this->view->currentPage = $currentPage + 1;
         }
     }
     return $mediaItems;
 }