Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
33.33% |
2 / 6 |
CRAP | |
33.93% |
19 / 56 |
| OrganizationController | |
0.00% |
0 / 1 |
|
33.33% |
2 / 6 |
70.53 | |
33.93% |
19 / 56 |
| behaviors | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| actions | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| actionIndex | |
0.00% |
0 / 1 |
4.66 | |
65.38% |
17 / 26 |
|||
| actionPrint | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 10 |
|||
| actionView | |
0.00% |
0 / 1 |
30.00 | |
0.00% |
0 / 15 |
|||
| findModel | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 3 |
|||
| <?php namespace frontend\controllers; | |
| use Yii; | |
| use frontend\models\OrganizationSearch; | |
| use common\models\Country; | |
| use common\models\Organization; | |
| use common\models\OrganizationProfile; | |
| use common\models\OrganizationType; | |
| use common\models\Supervisor; | |
| use yii\data\ActiveDataProvider; | |
| use yii\filters\AccessControl; | |
| use yii\helpers\ArrayHelper; | |
| use yii\web\Controller; | |
| use yii\web\NotFoundHttpException; | |
| use yii\web\Response; | |
| /** | |
| * OrganizationController implements the CRUD actions for Organization model. | |
| */ | |
| class OrganizationController extends Controller | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| 'access' => [ | |
| 'class' => AccessControl::className(), | |
| 'only' => ['update'], | |
| 'rules' => [ | |
| [ | |
| 'actions' => ['update'], | |
| 'allow' => true, | |
| 'roles' => ['@'], | |
| ], | |
| ], | |
| ], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function actions() | |
| { | |
| return [ | |
| 'update' => [ | |
| 'class' => 'frontend\controllers\organization\UpdateAction', | |
| ], | |
| ]; | |
| } | |
| /** | |
| * Lists all Organization models. | |
| * @return mixed | |
| */ | |
| public function actionIndex() | |
| { | |
| $searchModel = new OrganizationSearch(); | |
| $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
| $dataProvider->query = $dataProvider->query->with(['participants', 'participants.user', 'activityAreas']); | |
| $forbiddenParticipants = null; | |
| if(Yii::$app->user->can('eventUser')){ | |
| $participant = Yii::$app->user->getIdentity()->participant; | |
| $myMeetings = $participant->meetings; | |
| if(!empty($myMeetings)){ | |
| $forbiddenParticipants = ArrayHelper::map($myMeetings, 'guest_participant_id', 'host_participant_id'); | |
| } | |
| $myInvitations = $participant->invitations; | |
| if(!empty($myInvitations)){ | |
| $forbiddenParticipants2 = ArrayHelper::map($myInvitations, 'host_participant_id', 'guest_participant_id'); | |
| $forbiddenParticipants = ArrayHelper::merge($forbiddenParticipants, $forbiddenParticipants2); | |
| } | |
| $forbiddenParticipants[$participant->id] = $participant->id; | |
| } | |
| $organizationProfiles = OrganizationProfile::find()->select('name, id')->indexBy('id')->column(); | |
| $organizationTypes = OrganizationType::find()->select('name, id')->indexBy('id')->column(); | |
| $supervisors = Supervisor::find()->select('office_name, id')->indexBy('id')->column(); | |
| $countries = Country::find()->select('name, code')->orderBy('name')->indexBy('code')->column(); | |
| return $this->render('index', [ | |
| 'searchModel' => $searchModel, | |
| 'organizationProfiles' => $organizationProfiles, | |
| 'organizationTypes' => $organizationTypes, | |
| 'supervisors' => $supervisors, | |
| 'countries' => $countries, | |
| 'dataProvider' => $dataProvider, | |
| 'forbiddenParticipants' => $forbiddenParticipants, | |
| ]); | |
| } | |
| /** | |
| * Print a list all Organization models. | |
| * @return mixed | |
| */ | |
| public function actionPrint() | |
| { | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => Organization::find() | |
| ->with(['activityAreas', 'organizationProfile', 'organizationType', 'participants', 'participants.user']) | |
| ->active() | |
| ->orderBy([ | |
| '[[name]]' => 'ASC', | |
| ]), | |
| ]); | |
| $this->layout = false; | |
| Yii::$app->response->format = Response::FORMAT_RAW; | |
| return $this->render('print', [ | |
| 'dataProvider' => $dataProvider, | |
| ]); | |
| } | |
| /** | |
| * Displays a single Organization model. | |
| * @param integer $id | |
| * @return mixed | |
| */ | |
| public function actionView($id) | |
| { | |
| $forbiddenParticipants = []; | |
| if(!Yii::$app->user->isGuest && | |
| Yii::$app->user->getIdentity()->participant != null){ | |
| $participant = Yii::$app->user->getIdentity()->participant; | |
| $myMeetings = $participant->meetings; | |
| if(!empty($myMeetings)){ | |
| $forbiddenParticipants = ArrayHelper::map($myMeetings, 'guest_participant_id', 'host_participant_id'); | |
| } | |
| $myInvitations = $participant->invitations; | |
| if(!empty($myInvitations)){ | |
| $forbiddenParticipants2 = ArrayHelper::map($myInvitations, 'host_participant_id', 'guest_participant_id'); | |
| $forbiddenParticipants = ArrayHelper::merge($forbiddenParticipants, $forbiddenParticipants2); | |
| } | |
| $forbiddenParticipants[$participant->id] = $participant->id; | |
| } | |
| return $this->render('view', [ | |
| 'model' => $this->findModel($id), | |
| 'forbiddenParticipants' => $forbiddenParticipants, | |
| ]); | |
| } | |
| /** | |
| * 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 findModel($id) | |
| { | |
| if (($model = Organization::findOne($id)) !== null) { | |
| return $model; | |
| } else { | |
| throw new NotFoundHttpException('The requested page does not exist.'); | |
| } | |
| } | |
| } |