示例#1
0
 /**
  * Activation User method
  *
  * @package     base-app
  * @version     2.0
  */
 public function activation()
 {
     if ($this->getRole()) {
         // This user has login role, activation has already been completed
         return NULL;
     } else {
         // Add login role
         $role = new RolesUsers();
         $role->user_id = $this->id;
         $role->role_id = Roles::findFirst(array('name="login"'))->id;
         if ($role->create() === true) {
             return TRUE;
         } else {
             \Baseapp\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
示例#2
0
 /**
  * Get a list of roles a user has
  * Or check if user has specific role
  * by adding the role id or name
  *
  * @param $user_id
  * @return array
  */
 public static function getUserRoles($user_id, $role = FALSE)
 {
     // search if user has a specific role
     if ($role) {
         if (is_int($role)) {
             // searching by role if
             $search = RolesUsers::find(array('conditions' => "user_id = '{$user_id}'' AND role_id = '{$role}'"));
             if ($search) {
                 return TRUE;
             }
         } else {
             // search by role name
             $type = Roles::findFirstByName($role);
             //print_r($type);exit;
             if (count($type) > 0) {
                 $search = RolesUsers::find(array('conditions' => "user_id = '{$user_id}' AND role_id = '{$type->id}'"));
                 //print_r($type->id);exit;
                 if (count($search) > 0) {
                     return TRUE;
                 }
             }
         }
     } else {
         // get all user roles as an array
         $roles = RolesUsers::find(array('conditions' => "user_id = {$user_id}"));
         if ($roles) {
             $ro = array();
             foreach ($roles as $role) {
                 $r = Roles::findFirst(array("id = {$role->role_id}"));
                 $ro[] = array('id' => $role->role_id, 'name' => $r->name);
             }
             return $ro;
         }
     }
 }