Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = StackTrends::find()->joinWith(['stack' => function ($query) {
         $query->from(['stack' => 'stack']);
     }])->orderBy(['created_at' => SORT_DESC]);
     $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;
     }
     if ($this->created_at) {
         $date = explode(' - ', $this->created_at);
         if (count($date) == 2) {
             $query->andFilterWhere(['>=', $this::tableName() . '.created_at', $date[0] . ' 00:00:00']);
             $query->andFilterWhere(['<=', $this::tableName() . '.created_at', $date[1] . ' 23:59:59']);
         }
     }
     if ($this->updated_at) {
         $date = explode(' - ', $this->updated_at);
         if (count($date) == 2) {
             $query->andFilterWhere(['>=', $this::tableName() . '.updated_at', $date[0] . ' 00:00:00']);
             $query->andFilterWhere(['<=', $this::tableName() . '.updated_at', $date[1] . ' 23:59:59']);
         }
     }
     $query->andFilterWhere(['id' => $this->id, 'stack_id' => $this->stack_id, $this::tableName() . '.price' => $this->price])->andFilterWhere(['like', 'stack.code', $this->code])->andFilterWhere(['like', 'stack.name', $this->name])->orderBy(['created_at' => SORT_DESC]);
     return $dataProvider;
 }
Пример #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getStackTrends()
 {
     return $this->hasMany(StackTrends::className(), ['stack_id' => 'id']);
 }