Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 22
ChooseGuestAction
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
20.00
0.00% covered (danger)
0.00%
0 / 22
 run
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 15
 findParticipantModel
0.00% covered (danger)
0.00%
0 / 1
6.00
0.00% covered (danger)
0.00%
0 / 7
<?php
namespace backend\controllers\meeting;
use Yii;
use backend\models\ParticipantSearch;
use common\components\MeetingHelper;
use common\models\Participant;
use yii\base\Action;
use yii\data\ActiveDataProvider;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
use yii\web\NotFoundHttpException;
/**
 * Creates a new Meeting model.
 * If creation is successful, the browser will be redirected to the 'view' page.
 * @param integer $participant
 * @return mixed
 */
class ChooseGuestAction extends Action
{
    /**
     * @todo Dodac uprawnienie do wyboru goscia dla hosta (supervisor)
     */
    public function run($host)
    {
        $hostParticipant = $this->findParticipantModel($host);
        if(!Yii::$app->user->can('createMeeting', ['organization' => $hostParticipant->organization, 'host' => $hostParticipant]))
            throw new ForbiddenHttpException(Yii::t('app', 'You are not allowed to perform this action.'));
        $searchModel = new ParticipantSearch();
        $dataProvider = $searchModel->search(
            Yii::$app->request->queryParams,
            MeetingHelper::findAvailableParticipants($host)
        );
        return $this->controller->render('choose_guest', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
            'hostParticipant' => $hostParticipant,
        ]);
    }
    /**
     * 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 findParticipantModel($id)
    {
        if (($model = Participant::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}