Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 38 |
| TakeNoteAction | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
110.00 | |
0.00% |
0 / 38 |
| run | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 11 |
|||
| establishType | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| findModel | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| findMeetingModel | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
| <?php namespace frontend\controllers\meeting; | |
| use Yii; | |
| use common\models\Meeting; | |
| use common\models\MeetingNote; | |
| use yii\base\Action; | |
| use yii\web\BadRequestHttpException; | |
| use yii\web\ForbiddenHttpException; | |
| use yii\web\NotFoundHttpException; | |
| /** | |
| * Take a Meeting note model. | |
| * If creation is successful, the browser will be redirected to the 'view' page. | |
| * @param integer $meeting | |
| * @return mixed | |
| */ | |
| class TakeNoteAction extends Action | |
| { | |
| public function run($meeting) | |
| { | |
| $meetingModel = $this->findMeetingModel($meeting); | |
| $type = $this->establishType($meetingModel); | |
| $model = $this->findModel($meetingModel, $type); | |
| if($model->load(Yii::$app->request->post()) && $model->save()){ | |
| return $this->controller->redirect(['index']); | |
| } | |
| // Wyswietlenie formularza tworzenia spotkania | |
| return $this->controller->render('take-note', [ | |
| 'model' => $model, | |
| ]); | |
| } | |
| protected function establishType($meetingModel) | |
| { | |
| $userId = Yii::$app->user->id; | |
| if($meetingModel->hostParticipant->user->id == $userId){ | |
| return MeetingNote::TYPE_HOST; | |
| }else if($meetingModel->guestParticipant->user->id == $userId){ | |
| return MeetingNote::TYPE_GUEST; | |
| }else{ | |
| return MeetingNote::TYPE_ADMIN; | |
| } | |
| } | |
| /** | |
| * Finds the MeetingNote model based on Meeting model and Meeting note type. | |
| * If the model is not found, a new meeting note model will be initialized. | |
| * @param common\models\Meeting $meetingModel | |
| * @param integer $type | |
| * @return MeetingNote model | |
| */ | |
| protected function findModel($meetingModel, $type) | |
| { | |
| if (($model = $meetingModel->getMeetingNotes()->where(['type' => $type])->one()) !== null) { | |
| return $model; | |
| } else { | |
| $model = new MeetingNote(); | |
| $model->type = $type; | |
| $model->meeting_id = $meetingModel->id; | |
| return $model; | |
| } | |
| } | |
| /** | |
| * 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 findMeetingModel($id) | |
| { | |
| if (($model = Meeting::findOne($id)) !== null) { | |
| return $model; | |
| } else { | |
| throw new NotFoundHttpException('The requested page does not exist.'); | |
| } | |
| } | |
| } |