Created
November 14, 2014 09:45
-
-
Save raminious/88d10dfc72e25b875fe1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* get user roles | |
*/ | |
public function getRoles(){ | |
$roles = array(); | |
$sql = sprintf('select itemname from %s where userid = %d', Yii::app()->authManager->assignmentTable, Yii::app()->user->id); | |
//cache dependency | |
$dependency = new CDbCacheDependency('SELECT MAX(lastModified) FROM ' . Yii::app()->authManager->assignmentTable); | |
foreach (array_values(Yii::app()->db->cache(86400, $dependency)->createCommand($sql)->queryAll()) as $row) | |
$roles[] = $row['itemname']; | |
//add default roles to user if has no role | |
if (empty($roles)) | |
$roles[] = Yii::app()->user->isGuest ? 'guest' : 'authenticated'; | |
return $roles; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment