Esempio n. 1
0
 /**
  * Creates a query that tests the given field for the given value.
  * @param Field $field The field to test.
  * @param string $operator The operator, must be '<', '>' or '='.
  * @param mixed $value The value to test for.
  * @return Query The query.
  * @throws InvalidArgumentException When the operator is invalid.
  */
 protected function where(Field $field, $operator, $value)
 {
     if ($operator === '=' || $operator === '<' || $operator === '>') {
         return $this->whereRaw('`' . $field->getNameInDatabase() . '` ' . $operator . ' :value', [":value" => $field->serializeValue($value)]);
     }
     throw new InvalidArgumentException("Invalid operator: " . $operator);
 }
Esempio n. 2
0
 /**
  * Gets the serialized value of the given field.
  * @param Field $field The field.
  * @return string Serialized value of the field.
  */
 public function getField(Field $field)
 {
     if (!$this->isConstructed()) {
         throw new \BadMethodCallException("Not yet constructed");
     }
     $fieldName = $field->getName();
     return $field->serializeValue($this->{$fieldName});
 }
Esempio n. 3
0
 /**
  * Orders the results in descending order based on the value of this field.
  * @param Field $field The field to sort on.
  * @throws BadMethodCallException If {@link Field#needsJoin()} returns true.
  * @return Query This object.
  */
 public function orderDescending(Field $field)
 {
     if ($field->needsJoin()) {
         throw new BadMethodCallException("Field " . $field->getName() . " needs a join, so cannot be used for sorting");
     }
     $this->orderByStrings[] = '`' . $field->getNameInDatabase() . "` DESC";
     return $this;
 }