php - Regarding pagination in cakephp 2.0 with order by -


how deal order different models.for e.g. have careseekerjob model in association(belongsto) city,state,category , user model.i doing searching , want sort job price taking default paging of job table.

please refer code:- $searchdata = array(); $conditioncat = ''; $conditionsearch = '';
if(!empty($categories) && $categories!='-1') { $conditioncat = 'careseekerjob.category_id in ('.$categories.') '; } if($categories == '-1') { $conditionserv = '(1 = 1) '; } $conditionserv = ''; if(!empty($services) && $services!='-1') {

                  $serviceses = explode(',',$services);                   $servicename = '';                   $con = '(1 = 1) , '; $i='0';                   $servicename = '';                   foreach($serviceses $key=>$value)                   { $i++;                      $servicedata =  $this->service->find('first',array('conditions'=>array('service.id'=>$value)));                      $servicename = $servicedata['service']['name'];                      $con .= '(careseekerjob.services "%'.$servicename.'%")' ;                      if(count($serviceses) == $i){                          $con .= ' ';                      }else{                      $con .= ' or ';                      }                   }                    $conditionserv = $con;                }               if($services == '-1')                     {                        $conditionserv = '(1 = 1) ';                     }               $conditiontime = '';                if($timingess != '1')               {                        $start = '';                     $end = '';                     if($timingess == 'morning')                     {                        $start = date('h:i:s',strtotime('00:00:00'));                        $end = date('h:i:s',strtotime('11:59:00'));                     }                     elseif($timingess == 'afternoon')                     {                         $start = date('h:i:s',strtotime('11:59:00'));                         $end = date('h:i:s',strtotime('16:00:00'));                     }                     elseif($timingess == 'evening')                     {                         $start = date('h:i:s',strtotime('16:00:00'));                         $end = date('h:i:s',strtotime('20:00:00'));                     }                     elseif($timingess == 'night')                     {                         $start = date('h:i:s',strtotime('20:00:00'));                         $end = date('h:i:s',strtotime('23:59:00'));                     }                     elseif($timingess == 'morning,afternoon')                     {                                 $start = date('h:i:s',strtotime('00:00:00'));                                 $end = date('h:i:s',strtotime('16:00:00'));                      }                     elseif($timingess == 'morning,evening')                     {                                 $start = date('h:i:s',strtotime('00:00:00'));                                 $end = date('h:i:s',strtotime('20:00:00'));                      }                     elseif($timingess == 'morning,afternoon,evening')                     {                                 $start = date('h:i:s',strtotime('00:00:00'));                                 $end = date('h:i:s',strtotime('20:00:00'));                      }                     elseif($timingess == 'morning,afternoon,evening,night')                     {                         $start = date('h:i:s',strtotime('00:00:00'));                         $end = date('h:i:s',strtotime('23:59:00'));                      }                          $conditiontime = "( time(careseekerjob.starttime) >= time('".$start."') , time(careseekerjob.starttime) <= time('".$end."') ) ";                }                if($timingess == '1')                     {                        $conditiontime = '(1 = 1) ';                     }                     $conditionsearch = "";                    $conditionzip = "";                             if($searchtext != 1)                             {                                 if(is_numeric($searchtext))                                 {                                     $url1 = "https://maps.googleapis.com/maps/api/geocode/xml?address=" . $searchtext . "&sensor=false";                                     $details = simplexml_load_file($url1);                                       if ($details->status == 'ok') {                                    $sourcelat = $details->result->geometry->location->lat;                                    $sourcelon = $details->result->geometry->location->lng;                                    $radiuskm = 160.934;                                    $proximity = $this->radiussearch->mathgeoproximity($sourcelat, $sourcelon, $radiuskm);                                    $latmin=min($proximity["latitudemin"],$proximity["latitudemax"]);                                    $latmax=max($proximity["latitudemin"],$proximity["latitudemax"]);                                    $lonmin=min($proximity["longitudemin"],$proximity["longitudemax"]);                                    $lonmax=max($proximity["longitudemin"],$proximity["longitudemax"]);                                              $conditionzip=array("careseekerjob.lat between ? , ?" => array(number_format(min($proximity["latitudemin"],$proximity["latitudemax"]), 12, ".", ""), number_format(max($proximity["latitudemin"],$proximity["latitudemax"]), 12, ".", "")),"careseekerjob.long between ? , ?"=> array(number_format(max($proximity["longitudemin"],$proximity["longitudemax"]), 12, ".", ""),number_format(min($proximity["longitudemin"],$proximity["longitudemax"]), 12, ".", "")));                                      }                                     $conditionsearch = '(1 = 1)';                                   }                                   else{                                          $conditionsearch= array('or'=>array('careseekerjob.title like'=>'%'.$searchtext.'%','careseekerjob.zipcode'=>$searchtext));                                        }                              }else{                                 $conditionzip = '(1 = 1)';                                 $conditionsearch = '(1 = 1)';                               }        if($sort =='recent' )             {                      $condition= array('careseekerjob.job_status'=>'jobactive','careseekerjob.is_deleted'=>0,'careseekerjob.status'=>'active');                     $this->paginate = array(                                       'conditions' => array('and'=>array($condition,$conditioncat,$conditiontime,$conditionserv,$conditionsearch,$conditionzip)),                                       'limit' => 4,                                       'order' => array(                                           'careseekerjob.id' => 'desc'                                       )                                   );                       $searchdata = $this->paginate('careseekerjob');             }     elseif($sort =='distance' )             {                     $condition= array('careseekerjob.job_status'=>'jobactive','careseekerjob.is_deleted'=>0,'careseekerjob.status'=>'active');                     $this->paginate = array(                                        'conditions' => array('and'=>array($condition,$conditioncat,$conditiontime,$conditionserv,$conditionsearch,$conditionzip)),                                       'limit' => 4,                                       'order' => array(                                           'careseekerjob.lat' => 'desc'                                       ),                                    );                        $searchdata = $this->paginate('careseekerjob');             }elseif($sort =='price')             {                          $condition= array('careseekerjob.job_status'=>'jobactive','careseekerjob.is_deleted'=>0,'careseekerjob.status'=>'active');                          $this->paginate = array(                                       'conditions' => array('and'=>array($condition,$conditioncat,$conditiontime,$conditionserv,$conditionsearch,$conditionzip)),                                       'limit' => 4,                                       'order' => array(                                           'careseekerjob.rate' => 'desc'                                       )                                    );                       $searchdata = $this->paginate('careseekerjob');             } 


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -