Created
September 14, 2012 12:39
-
-
Save enyachoke/3721687 to your computer and use it in GitHub Desktop.
A three level user access control without rbac.Yii framework
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
<?php | |
/** | |
* Created by JetBrains PhpStorm. | |
* User: ubeergeek | |
* Date: 9/12/12 | |
* Time: 12:34 PM | |
* To change this template use File | Settings | File Templates. | |
*/ | |
class WebUser extends CWebUser{ | |
private $_user; | |
//is the user an admin ? | |
function getIsAdmin(){ | |
return ( $this->user && $this->user->accessLevel == User::LEVEL_ADMIN ); | |
} | |
//is the user a provider ? | |
function getIsProvider(){ | |
return ( $this->user && $this->user->accessLevel == User::LEVEL_PROVIDER ); | |
} | |
//is the user an Agent? | |
function getIsAgent(){ | |
return ( $this->user && $this->user->accessLevel == User::LEVEL_AGENT ); | |
} | |
//get the logged user | |
function getUser(){ | |
if( $this->isGuest ) | |
return; | |
if( $this->_user === null ){ | |
$this->_user = User::model()->findByPk( $this->id ); | |
} | |
return $this->_user; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment