public function searchAction() { $this->enableLayout(); $results = new Object\BlogArticle\Listing(); $results->setOrderKey("date"); $results->setOrder("DESC"); $q = $this->getParam("q"); $q = $q ? $q : "a"; $conditions = []; if ($q) { $conditions[] = "title LIKE " . $results->quote("%" . $q . "%"); $conditions[] = "intro LIKE " . $results->quote("%" . $q . "%"); $conditions[] = "content LIKE " . $results->quote("%" . $q . "%"); //$conditions[] = "tags LIKE " . $results->quote("%," . $q . ",%"); $conditions[] = "author LIKE " . $results->quote("%" . $q . "%"); $conditions[] = "authorTitle LIKE " . $results->quote("%" . $q . "%"); if (!empty($conditions)) { $results->setCondition(implode(" OR ", $conditions)); } $paginator = \Zend_Paginator::factory($results); $paginator->setCurrentPageNumber($this->getParam('page')); $paginator->setItemCountPerPage(5); $this->view->results = $paginator; } }
public function indexAction() { $this->enableLayout(); // get a list of news objects and order them by date $blogList = new Object\BlogArticle\Listing(); $blogList->setOrderKey("date"); $blogList->setOrder("DESC"); $conditions = []; if ($this->getParam("category")) { $conditions[] = "categories LIKE " . $blogList->quote("%," . (int) $this->getParam("category") . ",%"); } if ($this->getParam("archive")) { $conditions[] = "DATE_FORMAT(FROM_UNIXTIME(date), '%Y-%c') = " . $blogList->quote($this->getParam("archive")); } if (!empty($conditions)) { $blogList->setCondition(implode(" AND ", $conditions)); } $paginator = \Zend_Paginator::factory($blogList); $paginator->setCurrentPageNumber($this->getParam('page')); $paginator->setItemCountPerPage(5); $this->view->articles = $paginator; // get all categories $categories = Object\BlogCategory::getList(); // this is an alternative way to get an object list $this->view->categories = $categories; // archive information, we have to do this in pure SQL $db = \Pimcore\Db::get(); $ranges = $db->fetchCol("SELECT DATE_FORMAT(FROM_UNIXTIME(date), '%Y-%c') as ranges FROM object_5 GROUP BY DATE_FORMAT(FROM_UNIXTIME(date), '%b-%Y') ORDER BY ranges ASC"); $this->view->archiveRanges = $ranges; }