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 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 15
MeetingHostSupervisorRule
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 15
 execute
0.00% covered (danger)
0.00%
0 / 1
42.00
0.00% covered (danger)
0.00%
0 / 15
<?php
namespace common\rbac;
use common\models\Participant;
use common\models\Meeting;
use yii\rbac\Rule;
/**
 * Checks if host participant supervisor have rights to meeting entity
 */
class MeetingHostSupervisorRule extends Rule
{
    public $name = 'isMeetingHostSupervisor';
    /**
     * @param string|integer $user the user ID.
     * @param Item $item the role or permission that this rule is associated with
     * @param array $params parameters passed to ManagerInterface::checkAccess().
     * @return boolean a value indicating whether the rule permits the role or permission it is associated with.
     */
    public function execute($user, $item, $params)
    {
        if(isset($params['meeting']) && $params['meeting'] instanceof Meeting){
            $meetingHost = $params['meeting']->hostParticipant;
            if($meetingHost !== null){
                $organization = $meetingHost->organization;
                if($organization !== null){
                    $supervisor = $organization->supervisor;
                    if($supervisor !== null){
                        return $supervisor->user_id === $user;
                    }
                }
            }
        }
        return false;
    }
}