Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
21.43% |
3 / 14 |
CRAP | |
13.73% |
14 / 102 |
| MeetingController | |
0.00% |
0 / 1 |
|
21.43% |
3 / 14 |
965.29 | |
13.73% |
14 / 102 |
| behaviors | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| actions | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| actionIndex | |
100.00% |
1 / 1 |
1 | |
100.00% |
7 / 7 |
|||
| actionPrint | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 10 |
|||
| actionPrintWithNotes | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 8 |
|||
| actionView | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 5 |
|||
| actionAccept | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 10 |
|||
| actionRefuse | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 10 |
|||
| actionDismiss | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 7 |
|||
| actionConfirmInvitation | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 12 |
|||
| actionConfirmMeeting | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 11 |
|||
| actionRefuseMeeting | |
0.00% |
0 / 1 |
20.00 | |
0.00% |
0 / 11 |
|||
| findModel | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 3 |
|||
| findParticipantModelByUserId | |
0.00% |
0 / 1 |
3.07 | |
80.00% |
4 / 5 |
|||
| <?php namespace frontend\controllers; | |
| use Yii; | |
| use frontend\components\PdfHelper; | |
| use common\models\Meeting; | |
| use common\models\Participant; | |
| use common\models\EventTime; | |
| use common\models\EventTimeSlot; | |
| use yii\data\ActiveDataProvider; | |
| use yii\filters\AccessControl; | |
| use yii\filters\VerbFilter; | |
| use yii\web\BadRequestHttpException; | |
| use yii\web\Controller; | |
| use yii\web\ForbiddenHttpException; | |
| use yii\web\NotFoundHttpException; | |
| use yii\web\Response; | |
| /** | |
| * MeetingController implements the CRUD actions for Meeting model. | |
| */ | |
| class MeetingController extends Controller | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| 'access' => [ | |
| 'class' => AccessControl::className(), | |
| 'only' => ['index', 'print', 'print-with-notes', 'view', 'create', 'accept', 'refuse', 'dismiss', 'take-note'], | |
| 'rules' => [ | |
| [ | |
| 'actions' => ['index', 'print', 'print-with-notes', 'view', 'create', 'accept', 'refuse', 'dismiss', 'take-note'], | |
| 'allow' => true, | |
| 'roles' => ['eventUser'], | |
| ], | |
| ], | |
| ], | |
| 'verbs' => [ | |
| 'class' => VerbFilter::className(), | |
| 'actions' => [ | |
| 'accept' => ['post'], | |
| 'refuse' => ['post'], | |
| 'dismiss' => ['post'], | |
| ], | |
| ], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function actions() | |
| { | |
| return [ | |
| 'create' => [ | |
| 'class' => 'frontend\controllers\meeting\CreateAction', | |
| ], | |
| 'take-note' => [ | |
| 'class' => 'frontend\controllers\meeting\TakeNoteAction', | |
| ], | |
| ]; | |
| } | |
| /** | |
| * Lists all Meeting models. | |
| * @return mixed | |
| */ | |
| public function actionIndex() | |
| { | |
| $participant = $this->findParticipantModelByUserId(); | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => Meeting::find() | |
| ->isHostOrGuestFilter($participant->id) | |
| ->with(['table', 'eventSpan', 'hostParticipant', 'guestParticipant']), | |
| ]); | |
| return $this->render('index', [ | |
| 'dataProvider' => $dataProvider, | |
| ]); | |
| } | |
| /** | |
| * | |
| * @return mixed | |
| */ | |
| public function actionPrint() | |
| { | |
| $participant = $this->findParticipantModelByUserId(); | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => Meeting::find() | |
| ->isHostOrGuest($participant->id) | |
| ->with(['table', 'eventSpan', 'hostParticipant', 'guestParticipant', 'hostParticipant.user', 'guestParticipant.user']), | |
| ]); | |
| $this->layout = false; | |
| Yii::$app->response->format = Response::FORMAT_RAW; | |
| return $this->render('print', [ | |
| 'participant' => $participant, | |
| 'dataProvider' => $dataProvider, | |
| ]); | |
| } | |
| /** | |
| * | |
| * @return mixed | |
| */ | |
| public function actionPrintWithNotes() | |
| { | |
| $participant = $this->findParticipantModelByUserId(); | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => Meeting::find() | |
| ->isHostOrGuest($participant->id), | |
| ]); | |
| $this->layout = false; | |
| Yii::$app->response->format = Response::FORMAT_RAW; | |
| return $this->render('print-with-notes', [ | |
| 'dataProvider' => $dataProvider, | |
| ]); | |
| } | |
| /** | |
| * | |
| * @param integer $id | |
| * @return mixed | |
| */ | |
| public function actionView($id) | |
| { | |
| $model = $this->findModel($id); | |
| if(!(Yii::$app->user->can('updateInvitationState', ['meeting' => $model]) || Yii::$app->user->can('deleteMeeting', ['meeting' => $model]))) | |
| throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to perform this action.')); | |
| return $this->render('view', [ | |
| 'model' => $model, | |
| ]); | |
| } | |
| /** | |
| * | |
| * @param integer $id | |
| * @return mixed | |
| */ | |
| public function actionAccept($id) | |
| { | |
| $model = $this->findModel($id); | |
| if(!Yii::$app->user->can('updateInvitationState', ['meeting' => $model])) | |
| throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to perform this action.')); | |
| if(!Yii::$app->params['meeting.confirm.isRequired'] || empty($model->guest_confirmation_token)){ | |
| $model->is_confirmed_guest = true; | |
| if($model->save()){ | |
| Yii::$app->session->setFlash('success', Yii::t('app', 'Meeting has been confirmed.')); | |
| $model->sendAcceptedByGuestEmail(); | |
| } | |
| }else{ | |
| Yii::$app->getSession()->setFlash('warning', Yii::t('app', 'Status of meeting was not changed. You need to confirm this meeting by email first.')); | |
| } | |
| return $this->redirect(['index']); | |
| } | |
| /** | |
| * | |
| * @param integer $id | |
| * @return mixed | |
| */ | |
| public function actionRefuse($id) | |
| { | |
| $model = $this->findModel($id); | |
| if(!Yii::$app->user->can('updateInvitationState', ['meeting' => $model])) | |
| throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to perform this action.')); | |
| if(!Yii::$app->params['meeting.confirm.isRequired'] || empty($model->guest_confirmation_token)){ | |
| $model->is_confirmed_guest = false; | |
| if($model->save()){ | |
| Yii::$app->session->setFlash('success', Yii::t('app', 'Meeting has been refused.')); | |
| $model->sendRefusedByGuestEmail(); | |
| } | |
| }else{ | |
| Yii::$app->getSession()->setFlash('warning', Yii::t('app', 'Status of meeting was not changed. You need to confirm this meeting by email first.')); | |
| } | |
| return $this->redirect(['index']); | |
| } | |
| /** | |
| * Deletes an existing Meeting model. | |
| * If deletion is successful, the browser will be redirected to the 'index' page. | |
| * @param integer $id | |
| * @return mixed | |
| */ | |
| public function actionDismiss($id) | |
| { | |
| $model = $this->findModel($id); | |
| if(!Yii::$app->user->can('deleteMeeting', ['meeting' => $model])) | |
| throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to perform this action.')); | |
| if($model->delete()){ | |
| Yii::$app->session->setFlash('success', Yii::t('app', 'Meeting has been canceled.')); | |
| $model->sendCanceledByHostEmail(); | |
| } | |
| return $this->redirect(['index']); | |
| } | |
| /** | |
| * Confirm meeting invitation by host. | |
| * The browser will be redirected to the 'home' page. | |
| * @param string $token | |
| * @return mixed | |
| */ | |
| public function actionConfirmInvitation($token) | |
| { | |
| try { | |
| $model = Meeting::findByHostConfirmationToken($token); | |
| if($model){ | |
| $model->is_confirmed_host = true; | |
| $model->removeHostConfirmationToken(); | |
| $model->generateGuestConfirmationToken(); | |
| if($model->save()) { | |
| Yii::$app->session->setFlash('success', Yii::t('app', 'Meeting invitation has been confirmed and sended to guest.')); | |
| $model->sendGuestConfirmationEmail(); | |
| }else{ | |
| Yii::$app->session->setFlash('error', Yii::t('app', 'Meeting invitation has not been confirmed.')); | |
| } | |
| } | |
| } catch (InvalidParamException $e) { | |
| throw new BadRequestHttpException($e->getMessage()); | |
| } | |
| return $this->goHome(); | |
| } | |
| /** | |
| * Confirm meeting by guest. | |
| * The browser will be redirected to the 'home' page. | |
| * @param integer $id | |
| * @return mixed | |
| */ | |
| public function actionConfirmMeeting($token) | |
| { | |
| try { | |
| $model = Meeting::findByGuestConfirmationToken($token); | |
| if($model){ | |
| $model->is_confirmed_guest = true; | |
| $model->removeGuestConfirmationToken(); | |
| if($model->save()) { | |
| Yii::$app->session->setFlash('success', Yii::t('app', 'Meeting has been confirmed.')); | |
| $model->sendAcceptedByGuestEmail(); | |
| }else{ | |
| Yii::$app->session->setFlash('error', Yii::t('app', 'Meeting has not been confirmed.')); | |
| } | |
| } | |
| } catch (InvalidParamException $e) { | |
| throw new BadRequestHttpException($e->getMessage()); | |
| } | |
| return $this->goHome(); | |
| } | |
| /** | |
| * Refuse meeting by guest. | |
| * The browser will be redirected to the 'home' page. | |
| * @param integer $id | |
| * @return mixed | |
| */ | |
| public function actionRefuseMeeting($token) | |
| { | |
| try { | |
| $model = Meeting::findByGuestConfirmationToken($token); | |
| if($model){ | |
| $model->is_confirmed_guest = false; | |
| $model->removeGuestConfirmationToken(); | |
| if($model->save()) { | |
| Yii::$app->session->setFlash('success', Yii::t('app', 'Meeting has been refused.')); | |
| $model->sendRefusedByGuestEmail(); | |
| }else{ | |
| Yii::$app->session->setFlash('error', Yii::t('app', 'Meeting has not been refused.')); | |
| } | |
| } | |
| } catch (InvalidParamException $e) { | |
| throw new BadRequestHttpException($e->getMessage()); | |
| } | |
| return $this->goHome(); | |
| } | |
| /** | |
| * Finds the Meeting model based on its primary key value. | |
| * If the model is not found, a 404 HTTP exception will be thrown. | |
| * @param integer $id | |
| * @return Meeting the loaded model | |
| * @throws NotFoundHttpException if the model cannot be found | |
| */ | |
| protected function findModel($id) | |
| { | |
| if (($model = Meeting::findOne($id)) !== null) { | |
| return $model; | |
| } else { | |
| throw new NotFoundHttpException('The requested page does not exist.'); | |
| } | |
| } | |
| /** | |
| * Finds the Organization model based on its primary key value. | |
| * If the model is not found, a 404 HTTP exception will be thrown. | |
| * @param integer $id | |
| * @return Organization the loaded model | |
| * @throws NotFoundHttpException if the model cannot be found | |
| */ | |
| protected function findParticipantModelByUserId($user_id = null) | |
| { | |
| if ($user_id === null) { | |
| $user_id = Yii::$app->user->id; | |
| } | |
| if (($model = Participant::findOne(['user_id' => $user_id])) !== null) { | |
| return $model; | |
| } else { | |
| throw new NotFoundHttpException('The requested page does not exist.'); | |
| } | |
| } | |
| } |