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 / 12
ParticipantSupervisorRule
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 12
 execute
0.00% covered (danger)
0.00%
0 / 1
30.00
0.00% covered (danger)
0.00%
0 / 12
<?php
namespace common\rbac;
use common\models\Participant;
use yii\rbac\Rule;
/**
 * Checks if supervisor have rights to participant entity
 */
class ParticipantSupervisorRule extends Rule
{
    public $name = 'isParticipantSupervisor';
    /**
     * @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['participant']) && $params['participant'] instanceof Participant){
            $organization = $params['participant']->organization;
            if($organization !== null){
                $supervisor = $organization->supervisor;
                if($supervisor !== null){
                    return $supervisor->user_id === $user;
                }
            }
        }
        return false;
    }
}