Ejemplo n.º 1
0
 /**
  * 
  * @param mixed $lastPage
  * @param \Sooh\DB\Interfaces\All $db
  */
 protected function loopGetRecordsPage_buildWhere($db)
 {
     $lastPage = $this->lastPage;
     $sort_field_type = $this->sort_field_type;
     $sortMethod = array(0 => array('sort' => ']', 'rsort' => '['), -1 => array('sort' => '<', 'rsort' => '>'), 1 => array('sort' => '>', 'rsort' => '<'));
     $sorValIndex = array(0 => 0, -1 => 0, 1 => 1);
     if (sizeof($sort_field_type) == 1) {
         //单键
         $w = array();
         if (!empty($lastPage['_last_'])) {
             $k = key($sort_field_type);
             $sort = current($sort_field_type);
             $w[$k . $sortMethod[$this->pageStep][$sort]] = $lastPage['_last_']['_' . $k . '_'][$sorValIndex[$this->pageStep]];
             //echo ">>$k $sort $pageForward ".$sortMethod[$pageForward][$sort]." ".$lastPage['_'.$k.'_'][$pageForward]."\n";
             //echo ">>1>>".json_encode($w)."\n";
         }
         if (is_array($lastPage['where'])) {
             $w = $this->loopGetRecordsPage_mergeWhere($w, $lastPage['where']);
             //echo ">>2>>".json_encode($w)."\n";
         }
         //echo ">>3>>".json_encode($w)."\n";
         $where = $w;
     } else {
         //双键, 【=,>】,【>,null】
         $wEq = array();
         $wCmp = array();
         if (!empty($lastPage['_last_'])) {
             $k1 = key($sort_field_type);
             $sort1 = current($sort_field_type);
             array_shift($sort_field_type);
             $k2 = key($sort_field_type);
             $sort2 = current($sort_field_type);
             $wEq[$k1 . '='] = $lastPage['_last_']['_' . $k1 . '_'][$sorValIndex[$this->pageStep]];
             $wEq[$k2 . $sortMethod[$this->pageStep][$sort2]] = $lastPage['_last_']['_' . $k2 . '_'][$sorValIndex[$this->pageStep]];
             $wCmp[$k1 . $sortMethod[$this->pageStep][$sort1]] = $lastPage['_last_']['_' . $k1 . '_'][$sorValIndex[$this->pageStep]];
             if (is_array($lastPage['where'])) {
                 $wEq = $this->loopGetRecordsPage_mergeWhere($wEq, $lastPage['where']);
                 $wCmp = $this->loopGetRecordsPage_mergeWhere($wCmp, $lastPage['where']);
             }
             $where = $db->newWhereBuilder();
             $where->init('OR');
             $where->append(null, $db->newWhereBuilder()->append($wEq));
             $where->append(null, $db->newWhereBuilder()->append($wCmp));
             $where = $where->end();
         } else {
             if (is_array($lastPage['where'])) {
                 $where = $lastPage['where'];
             } else {
                 $where = $wEq;
             }
         }
     }
     //echo "WHERE=";
     //var_dump($where);
     return $where;
 }