/** * Méthode permettant de lister toutes les entrées du model * Gestion automatique du ORDER BY * @param String $pCondition Condition souhaitée pour la requête SQL * @return void */ public function listing($pCondition = null) { if (!$this->actions->isEnabled("listing")) { Go::to404(); } $this->setTitle($this->titles->get('listing')); $this->setTemplate("default", "listing"); $this->addContent("titles", $this->listTitle); $this->addContent("id", $this->model->id); if (!$pCondition) { $pCondition = Query::condition(); } $pConditionCount = clone $pCondition; for ($i = 0, $max = count($this->listTitle); $i < $max; $i++) { if (isset($_GET["order"]) && in_array($_GET["order"], $this->listTitle[$i])) { $pCondition->order($_GET["order"], isset($_GET["by"]) ? $_GET["by"] : "ASC"); $i = $max; } } if ($this->usePaginationOnList) { $nbDatas = $this->model->count($pConditionCount); $currentPage = isset($_GET["page"]) ? $_GET["page"] : 1; $pagination = new PaginationHandler($currentPage, $this->nbItemsByPage, $nbDatas); $pCondition->limit($pagination->first, $pagination->number); $data = $this->model->all($pCondition); $this->addContent("paginationInfo", $pagination->getPaginationInfo()); } else { $data = $this->model->all($pCondition); } $this->addContent("liste", $data); $this->addContent("h1", $this->h1->get('listing')); }
public function all($pCond = null, $pFields = "*") { $all = parent::all($pCond, $pFields); foreach ($all as &$post) { $post['categories'] = Query::select('b.*', 'post_category a')->join('main_category b', Query::JOIN_INNER, 'a.id_category=b.id_category')->andWhere('a.id_post', Query::EQUAL, $post['id_post'])->execute(); } return $all; }