Skip to content

Instantly share code, notes, and snippets.

@schmunk42
Created August 29, 2013 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmunk42/6375137 to your computer and use it in GitHub Desktop.
Save schmunk42/6375137 to your computer and use it in GitHub Desktop.
Yii RBAC bizrules with data example
class BizRule
{
/**
* Compares the data structure of AuthItem and AuthAssignment
* Attach this Bizrule to be an AuthItem, to compare the data structure of the AuthItem and
* assignment specified in itemname.
*
* @param $params
* @param $data
* @param $itemname
*
* @return bool
*/
static public function compareKeys($params, $data, $itemname)
{
$assignment = Yii::app()->authManager->getAuthAssignment($itemname, $params['userId']);
foreach ($data AS $key => $value) {
if (empty($assignment->data[$key])) {
return false;
}
}
return true;
}
/**
* Check if the assignment has a a data key 'language' which matches the application language
*
* @param $params
* @param $data
*
* @return bool
*/
static public function compareApplicationLanguage($params, $data)
{
//
if (isset($data['language']) && $data['language'] == Yii::app()->language) {
return true;
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment