Advertisement
Guest User

Untitled

a guest
May 24th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. public function findFiltered($filter,$curPage,$numItemsPerPage) {
  2. $query = $this->getFilterQuery($filter);
  3. $extraJoins = $query['extraJoins'];
  4. $extraWheres = $query['extraWheres'];
  5.  
  6. 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));
  7. }
  8.  
  9. public function countWorkshopsFilter($filter) {
  10. $query = $this->getFilterQuery($filter);
  11. $extraJoins = $query['extraJoins'];
  12. $extraWheres = $query['extraWheres'];
  13.  
  14. 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');
  15. }
  16.  
  17. public function getFilterQuery($filter) {
  18. $extraJoins = '';
  19. $extraWheres = '';
  20. if ($filter['title'] != '') {
  21. $extraWheres .= ' AND workshops.title LIKE ' . $this->db->quote('%'.$filter['title'].'%', \PDO::PARAM_STR);
  22. }
  23.  
  24. if (sizeof($filter['categories']) != 0) {
  25. if ($filter['categories'][0] != null) {
  26. $extraJoins .= ' INNER JOIN categories on workshops.categoryId = categories.categoryId';
  27. $extraWheres .= ' AND workshops.categoryId = ' . $this->db->quote($filter['categories'][0], \PDO::PARAM_INT);
  28. }
  29. }
  30. if (sizeof($filter['provinces']) != 0) {
  31. if ($filter['provinces'][0] != null) {
  32. $extraWheres .= ' AND locations.province = ' . $this->db->quote($filter['provinces'][0], \PDO::PARAM_STR);
  33. }
  34. }
  35.  
  36. return array('extraWheres' => $extraWheres, 'extraJoins' => $extraJoins);
  37.  
  38.  
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement