Exemplo n.º 1
7
 /**
  * @param QueryBuilder $builder
  * @param $data
  *
  * @return void
  */
 public function applyFilterConstraint(QueryBuilder $builder, $data)
 {
     if (empty($data)) {
         return;
     }
     $builder->whereIn($this->relation->getForeignKey(), explode(',', $data));
 }
Exemplo n.º 2
4
 private function selectWhereIn($keys, Builder $query)
 {
     $results = [];
     foreach (array_chunk($keys, 500) as $chunk) {
         $results = array_merge($results, $this->connection->table($this->connection->raw("({$query->toSql()}) as query"))->whereIn("__key", $chunk)->get());
     }
     return collect($results)->keyBy("__key")->toArray();
 }
Exemplo n.º 3
3
 /**
  * Process an "insert get ID" query.
  *
  * @param \Illuminate\Database\Query\Builder $query        	
  * @param string $sql        	
  * @param array $values        	
  * @param string $sequence        	
  * @return int
  */
 public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
 {
     $results = $query->getConnection()->selectFromWriteConnection($sql, $values);
     $sequence = $sequence ?: 'id';
     $result = (array) $results[0];
     $id = $result[$sequence];
     return is_numeric($id) ? (int) $id : $id;
 }
Exemplo n.º 4
2
 public function execute(Builder $query)
 {
     foreach ($this->getValuesIterator() as $groupBy) {
         $query->groupBy($groupBy->getValue());
     }
     return $query;
 }
Exemplo n.º 5
2
 /**
  * Process an "insert get ID" query.
  *
  * @param  \Illuminate\Database\Query\Builder  $query
  * @param  string  $sql
  * @param  array   $values
  * @param  string  $sequence
  * @return int
  */
 public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
 {
     $results = $query->getConnection()->select($sql, $values);
     $sequence = $sequence ?: 'id';
     $result = (array) $results[0];
     return (int) $result[$sequence];
 }
Exemplo n.º 6
1
 /**
  * Eloquent Scope for tag categories.
  * 
  * @param \Illuminate\Database\Query\Builder $query
  * @param string                             $category
  *
  * @return \Illuminate\Database\Query\Builder
  */
 public function scopeCategory($query, $category)
 {
     if (!is_null($category)) {
         return $query->where('category', '=', $category);
     }
     return $query;
 }
 /**
  * Find by conditions in request
  *
  * @param Builder $query
  * @param array|null $request
  * @return \Illuminate\Database\Query\Builder
  */
 public function scopeFindByRequest($query, $request = NULL)
 {
     if (is_null($request)) {
         $request = Input::all();
     }
     $findable = isset($this->findable) ? $this->findable : [];
     foreach ($request as $field => $value) {
         if (!in_array($field, $findable)) {
             continue;
         }
         if ($field == 'tag') {
             if (isset($request['tag_search']) && $request['tag_search'] == 'any') {
                 $query->withAnyTag($value);
             } else {
                 $query->withAllTags($value);
             }
             continue;
         }
         if (is_array($value)) {
             $query->whereIn($field, $value);
         } elseif (is_scalar($value)) {
             $query->where($field, '=', $value);
         }
     }
 }
Exemplo n.º 8
1
 /**
  * @param \Illuminate\Database\Query\Builder $query
  * @param string                             $type
  *
  * @return \Illuminate\Database\Query\Builder
  * @throws \Exception
  */
 public function scopeOfType($query, $type = 'image')
 {
     if (!in_array($type, ['plain', 'image', 'audio', 'video', 'application'])) {
         throw new \Exception();
     }
     return $query->where('mime', 'like', $type . '/%');
 }
Exemplo n.º 9
1
 public function execute(Builder $query)
 {
     $isWhere = false;
     $count = 0;
     foreach ($this->getValuesIterator() as $where) {
         $operator = $where->getOperator();
         if (array_key_exists($operator, WhereValidator::$especial_operator)) {
             $method = $where->getOperatorValue();
             switch ($method) {
                 case WhereValidator::$especial_operator['isNull']:
                 case WhereValidator::$especial_operator['isNotNull']:
                     $query->{$method}($where->getName());
                     break;
                 case WhereValidator::$especial_operator['between']:
                 case WhereValidator::$especial_operator['in']:
                     $query->{$method}($where->getName(), $where->getValue());
                     break;
             }
             continue;
         } else {
             if ($where->getOperatorValue() == WhereValidator::$operator['like']) {
                 $value = '%' . $where->getValue() . '%';
             } else {
                 $value = $where->getValue();
             }
         }
         $query->where($where->getName(), $where->getOperatorValue(), $value);
     }
     return $query;
 }
Exemplo n.º 10
1
 protected function compileJoins(LaravelBaseBuilder $query, $joins)
 {
     $sql = array();
     $query->setBindings(array(), 'join');
     foreach ($joins as $join) {
         $table = $this->wrapTable($join->table);
         // First we need to build all of the "on" clauses for the join. There may be many
         // of these clauses so we will need to iterate through each one and build them
         // separately, then we'll join them up into a single string when we're done.
         $clauses = array();
         foreach ($join->clauses as $where) {
             if (isset($where['type'])) {
                 $method = "where{$where['type']}";
                 $clauses[] = $where['boolean'] . ' ' . $this->{$method}($query, $where);
             } else {
                 $clauses[] = $this->compileJoinConstraint($where);
             }
         }
         foreach ($join->bindings as $binding) {
             $query->addBinding($binding, 'join');
         }
         // Once we have constructed the clauses, we'll need to take the boolean connector
         // off of the first clause as it obviously will not be required on that clause
         // because it leads the rest of the clauses, thus not requiring any boolean.
         $clauses[0] = $this->removeLeadingBoolean($clauses[0]);
         $clauses = implode(' ', $clauses);
         $type = $join->type;
         // Once we have everything ready to go, we will just concatenate all the parts to
         // build the final join statement SQL for the query and we can then return the
         // final clause back to the callers as a single, stringified join statement.
         $sql[] = "{$type} join {$table} on ({$clauses})";
     }
     return implode(' ', $sql);
 }
Exemplo n.º 11
1
 /**
  * {@inheritdoc}
  */
 public function where(Builder $query, $value, $operator = '=')
 {
     if ($value === self::NULL_VALUE) {
         $value = null;
     }
     return $query->where($this->initQuery($query), $operator, $value);
 }
Exemplo n.º 12
1
 /**
  * Create a new join clause instance.
  *
  * @param  \Illuminate\Database\Query\Builder $parentQuery
  * @param  string  $type
  * @param  string  $table
  * @return void
  */
 public function __construct(Builder $parentQuery, $type, $table)
 {
     $this->type = $type;
     $this->table = $table;
     $this->parentQuery = $parentQuery;
     parent::__construct($parentQuery->getConnection(), $parentQuery->getGrammar(), $parentQuery->getProcessor());
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function order(Builder $builder, $direction)
 {
     if ($this->columnClause !== null) {
         $builder->orderBy($this->columnClause, $direction);
     }
     return $this;
 }
 /**
  * Call apply() within an "and" block
  * @param \Illuminate\Database\Query\Builder $query
  * @return \Illuminate\Database\Query\Builder $query
  */
 public function applyAnd(\Illuminate\Database\Query\Builder $query)
 {
     $query->where(function ($query) {
         $this->apply($query);
     });
     return $query;
 }
Exemplo n.º 15
0
 /**
  * Constrain a query to an ability for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  bool  $strict
  * @return void
  */
 protected function constrainByModel($query, Model $model, $strict = false)
 {
     $query->where(function ($query) use($model, $strict) {
         $query->where($this->table . '.entity_type', $model->getMorphClass());
         $query->where($this->abilitySubqueryConstraint($model, $strict));
     });
 }
Exemplo n.º 16
0
 /**
  * @param Builder $query
  * @param int     $instanceId
  *
  * @return Builder
  */
 public function scopeInstanceId($query, $instanceId)
 {
     if (!empty($instanceId)) {
         return $query->where('instance_id', '=', $instanceId);
     }
     return $query;
 }
Exemplo n.º 17
0
 public function execute(Builder $query)
 {
     foreach ($this->getValuesIterator() as $orderBy) {
         $query->orderBy($orderBy->getName(), $orderBy->getValue());
     }
     return $query;
 }
Exemplo n.º 18
0
 /**
  * Process an "insert get ID" query.
  *
  * @param  \Illuminate\Database\Query\Builder  $query
  * @param  string  $sql
  * @param  array   $values
  * @param  string  $sequence
  * @return int
  */
 public function processInsertGetId(Builder $query, $sql, $values, $sequence = null)
 {
     $result = $query->getConnection()->selectFromWriteConnection($sql, $values)[0];
     $sequence = $sequence ?: 'id';
     $id = is_object($result) ? $result->{$sequence} : $result[$sequence];
     return is_numeric($id) ? (int) $id : $id;
 }
Exemplo n.º 19
0
 /**
  * Begin a fluent query against a database table.
  *
  * @param  string $table
  *
  * @return \Illuminate\Database\Query\Builder
  */
 public function table($table)
 {
     $processor = $this->getPostProcessor();
     $table = $this->db->prefix . $table;
     $query = new Builder($this, $this->getQueryGrammar(), $processor);
     return $query->from($table);
 }
Exemplo n.º 20
0
 /**
  * Filters a query object
  *
  * @param \Illuminate\Database\Query\Builder	$query
  * @param array									$selects
  *
  * @return void
  */
 public function filterQuery(QueryBuilder &$query, &$selects = null)
 {
     //if the field isn't empty
     if ($this->getOption('value') !== '') {
         $query->where($this->config->getDataModel()->getTable() . '.' . $this->getOption('field_name'), '=', $this->getOption('value'));
     }
 }
Exemplo n.º 21
0
 /**
  * {@inheritdoc}
  *
  * We will check for actual match rather than partial.
  */
 public function applyKeywordsFilter(Builder $builder, array $keywords)
 {
     foreach ($keywords as $keyword) {
         if (is_numeric($keyword)) {
             $builder->orWhere($this->id, '=', $keyword);
         }
     }
 }
Exemplo n.º 22
0
 /**
  * Create new joiner instance.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder $query
  * @param  \Illuminate\Database\Eloquent\Model $model
  * @return \Sofa\Eloquence\Relations\Joiner
  */
 public static function make($query, Model $model = null)
 {
     if ($query instanceof EloquentBuilder) {
         $model = $query->getModel();
         $query = $query->getQuery();
     }
     return new Joiner($query, $model);
 }
Exemplo n.º 23
0
 /**
  * Extend the list query
  *
  * @param  \Illuminate\Database\Query\Builder $query
  * @return \Illuminate\Database\Query\Builder
  */
 public function listExtendQuery($query)
 {
     $query->selectStatus()->with(['products' => function ($product) {
         $product->select('id');
     }, 'categories' => function ($category) {
         $category->select('id');
     }]);
 }
Exemplo n.º 24
0
 /**
  * Add an "on" clause to the join.
  *
  * @param  string  $first
  * @param  string  $operator
  * @param  string  $second
  * @param  string  $boolean
  * @param  bool  $where
  * @return \Illuminate\Database\Query\JoinClause
  */
 public function on($first, $operator, $second, $boolean = 'and', $where = false)
 {
     $this->clauses[] = compact('first', 'operator', 'second', 'boolean', 'where');
     if ($where) {
         $this->query->addBinding($second);
     }
     return $this;
 }
Exemplo n.º 25
0
 protected function paginate(Builder $builder, $perPage)
 {
     $page = Paginator::resolveCurrentPage();
     $total = $builder->count();
     $query = $builder->forPage($page, $perPage);
     $results = $query->get();
     return new LengthAwarePaginator($results, $total, $perPage, $page, ['path' => Paginator::resolveCurrentPath()]);
 }
 /**
  * @param Builder|EloquentBuilder $data
  * @return Traversable
  */
 protected function afterOperations($data)
 {
     if ($data instanceof EloquentBuilder) {
         return $data->get();
     } elseif ($data instanceof Builder) {
         return new ArrayIterator($data->get());
     }
     throw new RuntimeException('Unsupported type of data source.');
 }
Exemplo n.º 27
0
 /**
  * Evaluate query as string.
  *
  * @return string
  */
 public function getValue()
 {
     $sql = '(' . $this->query->toSql() . ')';
     if ($this->alias) {
         $alias = $this->query->getGrammar()->wrapTable($this->alias);
         $sql .= ' as ' . $alias;
     }
     return $sql;
 }
Exemplo n.º 28
0
 /**
  * Get things tagged with all of a given comma-separated list of tags.
  * @param \Illuminate\Database\Query\Builder $query
  * @param string $tagged
  */
 public function scopeTagged($query, $tagged)
 {
     foreach (explode(',', $tagged) as $tag) {
         $query->whereHas('tags', function ($query) use($tag) {
             $query->where('name', $tag);
         });
     }
     return $query;
 }
Exemplo n.º 29
0
 /**
  * Add a "where" clause to the given query.
  *
  * @param  \Illuminate\Database\Query\Builder $query
  * @param  string $key
  * @param  string $extraValue
  * @return void
  */
 protected function addWhere($query, $key, $extraValue)
 {
     if ($extraValue === 'NULL') {
         $query->whereNull($key);
     } elseif ($extraValue === 'NOT_NULL') {
         $query->whereNotNull($key);
     } else {
         $query->where($key, $extraValue);
     }
 }
Exemplo n.º 30
-1
 /**
  * Get prepared statement.
  *
  * @param Builder $query
  * @param string $sql
  * @return \PDOStatement|\Yajra\Pdo\Oci8
  */
 private function prepareStatement(Builder $query, $sql)
 {
     /** @var \Yajra\Oci8\Oci8Connection $connection */
     $connection = $query->getConnection();
     $pdo = $connection->getPdo();
     return $pdo->prepare($sql);
 }