/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = NurseStaffevent::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(['staffevent_ref' => $this->staffevent_ref, 'event_ref' => $this->event_ref, 'staff_ref' => $this->staff_ref, 'wardclerk' => $this->wardclerk, 'aid' => $this->aid, 'worker' => $this->worker, 'teamlead' => $this->teamlead, 'incharge' => $this->incharge, 'inp_id' => $this->inp_id, 'lastupdate' => $this->lastupdate]);
     $query->andFilterWhere(['like', 'team', $this->team]);
     return $dataProvider;
 }
 /**
  * Creates a new NurseStaffevent model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($event_ref)
 {
     $model = new NurseStaffevent();
     $event = NurseEvent::findOne($event_ref);
     $staff = NurseStaff::find()->where(['ward' => Yii::$app->user->identity->ward])->all();
     $staff_event = NurseStaffevent::find()->where('event_ref = :event_ref', [':event_ref' => $event_ref]);
     $dataProvider = new ActiveDataProvider(['query' => $staff_event]);
     if (isset($_POST['NurseStaffevent'])) {
         foreach ($staff as $v) {
             if (isset($_POST['NurseStaffevent'][$v->staff_ref]) && $_POST['NurseStaffevent'][$v->staff_ref]['staff_ref'] != 0) {
                 $model_s2 = new NurseStaffevent();
                 $model_s2->attributes = $_POST['NurseStaffevent'][$v->staff_ref];
                 if ($model_s2->validate()) {
                     $model_s2->save();
                 }
             }
         }
         return $this->refresh();
         //         return $this->redirect(['nurse-staffevent/create']);
     } else {
         return $this->render('create', ['model' => $model, 'staff' => $staff, 'event' => $event, 'staff_event' => $staff_event, 'dataProvider' => $dataProvider]);
     }
 }