Example #1
0
 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)");
 }
 /**
  * @Get("/{product_id:[0-9]+}/{params:[0-9a-zA-Z\-\_\.\:\,]+}", name="show-product")
  */
 public function indexAction()
 {
     $product_id = $this->filter->sanitize($this->dispatcher->getParam('product_id'), 'int');
     $lang = $this->filter->sanitize($this->dispatcher->getParam("lang"), 'string');
     // Selected product
     // Check if the product exists. Redirect to page 404 if not
     if (!($this->view->product = $product = PProductMain::findFirst($product_id))) {
         return $this->response->redirect('route404');
     }
     // Currency rate for selected currency
     $this->view->curr_rate = $curr_rate = PCrosscurrency::findFirst("title='{$this->currency}'")->currencyrate;
     // Delivery
     $expected_delivery = $product->oneProductTime + 25;
     $this->view->expected_delivery = date("d.m.Y", strtotime("now + {$expected_delivery} days"));
     //        $this->view->delivery = $delivery = $this->prodInfoService->deliveryCost($product, $delivery_zone);
     // List of categories to which the product belongs to
     $cat_tree = PCategory::getProductCatTree($product_id, $this->lang)->toArray();
     $cats = [];
     foreach ($cat_tree as $cat) {
         $cats[] = ['title' => $cat['title0'], 'catid' => $cat['catid0'], 'uri' => $cat['uri0']];
         $cats[] = ['title' => $cat['title1'], 'catid' => $cat['catid1'], 'uri' => $cat['uri1']];
         if (isset($cat['title2'])) {
             $cats[] = ['title' => $cat['title2'], 'catid' => $cat['catid2'], 'uri' => $cat['uri2']];
         }
         break;
     }
     $this->view->categories = $cats;
     // More from maker
     $params = ['index' => 'mhdev_' . $lang, 'type' => 'products', 'body' => ['query' => ['function_score' => ['query' => ['match' => ['maker_id' => $product->maker_id]], 'random_score' => new stdClass()]], 'size' => 6]];
     $this->view->maker_products = $this->elasticsearch->search($params)['hits']['hits'];
     // Most saleable
     $params = ['index' => 'mhdev_' . $lang, 'type' => 'products', 'body' => ['size' => 6, 'sort' => ['rating' => ['order' => 'desc']]]];
     $this->view->most_saleable = $this->elasticsearch->search($params)['hits']['hits'];
     $this->view->productId = "/" . $product_id;
     // Discount rate
     $this->view->discount = isset($product->productdiscount) ? $product->productdiscount : null;
     // URL of the page
     $this->view->current_url = $current_url = $this->request->getScheme() . '://' . $this->request->getHttpHost() . $this->request->getURI();
     // Shortened URL (goo.gl)
     $this->view->short_url = $this->prodInfoService->shortUrl($current_url);
     // Product title in respective language
     $this->view->prod_title = $product->getsingleInfo("lang='{$lang}'")->title;
     // Product availability (hold=1)
     $this->view->is_available = $product->hold == 1;
     //---------------------------------------------------------
     $router = $this->di['router'];
     $router->handle();
     //        var_dump($router->getMatchedRoute()->getpaths());
     $routeName = $router->getMatchedRoute()->getname();
     //        $langsAct = PLangs::find(["act=1 AND alias != '{$lang}'", 'order' => 'id']);
     $catUrls = PProdInfo::find("product_id={$product_id} AND coder_status=5 AND lang != '{$lang}'");
     $langsUrls = [];
     foreach ($catUrls as $l) {
         $langsUrls[$l->lang] = $this->url->get(array('for' => $routeName, 'lang' => $l->lang, 'product_id' => $product_id, 'params' => $l->url . '.html'));
     }
     $this->view->langs = $langsUrls;
     //---------------------------------------------------------
 }
Example #3
0
 /**
  * Table of moderated products grouped by languages and statuses
  */
 public function moderatedAction()
 {
     $stats['done'] = PProdInfo::count(["coder_status = 5", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['done_hold'] = PStats::count(["coder_status = 5 AND hold = 1", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['inmoder'] = PProdInfo::count(["coder_status = 3", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['inmoder_hold'] = PStats::count(["coder_status = 3 AND hold = 1", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['returned'] = PProdInfo::count(["coder_status = 6", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['returned_hold'] = PStats::count(["coder_status = 6 AND hold = 1", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['todo_hold'] = PStats::count(["coder_status < 3 AND hold = 1", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['translator'] = PProdInfo::count(["coder_status = 1", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['translator_hold'] = PStats::count(["coder_status = 1 AND hold = 1", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['hold_total'] = PStats::count(["hold = 1", 'group' => 'lang', 'order' => 'id'])->toArray();
     $stats['langs'] = PProdInfo::count(['group' => 'lang', 'order' => 'id'])->toArray();
     $this->view->total_ru = PStats::count("coder_status = 5 AND lang = 'ru'");
     $this->view->total = PProductMain::count();
     $this->view->total_hold = PProductMain::count("hold=1");
     $this->view->total_hold_photocoder = PProductMain::count("hold=1 AND status<4");
     $this->view->stats = $stats;
     $this->view->current_date = date('H:i:s d.m.Y');
 }
 public function listoflangsAction()
 {
     $this->view->disable();
     // List of all available languages for categories
     //        $langs = PCategory::count(['group' => 'lang', 'order' => 'id']);
     $langs = PProdInfo::count(['group' => 'lang', 'order' => 'id']);
     foreach ($langs as $lang) {
         $listoflangs[] = $lang->lang;
     }
     //        var_dump($listoflangs);
     echo json_encode($listoflangs, JSON_FORCE_OBJECT);
 }
Example #5
0
    public function moderAction()
    {
        $stats = [];
        $stats['done'] = PProdInfo::count(["coder_status = 5", 'group' => 'lang', 'order' => 'id']);
        $stats['done_hold'] = PStats::count(["coder_status = 5 AND hold = 1", 'group' => 'lang', 'order' => 'id']);
        $stats['inmoder'] = PProdInfo::count(["coder_status = 3", 'group' => 'lang', 'order' => 'id']);
        $stats['inmoder_hold'] = PStats::count(["coder_status = 3 AND hold = 1", 'group' => 'lang', 'order' => 'id']);
        $stats['returned'] = PProdInfo::count(["coder_status = 6", 'group' => 'lang', 'order' => 'id']);
        $stats['returned_hold'] = PStats::count(["coder_status = 6 AND hold = 1", 'group' => 'lang', 'order' => 'id']);
        $stats['todo_hold'] = PStats::count(["coder_status < 3 AND hold = 1", 'group' => 'lang', 'order' => 'id']);
        $stats['hold_total'] = PStats::count(["hold = 1", 'group' => 'lang', 'order' => 'id']);
        $langs = PProdInfo::count(['group' => 'lang', 'order' => 'id']);
        $total_ru = PStats::count("coder_status = 5 AND lang = 'ru'");
        $total = PProductMain::count();
        $date = date('d.m.Y');
        $titles = ["Сделано (5) (из них на холде)", "На модерации (3) (из них на холде)", "Возвращено (6) (из них на холде)", "Не обработано еще (0) (из них на холде)", "Замороженые товары (hold), всего"];
        $stat_titles = ["done", "inmoder", "returned"];
        $text = <<<TEXT
<p style="margin-bottom: 20px">Всего товаров: <span id="total">{$total}</span></p>
<p style="margin-bottom: 20px">Отчет на {$date}</p>
<table border='1'>
<tr>
<th></th>
TEXT;
        foreach ($langs as $lang => $stat) {
            $text .= "<th width='110px'>{$stat['lang']}</th>";
        }
        $text .= "</tr>";
        for ($i = 0; $i < 3; $i++) {
            $text .= "<tr><td>{$titles[$i]}</td>";
            foreach ($langs as $lang => $stat) {
                $text .= "<td>";
                foreach ($stats[$stat_titles[$i]] as $lang_total => $stat_total) {
                    if ($stat_total['lang'] == $stat['lang']) {
                        $text .= $stat_total['rowcount'] . " ";
                        foreach ($stats[$stat_titles[$i] . '_hold'] as $lang_hold => $stat_hold) {
                            if ($stat_hold['lang'] == $stat['lang']) {
                                $text .= "({$stat_hold['rowcount']})";
                            }
                        }
                    }
                }
                $text .= "</td>";
            }
            $text .= "</tr>";
        }
        $text .= "<tr><td>{$titles[3]}</td>";
        foreach ($langs as $lang => $stat) {
            $text .= "<td>";
            if ($stat['lang'] == 'ru') {
                $text .= $total - $stat['rowcount'];
            } else {
                $text .= $total_ru - $stat['rowcount'];
            }
            foreach ($stats['todo_hold'] as $lang_hold => $stat_hold) {
                if ($stat_hold['lang'] == $stat['lang']) {
                    $text .= "({$stat_hold['rowcount']})";
                }
            }
            $text .= "</td>";
        }
        $text .= "</tr>";
        $text .= "<tr><td>{$titles[4]}</td>";
        foreach ($langs as $lang => $stat) {
            $text .= "<td>";
            foreach ($stats['hold_total'] as $lang_hold => $stat_hold) {
                if ($stat_hold['lang'] == $stat['lang']) {
                    $text .= "{$stat_hold['rowcount']}";
                }
            }
            $text .= "</td>";
        }
        $text .= "</tr></table>";
        $text .= <<<TEXT
<br><br><b>Описание</b>
<p>Сделано (5) - товары со статусом перевода на данный язык == 5 ( в случае с RU статус копирайта == 5)</p>
<p>На модерации (3) - товары со статусом перевода на данный язык == 3 ( в случае с RU статус копирайта == 3)</p>
<p>Возвращено (6) - товары со статусом перевода на данный язык == 6 ( в случае с RU статус копирайта == 6)</p>
<p>Не обработано еще (0) - товары со статусом перевода на данный язык == 0 ( в случае с RU статус копирайта == 0)</p>
<p>Замороженые товары (hold) - товары со статусом hold == Да</p>
TEXT;
        $message[] = ['To' => '*****@*****.**', 'From' => POSTMARK_FROM, 'Subject' => "Количество отмодерированных товаров. Отчет за {$date}", 'HtmlBody' => $text];
        $client = new PostmarkClient(POSTMARK_API);
        //        var_dump($message);
        $send = $client->sendEmailBatch($message);
    }