Пример #1
0
 protected function leaveTeam()
 {
     global $tmpl;
     // perform sanity checks
     if (($result = $this->sanityCheck()) !== true) {
         $tmpl->assign('error', $result === false ? 'An unknown error occurred while checking your request' : $result);
     }
     // remove user from team
     if (!$this->user->removeTeamMembership($this->team->getID()) || !$this->user->update()) {
         $tmpl->assign('error', 'An unknown error occurred while leaving the team.');
     } else {
         // notify team members using a private message
         $pm = new pm();
         if (\user::getCurrentUserId() === $this->user->getID()) {
             // notify team members about left member
             $pm->setSubject($this->user->getName() . ' left your team');
             $pm->setContent('Player ' . $this->user->getName() . ' just left your team.');
             $pm->setTimestamp(date('Y-m-d H:i:s'));
             $pm->addTeamID($this->team->getID());
             // send it
             $pm->send();
         } else {
             // notify team members of kicked member
             $pm->setSubject($this->user->getName() . ' got kicked from your team');
             $pm->setContent('Player ' . $this->user->getName() . ' got kicked from your team by ' . \user::getCurrentUser()->getName() . '.');
             $pm->setTimestamp(date('Y-m-d H:i:s'));
             $pm->addTeamID($this->team->getID());
             // send it
             $pm->send();
             // notify kicked member of the kick
             $pm = new pm();
             $pm->setSubject('You got kicked from your team by ' . \user::getCurrentUser()->getName());
             $pm->setContent('Player ' . \user::getCurrentUser()->getName() . ' just kicked you from your team.');
             $pm->setTimestamp(date('Y-m-d H:i:s'));
             $pm->addUserID($this->user->getID());
             // send it
             $pm->send();
         }
         // tell joined user that join was successful
         $tmpl->assign('teamLeaveSuccessful', true);
     }
 }
Пример #2
0
 protected function joinTeam(user $user)
 {
     global $tmpl;
     // perform sanity checks
     if (($result = $this->sanityCheck()) !== true) {
         $tmpl->assign('error', $result === false ? 'An unknown error occurred while checking your request' : $result);
         return;
     }
     // join team
     if (!$this->user->addTeamMembership($this->team->getID()) || !$this->user->update()) {
         $tmpl->assign('error', 'An unknown error occurred while joining the team.');
     } else {
         // notify team members using a private message
         $pm = new pm();
         $pm->setSubject($user->getName() . ' joined your team');
         $pm->setContent('Congratulations, ' . $user->getName() . ' just joined your team.');
         $pm->setTimestamp(date('Y-m-d H:i:s'));
         $pm->addTeamID($this->team->getID());
         // send it
         $pm->send();
         // tell joined user that join was successful
         $tmpl->assign('teamJoinSuccessful', true);
     }
 }
Пример #3
0
 protected function deleteTeam()
 {
     global $site;
     global $tmpl;
     // perform sanity checks
     if (($result = $this->sanityCheck()) !== true) {
         $tmpl->assign('error', $result === false ? 'An unknown error occurred while checking your request' : $result);
         return;
     }
     // notify team members using a private message first because later we won't have the membership info
     $pm = new pm();
     $pm->setSubject(\user::getCurrentUser()->getName() . ' deleted ' . $this->team->getName());
     $pm->setContent('Player ' . \user::getCurrentUser()->getName() . ' just deleted the team ' . $this->team->getName() . ' you were member of.');
     $pm->setTimestamp(date('Y-m-d H:i:s'));
     $pm->addTeamID($this->team->getID());
     // send it
     $pm->send();
     // remove the members from team
     $members = $this->team->getUsers();
     foreach ($members as $member) {
         $member->removeTeamMembership($this->team->getID());
         $member->update();
     }
     unset($members);
     unset($member);
     // if team never matched deleted it from database, otherwise just mark it as deleted
     require_once $site->installationPath() . '/CMS/classes/match.php';
     $matchCount = \match::getMatchCountForTeamId($this->team->getID());
     if ($matchCount > 0 || $matchCount === false) {
         // set the teams status to deleted
         $this->team->setStatus('deleted');
         $deletionTask = $this->team->update();
     } else {
         // actually delete team
         $deletionTask = $this->team->delete();
     }
     if (!$deletionTask) {
         $tmpl->assign('error', 'An unknown error occurred while deleting the team.');
     } else {
         // tell joined user that deletion was successful
         $tmpl->assign('teamDeleteSuccessful', true);
     }
 }