Beispiel #1
0
 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;
 }
Beispiel #2
0
 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();
             }
         }
     }
 }
Beispiel #3
0
<?php

include 'db_connection.php';
include 'classes/team.php';
$connection = new db_connection();
$id = isset($_POST['id_hidden']) ? $_POST['id_hidden'] : NULL;
$name = $_POST['name'];
$description = $_POST['description'];
$team = new team($name, $description, $id);
/*Transaction status*/
$status = 'ok';
if (isset($_POST['id_hidden'])) {
    //Update
    if (!$team->update($connection)) {
        //Error
        $error = $connection->lastError();
        if ($error['errno'] == 1062) {
            //UQ value error
            $status = "repeat";
        } else {
            $status = "Error {$error['errno']}: {$error['error']}";
        }
    }
} else {
    //Insert
    if (!$team->insert($connection)) {
        //Error
        $error = $connection->lastError();
        if ($error['errno'] == 1062) {
            //UQ value error
            $status = "repeat";