public function indexAction() { $searchWords = ''; if (isset($_GET['page'])) { $currentPage = (int) $_GET["page"]; } else { $currentPage = 1; } if ($this->request->isPost()) { $name = $this->request->getPost('name'); $location = $this->request->getPost('location'); //$details = $this->request->getPost('details'); //$price_to = $this->request->getPost('price'); $brand = $this->request->getPost('brand'); $model = $this->request->getPost("model"); // $yearModel = $this->request->getPost("year_model"); // $condition = $this->request->getPost("condition"); // $bodyType = $this->request->getPost('body_type'); // $transmission = $this->request->getPost('transmission'); // $mileage = $this->request->getPost('mileage'); // $fuelType = $this->request->getPost('fuel_type'); $conditions = ''; if (!empty($name)) { $conditions = ' OR name LIKE :name:'; $bind['name'] = $name; } if (!empty($location)) { $conditions = ' OR location LIKE :location:'; $bind['location'] = $location; } // if (!empty($details)) { // $conditions = ' OR details LIKE :details:'; // $bind['details'] = $details; // } if (!empty($brand)) { $conditions = ' OR brand LIKE :brand:'; $bind['brand'] = $brand; } if (!empty($model)) { $conditions = ' OR model LIKE :model:'; $bind['model'] = $model; } // if (!empty($yearModel)) { // $conditions = ' OR year_model LIKE :year_model:'; // $bind['year_model'] = $yearModel; // } // if (!empty($condition)) { // $conditions = ' OR condition_id LIKE :condition_id:'; // $bind['condition_id'] = $condition_id; // } // if (!empty($bodyType)) { // $conditions = ' OR body_type LIKE :body_type:'; // $bind['body_type'] = $bodyType; // } // if (!empty($price_from) && !empty($price_to)) { // $conditions = ' price BETWEEN ?1 AND ?2'; // $bind[1] = $price_from; // $bind[2] = $price_to; // } //$this->view->disable(); $autos = Automotives::find(['columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind]); $this->view->setVar('autos', $autos); // $this->session->set("filter", [$name, $category_id, $price_from, $price_to]); } else { $autos = Automotives::find(['order' => 'id DESC']); $this->view->setVar('autos', $autos); } $paginator = new \Phalcon\Paginator\Adapter\Model(["data" => $autos, "limit" => 12, "page" => $currentPage]); $page = $paginator->getPaginate(); $this->view->setVar('auto_p', $page); }
public function searchAction() { $keyword = $this->request->get("find"); $location = $this->request->get("near"); $searchWords = ''; $this->view->setVar('find', $keyword); $this->view->setVar('near', $near); $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'country LIKE :country:', 'bind' => array('country' => $location))); $countryId = ''; if ($country) { $countryId = $country->id; } $conditions = ''; if (!empty($keyword)) { $conditions .= ' OR name LIKE :name:'; $bind['name'] = '%' . $keyword . '%'; $searchWords .= ', ' . $keyword; } if (!empty($location)) { $conditions .= ' OR street LIKE :street: OR city LIKE :city:'; $bind['street'] = '%' . $location . '%'; $bind['city'] = '%' . $location . '%'; $searchWords .= ', ' . $location; } if (!empty($countryId)) { $conditions .= ' OR country_id = :country_id:'; $bind['country_id'] = $countryId; $searchWords .= ', ' . $country->country; } $searchWords = substr($searchWords, 2); $business = Business::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind)); $this->view->setVar('business', $business); //CARS and TRUCKS $conditions = ''; $bind = array(); if (!empty($keyword)) { $conditions = ' OR name LIKE :name:'; $bind['name'] = '%' . $keyword . '%'; } if (!empty($keyword)) { $conditions .= ' OR brand LIKE :brand:'; $bind['brand'] = '%' . $keyword . '%'; } if (!empty($keyword)) { $conditions .= ' OR model LIKE :model:'; $bind['model'] = '%' . $keyword . '%'; } if (!empty($location)) { $conditions .= ' OR location LIKE :location:'; $bind['location'] = $location; } $autos = Automotives::find(['columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind]); $this->view->setVar('autos', $autos); $conditions = ''; $bind = array(); if (!empty($keyword)) { $conditions = 'name LIKE :name:'; $bind['name'] = '%' . $keyword . '%'; } $things = Things::find(['columns' => '*', 'conditions' => $conditions, 'bind' => $bind]); $this->view->setVar('things', $things); //JOBS $conditions = ''; $bind = array(); if (!empty($keyword)) { $conditions .= ' OR position LIKE :position:'; $bind['position'] = '%' . $keyword . '%'; $searchWords .= ', ' . $keyword; } if (!empty($keyword)) { $conditions .= ' OR company LIKE :company:'; $bind['company'] = '%' . $keyword . '%'; $searchWords .= ', ' . $keyword; } if (!empty($location)) { $conditions .= ' OR street LIKE :street:'; $bind['street'] = '%' . $location . '%'; $conditions .= ' OR city LIKE :city:'; $bind['city'] = '%' . $location . '%'; $searchWords .= ', ' . $location; } if (!empty($countryId)) { $conditions .= ' OR country_id LIKE :country_id:'; $bind['country_id'] = $countryId; $searchWords .= ', ' . $country->country; } $jobs = Jobs::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind)); $this->view->setVar('jobs', $jobs); }