Beispiel #1
0
 public function showTeams()
 {
     global $tmpl;
     global $user;
     global $db;
     // can user create a new team?
     $tmpl->assign('canCreateTeams', \user::getCurrentUserLoggedIn() && \user::getCurrentUser()->getPermission('allow_create_teams') && \user::getCurrentUser()->getIsTeamless());
     // tell template if user can reactivate maintained/deleted teams and there are teams that could be reactivated
     if ($user->getPermission('allow_reactivate_teams')) {
         $tmpl->assign('canReactivateTeams', count(\team::getDeletedTeamIds()) > 0);
     }
     if (!$tmpl->setTemplate('teamSystemList')) {
         $tmpl->noTemplateFound();
         die;
     }
     $tmpl->assign('title', 'Team overview');
     // get list of new, active, inactive and reactivated teams (no deleted and inactive teams)
     $teams = team::getNewTeamIds();
     $teams = array_merge($teams, team::getActiveTeamIds());
     $teams = array_merge($teams, team::getReactivatedTeamIds());
     $teams = team::getTeamsFromIds($teams);
     // sort teams by score, highest score first
     function scoreSort(team $a, team $b)
     {
         if ($a->getScore() === $b->getScore()) {
             return 0;
         }
         return $a->getScore() > $b->getScore() ? -1 : 1;
     }
     usort($teams, 'scoreSort');
     // display all teams that are not deleted or inactive as active
     $activeTeams = array();
     foreach ($teams as $team) {
         $activeTeams[] = $this->addToTeamList($team);
     }
     $teams = team::getTeamsFromIds(team::getInactiveTeamIds());
     usort($teams, 'scoreSort');
     $inactiveTeams = array();
     foreach ($teams as $team) {
         // use a temporary array for better readable (but slower) code
         // append team data
         $inactiveTeams[] = $this->addToTeamList($team);
     }
     $tmpl->assign('activeTeams', $activeTeams);
     $tmpl->assign('inactiveTeams', $inactiveTeams);
 }
Beispiel #2
0
 protected function maintainReactivatedTeams()
 {
     // permanently delete new teams which did not match in last 2 months
     $two_months_in_past = strtotime('-2 months');
     $two_months_in_past = strftime('%Y-%m-%d %H:%M:%S', $two_months_in_past);
     $teamIds = team::getNewTeamIds();
     foreach ($teamIds as $teamid) {
         $team = new team($teamid);
         if (($lastMatch = $team->getNewestMatchTimestamp()) && $lastMatch < $two_months_in_past) {
             $uids = $team->getUserIds();
             foreach ($uids as $userid) {
                 $user = new user($userid);
                 $user->removeTeamMembership($teamid);
                 $user->update();
             }
             $team->delete();
         }
     }
 }