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); }
protected function maintainInactiveTeams() { // 6 months long inactive teams will be marked as deleted during maintenance // inactive is defined as the team did not match and no member logged in during last 6 months $six_months_in_past = strtotime('-6 months'); $six_months_in_past = strftime('%Y-%m-%d %H:%M:%S', $six_months_in_past); $teamIds = team::getInactiveTeamIds(); foreach ($teamIds as $teamid) { // check if team matched during last 6 months $team = new team($teamid); if (($lastMatch = $team->getNewestMatchTimestamp()) && $lastMatch < $six_months_in_past) { $uids = $team->getUserIds(); // check if user logged in during last 6 months $memberLoggedInRecently = false; foreach ($uids as $userid) { $user = new user($userid); if (($lastLogin = $user->getLastLoginTimestampStr()) && $lastLogin > $six_months_in_past) { $memberLoggedInRecently = true; } } // team did not match and none of its users logged in during last 6 months if (!$memberLoggedInRecently) { foreach ($uids as $userid) { $user = new user($userid); $user->removeTeamMembership($teamid); $user->update(); } $team->setStatus('deleted'); $team->update(); } } } }