/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = BoothSchedules::find();
     // add conditions that should always apply here
     $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
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'booth_id' => $this->booth_id, 'attendee_id' => $this->attendee_id, 'function_id' => $this->function_id, 'cost_center_id' => $this->cost_center_id, 'status_id' => $this->status_id, 'catering' => $this->catering, 'created_on' => $this->created_on]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'product', $this->product])->andFilterWhere(['like', 'literature', $this->literature]);
     return $dataProvider;
 }
 /**
  * Updates an existing Booths model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $modelsBoothSchedules = $model->boothSchedules;
     if ($model->load(Yii::$app->request->post())) {
         //Load data from post
         $oldIDs = ArrayHelper::map($modelsBoothSchedules, 'id', 'id');
         $modelsBoothSchedules = Model::createMultiple(BoothSchedules::classname(), $modelsBoothSchedules);
         Model::loadMultiple($modelsBoothSchedules, Yii::$app->request->post());
         $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsBoothSchedules, 'id', 'id')));
         $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d');
         // validate all models
         $valid = $model->validate();
         if ($valid || !$valid) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($flag = $model->save(false)) {
                     if (!empty($deletedIDs)) {
                         BoothSchedules::deleteAll(['id' => $deletedIDs]);
                     }
                     foreach ($modelsBoothSchedules as $modelBoothSchedule) {
                         if (!empty($modelBoothSchedule->attendee_id)) {
                             $attendeeDetails = $modelBoothSchedule->attendee;
                             if (empty($modelBoothSchedule->booth_id)) {
                                 $modelBoothSchedule->booth_id = $model->id;
                                 //Below two lines can be removed
                                 $modelBoothSchedule->function_id = $attendeeDetails->function_Id;
                                 $modelBoothSchedule->cost_center_id = $attendeeDetails->group_Id;
                                 $modelBoothSchedule->isNewRecord = true;
                             }
                             $flag = $modelBoothSchedule->save(false);
                             if (!$flag) {
                                 //If data is not saved then rollback the transaction and break the loop
                                 $transaction->rollBack();
                                 break;
                             }
                         }
                     }
                 }
                 if ($flag) {
                     //If data is not saved then rollback the transaction  and redirect to view page
                     $transaction->commit();
                     return $this->redirect(['view', 'id' => $model->id]);
                 }
             } catch (\Exception $e) {
                 $transaction->rollBack();
             }
         }
     } else {
         //Booth date should be between congress start date and end date
         $congressDetail = CongressDetails::findOne($model->congress_id);
         $congressStartDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->start_date)->format('m-d-Y');
         $congressEndDate = \DateTime::createFromFormat('Y-m-d', $congressDetail->end_date)->format('m-d-Y');
         return $this->render('update', ['model' => $model, 'modelsBoothSchedules' => empty($modelsBoothSchedules) ? [new BoothSchedules()] : $modelsBoothSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]);
     }
 }
 /** Get remove My  Booth  */
 public function actionRemovemybooth()
 {
     $boothschedule = new BoothSchedules();
     $connection = Yii::$app->db;
     if (Yii::$app->request->post()) {
         $value = \Yii::$app->request->post();
         if (!empty($value['attendee_id']) && !empty($value['booth_id'])) {
             $userid = User::findOne(['id' => $value['attendee_id']]);
             if ($userid) {
                 $model = BoothSchedules::deleteAll('booth_id = :booth_id AND attendee_id = :attendee_id', [':booth_id' => $value['booth_id'], ':attendee_id' => $userid->attendee_id]);
                 if ($model) {
                     echo "Booth deleted successfully";
                 } else {
                     echo "error";
                 }
             } else {
                 echo "User is not exist in Contect List";
             }
         }
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBoothSchedules()
 {
     return $this->hasMany(BoothSchedules::className(), ['attendee_id' => 'id']);
 }
 /**
  * Finds the BoothSchedules model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return BoothSchedules the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = BoothSchedules::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBoothSchedules()
 {
     return $this->hasMany(BoothSchedules::className(), ['function_id' => 'ID']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBoothSchedules()
 {
     return $this->hasMany(BoothSchedules::className(), ['cost_center_id' => 'id']);
 }