示例#1
0
 /**
  * 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];
 }