public function listAction() { $this->_template = 'ItemsList'; Route::factory()->setAction('list'); // Filter parameters to array if need Filter::setFilterParameters(); // Set filter elements sortable Filter::setSortElements(); $page = !(int) Route::param('page') ? 1 : (int) Route::param('page'); // Check for existance $group = DB::select()->from('catalog_tree')->where('alias', '=', Route::param('alias'))->where('status', '=', 1)->as_object()->execute()->current(); if (!$group) { return Config::error(); } // Seo $this->setSeoForGroup($group); // Add plus one to views DB::update('catalog_tree')->set(array('views' => (int) $group->views + 1))->where('id', '=', $group->id)->execute(); // Get items list $result = Filter::getFilteredItemsList($this->limit, ($page - 1) * $this->limit, $this->sort, $this->type); // Generate filter add for sql queries $add = Filter::getSql(); // Count of parent groups $count = DB::query(Database::SELECT, 'SELECT COUNT(DISTINCT catalog.id) AS count FROM catalog ' . $add['join'] . 'WHERE catalog.parent_id = "' . $group->id . '" AND catalog.status = "1"' . $add['where'])->as_object()->execute()->current(); if ($count) { $count = $count->count; } else { $count = 0; } // Generate pagination $pager = Pager::factory($page, $count, $this->limit)->create(); // Render page $this->_content = View::tpl(array('result' => $result, 'pager' => $pager), 'Catalog/ItemsList'); }
public function indexAction() { // Get item information from database $item = DB::select('catalog.*', array('brands.name', 'brand_name'), array('brands.alias', 'brand_alias'), array('models.name', 'model_name'), array('catalog_tree.name', 'parent_name'))->from('catalog')->join('catalog_tree', 'LEFT')->on('catalog.parent_id', '=', 'catalog_tree.id')->join('brands', 'LEFT')->on('catalog.brand_id', '=', 'brands.id')->on('brands.status', '=', DB::expr('1'))->join('models', 'LEFT')->on('catalog.model_id', '=', 'models.id')->on('models.status', '=', DB::expr('1'))->where('catalog.status', '=', 1)->where('catalog.alias', '=', Route::param('alias'))->as_object()->execute()->current(); if (!$item) { return Config::error(); } Route::factory()->setParam('id', $item->id); Route::factory()->setParam('group', $item->parent_id); // Add to cookie viewed list Catalog::factory()->addViewed($item->id); // Add plus one to views DB::update('catalog')->set(array('views' => (int) $item->views + 1))->where('id', '=', $item->id)->execute(); // Seo $this->setSeoForItem($item); // Get images $images = DB::select('image')->from('catalog_images')->where('catalog_id', '=', $item->id)->order_by('sort')->as_object()->execute(); // Get item sizes $sizes = DB::select('sizes.*')->from('sizes')->join('catalog_sizes', 'LEFT')->on('catalog_sizes.size_id', '=', 'sizes.id')->where('catalog_sizes.catalog_id', '=', $item->id)->where('sizes.status', '=', 1)->order_by('sizes.name')->as_object()->execute(); // Get current item specifications list $specifications = DB::select('specifications.*')->from('specifications')->join('catalog_tree_specifications', 'LEFT')->on('catalog_tree_specifications.specification_id', '=', 'specifications.id')->where('catalog_tree_specifications.catalog_tree_id', '=', $item->parent_id)->where('specifications.status', '=', 1)->order_by('specifications.name')->as_object()->execute(); $res = DB::select()->from('specifications_values')->join('catalog_specifications_values', 'LEFT')->on('catalog_specifications_values.specification_value_id', '=', 'specifications_values.id')->where('catalog_specifications_values.catalog_id', '=', $item->id)->where('status', '=', 1)->where('catalog_specifications_values.specification_value_id', '!=', 0)->as_object()->execute(); $specValues = array(); foreach ($res as $obj) { $specValues[$obj->specification_id][] = $obj; } $spec = array(); foreach ($specifications as $obj) { if (isset($specValues[$obj->id]) and is_array($specValues[$obj->id]) and count($specValues[$obj->id])) { if ($obj->type_id == 3) { $spec[$obj->name] = ''; foreach ($specValues[$obj->id] as $o) { $spec[$obj->name] .= $o->name . ', '; } $spec[$obj->name] = substr($spec[$obj->name], 0, -2); } else { $spec[$obj->name] = $specValues[$obj->id][0]->name; } } } // Render template $this->_content = View::tpl(array('obj' => $item, 'images' => $images, 'sizes' => $sizes, 'specifications' => $spec), 'Catalog/Item'); }
/** * Get current module */ public static function module() { return Route::factory()->getModule(); }