本文整理汇总了PHP中Roles::getRoleInfoByID方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::getRoleInfoByID方法的具体用法?PHP Roles::getRoleInfoByID怎么用?PHP Roles::getRoleInfoByID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::getRoleInfoByID方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_user_role
/**
* Setting User role into database for the corresponding user and then load user role whenever that user is loaded.
* @param array of integers $user_role User is defining their access permission through this user role
*/
public function set_user_role($user_roles)
{
Logger::log("Enter: function User::add_user_role");
if (!$this->is_active) {
throw new PAException(OPERATION_NOT_PERMITTED, "User is already been deleted");
}
if (empty($user_roles)) {
throw new PAException(REQUIRED_PARAMETERS_MISSING, "Required variable not specified");
}
// Inserting user roles for corresponding user_id.
for ($i = 0; $i < count($user_roles); $i++) {
$role_info = Roles::getRoleInfoByID((int) $user_roles[$i]['role_id']);
$sql = 'SELECT * FROM {users_roles} WHERE user_id = ? AND role_id = ?';
$data = array($this->user_id, $user_roles[$i]['role_id']);
$res = Dal::query($sql, $data);
$row = $res->fetchRow(DB_FETCHMODE_OBJECT);
if (!empty($row) && is_object($row)) {
// role exists - just update role extra info
if (!empty($user_roles[$i]['extra'])) {
if ($role_info['type'] == 'group') {
$existing_extra = !empty($row->extra) ? unserialize($row->extra) : array();
$new_extra = unserialize($user_roles[$i]['extra']);
foreach ($new_extra['groups'] as $grp) {
if (empty($existing_extra['groups'])) {
$existing_extra['groups'] = array((int) $grp);
} else {
foreach ($existing_extra['groups'] as $_i => $_v) {
$existing_extra['groups'][$_i] = (int) $_v;
}
if (!in_array((int) $grp, $existing_extra['groups'])) {
array_push($existing_extra['groups'], (int) $grp);
}
}
}
$user_roles[$i]['extra'] = serialize($existing_extra);
}
$sql = 'UPDATE {users_roles} SET extra = ? WHERE user_id = ? AND role_id = ?';
$data = array($user_roles[$i]['extra'], $this->user_id, $user_roles[$i]['role_id']);
}
} else {
// role does not exists - assign new role
if (empty($user_roles[$i]['extra'])) {
// if extra info is empty - set default extras for new user role
$user_roles[$i]['extra'] = array('user' => true, 'network' => true, 'groups' => array());
}
$sql = 'INSERT into {users_roles} (user_id, role_id, extra) values (?, ?, ?)';
$data = array($this->user_id, $user_roles[$i]['role_id'], $user_roles[$i]['extra']);
}
Dal::query($sql, $data);
}
Logger::log("Exit: function User::add_user_role");
}
示例2: importRolesInfo
public function importRolesInfo()
{
$roles = new Roles();
$roles_data = array();
$roles_info = $roles->get_multiple(null, DB_FETCHMODE_ASSOC);
foreach ($roles_info as &$role) {
$roles_data[] = Roles::getRoleInfoByID($role['id'], DB_FETCHMODE_ASSOC);
}
return $roles_data;
}
示例3: restoreRoleSettings
private function restoreRoleSettings($restore_roles, $_msg = null)
{
try {
if (count($restore_roles) > 0) {
$roles = new Roles();
$roles_info = $roles->get_multiple(null);
foreach ($roles_info as $_role) {
$role = $roles->get($_role->id);
if (is_object($role)) {
if (!$role->read_only) {
$roles->delete((int) $_role->id);
}
}
}
foreach ($restore_roles as $role) {
$_role = Roles::getRoleInfoByID($role['id'], $fetch_mode = DB_FETCHMODE_ASSOC);
if (isset($_role['id'])) {
// existing role, need to update only
$new_role = new Roles();
$new_role->id = $role['id'];
$new_role->description = $role['description'];
$new_role->name = $role['name'];
$new_role->type = $role['type'];
$new_role->update();
Roles::delete_role_tasks($new_role->id);
if (!empty($role['tasks'])) {
$tasks = array();
foreach ($role['tasks'] as $task) {
$tasks[] = $task['id'];
}
Roles::assign_tasks_to_role($tasks, $new_role->id);
}
} else {
$new_role = new Roles();
$new_role->description = $role['description'];
$new_role->name = $role['name'];
$role_id = $new_role->create();
if ($role_id && !empty($role['tasks'])) {
$tasks = array();
foreach ($role['tasks'] as $task) {
$tasks[] = $task['id'];
}
Roles::assign_tasks_to_role($tasks, $role_id);
}
}
}
$error_msg = $_msg ? $_msg : __('Default Roles settings sucessfully restored.');
} else {
$error_msg = __('There is no Roles data in default XML settings file.');
}
} catch (Exception $e) {
$error = TRUE;
$error_msg = $e->getMessage();
}
return $error_msg;
}