/**
  * Show selected product
  *
  * @var int $category Parent category
  * @var int $id Selected product
  */
 public function viewAction()
 {
     $productsModel = new Model_DbTable_Products();
     $subproductsModel = new Model_DbTable_Subproducts();
     $categoriesModel = new Model_DbTable_Categories();
     $select = $subproductsModel->select()->order('order ASC');
     $id = $this->getRequest()->getParam("id");
     $category_id = $this->getRequest()->getParam("category");
     $product = $productsModel->find($id)->current();
     $subproducts = $product->findDependentRowset("Model_DbTable_Subproducts", 'SubproductsRel', $select);
     $this->view->product = $product;
     $keywords = $product['name'] . ',';
     for ($i = 0; $i < count($subproducts); $i++) {
         $keywords .= $subproducts[$i]['sku'] . ',';
         $keywords .= str_replace('A', '', $subproducts[$i]['sku']) . ',';
         $keywords .= str_replace(' ', '', $subproducts[$i]['sku']) . ',';
         $keywords .= str_replace(array(' ', 'A'), '', $subproducts[$i]['sku']) . ',';
     }
     $keywords .= $product['sku'];
     $category = $categoriesModel->find($category_id)->current();
     $description = "РВД,гидравлика,Рукава высокого давления,фитинги,шланги высокого давления,фланцы SAE,гидравлические рукава,гидравлические компоненты,";
     $description .= $category->name;
     while ($category->parent_id) {
         $category = $category->findParentRow('Model_DbTable_Categories');
         $description .= ',' . $category->name;
     }
     $this->view->headMeta()->appendName('keywords', $keywords);
     $this->view->headMeta()->appendName('description', $description);
     $this->view->headTitle()->prepend($product['sku'] . ' - ' . $product['name']);
     $this->view->subproducts = $subproducts;
     $this->view->prod_db = $productsModel;
 }
 public function navigationAction()
 {
     $bcn = new Zend_Navigation();
     $categoriesModel = new Model_DbTable_Categories();
     $category = $categoriesModel->find($this->getRequest()->getParam("category"))->current();
     if (!$category) {
         return;
     }
     $i = 0;
     $bcn->addPage(array("action" => "index", "controller" => "categories", "module" => "catalog", 'order' => $i, "params" => array('category' => $category->id), 'label' => $category->name));
     while ($category->parent_id) {
         $category = $category->findParentRow('Model_DbTable_Categories');
         $bcn->addPage(array("action" => "index", "controller" => "categories", "module" => "catalog", 'order' => $i, "params" => array('category' => $category->id), 'label' => $category->name));
         $i--;
     }
     $bcn->addPage(array("action" => "index", "controller" => "index", "module" => "catalog", 'label' => 'Каталог продукции', 'order' => $i));
     $bcn->addPage(array("action" => "index", "controller" => "index", "module" => "default", 'label' => 'Главная', 'order' => $i - 1));
     $this->view->navigation = $bcn;
 }
 /**
  * Generate selected category book and save it
  * 
  * @var int $page Current page
  * @var int $id   Category ID
  * @var string $pageEormat передается пользрвателем либо A5 либо A4
  * @var string $print передается пользователем либо true либо false
  */
 public function bycategoryAction()
 {
     if (!Zend_Auth::getInstance()->hasIdentity()) {
         throw new Zend_Exception("Page not found", 404);
     }
     set_time_limit(3600);
     $this->_helper->layout->disableLayout();
     $page = $this->getRequest()->getParam("page");
     $categoryId = $this->getRequest()->getParam("id");
     $exceptionList = $this->getRequest()->getParam("except");
     $this->secondTime = (int) $this->getRequest()->getParam("second_time");
     $pageFormat = $this->getRequest()->getParam("pageFormat");
     $print = $this->getRequest()->getParam("print");
     $pdfBook = new Model_Static_PdfBook($pageFormat, $print);
     $categoriesModel = new Model_DbTable_Categories();
     $pdfBook->logger = new Zend_Log();
     $pdfBook->logWriter = new Zend_Log_Writer_Stream(APPLICATION_ROOT . '/book.log');
     $pdfBook->logger->addWriter($pdfBook->logWriter);
     $pdfBook->logger->log('get params', Zend_Log::INFO);
     $category = $categoriesModel->find($categoryId)->current();
     $pdfBook->logger->log('get oject category', Zend_Log::INFO);
     $pdfBook->exceptionProductList = $this->getRequest()->getParam("except_products");
     $pdfBook->logger->log('get params product', Zend_Log::INFO);
     //передаем id категории и запускаем процесс генерации данной категории
     $book = $pdfBook->byCategory($category, $page, $exceptionList, $this->secondTime);
     $pdfBook->logger->log('Return generated pdfBook', Zend_Log::INFO);
     $topParent = $category->findTopParent();
     $pdfBook->addCategoryToIndex($topParent->id, $page, 0);
     $pdfBook->addCategoryToIndex($category->parent_id, $page, 1);
     //завершение  генерации одной категории
     $this->view->nextpage = $book->end_pages;
     $this->view->endpage = $this->view->nextpage + count($book->pages);
     $saveFilename = str_repeat("0", 4 - strlen($this->view->nextpage)) . $this->view->nextpage . '-' . ($this->view->endpage - 1) . '.pdf';
     $pdfBook->logger->log('Saving pages', Zend_Log::INFO);
     if ($this->secondTime == 1) {
         $book->save(APPLICATION_ROOT . $this::PDFBOOK_DIR . '/' . $saveFilename);
     }
 }
 /**
  * Delete category with confirmation
  */
 public function deleteAction()
 {
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $id = $this->getRequest()->getParam("id");
         $categoriesModel = new Model_DbTable_Categories();
         $category = $categoriesModel->find($id)->current();
         if (!$category) {
             throw new Zend_Exception("No category found", 404);
         }
         if ($this->getRequest()->getParam("confirmed") == 'true') {
             $category->delete();
             $this->_forward("index");
         } else {
             $this->view->category = $category;
         }
     } else {
         throw new Zend_Exception("Page not found", 404);
     }
 }