示例#1
0
 public function indexAction()
 {
     $searchWords = '';
     $jobs = array();
     if (isset($_GET["page"])) {
         $currentPage = (int) $_GET["page"];
     } else {
         $currentPage = 1;
     }
     if ($this->request->isPost()) {
         $position = $this->request->getPost('position');
         $company = $this->request->getPost('company');
         $address = $this->request->getPost('address');
         $jobCategoryId = $this->request->getPost('job_category_id');
         $salaryFrom = $this->request->getPost('salary_from');
         $salaryTo = $this->request->getPost('salary_to');
         $this->view->position = $position;
         $jobCategory = JobCategories::findFirst($jobCategoryId);
         $country = Countries::findFirst(array('columns' => '*', 'conditions' => 'country LIKE :country:', 'bind' => array('country' => $address)));
         $countryId = '';
         if ($country) {
             $countryId = $country->id;
         }
         $conditions = '';
         $bind = array();
         if (!empty($position)) {
             $conditions .= ' OR position LIKE :position:';
             $bind['position'] = '%' . $position . '%';
             $searchWords .= ', ' . $position;
         }
         if (!empty($company)) {
             $conditions .= ' OR company LIKE :company:';
             $bind['company'] = '%' . $company . '%';
             $searchWords .= ', ' . $company;
         }
         if (!empty($address)) {
             $conditions .= ' OR street LIKE :street:';
             $bind['street'] = '%' . $address . '%';
             $conditions .= ' OR city LIKE :city:';
             $bind['city'] = '%' . $address . '%';
             $searchWords .= ', ' . $address;
         }
         if (!empty($countryId)) {
             $conditions .= ' OR country_id LIKE :country_id:';
             $bind['country_id'] = $countryId;
             $searchWords .= ', ' . $country->country;
         }
         if (!empty($jobCategoryId)) {
             $conditions .= ' OR job_category_id LIKE :job_category_id:';
             $bind['job_category_id'] = $jobCategoryId;
             $searchWords .= ', ' . $jobCategory->name;
         }
         if (!empty($salaryFrom)) {
             $conditions .= ' OR salary_from LIKE :salary_from:';
             $bind['salary_from'] = $salaryFrom;
             $searchWords .= ', ' . $salaryFrom;
         }
         if (!empty($salaryTo)) {
             $conditions .= ' OR salary_to LIKE :salary_to:';
             $bind['salary_to'] = $salaryTo;
             $searchWords .= ', ' . $salaryTo;
         }
         $searchWords = substr($searchWords, 2);
         $jobs = Jobs::find(array('columns' => '*', 'conditions' => substr($conditions, 3), 'bind' => $bind));
     } else {
         $jobs = Jobs::find();
     }
     // Create a Model paginator, show 10 rows by page starting from $currentPage
     $paginator = new \Phalcon\Paginator\Adapter\Model(array("data" => $jobs, "limit" => 10, "page" => $currentPage));
     $page = $paginator->getPaginate();
     $this->view->setVar('searchWords', $searchWords);
     $this->view->setVar('jobs', $page);
     $jobCategories = JobCategories::find();
     $this->view->setVar('jobCategories', $jobCategories);
 }