Example #1
7
 /**
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public static function withoutOrders()
 {
     $instance = new static();
     $query = $instance->newQuery();
     $query->getQuery()->orders = [];
     return $query;
 }
Example #2
4
 public static function sync($fromDate = '')
 {
     $instance = new static();
     $newQuery = static::syncFilter($instance->newQuery()->where(function ($query) use(&$fromDate) {
         $query->where('created_at', '>', $fromDate)->orWhereNull('created_at');
     }));
     $updateQuery = static::syncFilter($instance->newQuery()->where('updated_at', '>', $fromDate)->where('created_at', '<', $fromDate));
     $deleteQuery = static::syncFilter($instance->newQuery()->onlyTrashed()->where('deleted_at', '>', $fromDate));
     if ($fromDate == '') {
         return array('new' => $newQuery->get()->toArray(), 'updated' => null, 'deleted' => null);
     }
     return array('new' => $newQuery->get()->toArray(), 'updated' => $updateQuery->get()->toArray(), 'deleted' => $deleteQuery->get()->toArray());
 }
Example #3
0
 public static function findBySlug($slug, $columns = ['*'])
 {
     $instance = new static();
     if (is_array($slug)) {
         return $instance->newQuery()->whereIn('slug', $slug)->get($columns);
     }
     return $instance->newQuery()->slug($slug)->get($columns);
 }
Example #4
0
 public static function find($id, $columns = array('*'))
 {
     if (is_array($id) && empty($id)) {
         return new Collection();
     }
     $instance = new static();
     $obj = $instance->newQuery()->find($id, $columns);
     if (is_array($id)) {
         $prop = new ReflectionProperty(get_class($obj), 'items');
     }
     $col = array();
     if (isset($prop->name)) {
         $prop->setAccessible(1);
         foreach ($prop->getValue($obj) as $k => $object) {
             $translation = Translations::find($object->table . "_" . $object->id . "_" . strtolower(Config::get('cms.currlang.code')));
             $object->setRawAttributes(json_decode($translation->translation, 1));
             $col[] = $object;
         }
         $prop->setValue($obj, $col);
     } else {
         $translation = Translations::find($obj->table . "_" . $obj->id . "_" . strtolower(Config::get('cms.currlang.code')));
         $obj->setRawAttributes(json_decode($translation->translation, 1));
         $seo = $obj->seo()->first();
         if (!is_null($seo)) {
             Config::set('cms.seo', $seo);
         }
     }
     //
     return $obj;
 }
 /**
  * Find a model by its primary key.
  * @param  string  $name
  * @param  mixed  $key
  * @param  array  $columns
  * @return \Illuminate\Support\Collection|static|null
  */
 public static function findBy($name, $key, $columns = array('*'))
 {
     $instance = new static();
     if (is_array($key) && empty($key)) {
         return $instance->newCollection();
     }
     return $instance->newQuery()->where($name, '=', $key)->get();
 }
 /**
  * {@inheritDoc}
  */
 public static function __callStatic($method, $parameters)
 {
     $instance = new static();
     if (in_array($method, array_keys($instance->paths))) {
         return $instance->newQuery()->from($instance->getPath($method));
     }
     return call_user_func_array(array($instance, $method), $parameters);
 }
 public static function with($relations)
 {
     if (is_string($relations)) {
         $relations = func_get_args();
     }
     $instance = new static();
     return $instance->newQuery()->with($relations);
 }
 /**
  * Get all of the models from the database. Overrides the base behavior to
  * add the category slug as a condition.
  *
  * @param array $columns
  *   An array of columns to access.
  *
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public static function all($columns = ['*'])
 {
     // If there's a defined taxonomy slug, attach that.
     $instance = new static();
     if (isset($instance->taxonomy_slug) && $instance->taxonomy_slug) {
         // Return a constrained collection.
         $columns = is_array($columns) ? $columns : func_get_args();
         return $instance->newQuery()->where('taxonomy', $instance->taxonomy_slug)->get($columns);
     }
     // Return the parent's behavior, if nothing is set.
     return parent::all($columns);
 }
Example #9
0
 /**
  * Add a basic where clause to the client query.
  * Normally, Illuminate\Database\Eloquent\Model handles this method (through __call()).
  * This implementation converts foreign ids from strings to MongoIds.
  *
  * @param  string  $column
  * @param  string  $operator
  * @param  mixed   $value
  * @param  string  $boolean
  * @return Jenssegers\Mongodb\Eloquent\Builder
  */
 public static function where($column, $operator = null, $value = null, $boolean = 'and')
 {
     if (func_num_args() == 2) {
         list($value, $operator) = array($operator, '=');
     }
     if ($column == 'lrs_id') {
         $value = new \MongoId($value);
     }
     $instance = new static();
     $query = $instance->newQuery();
     return $query->where($column, $operator, $value, $boolean);
 }
Example #10
0
 /**
  * Find a model by its primary key.
  *
  * @param  mixed                                          $id
  * @param  array                                          $columns
  * @return \Illuminate\Database\Eloquent\Model|Collection
  */
 public static function find($id, $columns = array('*'))
 {
     $instance = new static();
     if (is_array($id) && empty($id)) {
         return $instance->newCollection();
     }
     $query = $instance->newQuery();
     $key = $instance->table . '.' . $instance->primaryKey;
     if (is_array($id)) {
         return $query->whereIn($key, $id)->get($columns);
     }
     return $query->where($key, '=', $id)->first($columns);
 }
Example #11
0
 /**
  *
  * Method designed to save XML data into a table
  *
  * @param SimpleXMLElement $fieldData
  *
  * @return \Illuminate\Support\Collection
  */
 public static function createFromXml(\SimpleXMLElement $fieldData)
 {
     $instance = new static();
     if (!is_null($fieldData->attributes())) {
         foreach ($fieldData->attributes() as $k => $v) {
             if ($k == 'Resource') {
                 $instance->resource = $v;
             }
             if ($k == 'Lookup') {
                 $instance->lookup_id = $v;
             }
         }
     }
     $lookup = (array) $fieldData->xpath('Lookup');
     foreach ($lookup as $field) {
         $instance->exists = false;
         $field = (array) $field;
         $instance->id = $field['Value'];
         $instance->long = $field['LongValue'];
         $instance->short = $field['ShortValue'];
         $instance->save();
     }
     return $instance->newQuery()->where('lookup_id', $instance->lookup_id)->where('resource', $instance->resource)->get();
 }
Example #12
0
 /**
  * Static query scope. Returns a query scope with all nodes which are at
  * the middle of a branch (not root and not leaves).
  *
  * @return \Illuminate\Database\Query\Builder
  */
 public static function allTrunks()
 {
     $instance = new static();
     $grammar = $instance->getConnection()->getQueryGrammar();
     $rgtCol = $grammar->wrap($instance->getQualifiedRightColumnName());
     $lftCol = $grammar->wrap($instance->getQualifiedLeftColumnName());
     return $instance->newQuery()->whereNotNull($instance->getParentColumnName())->whereRaw($rgtCol . ' - ' . $lftCol . ' != 1')->orderBy($instance->getQualifiedOrderColumnName());
 }
Example #13
0
 /**
  * Fixes the tree based on parentage info.
  *
  * Requires at least one root node. This will not update nodes with invalid parent.
  *
  * @return int The number of fixed nodes.
  */
 public static function fixTree()
 {
     $model = new static();
     $columns = [$model->getKeyName(), $model->getParentIdName(), $model->getLftName(), $model->getRgtName()];
     $nodes = $model->newQuery()->defaultOrder()->get($columns)->groupBy($model->getParentIdName());
     self::reorderNodes($nodes, $fixed);
     return $fixed;
 }
Example #14
0
 /**
  * Kick off a new query.
  *
  * @return	Builder
  */
 public static function startQuery()
 {
     // Get a new instance of the model
     $instance = new static();
     return $instance->newQuery();
 }
Example #15
0
 /**
  * @param string $uuid
  *
  * @return Card
  */
 public static function byUuid($uuid)
 {
     $instance = new static();
     $query = $instance->newQuery();
     return $query->where('uuid', $uuid)->firstOrFail();
 }
Example #16
0
 /**
  * Get the files for fileable
  *
  * @param string $fileableId fileable identifier
  * @return Collection|static[]
  */
 public static function getByFileable($fileableId)
 {
     $model = new static();
     return $model->newQuery()->rightJoin($model->getFileableTable(), $model->getTable() . '.id', '=', $model->getFileableTable() . '.fileId')->where('fileableId', $fileableId)->select([$model->getTable() . '.*'])->get();
 }
 /**
  * Begin querying the model on a given connection.
  *
  * @param string|null $connection
  *
  * @return \Magister\Services\Database\Elegant\Builder
  */
 public static function on($connection = null)
 {
     $instance = new static();
     $instance->setConnection($connection);
     return $instance->newQuery();
 }
Example #18
0
 /**
  * Get query combining current model table with the specification table.
  * SELECT * FROM table1 JOIN specsTable ON table1.id = specsTable.table1_id
  *
  * @return mixed
  */
 public static function specsQuery()
 {
     $model = new static();
     $query = $model->newQuery();
     $specsTable = static::getSpecsTable();
     return $query->join($specsTable, "{$model->getTable()}.{$model->getKeyName()}", '=', "{$specsTable}.{$model->getForeignKey()}");
 }
Example #19
0
 public static function all($table = "null", $columns = array('*'))
 {
     $instance = new static();
     $instance->setTable($table);
     return $instance->newQuery()->get($columns);
 }
Example #20
0
 /**
  * Gets items for list.
  *
  * @param string $searchQuery
  * @param string $sort
  * @return \Illuminate\Pagination\LengthAwarePaginator
  */
 public static function getList($searchQuery = '', $sort = '')
 {
     $model = new static();
     $query = $model->newQuery();
     $queryBuilder = self::getListDescriptor()->getQueryBuilder();
     if ($queryBuilder) {
         $queryBuilder($query);
     }
     $searchBy = self::getSearchDescriptor();
     if (count($searchBy) && $searchQuery) {
         $query->where($query->getQuery()->raw('1 = 1'));
         $keywords = explode(' ', trim($searchQuery));
         foreach ($searchBy as $field => $search) {
             $query->orWhere(function ($query) use($field, $keywords) {
                 foreach ($keywords as $keyword) {
                     $query->where($field, 'like', '%' . trim($keyword) . '%');
                 }
             });
         }
         self::getSearchForm()->getField('query')->setOption('value', $searchQuery);
     }
     $sortBy = $model->getTable() . '.id';
     $sortDirection = '';
     if ($sort) {
         list($sortBy, $sortDirection) = explode('#', $sort);
     }
     $query->orderBy($sortBy, $sortDirection);
     $items = $query->paginate(static::getItemsPerPage());
     foreach ($items as $item) {
         self::attachStorages($item);
     }
     return $items;
 }
Example #21
0
 public static function findIP($ip)
 {
     $instance = new static();
     return $instance->newQuery()->where('ip', '=', $ip)->first();
 }
 /**
  * Re-Index All Content
  *
  * @return array
  */
 public static function reindex()
 {
     $instance = new static();
     $all = $instance->newQuery()->get(array('*'));
     return $all->reindex();
 }
 /**
  * Remove all gallery models of the given users from the databse.
  *
  * @param  array  $userIds
  * @return integer
  */
 public static function destroyByUsers(array $userIds)
 {
     $instance = new static();
     $models = $instance->newQuery()->join('wp_postmeta', 'wp_posts.ID', '=', 'wp_postmeta.post_id')->where('wp_posts.post_type', '=', $instance->attributes['post_type'])->where('wp_postmeta.meta_key', '=', 'pal_user_id')->whereIn('wp_postmeta.meta_value', $userIds)->select(['wp_posts.ID'])->get();
     return static::destroy($models->lists('ID'));
 }
Example #24
0
 /**
  * Returns all published versions of the model.
  *
  * @param array $columns
  *   An array of columns to access.
  *
  * @return Illuminate\Database\Eloquent\Builder
  */
 protected function published($columns = ['*'])
 {
     $columns = is_array($columns) ? $columns : func_get_args();
     // If there's a defined post type, attach that.
     $instance = new static();
     $query = $instance->newQuery();
     if (isset($instance->post_type) && $instance->post_type) {
         // Return a constrained collection.
         $query->where('post_type', $instance->post_type);
     }
     // Attach the columns.
     $query->where('post_status', static::POST_STATUS_PUBLISH);
     // Return the query.
     return $query;
 }
Example #25
0
 /**
  * Returns most popular tags of date period
  *
  * @param \DateTime|string      $since      begin date
  * @param \DateTime|string|null $until      end date
  * @param string|null           $instanceId instance id
  * @param int                   $take       take count
  * @return Collection|static[]
  */
 public static function getPopularPeriod($since, $until = null, $instanceId = null, $take = 15)
 {
     $model = new static();
     $query = $model->newQuery()->rightJoin($model->getTaggableTable(), $model->getTaggableTable() . '.tagId', '=', $model->getTable() . '.id')->select([$model->getTable() . '.*', new Expression('count(*) as cnt')])->groupBy($model->getTable() . '.word')->orderBy('cnt', 'desc')->orderBy('id', 'desc')->take($take);
     $model->wherePeriod($query, $since, $until);
     if ($instanceId !== null) {
         $query->where($model->getTable() . '.instanceId', $instanceId);
     }
     return $query->get();
 }
 public static function all($columns = ['*'])
 {
     $columns = is_array($columns) ? $columns : func_get_args();
     $instance = new static();
     return $instance->newQuery()->orderBy('title', 'desc')->get($columns);
 }
Example #27
0
 /**
  * Get all of the models from the datasource.
  *
  * @return \October\Rain\Halcyon\Collection|static[]
  */
 public static function all()
 {
     $instance = new static();
     return $instance->newQuery()->get();
 }
Example #28
0
 public static function findFirst($col, $val)
 {
     $instance = new static();
     return $instance->newQuery()->where($col, '=', $val)->first();
 }
Example #29
0
 /**
  * Get all of the models from the database.
  *
  * @param  array  $columns
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public static function all($columns = array('*'))
 {
     $instance = new static();
     return $instance->newQuery()->get($columns);
 }
Example #30
-2
 /**
  * Find a model by its primary key.
  *
  * @param  mixed  $id
  * @param  array  $columns
  * @return \Illuminate\Database\Eloquent\Model|Collection|static
  */
 public static function find($id, $columns = array('*'), $enforceOnRead = null)
 {
     $enforceOnRead = $enforceOnRead === null ? \Config::get('enforce.byDefault') : $enforceOnRead;
     $instance = new static();
     $model = $instance->newQuery()->find($id, $columns);
     return $enforceOnRead ? self::enforceOnRead($model) : $model;
 }