public function addTeamMembership($teamid) { $team = new team($teamid); if (!$team->exists()) { return false; } // find out if team allows anyone to join if (!static::getAllowedToJoinTeam($teamid)) { return false; } if ($team->getOpen()) { // anyone can join the team // just set the teamid $this->teamid = $teamid; } else { // team is closed, valid invitation or permission to join required \invitation::deleteOldInvitations(); $invitations = \invitation::getInvitationsForTeam($teamid, $this->origUserId); // delete all invitations of team for user // A user is not meant to join using one invite then leaving and joining again foreach ($invitations as $invitation) { $invitation->delete(); } $this->teamid = $teamid; } $team->setMemberCount($team->getMemberCount() + 1); $team->update(); return true; }