Advertisement
NFL

Untitled

NFL
Apr 22nd, 2014
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 63.42 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @author S.Serdyuk
  5.  * @copyright (c) 2013, WebAkula
  6.  * @title Каталог
  7.  * @description ...
  8.  */
  9. class Catalog_AdminController extends Core_Admin {
  10.  
  11.     public function init() {
  12.         parent::init();
  13.         $this->_breadcrumbs->addUrl('Каталог', array(), 'catalog', 'index');
  14.     }
  15.  
  16.     /**
  17.      * @title Главная страница
  18.      * @description Что сюда вывести?
  19.      */
  20.     public function indexAction() {
  21.        
  22.     }
  23.  
  24.     /**
  25.      * @title Бренды
  26.      * @description Управление брендами (производителями)
  27.      */
  28.     public function brandsAction() {
  29.         $action = $this->_getParam('action', null);
  30.         $model = new Catalog_Model_Brands;
  31.         $this->_breadcrumbs->addUrl('Бренды', array(), 'catalog', 'brands');
  32.         switch ($action) {
  33.             case 'index': default:
  34.                 $category = $this->_getParam('category', null);
  35.                 $this->view->list = $model->getList($category);
  36.                 $this->render('brands/index');
  37.                 break;
  38.             case 'add':
  39.                 $this->_breadcrumbs->addNode('Добавление бренда');
  40.                 $form = new Catalog_Form_Brands_Add;
  41.                 if ($this->getRequest()->isPost()) {
  42.                     $model = new Catalog_Model_Brands;
  43.                     $data = $this->getRequest()->getPost();
  44.  
  45.                     $data['category_id'] = $this->_getParam('category');
  46.                     unset($data['submit']);
  47.                     $data['data_id'] = $model->_getNextDataId();
  48.                     $model->insert($data);
  49.                     $this->_redirect($this->view->adminUrl('catalog', 'categories', array('action' => 'edit', 'id' => $data['category_id'], 'hash' => 'brands')));
  50.                 } else {
  51.                     $this->view->form = $form;
  52.                     $this->view->categoryId = $this->_getParam('category', null);
  53.                 }
  54.                 $this->render('brands/add');
  55.                 break;
  56.             case 'delete':
  57.                 $model = new Catalog_Model_Brands();
  58.                 $id = $this->_getParam('id');
  59.                 $brand = $model->getByDataId($id);
  60.                 //Zend_Debug::dump($brand);exit;
  61.                 $model->update(array('deleted' => 1), 'data_id=' . $brand['data_id']);
  62.                 $model = new Catalog_Model_Products;
  63.                 $model->update(array('deleted' => 1), 'brand_id=' . $brand['data_id'] . ' AND category_id=' . $brand['category_id']);
  64.                 $this->_redirect($this->view->adminUrl('catalog', 'categories', array('action' => 'edit', 'id' => $brand['category_id'], 'hash' => 'brands')));
  65.                 break;
  66.             case 'edit':
  67.                 $this->_breadcrumbs->addNode('Редактирование бренда');
  68.                 $form = new Catalog_Form_Brands_Edit;
  69.                 if ($this->getRequest()->isPost()) {
  70.                     $model = new Catalog_Model_Brands;
  71.                     $data = $this->getRequest()->getPost();
  72.  
  73.                     $data['category_id'] = $this->_getParam('category');
  74.                     unset($data['submit']);
  75.                     $data['data_id'] = $model->_getNextDataId();
  76.                     $model->insert($data);
  77.                     $this->_redirect($this->view->adminUrl('catalog', 'categories', array('action' => 'edit', 'id' => $data['category_id'], 'hash' => 'brands')));
  78.                 } else {
  79.                     $this->view->form = $form;
  80.                     $this->view->categoryId = $this->_getParam('category', null);
  81.                 }
  82.  
  83.                 break;
  84.         }
  85.     }
  86.  
  87.     /**
  88.      * @title Управление категориями
  89.      * @description Полное управление категориями каталога
  90.      */
  91.     public function categoriesAction() {
  92.         $this->view->headScript()->appendFile('/admin_style/js/admin/catalog/categories.js');
  93.         $action = $this->_getParam('action', null);
  94.         $model = new Catalog_Model_Categories;
  95.  
  96.  
  97.         switch ($action) {
  98.  
  99.             /**
  100.              * Основные действия по управлению категориями
  101.              */
  102.             case 'list':
  103.                 $this->_breadcrumbs->addNode('Управление категориями');
  104.                 $show = $this->_getParam('show', null);
  105.                 if (!is_null($show)) {
  106.                     $model = new Catalog_Model_Products;
  107.                     $this->view->products = $model->getCategory($show);
  108.                 }
  109.                 $this->render('categories/list');
  110.                 break;
  111.             case 'add':
  112.                 $this->_breadcrumbs->addUrl('Управление категориями', array(), 'catalog', 'categories')->addNode('Добавление категории');
  113.                 $form = new Catalog_Form_Categories_Add;
  114.                 if ($this->getRequest()->isPost()) {
  115.                     $data = $this->getRequest()->getPost();
  116.                     //exit(Zend_Debug::dump($data));
  117.                     if ($form->isValid($data)) {
  118.                         $properties = $data['properties'];
  119.                         $data['data_id'] = $model->_getNextDataId($data['parent_id'], $this->_currentLanguageId);
  120.                         $data['ordering'] = $model->_getNextOrdering($data['parent_id'], $this->_currentLanguageId);
  121.                         unset($data['submit'], $data['properties'], $data['MAX_FILE_SIZE']);
  122.                         $model->insert($data);
  123.                         $model = new Catalog_Model_Categories_Properties();
  124.                         foreach ($properties as $k => $p) {
  125.                             $model->insert(array(
  126.                                 'category_id' => $data['data_id'],
  127.                                 'property_id' => $k,
  128.                                 'default_values' => $p['default_values']
  129.                             ));
  130.                         }
  131.                         $this->_helper->flashMessenger->addMessage(_('Категория добавлена'));
  132.                         $this->_redirect($this->view->adminUrl('catalog', 'categories'));
  133.                     } else {
  134.                         $this->view->form = $form->populate($data);
  135.                     }
  136.                 } else {
  137.                     $parent = $this->_getParam('parent');
  138.                     $model = new Catalog_Model_Categories;
  139.                     $properties = new Catalog_Model_Properties;
  140.                     $data = $model->getByDataId($parent, $this->_currentLanguageId);
  141.                     if (!$data) {
  142.                         $data['title'] = 'Корневой элемент';
  143.                     }
  144.                     $this->view->parent = $data;
  145.                     $this->view->properties = $properties->getAll($this->_currentLanguageId);
  146.                     $path = Core_Helper_Tree::branch($parent, $model->getAll(true, $this->_currentLanguageId));
  147.                     $parts = array();
  148.                     foreach ($path as $p) {
  149.                         $parts[] = $p['title'];
  150.                     }
  151.                     if (!count($parts)) {
  152.                         $parts[] = 'Корневая категория';
  153.                     }
  154.                     $this->view->path = implode(' / ', array_reverse($parts));
  155.                     $this->view->form = $form;
  156.                     $this->render('categories/add');
  157.                 }
  158.                 break;
  159.             case 'add-translation':
  160.                 $this->_breadcrumbs->addUrl('Управление категориями', array(), 'catalog', 'categories')->addNode('Добавление перевода');
  161.                 $form = new Catalog_Form_Categories_Add;
  162.                 $model = new Catalog_Model_Categories;
  163.                 if ($this->getRequest()->isPost()) {
  164.                     $data = $this->getRequest()->getPost();
  165.  
  166.                     unset($data['submit']);
  167.                     $data['lang_id'] = $this->translationParam('lang_id');
  168.                     $data['data_id'] = $this->translationParam('data_id');
  169.                     //Zend_Debug::dump($data);
  170.                     $model->insert($data);
  171.                     $this->_redirect($this->view->adminUrl('catalog', 'categories'));
  172.                 } else {
  173.                     $id = $this->translationParam('data_id');
  174.                     $data = $model->getByDataId($id, $this->_currentLanguageId);
  175.                     $this->view->parent = $data;
  176.                     $this->view->form = $form;
  177.                     $this->render('multilingual/categories/add-translation');
  178.                 }
  179.                 break;
  180.             case 'remove':
  181.                 $this->_helper->layout()->disableLayout();
  182.                 $id = $this->_getParam('id');
  183.                 $model->removeNode($id);
  184.                 exit('success');
  185.                 break;
  186.             case 'edit':
  187.                 $this->_breadcrumbs->addUrl('Управление категориями', array(), 'catalog', 'categories')->addNode('Редактирование категории');
  188.                 $form = new Catalog_Form_Categories_Edit();
  189.                 if ($this->getRequest()->isPost()) {
  190.                     $data = $this->getRequest()->getPost();
  191.                     if ($form->isValid($data)) {
  192.                         $imgs = Core_Helper_File::receive();
  193.                         //exit(Zend_Debug::dump($imgs['images'][0]));
  194.                         if (mb_strlen($imgs['images'][0])) {
  195.                             $data['img'] = $imgs['images'][0];
  196.                         }
  197.                         $properties = $data['properties'];
  198.  
  199.                         $props = new Catalog_Model_Categories_Properties;
  200.                         $id = $data['data_id'];
  201.                         unset($data['properties'], $data['submit'], $data['data_id'], $data['MAX_FILE_SIZE']);
  202.                         if (APP_MULTILINGUAL) {
  203.  
  204.                             $model->update($data, array(
  205.                                 $model->getAdapter()->quoteInto('data_id = ?', $id),
  206.                                 $model->getAdapter()->quoteInto('lang_id = ?', $this->_currentLanguageId),
  207.                             ));
  208.                         } else {
  209.                             $model->update($data, $model->getAdapter()->quoteInto('data_id = ?', $id));
  210.                         }
  211.  
  212.                         foreach ($properties as $id => $data) { //$id - ID строки в таблице catalog_categories_propertie
  213.                             if ($data['use']) {
  214.                                 $props->update(array('default_values' => $data['default_values']), $props->getAdapter()->quoteInto('id = ?', $id));
  215.                             } else {
  216.                                 $props->delete($props->getAdapter()->quoteInto('id = ?', $id));
  217.                             }
  218.                         }
  219.                     } else {
  220.                         $this->view->form = $form->populate($data);
  221.                     }
  222.                     $this->_helper->flashMessenger->addMessage('Категория обновлена');
  223.                     $this->_redirect($this->view->adminUrl('catalog', 'categories'));
  224.                 } else {
  225.                     $id = $this->_getParam('id');
  226.                     $data = $model->getByDataId($id, $this->_currentLanguageId);
  227.                     //Zend_Debug::dump($data);
  228.                     $this->view->form = $form->populate($data);
  229.                     $path = Core_Helper_Tree::branch($data['parent_id'], $model->getAll(false, $this->_currentLanguageId));
  230.                     $parts = array();
  231.                     foreach ($path as $p) {
  232.                         $parts[] = $p['title'];
  233.                     }
  234.                     $this->view->parent = $model->getByDataId($data['parent_id'], $this->_currentLanguageId);
  235.                     $this->view->path = implode(' / ', array_reverse($parts));
  236.                     $properties = new Catalog_Model_Categories_Properties;
  237.                     $this->view->properties = $properties->getCategory($id);
  238.                     $properties = new Catalog_Model_Properties;
  239.                     $this->view->propertiesList = $properties->getAdditional($id);
  240.                     $filters = new Catalog_Model_Filters;
  241.                     $this->view->filters = $filters->getCategory($id);
  242.                     $this->view->data = $data;
  243.                     $brands = new Catalog_Model_Brands;
  244.                     $this->view->brands = $brands->getCategory($id, true);
  245.                     $this->render('categories/edit');
  246.                 }
  247.                 break;
  248.  
  249.             /**
  250.              * Сервисные, вспомогательные действия
  251.              */
  252.             case 'load':
  253.                 $model = new Catalog_Model_Categories;
  254.                 $list = $model->getJSON($this->_currentLanguageId);
  255.                 exit($list);
  256.                 break;
  257.             case 'sort':
  258.                 $this->_helper->layout()->disableLayout();
  259.                 $array = json_decode($this->getRequest()->getPost('data'));
  260.                 if (!isset($array->parent)) {
  261.                     $model->setRuntimeOrdering($array);
  262.                 } else {
  263.                     $model->update(array('parent_id' => $array->parent), $model->getAdapter()->quoteInto('data_id = ?', $array->node));
  264.                     $model->setRuntimeOrdering($array->list);
  265.                 }
  266.                 break;
  267.             case 'check-alias':
  268.                 $id = $this->_getParam('id');
  269.                 if (mb_strlen($this->_getParam('alias')))
  270.                     exit(!$model->get($this->_getParam('alias')) ? 'ok' : 'busy');
  271.                 exit('ok');
  272.                 break;
  273.             case 'add-property':
  274.                 $model = new Catalog_Model_Properties;
  275.                 $this->_helper->layout()->disableLayout();
  276.                 $id = $this->_getParam('id', null);
  277.                 $existing = $this->_getParam('existing', false);
  278.                 if ($existing) {
  279.                     $propId = $this->_getParam('propId');
  280.                 } else {
  281.                     $data = $this->getRequest()->getPost();
  282. //                    exit(Zend_Debug::dump($data));
  283.                     unset($data['add_existing_property']);
  284.                     $propId = $model->insert($data);
  285.                 }
  286.                 if (is_null($id)) {
  287.                     $list = $model->getAll();
  288.                     $checked = false;
  289.                 } else {
  290.  
  291.                     $model = new Catalog_Model_Categories_Properties;
  292.                     $model->insert(array(
  293.                         'category_id' => $id,
  294.                         'property_id' => $propId,
  295.                         'img' => $data['img']
  296.                     ));
  297.                     $list = $model->getCategory($id);
  298.                     $checked = true;
  299.                 }
  300.                 exit($this->view->partial('admin/categories/service/categories.phtml', array('properties' => $list, 'checked' => $checked)));
  301.                 break;
  302.             case 'add-properties':
  303.                 $model = new Catalog_Model_Categories_Properties;
  304.                 $this->_helper->layout()->disableLayout();
  305.                 $id = $this->_getParam('id', null);
  306.                 $data = $this->getRequest()->getPost();
  307.                 // exit(Zend_Debug::dump($data));
  308.                 $list = json_decode($data['list']);
  309.                 $extendProperties = json_decode($data['extendProperties']);
  310.                 $extendImages = json_decode($data['extendedImages']);
  311.                 //Zend_Debug::dump($extendImages);exit;
  312.                 //Zend_Debug::dump($extendProperties, 'ext');
  313.                 $catId = $data['extendedCategoryId'];
  314.                 foreach ($list as $propId) {
  315.  
  316.                     $insert = array(
  317.                         'category_id' => $id,
  318.                         'property_id' => $propId
  319.                     );
  320.                     if (in_array($propId, $extendProperties)) {
  321.                         $insert['default_values'] = $model->getDefaults($catId, $propId);
  322.                     }
  323.                     if (in_array($propId, $extendImages)) {
  324.                         $insert['img'] = $model->getImg($catId, $propId);
  325.                     }
  326.                     //  Zend_Debug::dump(in_array($extendProperties, $propId), 'in_arr');
  327.                     //Zend_Debug::dump($insert, 'ins');
  328.  
  329.                     $model->insert($insert);
  330.                     //Zend_Debug::dump();
  331.                 }//exit;
  332.                 $list = $model->getCategory($id);
  333.                 $checked = true;
  334.                 exit($this->view->partial('admin/categories/service/categories.phtml', array('properties' => $list, 'checked' => $checked)));
  335.                 break;
  336.             case 'unavailable-translations':
  337.                 $this->_helper->layout()->disableLayout();
  338.                 $model = new Catalog_Model_Categories;
  339.                 $translations = $model->getUnavailableTranslations($this->_getParam('id'));
  340.                 exit(json_encode($translations));
  341.                 break;
  342.             default:
  343.                 $this->_breadcrumbs->addNode('Управление категориями');
  344.                 $show = $this->_getParam('show', null);
  345.                 if (!is_null($show)) {
  346.                     $model = new Catalog_Model_Products;
  347.                     $this->view->products = $model->getCategory($show);
  348.                 }
  349.                 $this->render('categories/list');
  350.                 break;
  351.         }
  352.     }
  353.  
  354.     /**
  355.      * @title Характеристики
  356.      * @description Управление динамическими характеристиками
  357.      */
  358.     public function propertiesAction() {
  359.         $action = $this->_getParam('action', null);
  360.         $model = new Catalog_Model_Properties;
  361.  
  362.         switch ($action) {
  363.             case 'list': default:
  364.                 $this->_breadcrumbs->addNode('Список свойств');
  365.                 $data = $model->getAll();
  366.                 $this->view->list = $data;
  367.                 $this->render('properties/list');
  368.                 break;
  369.             case 'add-property-image':
  370.                 $this->_breadcrumbs->addNode('FOO');
  371.                 $this->_helper->layout()->disableLayout();
  372.                 //exit('aaaa');
  373.                 $files = Core_Helper_File::receive();
  374.  
  375.                 if (mb_strlen($files['images'][0])) {
  376.                     exit(json_encode(array('result' => 'success', 'img' => $files['images'][0])));
  377.                 } else {
  378.                     exit(json_encode(array('result' => 'success', 'img' => null)));
  379.                 }
  380.                 //Сервисная функция, асинхронная загрузка файла при добавлении свойства
  381.                 break;
  382.             case 'change-property-image':
  383.                 $data = $this->getRequest()->getPost();
  384.                 $img = Core_Helper_File::receive();
  385.                 $img = $img['images'][0];
  386.                 $model = new Catalog_Model_Categories_Properties;
  387.                 $model->update(array('img' => $img), "property_id=" . $data['property_id'] . " AND category_id=" . $data['category_id']);
  388.                 exit(json_encode(array('result' => 'success', 'img' => $img)));
  389.                 break;
  390.             case 'list-simple':
  391.                 $this->_helper->layout()->disableLayout();
  392.                 $id = $this->_getParam('id');
  393.                 $current = $this->_getParam('current', null);
  394.                 $data = $model->getAdditional($id);
  395.                 if (!is_null($current)) {
  396.                     $curr = $model->getAdditional($current);
  397.                     $data = array_diff_assoc($curr, $data);
  398.                 }
  399.                 //exit(Zend_Debug::dump($data));
  400.                 $this->view->list = $data;
  401.                 $this->view->current = $current;
  402.                 $this->render('properties/list-simple');
  403.                 break;
  404.             case 'list-extend-simple':
  405.                 $this->_helper->layout()->disableLayout();
  406.                 $model = new Catalog_Model_Categories;
  407.                 $data = $model->getAll();
  408.  
  409.                 $tree = new Core_Helper_Tree();
  410.                 $data = Core_Helper_Tree::build($data, 'parent_id', 'children', 'data_id');
  411.                 $this->view->list = $data;
  412.                 //Zend_Debug::dump($data);
  413.                 $this->render('properties/list-extend-simple');
  414.                 break;
  415.             case 'edit':
  416.                 $this->_breadcrumbs->addUrl('Свойства', array(), 'catalog', 'properties')->addNode('Редактирование свойства');
  417.                 $form = new Catalog_Form_Properties_Edit;
  418.                 if ($this->getRequest()->isPost()) {
  419.                     $data = $this->getRequest()->getPost();
  420.                     if ($form->isValid($data)) {
  421.                         $id = $data['id'];
  422.                         unset($data['submit'], $data['id']);
  423.                         //exit(Zend_Debug::dump($data));
  424.                         $model->update($data, 'id=' . $id);
  425.                         $this->_helper->flashMessenger->addMessage('Данные обновлены');
  426.                         $this->_redirect($this->view->adminUrl('catalog', 'properties'));
  427.                     } else {
  428.                         $this->view->form = $form->populate($data);
  429.                     }
  430.                 } else {
  431.                     $id = $this->_getParam('id');
  432.                     $data = $model->getByPk($id);
  433.                     $this->view->form = $form->populate($data);
  434.                 }
  435.                 $this->render('properties/edit');
  436.                 break;
  437.             case 'delete':
  438.                 $id = $this->_getParam('id');
  439.                 $model->update(array('deleted' => 1), 'id=' . $id);
  440.                 $this->_redirect($this->view->adminUrl('catalog', 'properties'));
  441.                 break;
  442.             case 'load':
  443.                 $this->_helper->layout()->disableLayout();
  444.                 $parent = $this->_getParam('id');
  445.                 $properties = new Catalog_Model_Categories_Properties;
  446.                 $propertiesList = $properties->getCategory($parent);
  447.                 /**
  448.                  * Собираем доступные динамические характеристики
  449.                  */
  450.                 foreach ($propertiesList as &$v) {
  451.                     if (in_array($v['type'], array(Core_Input::TYPE_CHECKBOX, Core_Input::TYPE_RADIO, Core_Input::TYPE_SELECT))) {
  452.                         $values = explode(',', $v['default_values']);
  453.                         foreach ($values as $k => $val) {
  454.                             if (!mb_strlen($val)) {
  455.                                 unset($values[$k]);
  456.                             }
  457.                         }
  458.                         if (count($values)) {
  459.                             array_walk($values, function(&$val, $key) {
  460.                                 $val = trim($val);
  461.                                 if (!mb_strlen($val)) {
  462.                                     unset($values[$key]);
  463.                                 }
  464.                             });
  465.                             switch ($v['type']) {
  466.                                 case Core_Input::TYPE_SELECT:
  467.                                     array_unshift($values, 'Выбрать');
  468.                                     break;
  469.                                 case Core_Input::TYPE_CHECKBOX:
  470.                                     $v['element'] = 'formMultiCheckbox';
  471.                                     break;
  472.                                 case Core_Input::TYPE_RADIO:
  473.                                     //No individual actions
  474.                                     break;
  475.                             }
  476.                             $v['values'] = array_combine(array_values($values), array_values($values));
  477.                         } else {
  478.                             switch ($v['type']) {
  479.                                 case Core_Input::TYPE_RADIO: case Core_Input::TYPE_SELECT:
  480.                                     $v['values'] = array('1' => 'Да', '0' => 'Нет');
  481.                                     break;
  482.                                 case Core_Input::TYPE_CHECKBOX:
  483.                                     $v['values'] = array('Да' => '1');
  484.                                     break;
  485.                             }
  486.                         }
  487.                     }
  488.                     if (!isset($v['element']))
  489.                         $v['element'] = 'form' . ucfirst($v['type']);
  490.                 }
  491.  
  492.                 $data = $this->view->partial('admin/categories/service/properties-ajax.phtml', array('properties' => $propertiesList));
  493.                 exit($data);
  494.                 break;
  495.         }
  496.     }
  497.  
  498.     /**
  499.      * @title Управление записями
  500.      * @description Управление материалами каталога
  501.      *
  502.      */
  503.     public function productsAction() {
  504.  
  505.         $action = $this->_getParam('action');
  506.  
  507.         $model = new Catalog_Model_Products;
  508.  
  509.         switch ($action) {
  510.             case 'add':
  511.                 $form = new Catalog_Form_Product_Add;
  512.                 $this->view->headScript()->appendFile('/admin_style/js/admin/catalog/attendant.js');
  513.                 $this->view->metagenerator()->enable();
  514.                 $this->_breadcrumbs->addNode('Добавление товара');
  515.                 $parent = $this->_getParam('parent', false);
  516.                 $ajax = $this->_getParam('ajax', false);
  517.  
  518.                 if ($this->getRequest()->isPost()) {
  519.                     $data = $this->getRequest()->getPost();
  520.                     //     if ($form->isValid($data)) {
  521.                     //exit(Zend_Debug::dump($data));
  522.                     $langId = null;
  523.                     if (APP_MULTILINGUAL) {
  524.                         $langId = $this->_currentLanguageId;
  525.                     }
  526.                     $properties = $data['properties'];
  527.                     $meta = $data['meta'];
  528.                     $imgAlts = $data['img_alt'];
  529.                     $additionals = $data['additionals'];
  530.                     $files = Core_Helper_File::receive();
  531.                     $moduleId = $model->getModuleId();
  532.                     unset($data['meta'], $data['properties'], $data['img_alt'], $data['img_file'], $data['submit'], $data['additionals']);
  533.                     $id = $model->_getNextDataId($langId);
  534.                     $data['ordering'] = $model->_getNextOrdering($langId);
  535.                     $data['data_id'] = $id;
  536.                     $data['lang_id'] = $langId;
  537.                     $model->insert($data);
  538.                     $meta['module_id'] = $moduleId;
  539.                     $meta['data_id'] = $id;
  540.                     if (APP_MULTILINGUAL) {
  541.                         $meta['lang_id'] = $langId;
  542.                     }
  543.                     $model = new Core_Model_Meta;
  544.                     $model->insert($meta);
  545.                     if (count($files['images'])) {
  546.                         $images = new Core_Model_Data_Images;
  547.                         foreach ($files['images'] as $i => $v) {
  548.                             $images->insert(array(
  549.                                 'module_id' => $moduleId,
  550.                                 'data_id' => $id,
  551.                                 'alt' => $imgAlts[$i],
  552.                                 'lang_id' => $langId,
  553.                                 'title' => $imgAlts[$i],
  554.                                 'file_path' => $v
  555.                             ));
  556.                         }
  557.                     }
  558.                     if (count($files['files'])) {
  559.                         $images = new Core_Model_Data_Files;
  560.                         foreach ($files['files'] as $i => $v) {
  561.                             $images->insert(array(
  562.                                 'module_id' => $moduleId,
  563.                                 'data_id' => $id,
  564.                                 'lang_id' => $langId,
  565.                                 'title' => $imgAlts[$i],
  566.                                 'file_path' => $v
  567.                             ));
  568.                         }
  569.                     }
  570.                     if (count($properties)) {
  571.                         //exit(Zend_Debug::dump($properties));
  572.                         $model = new Catalog_Model_Products_Properties;
  573.                         foreach ($properties as $propertyId => $property) {
  574.                             if (is_array($property)) {
  575.                                 foreach ($property as $val) {
  576.                                     $model->insert(array(
  577.                                         'product_id' => $id,
  578.                                         'property_id' => $propertyId,
  579.                                         'value' => $val
  580.                                     ));
  581.                                 }
  582.                             } else {
  583.                                 $model->insert(array(
  584.                                     'product_id' => $id,
  585.                                     'property_id' => $propertyId,
  586.                                     'value' => $property
  587.                                 ));
  588.                             }
  589.                         }
  590.                     }
  591.                     $additionals = explode(',', $additionals);
  592.                     $model = new Catalog_Model_Products_Attendant;
  593.                     foreach ($additionals as $v) {
  594.                         $model->insert(array(
  595.                             'parent_id' => $id,
  596.                             'attendant_id' => $v
  597.                         ));
  598.                     }
  599.                     $this->_helper->flashMessenger->addMessage('Данные добавлены');
  600.                     $this->_redirect($this->view->adminUrl('catalog', 'categories', array('show' => $data['category_id'])));
  601. //                    } else {
  602. //                        $this->view->form = $form->populate($data);
  603. //                    }
  604.                 } else {
  605.                     $categories = new Catalog_Model_Categories;
  606.                     $this->view->isNewProduct = true;
  607.                     if ($parent) {
  608.                         Catalog_Plugin_Metagenerator::setCategory($parent);
  609.                         $this->view->category = $categories->getByDataId($parent, $this->_currentLanguageId);
  610.                         $path = Core_Helper_Tree::branch($parent, $categories->getAll(true, $this->_currentLanguageId));
  611.                         $properties = new Catalog_Model_Categories_Properties;
  612.                         $parts = array();
  613.                         foreach ($path as $p) {
  614.                             $parts[] = $p['title'];
  615.                         }
  616.                         if (!count($parts)) {
  617.                             $parts[] = 'Корневая категория';
  618.                         }
  619.                         $this->view->path = implode(' / ', array_reverse($parts));
  620.                         $propertiesList = $properties->getCategory($parent);
  621.                         /**
  622.                          * Собираем доступные динамические характеристики
  623.                          */
  624.                         // Zend_Debug::dump($propertiesList);
  625.                         foreach ($propertiesList as &$v) {
  626.                             if (in_array($v['type'], array(Core_Input::TYPE_CHECKBOX, Core_Input::TYPE_RADIO, Core_Input::TYPE_SELECT))) {
  627.                                 $values = explode(',', $v['default_values']);
  628.                                 foreach ($values as $k => $val) {
  629.                                     if (!mb_strlen($val)) {
  630.                                         unset($values[$k]);
  631.                                     }
  632.                                 }
  633.                                 if (count($values)) {
  634.                                     array_walk($values, function(&$val, $key) {
  635.                                         $val = trim($val);
  636.                                         if (!mb_strlen($val)) {
  637.                                             unset($values[$key]);
  638.                                         }
  639.                                     });
  640.                                     switch ($v['type']) {
  641.                                         case Core_Input::TYPE_SELECT:
  642.                                             array_unshift($values, 'Выбрать');
  643.                                             break;
  644.                                         case Core_Input::TYPE_CHECKBOX:
  645.                                             $v['element'] = 'formMultiCheckbox';
  646.                                             break;
  647.                                         case Core_Input::TYPE_RADIO:
  648.                                             //No individual actions
  649.                                             break;
  650.                                     }
  651.                                     $v['values'] = array_combine(array_values($values), array_values($values));
  652.                                 } else {
  653.                                     switch ($v['type']) {
  654.                                         case Core_Input::TYPE_RADIO: case Core_Input::TYPE_SELECT:
  655.                                             $v['values'] = array('1' => 'Да', '0' => 'Нет');
  656.                                             break;
  657.                                         case Core_Input::TYPE_CHECKBOX:
  658.                                             $v['values'] = array('Да' => '1');
  659.                                             break;
  660.                                     }
  661.                                 }
  662.                             }
  663.                             if (!isset($v['element']))
  664.                                 $v['element'] = 'form' . ucfirst($v['type']);
  665.                         }
  666.  
  667.                         if ($ajax) {
  668.                             $data = $this->view->partial('admin/categories/service/properties-ajax.phtml', array('properties' => $propertiesList));
  669.                             exit($data);
  670.                         } else {
  671.                             $this->view->properties = $propertiesList;
  672.                         }
  673.  
  674.                         /**
  675.                          * /Подготовили и передали во view
  676.                          */
  677.                     } else {
  678.                         $list = $categories->getJSON();
  679.                         $this->view->list = $list;
  680.                     }
  681.                 }
  682.  
  683.                 $this->view->parent = $parent;
  684.                 $this->view->form = $form;
  685.                 $this->render('products/add');
  686.                 break;
  687.  
  688.             case 'check-alias':
  689.                 $model = new Core_Model_Meta;
  690.  
  691.                 $id = $this->_getParam('id');
  692.                 if (mb_strlen($this->_getParam('alias')))
  693.                     exit(!$model->checkAlias($this->_getParam('alias')) ? 'ok' : 'busy');
  694.                 exit('ok');
  695.                 break;
  696.  
  697.             case 'loadcategory':
  698.                 //exit('Мультиязычный вывод товаров в разработке!');
  699.                 $this->_helper->layout()->disableLayout();
  700.                 $id = $this->_getParam('id');
  701.  
  702.                 //Патч для рассылки, убираем лишние кнопки, дабы не плодить views.
  703.                 //Если передан параметр nocontrols - просто вывести список товаров с галочками
  704.                 $noControls = (bool) $this->_getParam('nocontrols');
  705.                 $data = $model->getAdminCategory($id, $this->_currentLanguageId);
  706.                 $content = $this->view->partial('admin/products/list-ajax.phtml', array('list' => $data, 'noControls' => $noControls));
  707.                 exit($content);
  708.                 break;
  709.             case 'add-color':
  710.                 $this->_breadcrumbs->addNode('Добавление цвета для продукта');
  711.                 $this->view->headScript()->appendFile('/admin_style/js/jquery.validate.pack.js');
  712.                 $this->view->headScript()->appendFile('/admin_style/js/admin/meta_generator/init.js');
  713.                 $form = new Catalog_Form_Product_AddColor;
  714.                 $properties = new Catalog_Model_Products_Properties;
  715.                 if ($this->getRequest()->isPost()) {
  716.                     $model = new Catalog_Model_Products;
  717.                     $data = $this->getRequest()->getPost();
  718.                     $properties = $data['properties'];
  719.                     $meta = $data['meta'];
  720.                     $imgAlts = $data['img_alt'];
  721.                     $additionals = $data['additionals'];
  722.                     $files = Core_Helper_File::receive();
  723.                     $moduleId = $model->getModuleId();
  724.                     unset($data['meta'], $data['properties'], $data['img_alt'], $data['img_file'], $data['submit'], $data['additionals']);
  725.                     $id = $model->_getNextDataId();
  726.                     $data['ordering'] = $model->_getNextOrdering();
  727.                     $data['data_id'] = $id;
  728.                     $data['parent_id'] = (int) $_GET['id'];
  729.  
  730.                     $info = $model->getByDataId($data['parent_id']);
  731.                     $data['category_id'] = $info['category_id'];
  732.                     //exit(Zend_Debug::dump($data));
  733.                     $model->insert($data);
  734.  
  735.  
  736.                     $meta['module_id'] = $moduleId;
  737.                     $meta['data_id'] = $id;
  738.                     $model = new Core_Model_Meta;
  739.                     $model->insert($meta);
  740.                     if (count($files['images'])) {
  741.                         $images = new Core_Model_Data_Images;
  742.                         foreach ($files['images'] as $i => $v) {
  743.                             $images->insert(array(
  744.                                 'module_id' => $moduleId,
  745.                                 'data_id' => $id,
  746.                                 'alt' => $imgAlts[$i],
  747.                                 'title' => $imgAlts[$i],
  748.                                 'file_path' => $v
  749.                             ));
  750.                         }
  751.                     }
  752.                     if (count($files['files'])) {
  753.                         $images = new Core_Model_Data_Files;
  754.                         foreach ($files['files'] as $i => $v) {
  755.                             $images->insert(array(
  756.                                 'module_id' => $moduleId,
  757.                                 'data_id' => $id,
  758.                                 'title' => $imgAlts[$i],
  759.                                 'file_path' => $v
  760.                             ));
  761.                         }
  762.                     }
  763.                     if (count($properties)) {
  764.                         //exit(Zend_Debug::dump($properties));
  765.                         $model = new Catalog_Model_Products_Properties;
  766.                         foreach ($properties as $propertyId => $property) {
  767.                             if (is_array($property)) {
  768.                                 foreach ($property as $val) {
  769.                                     $model->insert(array(
  770.                                         'product_id' => $id,
  771.                                         'property_id' => $propertyId,
  772.                                         'value' => $val
  773.                                     ));
  774.                                 }
  775.                             } else {
  776.                                 $model->insert(array(
  777.                                     'product_id' => $id,
  778.                                     'property_id' => $propertyId,
  779.                                     'value' => $property
  780.                                 ));
  781.                             }
  782.                         }
  783.                     }
  784.                     $this->_helper->flashMessenger->addMessage('Данные добавлены');
  785.                     $this->_redirect($this->view->adminUrl('catalog', 'products', array('action' => 'edit', 'id' => (int) $_GET['id'], 'hash' => 'colours')));
  786.                 } else {
  787.                     //exit('aaa');
  788.                     //  echo $this->view->adminUrl('catalog', 'products', array('action'=>'edit', 'id'=>2, 'hash'=>'colours'));
  789.                     // exit;
  790.                     $id = $this->_getParam('id');
  791.                     $data = $model->getByDataId($id);
  792.                     $meta = new Core_Model_Meta;
  793.                     $data['meta'] = $meta->getMeta($id);
  794.                     $images = new Core_Model_Data_Images;
  795.                     $this->view->images = $images->getData($id);
  796.                     $files = new Core_Model_Data_Files();
  797.                     $this->view->files = $files->getData($id);
  798.                     $this->view->form = $form->populate($data);
  799.                     $propertiesList = $properties->getProduct($id);
  800.                     $this->view->properties = $propertiesList;
  801.                     $this->view->isColorOf = $id;
  802.                     $this->render('products/add-color');
  803.                 }
  804.                 break;
  805.  
  806.             case 'edit':
  807.                 $this->view->headScript()->appendFile('/admin_style/js/admin/catalog/attendant.js');
  808.                 $this->view->metagenerator()->enable();
  809.                 $form = new Catalog_Form_Product_Edit;
  810.                 $properties = new Catalog_Model_Products_Properties;
  811.                 if ($this->getRequest()->isPost()) {
  812.                     $data = $this->getRequest()->getPost();
  813.                     // exit(Zend_Debug::dump($data));
  814.                     //  if ($form->isValid($data)) {
  815.  
  816.                     $dataId = $data['data_id'];
  817.                     $propertiesList = $data['properties'];
  818.                     $langId = null;
  819.                     if (APP_MULTILINGUAL) {
  820.                         $langId = $this->_currentLanguageId;
  821.                     }
  822.                     //  exit(Zend_Debug::dump($propertiesList));
  823.  
  824.                     $meta = new Core_Model_Meta;
  825.                     $moduleId = $meta->getModuleId();
  826.                     $aliasExists = $meta->checkAlias($data['meta']['alias'], $dataId, null, $langId) && mb_strlen($data['meta_alias']);
  827.                     if (!$aliasExists) {
  828.                         $files = Core_Helper_File::receive();
  829.                         $imgAlts = $data['img_alt'];
  830.                         //  exit(Zend_Debug::dump($files));
  831.                         if (APP_MULTILINGUAL) {
  832.                             $meta->update($data['meta'], array(
  833.                                 $meta->getAdapter()->quoteInto('data_id = ?', $dataId),
  834.                                 $meta->getAdapter()->quoteInto('module_id = ?', $moduleId),
  835.                                 $meta->getAdapter()->quoteInto('lang_id = ?', $langId)
  836.                             ));
  837.                         } else {
  838.                             $meta->update($data['meta'], array(
  839.                                 $meta->getAdapter()->quoteInto('data_id = ?', $dataId),
  840.                                 $meta->getAdapter()->quoteInto('module_id = ?', $moduleId)
  841.                             ));
  842.                         }
  843.  
  844.                         $additionals = explode(',', $data['additionals']);
  845.                         unset($data['submit'], $data['properties'], $data['meta'], $data['img_file'], $data['img_alt'], $data['additionals']);
  846.                         $model->update($data, $model->getAdapter()->quoteInto('data_id = ?', $dataId)); //Обновляем основную информацию о товаре
  847.                         $properties->delete($properties->getAdapter()->quoteInto('product_id = ?', $dataId));
  848.  
  849.  
  850.                         if (count($propertiesList)) {
  851.                             $properties->delete('product_id = ' . $dataId);
  852.                             //exit(Zend_Debug::dump($properties));
  853.                             foreach ($propertiesList as $propertyId => $property) {
  854.                                 if (is_array($property)) {
  855.                                     foreach ($property as $val) {
  856.                                         $properties->insert(array(
  857.                                             'product_id' => $dataId,
  858.                                             'property_id' => $propertyId,
  859.                                             'value' => $val
  860.                                         ));
  861.                                     }
  862.                                 } else {
  863.                                     $properties->insert(array(
  864.                                         'product_id' => $dataId,
  865.                                         'property_id' => $propertyId,
  866.                                         'value' => $property
  867.                                     ));
  868.                                 }
  869.                             }
  870.                         }
  871.                         if (count($files['images'])) {
  872.                             $images = new Core_Model_Data_Images;
  873.                             foreach ($files['images'] as $i => $v) {
  874.                                 $images->insert(array(
  875.                                     'module_id' => $moduleId,
  876.                                     'data_id' => $dataId,
  877.                                     'lang_id' => $langId,
  878.                                     'alt' => $imgAlts[$i],
  879.                                     'title' => $imgAlts[$i],
  880.                                     'file_path' => $v
  881.                                 ));
  882.                             }
  883.                         }
  884.                         if (count($files['files'])) {
  885.                             $images = new Core_Model_Data_Files;
  886.                             foreach ($files['files'] as $i => $v) {
  887.                                 $images->insert(array(
  888.                                     'module_id' => $moduleId,
  889.                                     'data_id' => $dataId,
  890.                                     'lang_id' => $langId,
  891.                                     'title' => $imgAlts[$i],
  892.                                     'file_path' => $v
  893.                                 ));
  894.                             }
  895.                         }
  896.  
  897.  
  898.                         $model = new Catalog_Model_Products_Attendant;
  899.                         $model->delete('parent_id = ' . $dataId);
  900.                         foreach ($additionals as $v) {
  901.                             $model->insert(array(
  902.                                 'parent_id' => $dataId,
  903.                                 'attendant_id' => $v
  904.                             ));
  905.                         }
  906.  
  907.                         $this->_helper->flashMessenger->addMessage('Данные обновлены');
  908.                         $this->_redirect($this->view->adminUrl('catalog', 'categories', array('show' => $data['category_id'])));
  909.                     } else {
  910.                         echo "ALIAS!";
  911.                     }
  912.                     //$meta->update($data['meta'], $v);
  913. //                    } else {
  914. //                        $this->vire->form = $form->populate($data);
  915. //                    }
  916.                     //Zend_Debug::dump($data);
  917.                 } else {
  918.                     $id = $this->_getParam('id');
  919.                     $data = $model->getByDataId($id, $this->_currentLanguageId);
  920.                     $this->view->isColorOf = (bool) $this->_getParam('isColorOf');
  921.                     $this->view->colors = $model->getColors($id);
  922.  
  923.                     $meta = new Core_Model_Meta;
  924.                     $data['meta'] = $meta->getMeta($id, $this->_currentLanguageId);
  925.  
  926.                     $images = new Core_Model_Data_Images;
  927.                     $this->view->images = $images->getData($id, $this->_currentLanguageId);
  928.                     $files = new Core_Model_Data_Files();
  929.                     $this->view->files = $files->getData($id, $this->_currentLanguageId);
  930.                     $this->view->form = $form->populate($data);
  931.                     $propertiesList = $properties->getProduct($id, $this->_currentLanguageId);
  932.                     $this->view->properties = $propertiesList;
  933.                     $this->view->data = $data;
  934.  
  935.                     $attendant = new Catalog_Model_Products_Attendant();
  936.                     $attendant = $attendant->getProduct($id);
  937.                     $this->view->attendant = $attendant;
  938.  
  939.  
  940.  
  941.                     $attIds = array();
  942.                     foreach ($attendant as $v) {
  943.                         $attIds[] = $v['data_id'];
  944.                     }
  945.                     $this->view->additionalsList = implode(',', $attIds);
  946.                     $this->render('products/edit');
  947.                 }
  948.                 break;
  949.             case 'delete':
  950.                 $id = $this->_getParam('id');
  951.  
  952.                 $model = new Catalog_Model_Products;
  953.                 $data = $model->getByDataId($id);
  954.                 $model->del($id);
  955.                 $this->_redirect($this->view->adminUrl('catalog', 'categories', array('show' => $data['category_id'])));
  956.                 exit;
  957.                 break;
  958.             case 'delete-color':
  959.  
  960.                 $id = $this->_getParam('id');
  961.  
  962.                 $model = new Catalog_Model_Products;
  963.                 $data = $model->getByDataId($id);
  964.                 $model->del($id);
  965.                 $this->_redirect($this->view->adminUrl('catalog', 'products', array('action' => 'edit', 'id' => $data['parent_id'], 'hash' => 'colours')));
  966.                 exit;
  967.                 break;
  968.         }
  969.     }
  970.  
  971.     /**
  972.      * @title Настройки модуля
  973.      * @description Управление настройками модуля
  974.      */
  975.     public function settingsAction() {
  976.         $action = $this->_getParam('action', 'index');
  977.         $form = new Catalog_Form_Settings;
  978.         $model = new Catalog_Model_Settings();
  979.         $this->_breadcrumbs->addNode('Настройки модуля');
  980.         switch ($action) {
  981.             case 'index': default:
  982.                 if ($this->getRequest()->isPost()) {
  983.                     $data = $this->getRequest()->getPost();
  984.                     unset($data['submit']);
  985.                     //exit(Zend_Debug::dump($data));
  986.                     foreach ($data as $prop => $value) {
  987.                         $model->update(array('value' => $value), "prop='$prop'");
  988.                     }
  989.                     $this->_helper->flashMessenger->addMessage('Настройки успешно обновлены');
  990.                     $this->_redirect($this->view->adminUrl('catalog', 'settings'));
  991.                 } else {
  992.                     $this->view->message = array_pop(array_merge($this->_helper->flashMessenger->getMessages(), $this->_helper->flashMessenger->getCurrentMessages()));
  993.                     $this->view->form = $form;
  994.                 }
  995.                 $this->render('settings/index');
  996.                 break;
  997.         }
  998.     }
  999.  
  1000.     /**
  1001.      * @title Поиск по каталогу
  1002.      * @description Поиск внутри админки
  1003.      * @service
  1004.      */
  1005.     public function searchAction() {
  1006.         if ($this->getRequest()->isXMLHttpRequest()) {
  1007.             $this->_helper->layout()->disableLayout();
  1008.             $model = new Catalog_Model_Products;
  1009.             $phrase = urldecode($this->_getParam('q'));
  1010.             $data = $model->search($phrase);
  1011.  
  1012.  
  1013.  
  1014.             exit(json_encode($data));
  1015.         }
  1016.     }
  1017.  
  1018.     /**
  1019.      * @title Фильтры
  1020.      * @description Управление фильтрами
  1021.      */
  1022.     public function filtersAction() {
  1023.         $this->_breadcrumbs->addNode('Управление фильтрами');
  1024.         $action = $this->_getParam('action');
  1025.         $model = new Catalog_Model_Filters();
  1026.         switch ($action) {
  1027.  
  1028.             case 'delete':
  1029.                 $id = $this->_getParam('id');
  1030.                 $model = new Catalog_Model_Filters;
  1031.                 $model->delete('id = ' . $id);
  1032.                 $model = new Catalog_Model_Filters_Values;
  1033.                 $model->delete('filter_id=' . $id);
  1034.                 $this->_redirect($_SERVER['HTTP_REFERER']);
  1035.                 break;
  1036.  
  1037.             case 'create':
  1038.  
  1039.                 $step = $this->_getParam('step', 1);
  1040.                 switch ($step) {
  1041.                     case 1:
  1042.  
  1043.                         if ($this->getRequest()->isPost()) {
  1044.                             $data = $this->getRequest()->getPost();
  1045.                            
  1046.                             $categoryId = $this->_getParam('cat');
  1047.                             $data['category_id'] = $categoryId;
  1048.                             $id = $model->insert($data); //ИД фильтра
  1049.                            
  1050.  
  1051.  
  1052.                             $this->_redirect($this->view->adminUrl('catalog', 'filters', array('action' => 'create', 'step' => 2, 'id' => $id, 'cat' => $categoryId)));
  1053.                         } else {
  1054.  
  1055.                             $cat = $this->_getParam('cat');
  1056.                             $settings = new Catalog_Model_Settings();
  1057.  
  1058.                             $props = new Catalog_Model_Categories_Properties;
  1059.                             $list = $props->getCategory($cat);
  1060.  
  1061.  
  1062.  
  1063.  
  1064.                             if ($settings->enable_price) {
  1065.                                 $list[] = array('title' => 'Цена',
  1066.                                     'property_id' => 'price');
  1067.                             }
  1068.                             if ($settings->enable_colors) {
  1069.                                 $list[] = array('title' => 'Цвета',
  1070.                                     'property_id' => 'color');
  1071.                             }
  1072.                             //exit(Zend_Debug::dump($list));
  1073.                             $this->view->fields = $list;
  1074.  
  1075.                             $this->render('filters/create/step1');
  1076.                         }
  1077.                         break;
  1078.                     case 2:
  1079.  
  1080.                         if ($this->getRequest()->isPost()) {
  1081.                             $data = $this->getRequest()->getPost();
  1082.  
  1083.                             $categoryId = $this->_getParam('cat');
  1084.                             $id = $this->_getParam('id');
  1085.  
  1086.                             $this->_redirect($this->view->adminUrl('catalog', 'filters', array(
  1087.                                         'action' => 'create',
  1088.                                         'step' => 3,
  1089.                                         'id' => $id,
  1090.                                         'cat' => $categoryId,
  1091.                                         'field' => $data['field']
  1092.                             )));
  1093.  
  1094.  
  1095.                             //exit(Zend_Debug::dump($data));
  1096.                         } else {
  1097.                             $id = $this->_getParam('id');
  1098.                             $info = $model->getByPk($id);
  1099.                             $cat = $this->_getParam('cat');
  1100.                             $settings = new Catalog_Model_Settings();
  1101.  
  1102.                             $props = new Catalog_Model_Categories_Properties;
  1103.                             $list = $props->getCategory($cat);
  1104.  
  1105.  
  1106.  
  1107.  
  1108.                             if ($settings->enable_price) {
  1109.                                 $list[] = array('title' => 'Цена',
  1110.                                     'property_id' => 'price');
  1111.                             }
  1112.                             if ($settings->enable_colors) {
  1113.                                 $list[] = array('title' => 'Цвета',
  1114.                                     'property_id' => 'color');
  1115.                             }
  1116.                             //exit(Zend_Debug::dump($list));
  1117.                             $this->view->fields = $list;
  1118.                             $this->view->info = $info;
  1119.                             $this->render('filters/create/step2');
  1120.                         }
  1121.  
  1122.                         break;
  1123.                     case 3:
  1124.                         $filters = new Catalog_Model_Filters();
  1125.                         if ($this->getRequest()->isPost()) {
  1126.                             $data = $this->getRequest()->getPost();
  1127.  
  1128.  
  1129.                             if (!isset($data['price_hidden'])) {
  1130.  
  1131.                                 $redirectToCategory = isset($data['end']);
  1132.                                 unset($data['end']);
  1133.                                 //   exit(Zend_Debug::dump($data));
  1134.                                 $data['property_id'] = $this->_getParam('field');
  1135.                                 $data['filter_id'] = $this->_getParam('id');
  1136.                                 $model = new Catalog_Model_Filters_Values();
  1137.                                 $id = $model->insert($data);
  1138.                                 //exit(var_dump($id));
  1139.                                 if (!$redirectToCategory) {
  1140.                                     $this->_redirect($_SERVER['HTTP_REFERER']);
  1141.                                 } else {
  1142.                                    
  1143.                                 }
  1144.                             } else {
  1145.  
  1146.                                 $data['property_id'] = -1; //-1 Статично для цены
  1147.                                 $data['filter_id'] = $this->_getParam('id');
  1148.                                 $priceType = $data['price_type'];
  1149.                                 unset($data['price_type'], $data['price_hidden']);
  1150.  
  1151.                                 switch ($priceType) {
  1152.                                     case 'auto':
  1153.                                         $model = new Catalog_Model_Filters_Values();
  1154.                                         $id = $model->insert($data);
  1155.                                         $this->_redirect($this->view->adminUrl('catalog', 'categories', array(
  1156.                                                     'action' => 'edit',
  1157.                                                     'id' => $this->_getParam('cat')
  1158.                                         )));
  1159.                                         break;
  1160.                                 }
  1161.                             }
  1162.                         } else {
  1163.                             //exit(Zend_Debug::dump('aaa'));
  1164.                             $props = new Catalog_Model_Categories_Properties;
  1165.                             $properties = new Catalog_Model_Properties;
  1166.                             $cat = $this->_getParam('cat'); //ID категории
  1167.                             $prop = $this->_getParam('field'); //ID поля
  1168.                             $id = $this->_getParam('id'); //ID фильтра
  1169.  
  1170.                             if ($prop == 'price') {
  1171.                                 $this->render('filters/create/price/type');
  1172.                             } elseif ($prop == 'color') {
  1173.                                 $data['property_id'] = $this->_getParam('field');
  1174.                                 $data['filter_id'] = '-2'; //-2 статично для цветовых решений
  1175.                                 $model = new Catalog_Model_Filters_Values();
  1176.                                 $id = $model->insert($data);
  1177.                                 $this->_redirect($this->view->adminUrl('catalog', 'categories', array(
  1178.                                             'action' => 'edit',
  1179.                                             'id' => $this->_getParam('cat')
  1180.                                 )));
  1181.                             } else {
  1182.                                 $defaults = $props->getDefaults($cat, $prop);
  1183.                                 $this->view->defaults = $defaults;
  1184.                                 $this->view->filter = $filters->getByPk($id);
  1185.                                 $this->view->property = $properties->getByPk($prop);
  1186.                                 $this->render('filters/create/step3');
  1187.                             }
  1188.                         }
  1189.  
  1190.                         break;
  1191.                 }
  1192.  
  1193.  
  1194.                 break;
  1195.             case 'edit':
  1196.  
  1197.                 if ($this->getRequest()->isPost()) {
  1198.                    
  1199.                 } else {
  1200.                     $this->view->form = true;
  1201.                 }
  1202.  
  1203.                 $this->render('filters/edit');
  1204.                 break;
  1205.         }
  1206.     }
  1207.  
  1208.     /**
  1209.      * @title Управление цветами
  1210.      * @description Цветовые решения для продуктов
  1211.      */
  1212.     public function coloursAction() {
  1213.         $this->_breadcrumbs->addNode('Управление цветами');
  1214.         $action = $this->_getParam('action');
  1215.         $model = new Catalog_Model_Colours;
  1216.         switch ($action) {
  1217.             case 'index': default:
  1218.                 $data = $model->getAll();
  1219.                 $this->view->list = $data;
  1220.                 $this->render('colours/list');
  1221.                 break;
  1222.             case 'add':
  1223.                 $this->view->headScript()->appendFile('/admin_style/js/jscolor/jscolor.js');
  1224.                 $form = new Catalog_Form_Colours_Add;
  1225.                 if ($this->getRequest()->isPost()) {
  1226.                     $data = $this->getRequest()->getPost();
  1227.                     if ($form->isValid($data)) {
  1228.                         unset($data['submit']);
  1229.                         $model->insert($data);
  1230.                         $this->_redirect($this->view->adminUrl('catalog', 'colours'));
  1231.                     } else {
  1232.                         $this->view->form = $form->populate($data);
  1233.                     }
  1234.                 } else {
  1235.                     $this->view->form = $form;
  1236.                 }
  1237.                 $this->render('colours/add');
  1238.                 break;
  1239.             case 'delete':
  1240.                 $id = $this->_getParam('id');
  1241.                 $model->delete('id=' . $id);
  1242.                 $this->_redirect($this->view->adminUrl('catalog', 'colours'));
  1243.                 break;
  1244.             case 'edit':
  1245.                 $this->view->headScript()->appendFile('/admin_style/js/jscolor/jscolor.js');
  1246.                 $form = new Catalog_Form_Colours_Edit;
  1247.                 if ($this->getRequest()->isPost()) {
  1248.                     $data = $this->getRequest()->getPost();
  1249.                     $id = $data['id'];
  1250.                     unset($data['id'], $data['submit']);
  1251.                     $model->update($data, 'id=' . $id);
  1252.                     $this->_redirect($this->view->adminUrl('catalog', 'colours'));
  1253.                 } else {
  1254.                     $id = $this->_getParam('id');
  1255.                     $this->view->form = $form->populate($model->getByPk($id));
  1256.                     $this->render('colours/add');
  1257.                 }
  1258.                 break;
  1259.         }
  1260.     }
  1261.  
  1262.     /**
  1263.      * @title Автоматический генератор мета-тегов
  1264.      * @description Управление автоматической генерацией мета-данных
  1265.      * @service
  1266.      */
  1267.     public function metageneratorAction() {
  1268.  
  1269.         $action = $this->_getParam('action');
  1270.         switch ($action) {
  1271.             case 'product-template':
  1272.                 $this->_helper->layout()->disableLayout();
  1273.                 $id = $this->_getParam('category');
  1274.                 $model = new Catalog_Model_Categories;
  1275.                 exit(json_encode($model->getMetaTemplate($id)));
  1276.                 break;
  1277.         }
  1278.     }
  1279.  
  1280.     protected function _recursive($array) {
  1281.         static $return = array();
  1282.         foreach ($array as $k => $v) {
  1283.             foreach ($v->children as $cid => $c) {
  1284.                 $return[] = array(
  1285.                     'title' => $c->title,
  1286.                     'parent_title' => $v->title,
  1287.                     'parent_id' => str_replace('f', '', $v->key),
  1288.                     'id' => str_replace('f', '', $c->key),
  1289.                     'link' => mb_strlen($c->href) ? $c->href : '',
  1290.                     'ordering' => $cid
  1291.                 );
  1292.             }
  1293.             $this->_recursive($v);
  1294.         }
  1295.         return $return;
  1296.     }
  1297.  
  1298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement