DaSourcerer/yii2-yiiboard

View on GitHub
components/rbac/PollRule.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace app\modules\yboard\components\rbac;

use yii\rbac\Rule;

/**
 * Checks if blog owner matches user passed via params
 */
class PollRule extends Rule
{
    public $name = 'isYourPoll';

    /**
     * @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)
    {
        return isset($params['poll']) ? $params['poll']->user_id == $user || $params['isModerator'] : false;
    }
}