Example #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);
 }
Example #2
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;
 }