Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param string $id
  *
  * @return ActiveDataProvider
  */
 public function search($params, $id = null)
 {
     $query = is_null($id) ? Articles::find()->with('category') : Articles::find()->where(['category_id' => $id])->with('category');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => ['pagesize' => 10, 'forcePageParam' => false, 'pageSizeParam' => false]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created' => $this->created, 'updated' => $this->updated, 'category_id' => $this->category_id, 'comments_status' => $this->comments_status, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Articles::find()->where(['publish_status' => 'publish']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'author_id' => $this->author_id, 'publish_date' => $this->publish_date, 'rank' => $this->rank]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'anons', $this->anons])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'picture_path', $this->picture_path])->andFilterWhere(['like', 'publish_status', $this->publish_status]);
     return $dataProvider;
 }
Esempio n. 3
0
 public function getArticlesPage($category = false)
 {
     $condition = ['category_id' => $category->id, 'status' => 10];
     if (!$category) {
         $condition = array_splice($condition, 1, 1);
     }
     $query = Articles::find()->where($condition)->with('category');
     if (!$query->count()) {
         return false;
     }
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $query->count(), 'forcePageParam' => false, 'pageSizeParam' => false]);
     $articles = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return ['articles' => $articles, 'pagination' => $pagination];
 }
Esempio n. 4
0
 public static function getModelForAutocomplete()
 {
     return Articles::find()->select(['id as value', 'title as value'])->asArray()->all();
 }
 /**
  * Updates an existing Comments model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->updated = date('Y-m-d');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     }
     $data = ArrayHelper::map(Articles::find()->all(), 'id', 'title');
     return $this->render('update', ['data' => $data, 'model' => $model, 'items' => $this->getItems()]);
 }