Example #1
0
 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 handleRemoveMemberRequest(Project $Project)
 {
     $GLOBALS['Session']->requireAuthentication();
     if (empty($_REQUEST['username'])) {
         return static::throwError(_('Parameter "username" required'));
     }
     if (!($Member = User::getByUsername($_REQUEST['username']))) {
         return static::throwError(_('User not found'));
     }
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         return static::respond('confirm', ['question' => sprintf(_('Are you sure you want to remove %s from %s?'), htmlspecialchars($Member->FullName), htmlspecialchars($Project->Title))]);
     }
     $ProjectMember = ProjectMember::getByWhere(['ProjectID' => $Project->ID, 'MemberID' => $Member->ID]);
     if ($ProjectMember) {
         $ProjectMember->destroy();
     }
     return static::respond('memberRemoved', ['data' => $ProjectMember, 'Project' => $Project, 'Member' => $Member]);
 }