config = $config; $this->controller = $controller; $this->db = $db; $this->helper = $helper; $this->items_manager = $items_manager; $this->language = $language; $this->operator_cat = $operator_cat; $this->operator_item = $operator_item; $this->pagination = $pagination; $this->request = $request; $this->template = $template; } /** * Display the shop index. * * @return Response * @access public */ public function shop() { $this->controller->check_shop(); $this->controller->create_shop('shop'); $this->controller->setup_carousel(); $this->controller->setup_panels(); $panels = [ 'limited' => ['carousel' => true, 'title' => 'ASS_ITEMS_LIMITED'], 'recent' => ['carousel' => true, 'title' => 'ASS_ITEMS_RECENT'], 'sale' => ['carousel' => true, 'title' => 'ASS_SALE_ITEMS'], 'featured' => ['carousel' => true, 'title' => 'ASS_FEATURED_ITEMS'], 'featured_sale' => ['carousel' => false], 'random' => ['carousel' => false], ]; uksort($panels, function($a, $b) { if ($this->config["ass_panel_{$a}_order"] == $this->config["ass_panel_{$b}_order"]) { return 0; } return $this->config["ass_panel_{$a}_order"] < $this->config["ass_panel_{$b}_order"] ? -1 : 1; }); foreach (array_keys($panels) as $panel) { if ($this->config["ass_panel_{$panel}_limit"]) { $this->operator_item->assign_specific_items($panel, $this->config["ass_panel_{$panel}_limit"]); } } $this->template->assign_vars(['ass_panels' => $panels]); return $this->helper->render('ass_shop.html', $this->language->lang('ASS_SHOP')); } /** * Display a shop category. * * @param string $category_slug The category slug * @param int $page The page number * @return Response * @access public */ public function category($category_slug, $page = 1) { $this->controller->check_shop(); $category = $this->operator_cat->load_entity($category_slug); $this->controller->create_shop('shop', $category); $this->controller->setup_panels(); $this->template->assign_vars($this->operator_cat->get_variables($category)); $sql_where = ''; $types = [0 => null]; $type_array = ['ASS_ALL']; foreach($this->operator_item->get_item_types($category->get_id()) as $type) { $types[] = $type; $type_array[] = $this->items_manager->get_type($type)->get_language('title'); } $params_array = [ 'above' => ['default' => '', 'sql' => 'i.item_price > {VALUE}'], 'below' => ['default' => '', 'sql' => 'i.item_price < {VALUE}'], 'gift' => ['default' => 0, 'sql' => 'i.item_gift = {VALUE}'], 'sale' => ['default' => 0, 'sql' => 'i.item_sale_start < ' . time() . ' AND i.item_sale_until < ' . time()], 'type' => ['default' => 0, 'sql' => 'i.item_type = {VALUE}'], 'title' => ['default' => '', 'sql' => $this->db->sql_lower_text('i.item_title') . ' {VALUE}', 'mb' => true], ]; $days_array = [ 0 => 'ASS_ALL', 1 => '1_DAY', 7 => '7_DAYS', 14 => '2_WEEKS', 30 => '1_MONTH', 90 => '3_MONTHS', 180 => '6_MONTHS', 365 => '1_YEAR', ]; $sort_array = [ 'order' => ['title' => 'ASS_ITEM_ORDER', 'sql' => 'i.item_order'], 'item' => ['title' => 'ASS_ITEM_TITLE', 'sql' => 'i.item_title'], 'price' => ['title' => 'ASS_ITEM_PRICE', 'sql' => 'i.item_price'], 'stock' => ['title' => 'ASS_ITEM_STOCK', 'sql' => 'i.item_stock'], 'time' => ['title' => 'ASS_ITEM_CREATE_TIME', 'sql' => 'i.item_create_time'], ]; $dir_array = [ 'desc' => ['title' => 'DESCENDING', 'sql' => 'DESC'], 'asc' => ['title' => 'ASCENDING', 'sql' => 'ASC'], ]; $days = $this->request->variable('days', 0, false, \phpbb\request\request_interface::GET); $sort = $this->request->variable('sort', 'order', true, \phpbb\request\request_interface::GET); $dir = $this->request->variable('direction', 'asc', true, \phpbb\request\request_interface::GET); $dir = in_array($dir, array_keys($dir_array)) ? $dir : 'asc'; $sort = in_array($sort, array_keys($sort_array)) ? $sort : 'order'; $days = in_array($days, array_keys($days_array)) ? $days : 0; $time = $days * \phpbbstudio\ass\helper\time::DAY; $params = [ 'sort' => $sort, 'direction' => $dir, ]; if ($time) { $params['days'] = $days; $sql_where .= ' AND i.item_create_time > ' . (time() - $time); } foreach ($params_array as $key => $param) { $value = $this->request->variable( $key, $params_array[$key]['default'], !empty($params_array[$key]['mb']), \phpbb\request\request_interface::GET ); if (!empty($value)) { $params[$key] = $value; $value_sql = $value !== -1 ? $value : 0; switch ($key) { case 'type': if (in_array($value, array_keys($type_array))) { $value_sql = "'" . $types[$value] . "'"; } break; case 'title': $value_sql = $this->db->sql_like_expression(utf8_strtolower($value_sql) . $this->db->get_any_char()); break; } $param_sql = str_replace('{VALUE}', $value_sql, $params_array[$key]['sql']); $sql_where .= ' AND ' . $param_sql; $this->template->assign_var('SORT_' . utf8_strtoupper($key), $value); } } $sql_dir = $dir_array[$dir]['sql']; $sql_order = $sort_array[$sort]['sql']; $limit = (int) $this->config['ass_items_per_page']; $start = ($page - 1) * $limit; $total = $this->operator_item->get_item_count($category->get_id()); $items = $this->operator_item->get_items($category->get_id(), $sql_where, $sql_order, $sql_dir, true, $limit, $start); foreach ($items as $item) { $this->template->assign_block_vars('ass_items', $this->operator_item->get_variables($item)); } $this->pagination->generate_template_pagination([ 'routes' => ['phpbbstudio_ass_category', 'phpbbstudio_ass_category_pagination'], 'params' => array_merge(['category_slug' => $category->get_slug()], $params), ], 'shop_pagination', 'page', $total, $limit, $start); $this->template->assign_vars([ 'ITEMS_COUNT' => $this->language->lang('ASS_ITEMS_COUNT', $total), 'SORT_DAYS' => $days, 'SORT_DAYS_ARRAY' => $days_array, 'SORT_DIR' => $dir, 'SORT_DIR_ARRAY' => $dir_array, 'SORT_SORT' => $sort, 'SORT_SORT_ARRAY' => $sort_array, 'SORT_TYPE_ARRAY' => $type_array, 'T_PANEL_SIZE' => $limit < 8 ? 6 : 3, ]); return $this->helper->render('ass_category.html', $category->get_title()); } /** * Display a shop item. * * @param string $category_slug The category slug * @param string $item_slug The item slug * @return Response * @access public */ public function item($category_slug, $item_slug) { $this->controller->check_shop(); $category = $this->operator_cat->load_entity($category_slug); $item = $this->operator_item->load_entity($item_slug, $category->get_slug(), $category->get_id()); if (!$this->operator_item->is_available($item)) { throw new shop_exception(410, 'ASS_ERROR_NOT_AVAILABLE'); } $this->controller->create_shop('shop', $category, $item); $this->controller->setup_carousel(); $this->controller->setup_panels(); if ($item->get_related_enabled()) { $this->operator_item->assign_related_items($item); } $this->template->assign_vars($this->operator_item->get_variables($item)); return $this->helper->render('ass_item.html', $item->get_title()); } }