Exemplo n.º 1
0
 public function action_index()
 {
     $materials = new Model_Material('groups');
     $gid = $this->request->param('id');
     $ready = array();
     //получаем набор фильтров
     $filters = $materials->getFieldsSet($gid);
     foreach ($filters as $filter) {
         if ($filter['for_filters'] == '1') {
             if ($filter['type'] == 'select') {
                 $value_set = array();
                 $set = $materials->getSelectValues($filter['id']);
                 foreach ($set as $set_item) {
                     $value_set[] = $set_item;
                 }
                 $filter['value_set'] = $value_set;
             }
             array_push($ready, $filter);
         }
     }
     $this->template->filters = $ready;
     $this->template->search_params = $_GET;
 }
Exemplo n.º 2
0
 public function action_new()
 {
     $fieldset = array();
     $group = new Model_Material('groups');
     $data['groups'] = $group->getTree();
     $gid = $this->request->param('id');
     if ($gid != NULL) {
         $fields = $group->getParams($gid);
         foreach ($fields as $field) {
             //генерируем код для каждого поля
             //если поле - список выбора
             if ($field['type'] == 'select') {
                 $values = $group->getSelectValues($field['id']);
                 $field['myValues'] = $values;
             }
             $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->render();
         }
         $data['fieldset'] = $fieldset;
     }
     if (isset($_POST['new_material'])) {
         $res = $group->newMaterial($_POST, $gid, $_FILES);
         if ($res) {
             Controller::redirect('admin/materials/' . $gid);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $folders = $this->getFolders();
     $pictures = $this->action_pictures($wpm['folder']);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user));
 }
Exemplo n.º 3
0
 public function action_new()
 {
     $fieldset = array();
     $folders = $this->getFolders();
     $group = new Model_Material('groups');
     $data['groups'] = $group->getTree();
     $gid = $this->request->param('id');
     if ($gid != NULL) {
         $fields = $group->getParams($gid);
         foreach ($fields as $field) {
             //генерируем код для каждого поля
             //если поле - список выбора
             if ($field['type'] == 'select') {
                 $values = $group->getSelectValues($field['id']);
                 $field['myValues'] = $values;
             }
             if ($field['type'] == 'photoalbum') {
                 $base = new Model_Base();
                 $options = $base->getOptions();
                 $field['photos_base_path'] = $options['photos_base_path'];
             }
             if ($field['type'] == 'files') {
                 $base = new Model_Base();
                 $options = $base->getOptions();
                 $field['files_base_path'] = $options['files_base_path'];
             }
             $fieldset[] = View::factory('admin/fields/' . $field['type'])->bind('data', $field)->bind('folders', $folders)->bind('multiselect', $field['multiselect'])->bind('user', $this->user)->render();
         }
         $data['fieldset'] = $fieldset;
     }
     if (isset($_POST['new_material'])) {
         //PC::debug($_POST);
         //var_dump($_POST);
         $res = $group->newMaterial($_POST, $gid, $_FILES);
         if ($res) {
             Controller::redirect('admin/materials/' . $gid);
         } else {
             $data['errors'] = $group->getErrors();
         }
     }
     if (isset($_POST['save_selects'])) {
         $selects = new Model_Params_Selects();
         $values = $_POST;
         unset($values['save_selects']);
         $selects->saveSelectsValues($values, $_POST['save_selects']);
     }
     if (isset($_POST['save_param'])) {
         $selects = new Model_Selects();
         $values = $_POST;
         unset($values['save_param']);
         $selects->saveSelectsParam($values, $_POST['save_param'], $_FILES);
     }
     $wpm['status'] = Cookie::get('wpm', FALSE);
     $wpm['folder'] = Cookie::get('wpm_folder', '');
     $pictures = $this->action_pictures($wpm['folder']);
     $this->template->content = View::factory('admin/admMaterials', array('data' => $data, 'folders' => $folders, 'pictures' => $pictures, 'wpm' => $wpm, 'user' => $this->user));
 }
Exemplo n.º 4
0
 public function action_index($options = array("catalog_id" => 4, "items_position_type" => "half"))
 {
     $this->setopt(array("name" => "catalog_id", "description" => "Ид каталога", "default" => $options["catalog_id"]));
     $this->setopt(array("name" => "items_position_type", "description" => "Способ отображения item'ов", "default" => $options["items_position_type"]));
     // --- tests ---------------------------------------------------------------
     $model_module = new Model_Module();
     $module = $model_module->get_module(176);
     $module->get_options();
     //$module->test(1382);
     $module->set(array("action" => "index"));
     // --- /tests --------------------------------------------------------------
     $model = array();
     $qdata = array();
     $param_array = array();
     $materials = new Model_Material('groups');
     $config = Kohana::$config->load('main')->site;
     $pageNum = intval(Arr::get($_GET, 'page', 0));
     $param = $this->getopt("catalog_id");
     //$param = $this->request->param('id');
     //PC::debug($pageNum);
     $params = explode('/', $param);
     $gid = $params[0];
     foreach ($params as $paramName) {
         if (preg_match("/page(\\d)/", $paramName)) {
             $pageNum = str_replace('page', '', $paramName);
         }
     }
     $template = $this->request->param('template');
     if ($template) {
         $this->template = View::factory('widgets/' . $template);
     }
     //search for template
     $widget = new Model_Widget();
     $widgetData = $this->widget_data;
     if ($widgetData['template']) {
         $this->template = View::factory('widgets/' . $widgetData['template']);
     }
     $query = Arr::get($widgetData, 'query');
     if ($query != '') {
         $queries = explode('&', $query);
         foreach ($queries as $q) {
             $rr = explode('=', $q);
             if (!isset($param_array[$rr[0]])) {
                 $qdata[$rr[0]][] = $rr[1];
             }
         }
     }
     //counters
     $group = $materials->getGroup($gid);
     $material_count = $group['materials'];
     $search_string = Arr::get($param_array, 'art', NULL);
     //проверяем кодировку
     $res = mb_detect_encoding($search_string, array('UTF-8', 'Windows-1251'));
     if ($res != 'UTF-8') {
         $search_string = iconv($res, 'UTF-8', $search_string);
     }
     if (isset($param_array['go'])) {
         unset($param_array['go']);
     }
     if (isset($param_array['price'])) {
         $pricer = explode(';', $param_array['price']);
         $qdata['price_from'] = intval(Arr::get($pricer, 0) * 1000);
         $qdata['price_to'] = intval(Arr::get($pricer, 1) * 1000);
         unset($param_array['price']);
     }
     if (isset($param_array['sort'])) {
         $qdata['sort'] = addslashes($param_array['sort']);
     }
     $qparams = array_keys($param_array);
     //получаем доступные параметры
     $params = $materials->getFieldsSet($gid);
     foreach ($params as $param) {
         if ($param['for_filters'] == 1) {
             if (in_array($param['name'], $qparams)) {
                 switch ($param['type']) {
                     case 'select':
                         if (is_array($param_array[$param['name']])) {
                             $selvalues = $materials->getSelectValues($param['id']);
                             $vals = array_values($param_array[$param['name']]);
                             foreach ($selvalues as $value) {
                                 if (in_array($value->value, $vals)) {
                                     $qdata[$param['name']][] = $value->value;
                                 }
                             }
                         }
                         break;
                     case 'price':
                         $arr = explode(';', $param_array[$param['name']]);
                         $qdata[$param['name'] . '_from'] = intval(Arr::get($arr, 0));
                         $qdata[$param['name'] . '_to'] = intval(Arr::get($arr, 1));
                         break;
                     case 'chars':
                         $qdata[$param['name']] = addslashes($param_array[$param['name']]);
                         break;
                 }
             }
         }
     }
     //получаем данные для сортировки
     //$this->template->searchtext = $search_string;
     //$this->template->search_params = $param_array;
     // Сколько найдено материалов?
     $material_count = $materials->getCountFullMaterials2($gid, $search_string, $qdata);
     // Номер текущей страницы
     $current_page = 1;
     if (isset($_GET["page"])) {
         //if ($_GET["page"] !== 0)
         $current_page = $_GET["page"];
     }
     // Вывод всех материалов на одной странице
     $model["limit"]["text"] = "Показать все на странице";
     $model["limit"]["href"] = URL::query(array("limit" => false, "page" => 1));
     $material_limit = 24;
     if (isset($_GET["limit"])) {
         if (!$_GET["limit"]) {
             $model["limit"]["text"] = "Постраничное разделение";
             $model["limit"]["href"] = URL::query(array("limit" => true));
             $material_limit = $material_count;
             //$current_page = 1;
         }
     } else {
         $material_limit = 24;
         // Материалов на странице
     }
     $max_page = ceil($material_count / $material_limit);
     // Максимальная страница
     $material_offset = $material_limit * ($current_page - 1);
     // Смещение материалов
     // страница существует
     if ($current_page <= $max_page) {
         $items = $materials->getFullMaterials2($gid, $material_limit, $material_offset, $search_string, $qdata);
     } else {
         $items = [];
     }
     // Хлебные крошки
     $this->load_module("breadcrumb", "/widgets/Breadcrumb/index");
     // --- Выбор способа отображения item'ов ---------------------------------------------------
     $model["items_position_type"] = Arr::get($_COOKIE, "items_position_type", $this->getopt("items_position_type"));
     $this->load_module("item_position", "/widgets/ItemPosition/index");
     // --- /Выбор способа отображения item'ов ---------------------------------------------------
     // --- Пагинация --------------------------------------------------------------------------
     $this->load_module("pagination", "/widgets/Pagination/index", array("current" => $current_page, "max" => $max_page, "count" => 5));
     // --- /Пагинация -------------------------------------------------------------------------
     // Для корзины
     echo '<script>var items = JSON.parse(\'' . json_encode($items) . '\');</script>';
     $model["items"] = $items;
     // Кол-во найденых материалов
     $model["material_count"] = $material_count;
     // Изменение модели
     foreach ($model["items"] as $item_id => $item) {
         $new_model = array();
         // id материала
         $new_model["id"] = $item_id;
         // Формат цены
         $new_model["price"] = number_format($item["price"], 0, '', ' ');
         // Формат старой цены
         if (isset($item['old_price'])) {
             $new_model["old_price"] = number_format($item["old_price"], 0, '', ' ');
         }
         // Изображение
         if (isset($item['photos'][0])) {
             $new_model["photo"] = Route::url('miniimg3', array('filename' => $item['photos'][0]['value']));
         } else {
             $new_model["photo"] = Route::url('miniimg3', array('filename' => '/img/noimg.png'));
         }
         // Акция
         if (isset($item["stock"])) {
             $new_model["stock"] = " " . $item["stock"][0]["value"];
         }
         //$new_model["stock"] = "new"; //test
         // Ссылка на материал
         $new_model["href"] = "/" . $item["node"] . $item["url"] . ".html";
         // --- Обрезаем длинные поля --------------------------------------------------------
         // Название
         $new_model["name"] = $item["name"];
         if (strlen($item["name"]) > 80) {
             $new_model["name"] = Text::limit_chars($item["name"], 77);
         }
         // Описание
         $new_model["description"] = $item["description"];
         if (strlen($item["description"]) > 80) {
             $new_model["description"] = Text::limit_chars($item["description"], 77);
         }
         // --- /Обрезаем длинные поля -------------------------------------------------------
         $model["items"][$item_id] = array_merge($model["items"][$item_id], $new_model);
     }
     if ($material_count == 0) {
         $Menu = new Controller_Widgets_Menu($this->request, $this->response);
         $Menu->action_graph(array("parent_id" => Arr::get($GLOBALS, 'categoryId')));
         $this->body($Menu->get_body());
         /*$this->load_module("graph_menu", "/widgets/Graph_Menu/index", array(
         			"parent_id" => Arr::get($GLOBALS, 'categoryId'),
         		));*/
     } else {
         $this->set_template("/widgets/w_catalog.php", "twig")->render($model)->body();
     }
 }