/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function searchAttendees($params) { $query = MeetingSchedules::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, 'congress_id' => $this->congress_id, 'meeting_id' => $this->meeting_id, 'attendee_id' => $this->attendee_id, 'ol_attendee_id' => $this->ol_attendee_id, 'state_rule' => $this->state_rule, 'consultant' => $this->consultant]); $query->andWhere('attendee_id is not null'); return $dataProvider; }
/** * Finds the MeetingSchedules model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MeetingSchedules the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MeetingSchedules::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getMeetingSchedules0() { return $this->hasMany(MeetingSchedules::className(), ['attendee_id' => 'id']); }
/** * Updates an existing MeetingDetails 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); $modelMeetingSchedules = $model->meetingSchedules; if ($model->load(Yii::$app->request->post())) { $oldIDs = ArrayHelper::map($modelMeetingSchedules, 'id', 'id'); $modelMeetingSchedules = Model::createMultiple(MeetingSchedules::classname(), $modelMeetingSchedules); Model::loadMultiple($modelMeetingSchedules, Yii::$app->request->post()); $deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelMeetingSchedules, 'id', 'id'))); // ajax validation if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ArrayHelper::merge(ActiveForm::validateMultiple($modelMeetingSchedules), ActiveForm::validate($model)); } $model->date = \DateTime::createFromFormat('m-d-Y', $model->date)->format('Y-m-d'); // validate all models $valid = $model->validate(); if ($valid) { $transaction = \Yii::$app->db->beginTransaction(); try { if ($flag = $model->save(false)) { if (!empty($deletedIDs)) { MeetingSchedules::deleteAll(['id' => $deletedIDs]); } foreach ($modelMeetingSchedules as $modelMeetingSchedule) { if (empty($modelMeetingSchedule->congress_id)) { $modelMeetingSchedule->meeting_id = $model->id; $modelMeetingSchedule->congress_id = $model->congress_id; $modelMeetingSchedule->isNewRecord = true; } if ($modelMeetingSchedule->attendee_id > 0 || $modelMeetingSchedule->ol_attendee_id > 0) { $flag = $modelMeetingSchedule->save(false); } } $postData = \Yii::$app->request->post(); $olAttendeeData = isset($postData['OlAttendees']) ? $postData['OlAttendees'] : []; foreach ($olAttendeeData as $olAttendeeInfo) { // print_r($olAttendeeInfo); if (!empty($olAttendeeInfo['name']) && (!isset($olAttendeeInfo['id']) || empty($olAttendeeInfo['id']))) { $olAttendeeModel = new \backend\models\OlAttendees(); $olAttendeeModel->user_type_id = 1; $parts = explode(" ", $olAttendeeInfo['name']); $lastname = array_pop($parts); $firstname = implode(" ", $parts); $olAttendeeModel->first_name = $firstname; $olAttendeeModel->last_name = $lastname; $olAttendeeModel->name = $olAttendeeInfo['name']; $olAttendeeModel->ol_bio = $olAttendeeInfo['ol_bio']; $olAttendeeModel->ol_phone_no = $olAttendeeInfo['ol_phone_no']; $olAttendeeModel->ol_email = $olAttendeeInfo['ol_email']; $olAttendeeModel->is_active = 1; $olAttendeeModel->isNewRecord = true; if ($olAttendeeModel->validate()) { if ($flag = $olAttendeeModel->save(false)) { $olAttendeeId = $olAttendeeModel->id; $meetingScheduleModel = new MeetingSchedules(); $meetingScheduleModel->meeting_id = $model->id; $meetingScheduleModel->congress_id = $model->congress_id; $meetingScheduleModel->ol_attendee_id = $olAttendeeId; $meetingScheduleModel->isNewRecord = true; $flag = $meetingScheduleModel->save(false); if (!$flag) { $transaction->rollBack(); break; } } } } } } if ($flag) { $transaction->commit(); return $this->redirect(['view', 'id' => $model->id]); } } catch (\Exception $e) { $transaction->rollBack(); } } } else { //Meeting 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, 'modelMeetingSchedules' => empty($modelMeetingSchedules) ? [new MeetingSchedules()] : $modelMeetingSchedules, 'congressStartDate' => $congressStartDate, 'congressEndDate' => $congressEndDate]); } }
/** * Remove meeting from user's schedule */ public function actionRemovemeeting() { $connection = Yii::$app->db; if (Yii::$app->request->post()) { $value = \Yii::$app->request->post(); $user = User::findOne(['id' => $value['userid']]); if ($user) { $congress = $value['congress']; $meetingid = $value['meeting']; $model = \backend\models\MeetingSchedules::deleteAll('congress_id = :congress_id AND meeting_id = :meeting_id AND attendee_id = :attendee_id', [':congress_id' => $congress, ':meeting_id' => $meetingid, ':attendee_id' => $user->attendee_id]); if ($model) { echo 'Meeting deleted successfully'; } } else { echo "User is not exist in Contect List"; } } }