Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Data::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(['id' => $this->id, 'first_p' => $this->first_p, 'sec_p' => $this->sec_p, 'quantity' => $this->quantity]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'meta_k', $this->meta_k])->andFilterWhere(['like', 'meta_d', $this->meta_d])->andFilterWhere(['like', 'cat', $this->cat])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'image', $this->image]);
     return $dataProvider;
 }
 public function actionComplete()
 {
     $id = Yii::$app->request->get('id');
     $model = Orders::findOne($id);
     if ($model->complite == 1) {
         $complite = 2;
     } else {
         $complite = 1;
     }
     $products = unserialize($model->product);
     foreach ($products as $key => $val) {
         $q = Data::find()->where(['title' => $val['title']])->one();
         if ($complite == 2) {
             $q->quantity = $q->quantity - $val['quantity'];
         } else {
             $q->quantity = $q->quantity + $val['quantity'];
         }
         $q->update();
     }
     $model->complite = $complite;
     $model->update();
 }