public function indexAction() { $type = $this->dispatcher->getParam('type', 'string'); $typeModel = Type::getCachedBySlug($type); if (!$typeModel) { throw new Exception("Publication hasn't type = '{$type}''"); } $typeLimit = $typeModel->getLimit() ? $typeModel->getLimit() : 10; $limit = $this->request->getQuery('limit', 'string', $typeLimit); if ($limit != 'all') { $paginatorLimit = (int) $limit; } else { $paginatorLimit = 9999; } $page = $this->request->getQuery('page', 'int', 1); /*$publications = Publication::find(array( "type_id = {$typeModel->getId()}", "order" => "date DESC", ));*/ $publicationHelper = new PublicationHelper(); $fields = $publicationHelper->translateFieldsSubQuery(); $columns = ['p.*', 't_slug' => 't.slug']; $columns = array_merge($columns, $fields); $qb = $this->modelsManager->createBuilder()->columns($columns)->addFrom('Publication\\Model\\Publication', 'p')->leftJoin('Publication\\Model\\Type', null, 't')->andWhere('t.slug = :type:', ['type' => $type])->andWhere('p.date <= NOW()')->orderBy('p.date DESC'); $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(["builder" => $qb, "limit" => $paginatorLimit, "page" => $page]); $this->view->paginate = $paginator->getPaginate(); $this->helper->title()->append($typeModel->getHeadTitle()); if ($page > 1) { $this->helper->title()->append($this->helper->translate('Страница №') . ' ' . $page); } $this->view->title = $typeModel->getTitle(); $this->view->format = $typeModel->getFormat(); $this->view->type = $type; $this->helper->menu->setActive($type); }
public function datareturn($builder) { $this->response->setHeader("Content-Type", "application/json; charset=utf-8"); $limit = $this->request->getQuery('rows', 'int'); $page = $this->request->getQuery('page', 'int'); if (empty($builder)) { return; } else { if (is_null($limit)) { $limit = 10; } if (is_null($page)) { $page = 1; } $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => $limit, "page" => $page)); $page = $paginator->getPaginate(); $ans = array(); $ans['total'] = $page->total_pages; $ans['page'] = $page->current; $ans['records'] = $page->total_items; foreach ($page->items as $key => $item) { if (isset($item->sex)) { $item->sex = $item->sex == 1 ? '男' : '女'; } $ans['rows'][$key] = $item; } echo json_encode($ans); } $this->view->disable(); }
public function indexAction() { $currentPage = $this->request->getQuery('page', null, 1); $builder = $this->modelsManager->createBuilder()->from('Visitcategory')->where("idAccount = {$this->user->idAccount}")->orderBy('Visitcategory.created'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 15, "page" => $currentPage)); $page = $paginator->getPaginate(); $this->view->setVar("page", $page); }
public function indexAction() { $currentPage = $this->request->getQuery('page', null, 1); // GET $builder = $this->modelsManager->createBuilder()->from('Ciuu')->orderBy('created'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 30, "page" => $currentPage)); $page = $paginator->getPaginate(); $this->view->setVar("page", $page); }
public function indexAction() { if ($this->request->hasPost('od') && $this->request->getPost('od') == 'y') { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); } $zap = ''; if ($this->request->hasPost('cat_id') && $this->request->isAjax()) { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $cat_id = $this->request->getPost('cat_id'); if (isset($cat_id) && is_numeric($cat_id)) { if ($this->request->hasPost('sub-cat')) { $zap = "id = {$cat_id}"; $c_cat = 1; } else { $zap = "id = {$cat_id} or id_sub = {$cat_id}"; $c_cat = 1; } foreach (Categories::find(array("{$zap}")) as $csv) { $c_cat = $c_cat + $csv->proposal->count(); } if ($c_cat == 1) { $this->view->disable(); echo 1; die; } } } ///////////////// Пагинация if (!empty($_POST['page'])) { $currentPage = $_POST["page"]; } else { $currentPage = 1; } // Chat::find(array('order' => 'creation_date DESC')) if (empty($zap)) { $zaps = ''; } else { $query = $this->modelsManager->createQuery("SELECT id FROM Categories WHERE " . $zap)->execute()->toArray(); foreach ($query as $f) { $cats_id[] = $f['id']; } // $this->elements->var_print($cats_id); $sre = implode(" ,", $cats_id); $zaps = " category_id IN ({$sre})"; // echo $zaps; } $bield = $this->modelsManager->createBuilder()->from('Proposal')->where($zaps)->orderBy('creation_date DESC'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $bield, "limit" => 10, "page" => $currentPage)); $page = $paginator->getPaginate(); foreach ($page->items as $prop) { foreach ($prop->dannproposal as $dann) { $props[$prop->id][$dann->fieldtype->id] = $dann->dann; $props[$prop->id]['cat'] = $prop->categories->name; } } $this->view->setVars(array('cl' => count($page->items), 'prop' => $props = isset($props) ? $props : false, 'page_num' => $page->current, 'page_total' => $page->total_pages)); }
public function indexAction() { $account = $this->user->account; $currentPage = $this->request->getQuery('page', null, 1); // GET $builder = $this->modelsManager->createBuilder()->from('User')->join('Role', 'User.idRole = Role.idRole')->where("User.idAccount = {$account->idAccount}")->orderBy('User.created'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 20, "page" => $currentPage)); $page = $paginator->getPaginate(); $this->view->setVar("page", $page); }
public function indexAction() { $currentPage = $this->request->getQuery('page', null, 1); // GET $builder = $this->modelsManager->createBuilder()->from('Paymentplan')->leftJoin('Pxr', 'Paymentplan.idPaymentplan = Pxr.idPaymentplan')->groupBy('Paymentplan.idPaymentplan')->orderBy('Paymentplan.created'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 30, "page" => $currentPage)); $page = $paginator->getPaginate(); $reports = Report::find(); $this->view->setVar("page", $page); $this->view->setVar("reports", $reports); }
/** * @param int $currentPage * @param int $limit */ public function queryBuilderAction($currentPage = 10, $limit = 10) { $startMemoryUsage = memory_get_peak_usage(); $startTime = microtime(true); $currentPage = max(1, (int) $currentPage); $limit = max(1, (int) $limit); $modelsManager = $this->di->getShared('modelsManager'); $builder = $modelsManager->createBuilder()->from('\\Models\\User'); $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(["builder" => $builder, "limit" => $limit, "page" => $currentPage]); $paginator->getPaginate(); $finishTime = microtime(true); $finishMemoryUsage = memory_get_peak_usage(); echo "Memory peak usage: "; echo $finishMemoryUsage - $startMemoryUsage . "\n"; echo "Time: "; echo $finishTime - $startTime . "\n"; }
public static function getTasks($page, $perpage = 10, $sort = null) { $sortFields = ['exec_time' => 'task.exec_time', 'id' => 'task.id']; $sortValue = ['up' => 'ASC', 'down' => 'DESC']; $o = new self(); $builder = $o->modelsManager->createBuilder()->columns(['task.*'])->from(['task' => '\\ReactQue\\TimerModel']); if ($sort) { $sortArr = []; foreach ($sort as $k => $v) { if (array_key_exists($k, $sortFields) && array_key_exists($v, $sortValue)) { $sortArr[] = $sortFields[$k] . ' ' . $sortValue[$v]; } } if ($sortArr) { $builder->orderBy($sortArr); } } $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => $perpage, "page" => $page)); return $paginator->getPaginate(); }
/** * Setup paginator. * * @param \Engine\Mvc\Model\Query\Builder $queryBuilder * @return \ArrayObject */ protected function _getPaginator(\Engine\Mvc\Model\Query\Builder $queryBuilder, $limit, $page) { $paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(['builder' => $queryBuilder, 'limit' => $limit, 'page' => $page]); return $paginator->getPaginate(); }
protected function getPaginationWithQueryBuilder($builder, $page) { $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => self::DEFAULT_LIMIT, "page" => $page)); return $paginator->getPaginate(); }
public function t1estQueryBuilderPaginator() { $di = $this->_loadDI(); $builder = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->orderBy('cedula')->limit(500, 0); //var_dump($builder->getPhql()); return; $builder = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->orderBy('cedula'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 1); $this->assertEquals($page->next, 2); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 1); $this->assertEquals($page->total_pages, 218); //Middle page $paginator->setCurrentPage(100); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 99); $this->assertEquals($page->next, 101); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 100); $this->assertEquals($page->total_pages, 218); //Last page $paginator->setCurrentPage(218); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 217); $this->assertEquals($page->next, 218); $this->assertEquals($page->last, 218); $this->assertEquals($page->current, 218); $this->assertEquals($page->total_pages, 218); }
public function associerContexteEditAction($param) { $numberPage = 1; if (strpos($param, "&") > 0) { //Ok, Ok, c'est pas joli... il faudra parser. $numberPage = substr($param, strpos($param, "&page=") + 6); $param = substr($param, 0, strpos($param, "&")); } if ($this->startsWith($param, "contexte_id")) { $contexte_id = intval(substr($param, strrpos($param, "=") + 1)); // Sauvegarde du formulaire $act_id = $id = 0; $nouvelleValeur = FALSE; // $a_creer = TRUE; // L'instance de couche contexte doit être créée foreach ($_POST as $attribut_id => $valeur) { if ($this->endsWith($attribut_id, "_")) { $couche_contexte_id = 0; } else { $couche_contexte_id = intval(substr($attribut_id, strrpos($attribut_id, "_") + 1)); } $attribut_id = substr($attribut_id, 0, strrpos($attribut_id, "_")); $id = intval(substr($attribut_id, strrpos($attribut_id, "_") + 1)); $attribut = substr($attribut_id, 0, strrpos($attribut_id, "_")); /* var_dump($contexte_id); var_dump($id); var_dump($attribut_id); var_dump($attribut); var_dump($valeur); */ if ($id > 0) { //C'est un attribut if ($act_id != $id) { //une autre ligne if ($act_id != 0 && $nouvelleValeur) { $igoCouchecontexte->save(); if (!($igoCouchecontexte->est_visible || $igoCouchecontexte->est_active)) { $igoCouchecontexte->delete(); } } $nouvelleValeur = FALSE; $a_creer = TRUE; } if ($a_creer) { if ($couche_contexte_id == 0) { $igoCouchecontexte = new IgoCoucheContexte(); //$igoCouche=IgoCouche::findFirst("id=" . $id); $igoCouchecontexte->contexte_id = $contexte_id; $igoCouchecontexte->groupe_id = $id; } else { $igoCouchecontexte = IgoCoucheContexte::findFirst("id=" . $couche_contexte_id); } $nouvelleValeur = $igoCouchecontexte->est_visible || $igoCouchecontexte->est_active; $igoCouchecontexte->est_visible = FALSE; $igoCouchecontexte->est_active = FALSE; $a_creer = FALSE; } if (isset($valeur) && $valeur != 0 && trim($valeur) != "" && !is_null($valeur) && $valeur != FALSE) { $nouvelleValeur = TRUE; } $act_id = $id; $igoCouchecontexte->{$attribut} = $valeur; } } if ($act_id != 0 && $nouvelleValeur) { $igoCouchecontexte->save(); if (!($igoCouchecontexte->est_visible || $igoCouchecontexte->est_active)) { $igoCouchecontexte->delete(); } } $this->flash->notice("Changements sauvegardés"); //Requête $phql = $this->modelsManager->createBuilder()->columns("IgoCoucheContexte.id as id," . "IgoGroupe.id as groupe_id," . "nom," . "IgoGroupe.description," . "ind_fond_de_carte," . "est_visible," . "est_active")->from('IgoGroupe')->leftjoin('IgoCoucheContexte')->where("IgoCoucheContexte." . $param . " OR IgoCoucheContexte.contexte_id IS NULL")->orderBy('contexte_id'); } $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $phql, "limit" => 10, "page" => $numberPage)); $this->view->page = $paginator->getPaginate(); }
public function testQueryBuilderPaginatorGroupBy() { require 'unit-tests/config.db.php'; if (empty($configMysql)) { $this->markTestSkipped('Test skipped'); return; } $di = $this->_loadDI(); $builder = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->orderBy('cedula')->groupBy(['email']); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 1); $this->assertEquals($page->next, 2); $this->assertEquals($page->last, 18); $this->assertEquals($page->limit, 10); $this->assertEquals($page->current, 1); $this->assertEquals($page->total_items, 178); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); //Middle page $paginator->setCurrentPage(10); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 9); $this->assertEquals($page->next, 11); $this->assertEquals($page->last, 18); $this->assertEquals($page->current, 10); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); //Last page $paginator->setCurrentPage(18); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 9); $this->assertEquals($page->before, 17); $this->assertEquals($page->next, 18); $this->assertEquals($page->last, 18); $this->assertEquals($page->current, 18); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); // test of getter/setters of querybuilder adapter // -- current page -- $currentPage = $paginator->getCurrentPage(); $this->assertEquals($currentPage, 18); // -- limit -- $rowsLimit = $paginator->getLimit(); $this->assertEquals($rowsLimit, 10); $setterResult = $paginator->setLimit(25); $rowsLimit = $paginator->getLimit(); $this->assertEquals($rowsLimit, 25); $this->assertEquals($setterResult, $paginator); // -- builder -- $queryBuilder = $paginator->getQueryBuilder(); $this->assertEquals($builder, $queryBuilder); $builder2 = $di['modelsManager']->createBuilder()->columns('cedula, nombres')->from('Personnes')->groupBy(['email']); $setterResult = $paginator->setQueryBuilder($builder2); $queryBuilder = $paginator->getQueryBuilder(); $this->assertEquals($builder2, $queryBuilder); $this->assertEquals($setterResult, $paginator); }
protected function getPaginatorByQueryBuilder($builder, $limit, $page) { $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(['builder' => $builder, 'limit' => $limit, 'page' => $page]); return $this->cyclingPage($paginator->getPaginate()); }
public function showusersAction($id) { $account = Account::findFirst(array('conditions' => 'idAccount = ?1', 'bind' => array(1 => $id))); if (!$account) { $this->flashSession->warning("No existe la cuenta, por favor valide la información"); return $this->response->redirect("account"); } $currentPage = $this->request->getQuery('page', null, 1); // GET $builder = $this->modelsManager->createBuilder()->from('User')->join('Role', 'User.idRole = Role.idRole')->where("User.idAccount = {$account->idAccount}")->orderBy('User.created'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 30, "page" => $currentPage)); $page = $paginator->getPaginate(); $this->view->setVar("page", $page); $this->view->setVar('account', $account); }
public function testIssue2739() { require 'unit-tests/config.db.php'; if (empty($configMysql)) { $this->markTestSkipped('Test skipped'); return; } $di = $this->_loadDI(); $builder = $di['modelsManager']->createBuilder()->columns('Robots.name')->from('Robots')->join('RobotsParts', 'Robots.id = p.robots_id', 'p'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); }
private function _paginatorBuilderTest($builder) { $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $builder, "limit" => 10, "page" => 1)); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 1); $this->assertEquals($page->next, 2); $this->assertEquals($page->last, 18); $this->assertEquals($page->limit, 10); $this->assertEquals($page->current, 1); $this->assertEquals($page->total_items, 178); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); //Middle page $paginator->setCurrentPage(10); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 10); $this->assertEquals($page->before, 9); $this->assertEquals($page->next, 11); $this->assertEquals($page->last, 18); $this->assertEquals($page->current, 10); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); //Last page $paginator->setCurrentPage(18); $page = $paginator->getPaginate(); $this->assertEquals(get_class($page), 'stdClass'); $this->assertEquals(count($page->items), 9); $this->assertEquals($page->before, 17); $this->assertEquals($page->next, 18); $this->assertEquals($page->last, 18); $this->assertEquals($page->current, 18); $this->assertEquals($page->total_pages, 18); $this->assertInternalType('int', $page->total_items); $this->assertInternalType('int', $page->total_pages); }
public function indexAction() { if ($this->request->hasPost('up')) { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); } if ($this->request->hasPost('cat_id') && $this->request->isAjax()) { $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $cat_id = $this->request->getPost('cat_id'); } if (!empty($_POST['page'])) { $currentPage = $_POST["page"]; } else { $currentPage = 1; } if ($this->modelsCache->exists('filter-' . $this->session->get('user_id'))) { $filter = $this->modelsCache->get('filter-' . $this->session->get('user_id')); //$this->elements->var_print($filter); $aOff = $aDann = $aUser = $aTabs = array(); // Следующая строка будет добавляться, видимо, всегда -- мы всегда будем искать в конкретной категории $aOff[] = "o.category_id = {$filter['cat_id']}"; $rq_type = 0; $rq_type += isset($filter['price-from']) && is_numeric($filter['price-from']) && $filter['price-from'] >= 0 ? 1 : 0; $rq_type += isset($filter['price-to']) && is_numeric($filter['price-to']) && $filter['price-to'] >= 0 ? 2 : 0; $price_id = 5; switch ($rq_type) { case 0: // Ничего не добавляет, пусто break; case 1: $aDann[] = "do.field_type_id = {$price_id} and do.dann >= {$filter['price-from']}"; break; case 2: $aDann[] = "do.field_type_id = {$price_id} and do.dann <= {$filter['price-to']}"; break; case 3: $aDann[] = "do.field_type_id = {$price_id} and do.dann between {$filter['price-from']} and {$filter['price-to']}"; break; } // 4 как код города мы здесь задаём вручную -- потом это можно будет поменять, если нужно if (isset($filter['city']) && strlen(trim($filter['city'])) > 0) { $aDann[] = "do.field_type_id = 4 and do.dann like '%{$filter['city']}%'"; } // ICH -- все обработки полей вставляем здесь $aFromTo = array(); $rRes = $rRes1 = array(); foreach ($filter as $key => $val) { if (preg_match('/^(to|from)fiel-(\\d+)$/', $key, $rRes)) { $aFromTo[$rRes[2]][$rRes[1]] = $val; } elseif ($key == $val) { if (preg_match('/^fiel-(\\d+)$/', $key, $rRes1)) { $aDann[] = "do.field_type_id = {$rRes1[1]} and do.dann = 'y'"; } else { switch ($key) { case 'tel': $aUser[] = 'u.phone is not null'; break; case 'image': $aOff[] = 'o.image is not null'; break; case 'trof': break; default: // Какая-то непредусмотренная фигня break; } } // $rRes1[1] содержит интересующее нас число } } // $this->elements->var_print($aFromTo); foreach ($aFromTo as $key => $val) { $rq_type = 0; $rq_type += isset($filter["fromfiel-{$key}"]) && is_numeric($filter["fromfiel-{$key}"]) && $filter["fromfiel-{$key}"] >= 0 ? 1 : 0; $rq_type += isset($filter["tofiel-{$key}"]) && is_numeric($filter["tofiel-{$key}"]) && $filter["tofiel-{$key}"] >= 0 ? 2 : 0; switch ($rq_type) { case 0: // Ничего не добавляет, пусто break; case 1: $aDann[] = "do.field_type_id = {$key} and DannOffers.dann >= " . $filter["fromfiel-{$key}"]; break; case 2: $aDann[] = "do.field_type_id = {$key} and do.dann <= " . $filter["tofiel-{$key}"]; break; case 3: $aDann[] = "do.field_type_id = {$key} and do.dann between " . $filter["fromfiel-{$key}"] . ' and ' . $filter["tofiel-{$key}"]; break; } // switch } // foreach // Тут начинается сборка запроса на основании подготовленных массивов $nDann = count($aDann); $hasDann = $nDann > 0; $hasUser = count($aUser) > 0; $aTabs[] = 'Offers o'; if ($hasDann) { $aTabs[] = 'DannOffers do'; $aOff[] = 'o.id = do.offers_id'; $rqDann = $this->ic->fsis($aDann, NULL, '(%s)', "\n or ", "\n and (%s)"); } if ($hasUser) { $aTabs[] = 'User u'; $aOff[] = 'o.user_id = u.id'; } $rqFrom = implode(', ', $aTabs); //$rqDann = implode(' or ', $aDann); $rqSql = "select o.id from {$rqFrom}\n where "; $rqSql .= implode("\n and ", $aOff); if ($hasUser) { $rqSql .= "\n and " . implode(' and ', $aUser); } //$rqSql .= "\n and ($rqDann)\n"; if ($hasDann) { $rqSql .= $rqDann; } // Здесь мы пройдёмся по юзерсу if ($hasDann) { $rqSql .= "\ngroup by o.id\nhaving count(do.id) = {$nDann}"; } // limit можно добавить здесь, когда придёт время // $this->elements->var_print(nl2br($rqSql)); // $this->elements->var_print($rqSql); ////// Начало SQL запроса $query = $this->modelsManager->createQuery($rqSql)->execute()->toArray(); $a0 = array(); foreach ($query as $val) { $a0[] = $val['id']; } $inClause = count($a0) > 0 ? 'id in (' . implode(', ', $a0) . ')' : ''; ////// Конец SQL запроса дальше выборка. $paginator = new Phalcon\Paginator\Adapter\Model(array("data" => Offers::find(array("{$inClause}", 'order' => 'creation_date DESC')), "limit" => 10, "page" => $currentPage)); $page = $paginator->getPaginate(); foreach ($page->items as $offers) { if (isset($offers->image)) { $im = 1; } else { $im = 0; } $off[$offers->id]['name'] = array($offers->name, $im, $offers->status, $offers->user->phone, $offers->categories->name); foreach ($offers->dannoffers as $dan) { $off[$offers->id][$dan->fieldtype->id] = $dan->dann; } } if (strlen($inClause) == 0) { $this->flash->error("Ничего не найдено фильтр сброшен"); $this->modelsCache->delete('filter-' . $this->session->get('user_id')); } if ($currentPage <= 1) { $this->modelsCache->delete('filter-' . $this->session->get('user_id')); } } else { $zap = 0; if (isset($cat_id) && is_numeric($cat_id)) { if ($this->request->getPost('sub_cat') == 'y') { $zap = "id = {$cat_id}"; } else { $zap = "id = {$cat_id} or id_sub = {$cat_id}"; } $c_cat = 1; foreach (Categories::find(array("{$zap}")) as $csv) { $c_cat = $c_cat + $csv->offers->count(); } if ($c_cat == 1) { $this->view->disable(); echo 1; die; } } ///////////////////// Пагинация $this->cache->save('zap', $zap); if (empty($zap)) { $zaps = ''; } else { $query = $this->modelsManager->createQuery("SELECT id FROM Categories WHERE " . $zap)->execute()->toArray(); foreach ($query as $f) { $cats_id[] = $f['id']; } // $this->elements->var_print($hj); $sre = implode(" ,", $cats_id); $zaps = " category_id IN ({$sre})"; } $bield = $this->modelsManager->createBuilder()->from('Offers')->where($zaps)->orderBy('creation_date DESC'); $paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array("builder" => $bield, "limit" => 10, "page" => $currentPage)); $page = $paginator->getPaginate(); foreach ($page->items as $offers) { if (isset($offers->image)) { $im = 1; } else { $im = 0; } // Выдавать в таком виде результат $off[$offers->id]['name'] = array($offers->name, $im, $offers->status, $offers->user->phone, $offers->categories->name); foreach ($offers->dannoffers as $dan) { $off[$offers->id][$dan->fieldtype->id] = $dan->dann; } } } $this->view->setVars(array("off" => $off = isset($off) ? $off : false, 'page_num' => $page->current, 'page_total' => $page->total_pages)); }