public static function getInstance() { if (isset(self::$_instance)) { return self::$_instance; } $c = __CLASS__; self::$_instance = new $c(); $res = db_query_params('SELECT r.role_id FROM pfo_role r, pfo_role_class c WHERE r.role_class = c.class_id AND c.class_name = "$1"', array('PFO_RoleLoggedIn')); if (!$res || !db_numrows($res)) { throw new Exception("No PFO_RoleLoggedIn role in the database"); } self::$_instance->_role_id = db_result($res, 0, 'role_id'); $hook_params = array(); $hook_params['role'] =& self::$_instance; plugin_hook("role_get", $hook_params); self::$_instance->fetchData(self::$_instance->_role_id); return self::$_instance; }
public function getRoleById($role_id) { if (array_key_exists($role_id, $this->_cached_roles)) { return $this->_cached_roles[$role_id]; } if (USE_PFO_RBAC) { $res = db_query_params('SELECT c.class_name, r.home_group_id FROM pfo_role r, pfo_role_class c WHERE r.role_class = c.class_id AND r.role_id = $1', array($role_id)); if (!$res || !db_numrows($res)) { return NULL; } $class_id = db_result($res, 0, 'class_name'); switch ($class_id) { case 'PFO_RoleExplicit': $group_id = db_result($res, 0, 'home_group_id'); $group = group_get_object($group_id); $this->_cached_roles[$role_id] = new Role($group, $role_id); return $this->_cached_roles[$role_id]; case 'PFO_RoleAnonymous': $this->_cached_roles[$role_id] = RoleAnonymous::getInstance(); return $this->_cached_roles[$role_id]; case 'PFO_RoleLoggedIn': $this->_cached_roles[$role_id] = RoleLoggedIn::getInstance(); return $this->_cached_roles[$role_id]; default: throw new Exception("Not implemented"); } } else { $res = db_query_params('SELECT group_id FROM role r WHERE role_id = $1', array($role_id)); if (!$res || !db_numrows($res)) { return NULL; } $group_id = db_result($res, 0, 'group_id'); $group = group_get_object($group_id); return new Role($group, $role_id); } }