/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); $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(['idnews' => $this->idnews, 'idcategory' => $this->idcategory, 'created' => $this->created, 'modified' => $this->modified, 'published' => $this->published, 'trashed' => $this->trashed, 'owner' => $this->owner]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'matter', $this->matter]); return $dataProvider; }
private function getNews($timestamp) { $assignedData = array(); $updatedData = array(); $data = array(); $status = array('code' => '0', 'errorMessage' => ""); if ($timestamp == 0) { $assignedData = News::find()->asArray()->all(); } else { $assignedData = News::find()->where('published = 1 And :timestamp < UNIX_TIMESTAMP(created)', [':timestamp' => $timestamp])->asArray()->all(); $updatedData = News::find()->where('published = 1 And ((:timestamp >= UNIX_TIMESTAMP(created) And :timestamp <= UNIX_TIMESTAMP(modified)))', [':timestamp' => $timestamp])->asArray()->all(); } $data['assignedData'] = $assignedData; $data['updatedData'] = $updatedData; return ['status' => $status, 'data' => $data]; }
/** * Finds the News model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return News the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = News::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }