/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Rents::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, 'book_id' => $this->book_id, 'user_id' => $this->user_id, 'rent_date' => $this->rent_date, 'prev_date' => $this->prev_date, 'status' => $this->status]);
     return $dataProvider;
 }
 /**
  * Updates a new Rents model with closing info.
  * @return mixed
  */
 public function actionClose()
 {
     if (isset($_GET['book_id'])) {
         if ($model = Rents::find()->where(['book_id' => $_GET['book_id'], 'user_id' => Yii::$app->user->id, 'status' => 'rented'])->one()) {
             $model->prev_date = date('Y-m-d', time());
             $model->status = 'closed';
             $model->save();
             $book = Books::findOne($model->book_id)->updateStatus('available');
         }
         return $this->redirect(['book/index']);
     } else {
         return $this->redirect(['book/index']);
     }
 }