/**
  * @Get("/{catalog_id:[0-9]+}", name="show-catalog")
  */
 public function indexAction()
 {
     $catalog_id = $this->filter->sanitize($this->dispatcher->getParam('catalog_id'), 'int');
     //        $lang = $this->filter->sanitize($this->dispatcher->getParam("lang"), 'string');
     // If catalog is not found
     if ($catalog_id == null or !($catalog = PAdvCampaigns::findFirst($catalog_id))) {
         return $this->response->redirect('/');
     }
     // All products for the campaign
     $products = PAdvProducts::find("campaign_id={$catalog_id}")->toArray();
     $params = ['index' => 'mhdev_' . $this->lang, 'type' => 'products', 'body' => ['ids' => array_column($products, 'product_id')]];
     $result = $this->elasticsearch->mget($params);
     if (!isset($this->persistent->pagination)) {
         $this->persistent->pagination = ['page' => 1, 'limit' => 40];
     }
     $paginator = new ArrayPaginator(["data" => $result['docs'], "limit" => $this->persistent->pagination['limit'], "page" => $this->persistent->pagination['page']]);
     //        var_dump($this->persistent->pagination);
     $this->view->page = $paginator->getPaginate();
     // Show items per page number
     $this->view->pagination_limit = $this->persistent->pagination['limit'];
     $this->view->catalog = $catalog;
     $currency = $catalog->currencyCode;
     // Get currency info for catalog currency
     $this->view->currency = $this->currenciesService->getCurrencyInfo($currency);
 }
 public function pageByData($data, $currentPage = 1, $limit = self::LIMIT_ITEM)
 {
     if (empty($limit)) {
         $limit = self::LIMIT_ITEM;
     }
     $paginator = new PaginatorArray(array("data" => $data, "limit" => $limit, "page" => $currentPage));
     return $paginator->getPaginate();
 }
Example #3
0
 public function searchAction()
 {
     $response = new \Phalcon\Http\Response();
     $currentPage = (int) $this->request->getPost("page");
     $searchList = Git::searchRepositores($this->request->getPost("query"));
     $paginator = new PaginatorArray(array("data" => $searchList, "limit" => 5, "page" => $currentPage));
     $this->page = $paginator->getPaginate();
     $this->simpleView->setVar("searchList", $this->page);
     $body = $this->simpleView->render('main/search');
     return $response->setContent($body);
 }
Example #4
0
 /**
  * Index action - display all payments
  *
  * @package     las
  * @version     1.0
  */
 public function indexAction()
 {
     $this->tag->setTitle(__('Payments'));
     // Available sort to choose
     $this->filter->add('in_array', function ($value) {
         return in_array($value, ['client', 'client DESC', 'date', 'date DESC', 'description', 'description DESC', 'amount', 'amount DESC', 'status', 'status DESC']) ? $value : null;
     });
     // Check if limit to client's payments
     if ($client = $this->request->getQuery('client', 'int', null, true)) {
         $data = $this->db->fetchAll('SELECT *, (SELECT fullName FROM clients WHERE clients.id = payments.client_id) AS client FROM payments WHERE client_id = :client ORDER BY ' . $this->request->getQuery('order', 'in_array', 'id', true), \Phalcon\Db::FETCH_OBJ, ['client' => $client]);
     } else {
         $data = $this->db->fetchAll('SELECT *, (SELECT fullName FROM clients WHERE clients.id = payments.client_id) AS client FROM payments ORDER BY ' . $this->request->getQuery('order', 'in_array', 'id', true), \Phalcon\Db::FETCH_OBJ);
     }
     // Get payments, client and prepare pagination
     $paginator = new Paginator(["data" => $data, "limit" => $this->request->getQuery('limit', 'int', 20, true), "page" => $this->request->getQuery('page', 'int', 1, true)]);
     $this->view->setVars(['pagination' => $paginator->getPaginate()]);
 }
Example #5
0
 /**
  * Index action - display all clients
  *
  * @package     las
  * @version     1.0
  */
 public function indexAction()
 {
     $this->tag->setTitle(__('Clients'));
     // Available sort to choose
     $this->filter->add('in_array', function ($value) {
         return in_array($value, ['address', 'address DESC', 'balance', 'balance DESC', 'fullName', 'fullName DESC', 'status', 'status DESC']) ? $value : null;
     });
     // Check if limit to client's status
     $status = $this->request->getQuery('status', 'int', null, true);
     if ($status !== null) {
         $data = $this->db->fetchAll('SELECT *, (SELECT sum(amount) FROM payments WHERE payments.client_id = clients.id AND payments.status = ' . Payments::SUCCESS . ') AS balance FROM clients WHERE status=:status ORDER BY ' . $this->request->getQuery('order', 'in_array', 'id', true), \Phalcon\Db::FETCH_OBJ, ['status' => $status]);
     } else {
         $data = $this->db->fetchAll('SELECT *, (SELECT sum(amount) FROM payments WHERE payments.client_id = clients.id AND payments.status = ' . Payments::SUCCESS . ') AS balance FROM clients ORDER BY ' . $this->request->getQuery('order', 'in_array', 'id', true), \Phalcon\Db::FETCH_OBJ);
     }
     // Get clients, their balance and prepare pagination
     $paginator = new Paginator(["data" => $data, "limit" => $this->request->getQuery('limit', 'int', 20, true), "page" => $this->request->getQuery('page', 'int', 1, true)]);
     $this->view->setVars(['pagination' => $paginator->getPaginate()]);
 }
Example #6
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)");
 }
 /**
  * parseGridSubmit function.
  *
  * @access public
  * @return mixed
  */
 protected function renderGrid($class)
 {
     $filterKey = $this->router->getControllerName();
     $conditions = [];
     $this->gridFilters = $this->getGridFilters();
     if (!empty($this->gridFilters[$filterKey]['conditions'])) {
         $conditions = $this->gridFilters[$filterKey]['conditions'];
     }
     /*
     if (isset($conditions['having']) && $conditions['having'] == 1) {
         unset($conditions['having']);
     }
     */
     $builder = $this->modelsManager->createBuilder($conditions);
     $builder->from(['a' => $class]);
     if (!empty(self::$grid['query'])) {
         if (!empty(self::$grid['query']['columns'])) {
             $builder->columns(self::$grid['query']['columns']);
         }
         foreach (self::$grid['query']['joins'] as $join) {
             if (in_array($join['type'], ['innerJoin', 'leftJoin', 'rightJoin', 'join'])) {
                 $builder->{$join}['type']($join['model'], $join['on'], $join['alias']);
             }
         }
         if (!empty(self::$grid['query']['groupBy'])) {
             $builder->groupBy(self::$grid['query']['groupBy']);
         }
     }
     if (!empty($this->gridFilters[$filterKey]['order'])) {
         $builder->orderBy($this->gridFilters[$filterKey]['order']);
     }
     $collections = $builder->getQuery()->execute()->toArray();
     if (!count($collections)) {
         if (!$this->request->isAjax()) {
             $this->flashSession->notice(t("The search did not match any collection."));
         } else {
             /*
             $this->setJsonResponse();
             $this->jsonMessages['messages'][] = ['type'    => 'notice',
                                                  'content' => t('The search did not match any collection.')
             ];
             */
             //return $this->jsonMessages;
         }
     }
     $this->assets->addCss('backend/js/chosen/chosen.css');
     $this->assets->addJs('backend/js/datatables/jquery.dataTables.min.js');
     $paginator = new Paginator(['data' => $collections, 'limit' => empty($this->gridFilters[$filterKey]['perPage']) ? $this->perPage : $this->gridFilters[$filterKey]['perPage'], 'page' => empty($this->gridFilters[$filterKey]['page']) ? $this->numberPage : $this->gridFilters[$filterKey]['page']]);
     // Passing variables to view
     $this->view->setVars(['paginator' => $paginator->getPaginate(), 'filters' => !empty($this->gridFilters[$filterKey]['post']) ? $this->gridFilters[$filterKey]['post'] : [], 'perPage' => empty($this->gridFilters[$filterKey]['perPage']) ? $this->perPage : $this->gridFilters[$filterKey]['perPage'], 'params' => static::$grid]);
 }
Example #8
0
 /**
  * Get pagination from array
  *
  * @param array $arrayRow
  * @param int $paginationLimit
  * @param int $currentPage
  * @return \stdClass
  */
 public static function getPaginationNativeArray($arrayRow, $paginationLimit, $currentPage)
 {
     $pagination = new PaginationNativeArray(['data' => $arrayRow, 'limit' => self::checkInt($paginationLimit), 'page' => self::checkInt($currentPage)]);
     return $pagination->getPaginate();
 }
Example #9
0
 /**
  * @param $name
  *
  * @return string
  */
 public function __get($name)
 {
     return $this->translate->_($name);
 }
Example #10
0
 public function verOrdenesAction($planillaId)
 {
     parent::importarJsSearch();
     $numberPage = 1;
     $orden = Orden::findByOrden_planillaId($planillaId);
     if (count($orden) == 0) {
         $this->flash->notice("La planilla seleccionada no contiene ordenes cargadas.");
         return $this->dispatcher->forward(array("controller" => "planilla", "action" => "search"));
     }
     $tabla = $this->generarTablaDeOrdenes($orden);
     $paginator = new Paginator(array("data" => $tabla, "limit" => 100000, "page" => $numberPage));
     $this->view->page = $paginator->getPaginate();
     $planilla = Planilla::findFirstByPlanilla_id($planillaId);
     if ($planilla) {
         $this->view->planilla = $planilla;
     }
     $this->view->pick('orden/search');
 }
 public function set_grid_files($mode, $file_type, $file_names)
 {
     $grid_params = array();
     $no_items = "";
     $numberPage = 1;
     if ($this->request->isGet()) {
         $numberPage = $this->request->getQuery("page", "int");
     }
     //Set search columns
     $search_columns = array(array('name' => 'name', 'title' => 'File Name', 'size' => 30, 'div_class' => "input-control full-size", 'label_class' => 'search'), array('name' => 'type', 'title' => 'Type', 'size' => 30, 'div_class' => "input-control full-size", 'label_class' => 'search'), array('name' => 'size', 'title' => 'Size', 'size' => 30, 'div_class' => "input-control full-size", 'label_class' => 'search'));
     //Set grid Paginator
     $paginator = new PaginatorArray(array("data" => $file_names, "limit" => 10, "page" => $numberPage));
     if (count($file_names) == 0) {
         $no_items = "files.list.no_data";
     }
     switch ($mode) {
         case 'list':
             $listroute = 'file/list/' . $file_type;
             break;
         case 'search':
             $listroute = 'file/search/' . $file_type;
             break;
     }
     switch ($file_type) {
         case 'image':
             $title = 'Images';
             break;
         case 'video':
             $title = 'Videos';
             break;
         case 'document':
             $title = 'Documents';
             break;
         case 'other':
             $title = 'Other Files';
             break;
     }
     $this->get_modal_assets();
     $this->view->noitems = $no_items;
     $this->view->searchroute = 'file/search/' . $file_type;
     $this->view->file_names = $file_names;
     $this->view->searchcolumns = $search_columns;
     $this->view->showroute = 'file/show/';
     $this->view->title = $title;
     $this->view->listroute = $listroute;
     $this->view->page = $paginator->getPaginate();
     $this->view->download_path = $this->file_params['download_files_path'];
     $this->view->pick('files/filelist');
 }
Example #12
0
 /**
  * Paginate results
  *
  * @access public
  * @return array
  *
  * @author Christian Esperar <*****@*****.**>
  */
 public function paginate($list, $currentPage, $limit = 10)
 {
     //Passing an array as data
     $paginator = new NativeArray(array("data" => $list, "limit" => $limit, "page" => $currentPage));
     // Return the paginated results
     return $paginator->getPaginate();
 }
Example #13
0
 public function getPaginate()
 {
     return parent::getPaginate();
 }