function allAction() { $fc = FrontController::getInstance(); $model = new FrontModel(); $productModel = new ProductTableModel(); $productModel->setTable('product'); $params = $fc->getParams(); $condition = ''; $paramsMap = ['brand', 'color', 'category_id', 'subcategory_id']; if (!empty($params)) { $condition .= 'WHERE'; foreach ($params as $name => $value) { if (in_array(strtolower($name), $paramsMap)) { $condition .= " product.{$name} = '{$value}' AND"; } } $condition .= ' main = 1'; if (strpos(strtolower($condition), 'join') || strpos(strtolower($condition), 'union')) { $condition = ''; } } //for pagination $num = (new AdminWidgets())->getNum('product', substr($condition, 0, -13)); $page = $fc->getParams()['page'] ? filter_var($fc->getParams()['page'], FILTER_SANITIZE_NUMBER_INT) : 1; $limit = $fc->getParams()['limit'] ? filter_var($fc->getParams()['limit'], FILTER_SANITIZE_NUMBER_INT) : 20; $orderBy = $fc->getParams()['orderBy'] ? filter_var($fc->getParams()['orderBy'], FILTER_SANITIZE_STRING) : 'id'; $direction = $fc->getParams()['direction'] ? filter_var($fc->getParams()['direction'], FILTER_SANITIZE_STRING) : 'asc'; $offset = $limit * $page - $limit; $popProducts = (new IndexWidgets())->recAndPopProductsWidget('popular', 3); $recProducts = (new IndexWidgets())->recAndPopProductsWidget('recommended'); // \app\helpers\Helper::g($condition); exit; $model->setData(['products' => $productModel->getAllProducts('*', $condition . " ORDER BY product.{$orderBy} " . strtoupper($direction) . " LIMIT {$limit} OFFSET {$offset}"), 'popularProducts' => Generator::popularProducts($popProducts, 3), 'recommendedProducts' => Generator::recommendedProducts($recProducts), 'page' => $page, 'offset' => $offset, 'start' => $offset + 1, 'end' => $limit * $page < $num ? $limit * $page : $num, 'paginationOptions' => ['brand' => $fc->getParams()['brand'] ? filter_var($fc->getParams()['brand'], FILTER_SANITIZE_STRING) : '', 'color' => $fc->getParams()['color'] ? filter_var($fc->getParams()['color'], FILTER_SANITIZE_STRING) : '', 'category_id' => $fc->getParams()['category_id'] ? filter_var($fc->getParams()['category_id'], FILTER_SANITIZE_STRING) : '', 'subcategory_id' => $fc->getParams()['subcategory_id'] ? filter_var($fc->getParams()['subcategory_id'], FILTER_SANITIZE_STRING) : '', 'limit' => $limit, 'orderBy' => $orderBy, 'direction' => $direction, 'table' => 'product', 'num' => $num]]); $output = $model->render('../views/product/all.php', 'withoutSlider'); $fc->setPage($output); }
function indexAction() { $fc = FrontController::getInstance(); $model = new FrontModel(); $popProducts = (new IndexWidgets())->recAndPopProductsWidget('popular', 6); $recProducts = (new IndexWidgets())->recAndPopProductsWidget('recommended'); $model->setData(['slides' => IndexWidgets::getSliderWidget(), 'currentCategory' => (new IndexWidgets())->currentCategoryWidget(Helper::getSiteConfig()->currentCategoryWidget), 'popularProducts' => Generator::popularProducts($popProducts, 6), 'recommendedProducts' => Generator::recommendedProducts($recProducts)]); $output = $model->render('../views/index.php', 'main'); $fc->setPage($output); }