Skip to content

Instantly share code, notes, and snippets.

@raminious
Created November 14, 2014 09:45
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 raminious/88d10dfc72e25b875fe1 to your computer and use it in GitHub Desktop.
Save raminious/88d10dfc72e25b875fe1 to your computer and use it in GitHub Desktop.
/*
* 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