Example #1
0
 /**
  * Set model default order to query
  *
  * @param bool $reverse
  * @return \Engine\Mvc\Model\Query\Builder
  */
 public function orderNatural($reverse = false)
 {
     $direction = $this->_model->getOrderAsc();
     if ($order = $this->_model->getOrderExpr()) {
         if (!is_array($order)) {
             $order = [$order];
         }
         if (!is_array($direction)) {
             $direction = [$direction];
         }
         $orderPre = [];
         foreach ($order as $i => $key) {
             $direction[$i] = $direction[$i] ^ $reverse ? "ASC" : "DESC";
             $alias = $this->getCorrelationName($key);
             $orderPre[] = $alias . "." . $key . " " . $direction[$i];
         }
         $this->orderBy(implode(",", $orderPre));
     }
     return $this;
 }