Пример #1
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);
     }
 }
Пример #2
0
 protected function reactivateTeam()
 {
     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;
     }
     $tmpl->assign('teamName', $this->team->getName());
     $tmpl->assign('teamid', $this->team->getID());
     $tmpl->assign('userName', $this->user->getName());
     $tmpl->assign('userid', $this->user->getID());
     // reactivate team with chosen leader
     // issue an invitation for team leader so he can join
     $invitation = new invitation();
     $invitation->forUserId($this->user->getID());
     $invitation->toTeam($this->team->getID());
     $invitation->insert(false);
     // now change team status to reactivate and add the user to team then make the user leader
     if (!$this->team->setStatus('reactivated') || !$this->team->update() || !$this->user->addTeamMembership($this->team->getID()) || !$this->user->update() || !$this->team->setLeaderId($this->user->getID()) || !$this->team->update()) {
         /* var_dump($this->user->addTeamMembership($this->team->getID())); */
         $tmpl->assign('error', 'An unknown error occurred while reactivating the team.');
     } else {
         // notify team members using a private message
         $pm = new pm();
         $pm->setSubject(\user::getCurrentUser()->getName() . ' reactivated team ' . $this->team->getName());
         $pm->setContent('Congratulations: Player ' . \user::getCurrentUser()->getName() . ' reactivated team ' . $this->team->getName() . ' with you as its leader.');
         $pm->setTimestamp(date('Y-m-d H:i:s'));
         $pm->addUserID($this->user->getID());
         // send it
         $pm->send();
         // tell user that team reactivation was successful
         $tmpl->assign('teamReactivationSuccessful', true);
     }
 }
Пример #3
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);
     }
 }
Пример #4
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);
     }
 }
Пример #5
0
 public static function sendWelcomeMessage($id)
 {
     global $config;
     $subject = $config->getValue('login.welcome.subject') ? $config->getValue('login.welcome.subject') : 'Welcome';
     $content = $config->getValue('login.welcome.content') ? $config->getValue('login.welcome.content') : 'Welcome and thanks for registering at this website!' . "\n" . 'In the FAQ you can find the most important informations' . ' about organising and playing matches.' . "\n\n" . 'See you on the battlefield.';
     // prepare welcome message
     $pm = new pm();
     $pm->setSubject($subject);
     $pm->setContent($content);
     $pm->setTimestamp(date('Y-m-d H:i:s'));
     $pm->addUserID($id);
     // send it
     $pm->send();
 }
Пример #6
0
 public function insert($sendPM = true)
 {
     global $db;
     if (count($this->teamids) > 0) {
         foreach ($this->teamids as $teamid) {
             if (count($this->userids) > 0) {
                 $query = $db->prepare('INSERT INTO `invitations` (`userid`, `teamid`, `expiration`) VALUES (:userid, :teamid, :expiration)');
                 foreach ($this->userids as $userid) {
                     if (!$db->execute($query, array(':userid' => array((int) $userid, PDO::PARAM_INT), ':teamid' => array((int) $teamid, PDO::PARAM_INT), ':expiration' => array(strftime('%Y-%m-%d %H:%M:%S', $this->expiration), PDO::PARAM_STR)))) {
                         return false;
                     }
                     if ($sendPM) {
                         $pm = new pm();
                         $pm->setSubject(\user::getCurrentUser()->getName() . ' invited you to ' . (new team($teamid))->getName());
                         $pm->setContent('Congratulations: ' . \user::getCurrentUser()->getName() . ' invited you to ' . (new team($teamid))->getName() . '. The invitation is valid until ' . strftime('%Y-%m-%d %H:%M:%S', $this->expiration) . '.');
                         $pm->setTimestamp(date('Y-m-d H:i:s'));
                         $pm->addUserID($userid);
                         // send it
                         $pm->send();
                     }
                 }
             }
         }
     }
     return true;
 }