public function idAction($seller_id = null, $selected_lang = null) { // Access control with backdoor for admins if ($this->auth->id != Marketseller::findFirst("id={$seller_id} AND (active=1 OR active IS NULL)")->user_id && $this->auth->role_id != 5) { $this->flash->error("У вас нет доступа к этому виртуальному магазину!"); return $this->response->redirect("seller/index"); } // Find languages for a marketplace $seller = Marketseller::findFirst("id={$seller_id}"); $langs = $seller->Marketplace->prefs; $langs = preg_split('/[,\\s]/', $langs, 0, PREG_SPLIT_NO_EMPTY); // $list_of_langs = "'".join("', '", $langs)."'"; $selected_lang = $selected_lang != null ? $selected_lang : $langs[0]; $lng = $selected_lang == 'all' ? $langs : [$selected_lang]; // var_dump($lng); $tmaterial_id = Marketseller::findFirst($seller_id)->tmaterial_id; // Search by id $search_id = null; if ($this->request->isPost()) { $id = $this->request->getPost('search_id', 'int'); $search_id = " AND info.product_id = {$id}"; } $products_array = []; foreach ($lng as $l) { $table = new PProdInfo(); $sql = "SELECT info.id, sel.*, cat.title AS category FROM p_prod_info AS info\n LEFT JOIN p_product_main AS main\n ON main.id = info.product_id\n LEFT JOIN p_selection_seller AS sel\n ON sel.id = info.product_id AND sel.lang = '{$l}'\n LEFT JOIN p_category AS cat\n ON main.category_id = cat.category_id\n WHERE sel.hold = 0 AND sel.title IS NOT NULL AND info.lang = '{$l}' AND info.coder_status = 5 AND cat.lang = 'ru' AND main.tmaterial_id = {$tmaterial_id}{$search_id};"; $selection = new Resultset(null, $table, $table->getReadConnection()->query($sql)); $selection = $selection->toArray(); $placement = MPlacement::find("marketseller_id = {$seller_id} AND langcode = '{$l}' AND (active=1 OR active IS NULL)")->toArray(); for ($i = 0; $i < count($selection); $i++) { $products_array[$selection[$i]['id']] = $selection[$i]; } foreach ($placement as $prod) { if (isset($products_array[$prod['product_id']])) { unset($products_array[$prod['product_id']]); } } } // Paginator $perpage = $this->request->getQuery('perpage', 'int') ? $this->request->getQuery('perpage', 'int') : 10; $page = $this->request->getQuery('page', 'int') ? $this->request->getQuery('page', 'int') : 1; // $paginator = new Paginator([ $paginator = new PaginatorArray(["data" => $products_array, "limit" => (int) $perpage, "page" => (int) $page]); $this->view->products = $paginator->getPaginate(); // $this->view->products_count = $products; $this->view->products_count = $products_array; $this->view->seller_id = $seller_id; $this->view->seller = $seller; $this->view->langs = $langs; $this->view->selected_lang = $selected_lang; $this->view->placed_today = $this->modelService->getStat('done', 'seller', 'all', 'day'); $this->view->placed_month = $this->modelService->getStat('done', 'seller', 'all', 'month'); // Check if a user is an autoplacer $this->view->is_autoplacer = AccRoles::findFirst("user_id={$this->auth->id} AND (role_id=5 OR role_id=2000)"); }
/** * Number of products available for placement for each of virtual category */ public function virtcatsAction() { $langs = PProdInfo::count(['group' => 'lang', 'order' => 'id']); foreach ($langs as $lang) { $all_langs[] = $lang->lang; } // Stats $table = new PProdInfo(); $sql = "SELECT pg.title, pg.id, info.lang, COUNT(info.id) AS count FROM p_prod_info AS info\n JOIN p_product_main AS main ON main.id = info.product_id\n JOIN p_category_group AS pg ON pg.id = main.tmaterial_id\n WHERE main.hold = 0 AND info.coder_status = 5\n GROUP BY main.tmaterial_id, info.lang\n ORDER BY pg.title, info.id;"; $stats = new Resultset(null, $table, $table->getReadConnection()->query($sql)); $stats = $stats->toArray(); $group = []; foreach ($all_langs as $lang) { foreach ($stats as $stat) { if ($stat['lang'] == $lang) { $group[$stat['title']][$stat['lang']] = (int) $stat['count']; } } } $this->view->all_langs = $all_langs; $this->view->group = $group; }