关于cakephp 2.0中的分页与order by

时间:2013-10-07 12:28:56

标签: php cakephp-2.0

如何处理不同型号的订单。例如我有一个CareseekerJob模型,它与城市,州,类别和用户模型相关联(belongsTO)。我正在搜索并希望按价格对作业进行排序,但它默认采用作业表的分页。

请参阅代码: -                    $ 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) AND '; $i='0';
                  $servicename = '';
                  foreach($serviceses as $key=>$value)
                  { $i++;
                     $servicedata =  $this->Service->find('first',array('conditions'=>array('Service.id'=>$value)));
                     $servicename = $servicedata['Service']['name'];
                     $con .= '(CareseekerJob.services LIKE "%'.$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."') and 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 ? AND ?" => array(number_format(min($proximity["latitudeMin"],$proximity["latitudeMax"]), 12, ".", ""), number_format(max($proximity["latitudeMin"],$proximity["latitudeMax"]), 12, ".", "")),"CareseekerJob.long BETWEEN ? AND ?"=> 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');
            }

0 个答案:

没有答案