/** * Update the user project role in the project * @param string $projectId * @param string $userId * @param string $projectRole * @return string - userId */ public static function updateUserRole($projectId, $userId, $projectRole = ProjectRoles::CONTRIBUTOR) { CodeGuard::checkNotFalseAndThrow($projectId, '$projectId'); CodeGuard::checkNotFalseAndThrow($userId, 'userId'); //CodeGuard::assertInArrayOrThrow($role, array(ProjectRoles::CONTRIBUTOR, ProjectRoles::MANAGER)); // Add the user to the project $user = new UserModel($userId); $project = ProjectModel::getById($projectId); if ($userId == $project->ownerRef->asString()) { throw new \Exception("Cannot update role for project owner"); } // TODO: Only trigger activity if this is the first time they have been added to project $usersDto = ProjectCommands::usersDto($projectId); if (!$project->users->offsetExists($userId)) { ActivityCommands::addUserToProject($project, $userId); } $project->addUser($userId, $projectRole); $user->addProject($projectId); $project->write(); $user->write(); return $userId; }
public function project_usersDto() { return ProjectCommands::usersDto($this->_projectId); }