Example #1
0
 /**
  * Parse the given string as a relation query.
  * 
  * @param string $string
  */
 public function __construct($string)
 {
     parent::__construct($string);
     list($relation, $value) = explode(Factory::syntax('symbols', 'relation', ':'), $string);
     $this->relation = $relation;
     $this->value = $value;
 }
Example #2
0
 /**
  * Parse the given string as an range query.
  * 
  * @param string $string
  */
 public function __construct($string)
 {
     parent::__construct($string);
     $values = explode(Factory::syntax('symbols', 'delim', '|'), $string);
     foreach ($values as $value) {
         $this->values[] = OperatorQuery::make($value);
     }
 }
Example #3
0
 /**
  * Parse the given string as an operator query.
  * 
  * @param string $string
  */
 public function __construct($string)
 {
     parent::__construct($string);
     $this->operator = Factory::syntax('symbols', 'equals', '=');
     $this->value = $string;
     $operators = [Factory::syntax('symbols', 'equals', '='), Factory::syntax('symbols', 'bigger', ']'), Factory::syntax('symbols', 'smaller', '['), Factory::syntax('symbols', 'like', '~'), Factory::syntax('symbols', 'not', '!')];
     if (in_array($string[0], $operators)) {
         $this->operator = $string[0];
         $this->value = substr($string, 1);
     }
     $this->method = $this->getMethodFromOperator($this->operator);
 }
 /**
  * Apply the inquiry with an optional operator query to the query itself.
  * 
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  string                                 $attribute
  * @param  \Bycedric\Inquiry\Queries\Query        $operator
  * @param  bool                                   $comparator
  * @return \Illuminate\Database\Eloquent\Builder
  */
 private function applyQuery($query, $attribute, $operator, $comparator = 'and')
 {
     // check if operator is a range query
     if ($operator instanceof RangeQuery) {
         // iterate the values and apply to the query for each seperate operator
         foreach ($operator->getValues() as $value) {
             $this->applyQuery($query, $attribute, $value, $operator->isAllSameOperator('=') ? 'or' : 'and');
         }
         // stop executing
         return $query;
     }
     // get the value and method
     $value = $operator->getValue();
     $method = $operator->getMethod();
     // check if the value is null
     if (is_null($value)) {
         // check if the method or operator is an inverter
         if ($operator->isNot()) {
             // applying whereNotNull
             return $query->whereNotNull($attribute, $comparator);
         }
         // applying whereNull
         return $query->whereNull($attribute, $comparator);
     }
     // check if the method is LIKE
     if ($method == 'LIKE') {
         // add % to the value
         $value = '%' . str_replace(' ', '%', $value) . '%';
     }
     // applying query
     return $query->where($attribute, $method, $value, $comparator);
 }