Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function findFiltered($filter,$curPage,$numItemsPerPage) {
- $query = $this->getFilterQuery($filter);
- $extraJoins = $query['extraJoins'];
- $extraWheres = $query['extraWheres'];
- return $this->db->fetchAll('SELECT workshops.workshopId, workshops.title,workshops.content,locations.city,workshops.addedOn, workshops.capacity from '. $this->getTableName() . ' INNER JOIN locations on locations.locationId = workshops.locationId' . $extraJoins . ' WHERE workshops.capacity > 0' . $extraWheres .' GROUP BY workshops.workshopId ORDER BY workshops.workshopId DESC LIMIT ' . (int) (($curPage - 1) * $numItemsPerPage) . ',' .(int) ($numItemsPerPage));
- }
- public function countWorkshopsFilter($filter) {
- $query = $this->getFilterQuery($filter);
- $extraJoins = $query['extraJoins'];
- $extraWheres = $query['extraWheres'];
- return $this->db->fetchAll('SELECT COUNT(*) FROM '. $this->getTableName() .' INNER JOIN users ON workshops.host = users.userId' . $extraJoins . ' WHERE workshops.capacity > 0' . $extraWheres . ' ORDER BY workshops.workshopId');
- }
- public function getFilterQuery($filter) {
- $extraJoins = '';
- $extraWheres = '';
- if ($filter['title'] != '') {
- $extraWheres .= ' AND workshops.title LIKE ' . $this->db->quote('%'.$filter['title'].'%', \PDO::PARAM_STR);
- }
- if (sizeof($filter['categories']) != 0) {
- if ($filter['categories'][0] != null) {
- $extraJoins .= ' INNER JOIN categories on workshops.categoryId = categories.categoryId';
- $extraWheres .= ' AND workshops.categoryId = ' . $this->db->quote($filter['categories'][0], \PDO::PARAM_INT);
- }
- }
- if (sizeof($filter['provinces']) != 0) {
- if ($filter['provinces'][0] != null) {
- $extraWheres .= ' AND locations.province = ' . $this->db->quote($filter['provinces'][0], \PDO::PARAM_STR);
- }
- }
- return array('extraWheres' => $extraWheres, 'extraJoins' => $extraJoins);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement