/** * Show update permissions page * * @param void * @return null */ function update_permissions() { $user = Users::findById(get_id()); if (!$user instanceof User) { flash_error(lang('user dnx')); $this->redirectToReferer(get_url('dashboard')); } // if if (!$user->canUpdatePermissions(logged_user())) { flash_error(lang('no access permissions')); $this->redirectToReferer(get_url('dashboard')); } // if $company = $user->getCompany(); if (!$company instanceof Company) { flash_error(lang('company dnx')); $this->redirectToReferer(get_url('dashboard')); } // if $projects = $company->getProjects(); if (!is_array($projects) || !count($projects)) { flash_error(lang('no projects owned by company')); $this->redirectToReferer($company->getViewUrl()); } // if $permissions = ProjectUsers::getNameTextArray(); $redirect_to = array_var($_GET, 'redirect_to'); if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) { $redirect_to = $user->getCardUrl(); } // if tpl_assign('user', $user); tpl_assign('company', $company); tpl_assign('projects', $projects); tpl_assign('permissions', $permissions); tpl_assign('redirect_to', $redirect_to); if (array_var($_POST, 'submitted') == 'submitted') { DB::beginWork(); foreach ($projects as $project) { $relation = ProjectUsers::findById(array('project_id' => $project->getId(), 'user_id' => $user->getId())); // findById if (array_var($_POST, 'project_permissions_' . $project->getId()) == 'checked') { if (!$relation instanceof ProjectUser) { $relation = new ProjectUser(); $relation->setProjectId($project->getId()); $relation->setUserId($user->getId()); } // if foreach ($permissions as $permission => $permission_text) { $permission_value = array_var($_POST, 'project_permission_' . $project->getId() . '_' . $permission) == 'checked'; $setter = 'set' . Inflector::camelize($permission); $relation->{$setter}($permission_value); } // foreach $relation->save(); } else { if ($relation instanceof ProjectUser) { $relation->delete(); } // if } // if } // if DB::commit(); flash_success(lang('success user permissions updated')); $this->redirectToUrl($redirect_to); } // if }