Пример #1
0
 /**
  * Will apply conditions defined inside $m onto query $q.
  *
  * @param Model            $m
  * @param \atk4\dsql\Query $q
  *
  * @return \atk4\dsql\Query
  */
 public function initQueryConditions($m, $q)
 {
     if (!isset($m->conditions)) {
         // no conditions are set in the model
         return $q;
     }
     foreach ($m->conditions as $cond) {
         // Options here are:
         // count($cond) == 1, we will pass the only
         // parameter inside where()
         if (count($cond) == 1) {
             $q->where($cond[0]);
             continue;
         }
         if (is_string($cond[0])) {
             $cond[0] = $m->getElement($cond[0]);
         }
         if (count($cond) == 2) {
             if ($cond[0] instanceof Field) {
                 $cond[1] = $this->typecastSaveField($cond[0], $cond[1]);
             }
             $q->where($cond[0], $cond[1]);
         } else {
             if ($cond[0] instanceof Field) {
                 $cond[2] = $this->typecastSaveField($cond[0], $cond[2]);
             }
             $q->where($cond[0], $cond[1], $cond[2]);
         }
     }
     return $q;
 }