public function save($deep = true) { HandleBehavior::onSave($this); if (!$this->Maintainer) { $this->Maintainer = $GLOBALS['Session']->Person; } parent::save($deep); if (!$this->Members) { ProjectMember::create(['ProjectID' => $this->ID, 'MemberID' => $this->Maintainer->ID, 'Role' => 'Founder'], true); } }
public static function handleAddMemberRequest(Project $Project) { $GLOBALS['Session']->requireAuthentication(); if (empty($_POST['username'])) { return static::throwError(_('Parameter "username" required')); } if (!($Member = User::getByUsername($_POST['username']))) { return static::throwError(_('User not found')); } $recordData = ['ProjectID' => $Project->ID, 'MemberID' => $Member->ID]; if (ProjectMember::getByWhere($recordData)) { return static::throwError(_('This member is already in this project')); } $ProjectMember = ProjectMember::create($recordData); if (!empty($_POST['role'])) { $ProjectMember->Role = $_POST['role']; } $ProjectMember->save(); return static::respond('memberAdded', ['data' => $ProjectMember, 'Project' => $Project, 'Member' => $Member]); }