Exemplo n.º 1
0
 public function action_index()
 {
     require_once APPPATH . "classes/Controller/Widgets/Menu.php";
     $menu = new Controller_Widgets_Menu($this->request, $this->response);
     $menu->get_config();
     PC::debug($menu->module_config);
     PC::debug($menu->request);
     PC::debug($menu->response);
 }
Exemplo n.º 2
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();
     }
 }