Ejemplo n.º 1
0
 public function getString(QueryContext $context)
 {
     $field = FieldInfo::make($this->field);
     if ($this->value instanceof Raw) {
         return $field->getName($context) . " {$this->operator} {$this->value}";
     } else {
         $context->param($this->value);
         return $field->getName($context) . " {$this->operator} ?";
     }
 }
Ejemplo n.º 2
0
 public static function toString(QueryContext $context, array $orders)
 {
     if (empty($orders)) {
         return null;
     }
     $statements = array();
     foreach ($orders as $item) {
         $field = FieldInfo::make($item->field)->getName($context);
         /**
          * @var OrderInfo $item
          */
         $statements[] = "{$field} {$item->sort}";
     }
     return implode(',', $statements);
 }
Ejemplo n.º 3
0
 private static function parseJoinInfo(QueryContext $context, JoinInfo $join)
 {
     $context->schema($join->schema);
     $conditions = array();
     if (isset($join->clause)) {
         $joinQuery = new JoinQuery();
         call_user_func($join->clause, $joinQuery);
         $conditions = $joinQuery->getConditions();
         if (!$joinQuery->getSoftDeleteLess() && $join->schema->getSoftDelete()) {
             $conditions[] = JoinConditionInfo::make(ConditionInfo::CONDITION_AND, TableSchema::SOFT_DELETE_FIELD, '=', 0, false);
         }
     } else {
         $conditions[] = $join->condition;
     }
     $statements = array();
     $statements[] = $join->leftJoin ? "LEFT JOIN" : "JOIN";
     $statements[] = $join->schema->getSymbol();
     if (count($conditions) > 0) {
         $statements[] = "ON (";
         $first = false;
         foreach ($conditions as $item) {
             $items = array();
             /**
              * @var JoinConditionInfo $item
              */
             if (!$first) {
                 $first = true;
             } else {
                 $items[] = $item->orAnd;
             }
             if (!$item->whereCondition) {
                 $field = FieldInfo::make($item->onField);
                 $value = FieldInfo::make($item->onValue);
                 $items[] = $field->getName($context) . " {$item->onOperator} " . $value->getName($context);
             } else {
                 if ($item->onValue instanceof Raw) {
                     $items[] = "{$item->onField} {$item->onOperator} " . $item->onValue->getValue();
                 } else {
                     $items[] = "{$item->onField} {$item->onOperator} ?";
                     $context->param($item->onValue);
                 }
             }
             $statements[] = implode(' ', $items);
         }
         $statements[] = ")";
     }
     return implode(' ', $statements);
 }
Ejemplo n.º 4
0
 public static function toString(QueryContext $context, $groups)
 {
     if (empty($groups)) {
         return null;
     }
     $fields = array();
     /** @var GroupInfo $item */
     foreach ($groups as $item) {
         if (!empty($item->groups)) {
             foreach ($item->groups as $group) {
                 $fields[] = FieldInfo::make($group)->getName($context);
             }
         }
     }
     return implode(',', $fields);
 }