获取文章列表ActiveDataProvider

@param array $where
@return \yii\data\ActiveDataProvider
971644
public static function getArticleList($where = [])
    {
        $where = array_merge($where, ['type' => ArticleModel::ARTICLE, 'status'=>ArticleModel::ARTICLE_PUBLISHED]);
        $query = ArticleModel::find()->select([])->where($where);
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'defaultOrder' => [
                    'sort' => SORT_ASC,
                    'id' => SORT_DESC,
                ]
            ]
        ]);
        return $dataProvider;
    }
714627
public function search($params)
    {
        $query = Tag::find()->orderBy(['id' => SORT_DESC]);

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }
        $query->andFilterWhere(['like', 'name', $this->name]);

        return $dataProvider;
    }
671041
public function search($params)
    {
        $query = Media::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'defaultOrder' => ['id' => SORT_DESC],
            ],
        ]);
        $this->load($params);
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere([
            'id' => $this->id,
            'size' => $this->size,
            'model_id' => $this->model_id,
            'created_at' => $this->created_at,
        ]);
        $query->andFilterWhere(['like', 'file', $this->file])
            ->andFilterWhere(['like', 'type', $this->type])
            ->andFilterWhere(['like', 'name', $this->type])
            ->andFilterWhere(['like', 'model', $this->type]);
        return $dataProvider;
    }
1374115
public function search($params)
    {
        $query = SeoRedirect::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'defaultOrder' => ['id' => SORT_DESC],
            ],
        ]);
        $this->load($params);
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere([
            SeoRedirect::tableName() . '.id' => $this->id,
            SeoRedirect::tableName() . '.code' => $this->code,
        ])->andFilterWhere(['LIKE', SeoRedirect::tableName() . '.from', $this->from])
            ->andFilterWhere(['LIKE', SeoRedirect::tableName() . '.to', $this->to]);
        return $dataProvider;
    }
502400
public function updateOrCreateBy(array $where, array $inputs = [])
    {
        $inputs = $this->purifyInputs($inputs);

        $query = $this->make();

        $query = $this->applyWhere($query, $where);

        $model = $query->first();

        if ($model) {
            $model->update($inputs);

            return $model;
        } else {
            return $this->model->create($inputs);
        }
    }
1117110
public function GetCountWhere($Where = FALSE) {
      if (is_array($Where))
         $this->SQL->Where($Where);
         
      return $this->SQL->Select('CommentID', 'count', 'CountComments')
         ->From('Comment')
         ->Get()
         ->FirstRow()
         ->CountComments;
   }
245189
public function deleteWhere(array $where)
    {
        $this->applyScope();

        $temporarySkipPresenter = $this->skipPresenter;
        $this->skipPresenter(true);

        $this->applyConditions($where);

        $deleted = $this->model->delete();

        event(new RepositoryEntityDeleted($this, $this->model->getModel()));

        $this->skipPresenter($temporarySkipPresenter);
        $this->resetModel();

        return $deleted;
    }
1209322
public function parseWhere($where)
    {
        if (empty($where)) {
            $where = [];
        }

        $filter = [];
        foreach ($where as $logic => $val) {
            foreach ($val as $field => $value) {
                if ($value instanceof \Closure) {
                    // 使用闭包查询
                    $query = new MongoQuery($this->connection);
                    call_user_func_array($value, [& $query]);
                    $filter[$logic][] = $this->parseWhere($query->getOptions('where'));
                } else {
                    if (strpos($field, '|')) {
                        // 不同字段使用相同查询条件（OR）
                        $array = explode('|', $field);
                        foreach ($array as $k) {
                            $filter['$or'][] = $this->parseWhereItem($k, $value);
                        }
                    } elseif (strpos($field, '&')) {
                        // 不同字段使用相同查询条件（AND）
                        $array = explode('&', $field);
                        foreach ($array as $k) {
                            $filter['$and'][] = $this->parseWhereItem($k, $value);
                        }
                    } else {
                        // 对字段使用表达式查询
                        $field = is_string($field) ? $field : '';
                        $filter[$logic][] = $this->parseWhereItem($field, $value);
                    }
                }
            }
        }
        return $filter;
    }
920845
public function update(array $data, array $where)
    {
        if (!$where) {
            die ('Where is required');
        }

        if (!$data) {
            die ('Data is required');
        }

        return $this->_update($data, $where);
    }
444519
protected function checkBeforeSave($data, $where)
    {
        if (!empty($data)) {

            // 数据对象赋值
            foreach ($data as $key => $value) {
                $this->setAttr($key, $value, $data);
            }

            if (!empty($where)) {
                $this->exists      = true;
                $this->updateWhere = self::parseWhere($where);
            }
        }

        // 数据自动完成
        $this->autoCompleteData($this->auto);

        // 事件回调
        if (false === $this->trigger('before_write')) {
            return false;
        }

        return true;
    }
922872
public function search($params)
    {
        $query = $this->finder->getUserQuery();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]],
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $modelClass = $query->modelClass;
        $table_name = $modelClass::tableName();

        if ($this->created_at !== null) {
            $date = strtotime($this->created_at);
            $query->andFilterWhere(['between', $table_name . '.created_at', $date, $date + 3600 * 24]);
        }

        $query->andFilterWhere(['like', $table_name . '.username', $this->username])
              ->andFilterWhere(['like', $table_name . '.email', $this->email])
              ->andFilterWhere([$table_name . '.id' => $this->id])
              ->andFilterWhere([$table_name . '.registration_ip' => $this->registration_ip]);

        return $dataProvider;
    }
1223935
public function search($params)
    {
        $query = self::find()->orderBy('created_at DESC');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            return $dataProvider;
        }

        if ($this->tagIds) {
            $query->joinWith('tags')->andFilterWhere(['in', Tag::tableName() . '.id', $this->tagIds]);
        }

        return $dataProvider;
    }
946728
public function firstOrFailBy(array $where = [], array $with = [])
    {
        $query = $this->make($with);

        $query = $this->applyWhere($query, $where);

        return $query->firstOrFail();
    }
791592
public function deleteWhere(array $where)
    {
        $this->applyScope();

        $this->applyConditions($where);

        $deleted = $this->model->delete();

        event(new RepositoryEntityDeleted($this, $this->model->getModel()));

        $this->resetModel();

        return $deleted;
    }
1098876
public function search($params = [])
    {
        $query = Server::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'osimage' => $this->osimage,
            'livecd'  => $this->livecd,
        ]);

        return $dataProvider;
    }
1337808
public function search($params)
    {
        $query = self::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => ['defaultOrder' => ['id' => SORT_DESC]],
            'pagination' => [
                'pageSize' => $this->pageSize,
            ],
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere(['id' => $this->id]);
        $query->andFilterWhere(['like', 'jobCode', $this->jobCode]);
        $query->andFilterWhere(['status' => $this->status]);
        $query->andFilterWhere(['like', 'messages', $this->messages]);

        return $dataProvider;
    }
911648
public function isOne(Array $where)
    {
        $param = '';
        foreach ($where as $key => $value) {
            if (is_int($key)) { //如果下标是数字，则不用下标拼装sql
                $param .= $value . ' AND ';
            } else {
                $param .= "$key='$value' AND ";
            }
        }
        $param = substr($param, 0, -4);
        $this->sql = "SELECT count(*) FROM { $this->_table } WHERE $param LIMIT 1";
        return $this->execute()->rowCount();
    }