Example #1
0
 /**
  * Метод фильтрует данные по словам
  *
  * @param string|int $search
  * @param null       $value       word
  * @param string     $delimiter   equal sign - '=', 'like' ...
  * @param string     $beforeValue First sign before value
  * @param string     $afterValue  Last sign after value
  */
 protected function filterSearch($search, $value = null, $delimiter = '=', $beforeValue = '', $afterValue = '')
 {
     if ($search) {
         $value = trim($value);
         $search = trim($search);
         /** @var Model $model */
         $model = $this->_query->getModel();
         // поиск по словам
         if (is_string($search) || is_numeric($search)) {
             $this->_query->where(function ($query) use($model, $search, $value, $delimiter, $beforeValue, $afterValue) {
                 /** @var \Illuminate\Database\Eloquent\Builder $query */
                 $tableName = $model->getTable();
                 if ($value) {
                     if (Model::hasColumn($model, $search)) {
                         $query->orWhere($tableName . '.' . $search, $delimiter, $beforeValue . $value . $afterValue);
                     }
                 } else {
                     foreach (\Schema::getColumnListing($tableName) as $column) {
                         // из-за проблем поиска с кириллицей, костыль.
                         if (!preg_match("/[\\w]+/i", $search)) {
                             if (FilterEnum::hasFilterExecuteForCyrillicColumn($column)) {
                                 continue;
                             }
                         }
                         if (Model::hasColumn($model, $column)) {
                             $query->orWhere($tableName . '.' . $column, 'like', '%' . $search . '%');
                         }
                     }
                 }
             });
         }
     }
 }
 public function setSlugAttribute($value)
 {
     $ins = new static();
     if ($ins->where('slug', $value)->count() > 0) {
         $value = $value . '-' . time();
     }
     $this->attributes['slug'] = $value;
 }
 public static function getConfiguration($key)
 {
     $model = new static();
     $row = $model->where('configuration_key', '=', $key)->first();
     if ($row != null) {
         return $row->configuration_value;
     }
 }
Example #4
0
 public static function findAll($where = null, $params = [])
 {
     $self = new static();
     $self->select();
     if ($where !== null) {
         $self->where($where, $params);
     }
     return $self->all();
 }
 public static function modify($key, $value, $lang)
 {
     if (!is_null($lang)) {
         $setting = static::where('locale', $lang);
     } else {
         $setting = new static();
     }
     $setting->where('key', $key)->update(['value' => $value]);
 }
Example #6
0
 /**
  * Get all of the models from the database.
  *
  * @param  Builder  $qb
  * @param  array    $where
  * @param  integer  $paginate (per page)
  *
  * @return \Illuminate\Database\Eloquent\Collection|static[]
  */
 public static function all(Builder $qb, $where = [], $paginate = 0)
 {
     $instance = new static();
     $request = App::make('Illuminate\\Http\\Request');
     $qb = $instance->where($qb, $where, $request);
     $qb = $instance->with($qb, $request);
     $qb = $instance->take($qb, $request);
     $paginate = Input::query('paginate', $paginate);
     return $paginate ? $qb->paginate($paginate) : $qb->get();
 }
Example #7
0
 /**
  * Build a "DELETE" query
  *
  * @param mixed $table Name of table (string of [table => alias]) to delete from
  * @param mixed[] $where Where clause array
  * @return Automatorm\Database\QueryBuilder
  */
 public static function delete($table, $where = [])
 {
     $query = new static('delete');
     $query->where($where);
     if ($table instanceof QueryBuilder) {
         $query->table_subquery = $table->resolve();
     } else {
         $query->table = $table;
     }
     return $query;
 }
Example #8
0
 /**
  * @param \Illuminate\Database\Eloquent\Builder|static $query
  * @param string $keyword
  * @param boolean $matchAllFields
  */
 public static function scopeSearch($query, $keyword, $matchAllFields = false)
 {
     return static::where(function ($query) use($keyword, $matchAllFields) {
         foreach (static::getSearchFields() as $field) {
             if ($matchAllFields) {
                 $query->where($field, 'LIKE', "%{$keyword}%");
             } else {
                 $query->orWhere($field, 'LIKE', "%{$keyword}%");
             }
         }
     });
 }
Example #9
0
 /**
  * @param string $slug
  * @param string $locale    optional, restrict search to given locale
  * @return mixed
  */
 public static function findBySlug($slug, $locale = null)
 {
     $model = new static();
     if ($model->storeSlugLocally()) {
         return $model::findBySlug($slug);
     }
     $id = $model->findRecordIdForSlugFromCmsTable($slug, $locale);
     // if it is translated, return by entry ID instead
     if ($model->isTranslationModel()) {
         return $model->where(config('pxlcms.translatable.translation_foreign_key'), $id)->first();
     }
     return $model->find($id);
 }
Example #10
0
 public static function userOverDueTasks()
 {
     $task = new static();
     return $task->where('user_id', Auth::user()->id)->where('completed', false)->where('due_date', '<', Carbon::now())->orderBy('due_date', 'ASC')->with('recruit')->get();
 }
Example #11
0
 public static function getByPublicCode($code)
 {
     $instance = new static();
     return $instance->where('public_code', $code)->firstOrFail();
 }
Example #12
0
 public static function reset($sql = '')
 {
     // 保存最后的数据库操作语句
     if ($sql) {
         static::$lastSql = $sql;
     }
     static::$pdo = '';
     static::$pk = array('key' => 'id', 'value' => '');
     static::$table = '';
     // 默认是 AR 的调用模式, 获取当前 AR 类名,即为表名
     static::$where = '';
     static::$orWhere = '';
     static::$sqlSelect = array('fields' => '', 'group' => '', 'order' => '', 'limit' => '');
     static::$saveData = [];
     static::$bindValue = [];
 }
Example #13
0
 /**
  * Create view from params
  *
  * @param   array $params
  * @param   array $columns
  *
  * @return  static
  */
 public static function fromParams(array $params, array $columns = null)
 {
     $view = new static(MonitoringBackend::instance($params['backend']), $columns);
     foreach ($params as $key => $value) {
         if ($view->isValidFilterTarget($key)) {
             $view->where($key, $value);
         }
     }
     if (isset($params['sort'])) {
         $order = isset($params['order']) ? $params['order'] : null;
         if ($order !== null) {
             if (strtolower($order) === 'desc') {
                 $order = self::SORT_DESC;
             } else {
                 $order = self::SORT_ASC;
             }
         }
         $view->sort($params['sort'], $order);
     }
     return $view;
 }
Example #14
0
 /**
  *  Function to check if slug exists
  *
  * @access  public
  * @param   string          $slugField
  * @param   string          $slug
  * @param   integer|string  $id
  * @return  string          $slug
  */
 public static function checkSlug($slugField, $slug, $id = null)
 {
     $instance = new static();
     $slug = $slug;
     $query = $instance->where($slugField, $slug);
     if ($id != null) {
         $query->whereNotIn($instance->getKeyName(), [$id]);
     }
     $nObjects = $query->count();
     if ($nObjects > 0) {
         $suffix = 0;
         while ($nObjects > 0) {
             $suffix++;
             $slug = $slug . '-' . $suffix;
             $nObjects = $instance->where($slugField, $slug)->count();
         }
     }
     return $slug;
 }
 /**
  * Get all existing slugs that are similar to the given slug.
  *
  * @param string $slug
  * @return array
  */
 protected function getExistingSlugs($slug)
 {
     $config = $this->getSluggableConfig();
     $save_to = $config['save_to'];
     $include_trashed = $config['include_trashed'];
     $instance = new static();
     $query = $instance->where($save_to, 'LIKE', $slug . '%');
     // include trashed models if required
     if ($include_trashed && $this->usesSoftDeleting()) {
         $query = $query->withTrashed();
     }
     // get a list of all matching slugs
     $list = $query->lists($save_to, $this->getKeyName());
     // Laravel 5.0/5.1 check
     return $list instanceof Collection ? $list->all() : $list;
 }
 /**
  * Retrieves tree by condition.
  *
  * @param mixed $column
  * @param mixed $operator
  * @param mixed $value
  * @param array $columns
  * @return \Franzose\ClosureTable\Extensions\Collection
  */
 public static function getTreeWhere($column, $operator = null, $value = null, array $columns = ['*'])
 {
     /**
      * @var Entity $instance
      */
     $instance = new static();
     $columns = $instance->prepareTreeQueryColumns($columns);
     return $instance->where($column, $operator, $value)->get($columns)->toTree();
 }
Example #17
0
 /**
  * Find a comment by post ID
  *
  * @param int $postId
  * @return \Corcel\Comment
  */
 public static function findByPostId($postId)
 {
     $instance = new static();
     return $instance->where('comment_post_ID', $postId)->get();
 }
Example #18
0
 /**
  * Load the first entity by it's attribute
  *
  * @param $attribute
  * @param $value
  * @param array $columns
  * @return mixed
  */
 public static function findByAttribute($attribute, $value, $columns = ['*'])
 {
     $model = new static();
     return $model->where($attribute, '=', $value)->first($columns);
 }
Example #19
0
 /**
  * @param \Illuminate\Database\Query\Builder|static $query
  *
  * @return \Illuminate\Database\Query\Builder|static
  */
 public function scopeFeatured($query)
 {
     return $query->where("{$this->table}.featured", 1);
 }
Example #20
0
 public static function getBySlug($slug)
 {
     $instance = new static();
     $config = \App::make('config')->get('eloquent-sluggable::config');
     $config = array_merge($config, $instance->sluggable);
     return $instance->where($config['save_to'], $slug)->get();
 }
Example #21
0
 public static function getPermissionByName($name)
 {
     $instance = new static();
     return $instance->where('name', '=', $name)->first();
 }
Example #22
0
 public static function getByKey($key)
 {
     $model = new static();
     return $model->where('key', '=', $key)->first();
 }
 public static function findBySlug($slug)
 {
     $instance = new static();
     $config = $instance->getSluggableConfig();
     return $instance->where(\DB::raw($config['save_to_dbcol']), $slug)->first();
 }
 /**
  * @param static $query
  */
 public function scopeNuevos($query)
 {
     return $query->where('leido', 0);
 }
 public static function getMostActiveApps($count = 5)
 {
     $ins = new static();
     $client = new Client(['base_uri' => config('analytics.base_url')]);
     try {
         $response = $client->get('total-hits', ['headers' => ['X-API-KEY' => config('analytics.X-API-KEY'), 'X-API-SECRET' => config('analytics.X-API-SECRET')], 'query' => ['hit_contents' => 'api_key']]);
     } catch (\Exception $e) {
         return false;
     }
     if ($response->getStatusCode() != 200) {
         return false;
     }
     $result = json_decode($response->getBody()->getContents(), true);
     $result_apps = $result['api_key']['data'];
     usort($result_apps, function ($a, $b) {
         return $b['hit'] - $a['hit'];
     });
     return array_map(function ($app) use($ins) {
         $info = $ins->where('key', $app['info'])->first(['_id', 'name', 'key']);
         $app['id'] = $info->id;
         $app['name'] = $info->name;
         $app['key'] = $info->key;
         unset($app['info']);
         return $app;
     }, array_slice($result_apps, 0, $count));
 }
Example #26
0
 /**
  * @param \Illuminate\Database\Query\Builder|static $query
  * @param string $system_name
  *
  * @return \Illuminate\Database\Query\Builder|static
  */
 public function scopeSystemName($query, $system_name)
 {
     return $query->where('system_name', $system_name);
 }
Example #27
0
File: Base.php Project: nblight/mvc
 private static function reset()
 {
     static::$select = '*';
     static::$where = '';
     static::$orderby = '';
     static::$limit = '';
 }
Example #28
0
 /**
  * Get admin member lists with pagination.
  *
  * @param  integer $perPage
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public static function getAdminWithPaginate($perPage = 20)
 {
     $instance = new static();
     return $instance->where('role', '=', 'admin')->latest()->paginate($perPage);
 }
Example #29
0
 /**
  * Get all existing slugs that are similar to the given slug.
  *
  * @param string $slug
  * @return array
  */
 protected function getExistingSlugs($slug)
 {
     $config = $this->getSluggableConfig();
     $save_to = $config['save_to'];
     $include_trashed = $config['include_trashed'];
     $instance = new static();
     //check for direct match or something that has a separator followed by a suffix
     $query = $instance->where(function ($query) use($save_to, $config, $slug) {
         $query->where($save_to, $slug);
         $query->orWhere($save_to, 'LIKE', $slug . $config['separator'] . '%');
     });
     // include trashed models if required
     if ($include_trashed && $this->usesSoftDeleting()) {
         $query = $query->withTrashed();
     }
     // get a list of all matching slugs
     $list = $query->lists($save_to, $this->getKeyName());
     // Laravel 5.0/5.1 check
     return $list instanceof Collection ? $list->all() : $list;
 }
 /**
  * Returns all transactions by the specified state.
  *
  * @param string $state
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public static function getByState($state)
 {
     $instance = new static();
     return $instance->where('state', $state)->get();
 }