本文整理汇总了PHP中Roles::findById方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::findById方法的具体用法?PHP Roles::findById怎么用?PHP Roles::findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::findById方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRole
/**
* Return role
*
* @param void
* @return Role
*/
function getRole()
{
if ($this->role === false) {
$role_id = $this->getRoleId();
$this->role = $role_id ? Roles::findById($this->getRoleId()) : null;
}
// if
return $this->role;
}
示例2: __construct
/**
* Constructor
*
* @param Request $request
* @return RolesAdminController
*/
function __construct($request)
{
parent::__construct($request);
$this->wireframe->addBreadCrumb(lang('Roles'), assemble_url('admin_roles'));
$role_id = $this->request->getId('role_id');
if ($role_id) {
$this->active_role = Roles::findById($role_id);
}
// if
if (instance_of($this->active_role, 'Role')) {
$this->wireframe->addBreadCrumb($this->active_role->getName(), $this->active_role->getViewUrl());
} else {
$this->active_role = new Role();
}
// if
if ($this->request->getAction() == 'index') {
$this->wireframe->addPageAction(lang('New System Role'), assemble_url('admin_roles_add_system'));
$this->wireframe->addPageAction(lang('New Project Role'), assemble_url('admin_roles_add_project'));
}
// if
$this->smarty->assign(array('active_role' => $this->active_role));
}
示例3: getAutoAssignRole
/**
* Return auto assign role based on auto assign role ID
*
* @param void
* @return Role
*/
function getAutoAssignRole()
{
$role_id = $this->getAutoAssignRoleId();
return $role_id ? Roles::findById($role_id) : null;
}
示例4: role
/**
* Show role details
*
* @param void
* @return null
*/
function role()
{
$role_id = $this->request->getId('role_id');
if ($role_id) {
$role = Roles::findById($role_id);
if (instance_of($role, 'Role')) {
if ($role->getType() == ROLE_TYPE_SYSTEM) {
$default_role_id = ConfigOptions::getValue('default_role');
$serve_as = 'system_role';
$role_data = array('id' => $role->getId(), 'name' => $role->getName(), 'is_default' => $role->getId() == $default_role_id, 'permissions' => array());
$system_permissions = Permissions::findSystem();
foreach ($system_permissions as $permission) {
$role_data['permissions'][$permission] = (bool) $role->getPermissionValue($permission, false);
}
// foreach
} else {
$serve_as = 'project_role';
$role_data = array('id' => $role->getId(), 'name' => $role->getName(), 'permissions' => array());
foreach (array_keys(Permissions::findProject()) as $permission) {
$role_data['permissions'][$permission] = (int) $role->getPermissionValue($permission, 0);
}
// foreach
}
// if
$this->serveData($role_data, $serve_as);
}
// if
}
// if
$this->httpError(HTTP_ERR_NOT_FOUND);
}
示例5: add_to_projects
/**
* Show and process add to projects page
*
* @param void
* @return null
*/
function add_to_projects()
{
if ($this->active_user->isNew()) {
$this->httpError(HTTP_ERR_NOT_FOUND);
}
// if
if (!$this->logged_user->isProjectManager()) {
$this->httpError(HTTP_ERR_FORBIDDEN);
}
// if
$add_to_projects_data = $this->request->post('add_to_projects');
$this->smarty->assign(array('add_to_projects_data' => $add_to_projects_data, 'exclude_project_ids' => Projects::findProjectIdsByUser($this->active_user)));
if ($this->request->isSubmitted()) {
$errors = new ValidationErrors();
$projects = null;
if (is_foreachable($add_to_projects_data['projects'])) {
$projects = Projects::findByIds($add_to_projects_data['projects']);
}
// if
if (!is_foreachable($projects)) {
$errors->addError(lang('Please select projects'), 'projects');
}
// if
if ($add_to_projects_data['role_id']) {
$role = Roles::findById($add_to_projects_data['role_id']);
$permissions = null;
if (!instance_of($role, 'Role') || !($role->getType() == ROLE_TYPE_PROJECT)) {
$errors->addError(lang('Invalid project role'), 'project_permissions');
}
// if
} else {
$role = null;
$permissions = array_var($add_to_projects_data, 'permissions');
}
// if
if ($errors->hasErrors()) {
$this->smarty->assign('errors', $errors);
} else {
$added = 0;
foreach ($projects as $project) {
$add = $project->addUser($this->active_user, $role, $permissions);
if ($add && !is_error($add)) {
$added++;
}
// if
}
// foreach
if ($added == 1) {
flash_success(':name has been added to 1 project', array('name' => $this->active_user->getDisplayName()));
} else {
flash_success(':name has been added to :count projects', array('name' => $this->active_user->getDisplayName(), 'count' => $added));
}
// if
$this->redirectToUrl($this->active_user->getViewUrl());
}
// if
}
// if
}
示例6: user_permissions
/**
* Show and process user permissions page
*
* @param void
* @return null
*/
function user_permissions()
{
if (!$this->active_project->canEdit($this->logged_user)) {
$this->httpError(HTTP_ERR_FORBIDDEN);
}
// if
$user = Users::findById($this->request->getId('user_id'));
if (!instance_of($user, 'User')) {
$this->httpError(HTTP_ERR_NOT_FOUND);
}
// if
if ($user->isProjectManager() || $user->isProjectLeader($this->active_project)) {
flash_error(':user has all permissions in this project', array('user' => $user->getDisplayName()));
$this->redirectToReferer($this->active_project->getPeopleUrl());
}
// if
$project_user = ProjectUsers::findById(array('user_id' => $user->getId(), 'project_id' => $this->active_project->getId()));
if (!instance_of($project_user, 'ProjectUser')) {
$this->httpError(HTTP_ERR_NOT_FOUND);
}
// if
if (!$this->logged_user->canChangeProjectPermissions($user, $this->active_project)) {
$this->httpError(HTTP_ERR_FORBIDDEN);
}
// if
$this->smarty->assign(array('active_user' => $user, 'project_user' => $project_user));
if ($this->request->isSubmitted()) {
$project_permissions = $this->request->post('project_permissions');
$role = null;
$role_id = (int) array_var($project_permissions, 'role_id');
if ($role_id) {
$role = Roles::findById($role_id);
}
// if
if (instance_of($role, 'Role') && $role->getType() == ROLE_TYPE_PROJECT) {
$permissions = null;
} else {
$role = null;
$permissions = array_var($project_permissions, 'permissions');
if (!is_array($permissions)) {
$permissions = null;
}
// if
}
// if
$update = $this->active_project->updateUserPermissions($user, $role, $permissions);
if ($update && !is_error($update)) {
if ($this->request->isApiCall()) {
$this->httpOk();
} else {
flash_success('Permissions have been updated successfully');
}
// if
} else {
if ($this->request->isApiCall()) {
$this->serveData($update);
} else {
flash_error('Failed to update permissions');
}
// if
}
// if
$this->redirectToUrl($this->active_project->getPeopleUrl());
} else {
if ($this->request->isApiCall()) {
$this->httpError(HTTP_ERR_BAD_REQUEST);
}
// if
}
// if
}