Created
August 29, 2013 07:31
-
-
Save schmunk42/6375137 to your computer and use it in GitHub Desktop.
Yii RBAC bizrules with data example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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