예제 #1
0
 public function indexAction()
 {
     $searchWords = '';
     //$things = [];
     if (isset($_GET['page'])) {
         $currentPage = (int) $_GET["page"];
     } else {
         $currentPage = 1;
     }
     if ($this->request->isPost()) {
         $name = $this->request->getPost('name');
         $category_id = $this->request->getPost('thing_category_id');
         $price_from = $this->request->getPost('price_from');
         $price_to = $this->request->getPost('price_to');
         $conditions = '';
         if (!empty($name)) {
             $conditions = ' OR name LIKE :name:';
             $bind['name'] = $name;
         }
         if (!empty($category_id)) {
             $conditions = ' OR thing_category_id LIKE :category:';
             $bind['category'] = $category_id;
         }
         // if (!empty($price_from) && !empty($price_to)) {
         //     $conditions = ' price BETWEEN ?1 AND ?2';
         //     $bind[1] = $price_from;
         //     $bind[2] = $price_to;
         // }
         //$this->view->disable();
         $things = Things::find(['columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind]);
         $this->view->setVars(['things' => $things, 'thing_categories' => ThingCategories::find()]);
         // $this->session->set("filter", [$name, $category_id, $price_from, $price_to]);
     } else {
         $things = Things::find(['order' => 'id DESC']);
         $this->view->setVars(['things' => $things, 'thing_categories' => ThingCategories::find()]);
     }
     $paginator = new \Phalcon\Paginator\Adapter\Model(["data" => $things, "limit" => 12, "page" => $currentPage]);
     $page = $paginator->getPaginate();
     $this->view->setVar('thing_p', $page);
 }
예제 #2
0
 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);
 }