public function getGamesPlayed() { $teams = Team::get(); $count = 0; foreach ($teams as $team) { if ($team->PlayerOne == $this->ID || $team->PlayerTwo == $this->ID) { $count++; } } return $count; }
public function assignTeamsForm($game_id) { $teams = Team::get(); $teamOne = DropdownField::create('TeamOne', 'Team One', $teams->map('ID', 'getTeamNames')); $teamTwo = DropdownField::create('TeamTwo', 'Team Two', $teams->map('ID', 'getTeamNames')); $gameID = HiddenField::create('GameID', 'Game ID', $game_id); $fields = new FieldList($teamOne, $teamTwo, $gameID); $actions = new FieldList(FormAction::create("doAssignTeams")->setTitle("Assign Teams to this game")); $required = new RequiredFields('TeamOne', 'TeamTwo'); $form = Form::create($this, 'doAssignTeams', $fields, $actions, $required); $form->setTemplate('forms/AssignTeamsForm'); return $form; }
public function get_teams($team_id, $joint_id = 0) { // if it's a joint, let's deal it as a joing if ($joint_id > 0) { // get all the joint entries so we have all the teams $joint = new Joint(); $joint->where("joint_id", $joint_id)->get(); // not an existing joint? if ($joint->result_count() < 1) { log_message('error', 'get_teams: joint -> joint not found'); return false; } // result array $teamarray = array(); foreach ($joint->all as $key => $join) { if (!($team = $this->get_cached($join->team_id))) { $team = new Team(); $team->where('id', $join->team_id); $team->get(); } $teamarray[] = $team->get_clone(); } if (empty($teamarray)) { log_message('error', 'get_teams: joint -> no teams found'); return false; } return $teamarray; } // if we're here, it means it's a simple team if (!($team = $this->get_cached($team_id))) { $team = new Team($team_id); } return array($team); }
/** * Enter a new match to the database * @param int $a Team A's ID * @param int $b Team B's ID * @param int $a_points Team A's match points * @param int $b_points Team B's match points * @param int $duration The match duration in minutes * @param int|null $entered_by The ID of the player reporting the match * @param string|DateTime $timestamp When the match was played * @param int[] $a_players The IDs of the first team's players * @param int[] $b_players The IDs of the second team's players * @param string|null $server The address of the server where the match was played * @param int|null $port The port of the server where the match was played * @param string $replayFile The name of the replay file of the match * @param string $mapPlayed The name of the map where the map was played, only for rotational leagues * @return Match An object representing the match that was just entered */ public static function enterMatch($a, $b, $a_points, $b_points, $duration, $entered_by, $timestamp = "now", $a_players = array(), $b_players = array(), $server = null, $port = null, $replayFile = null, $mapPlayed = null) { $team_a = Team::get($a); $team_b = Team::get($b); $a_elo = $team_a->getElo(); $b_elo = $team_b->getElo(); $diff = self::calculateEloDiff($a_elo, $b_elo, $a_points, $b_points, $duration); // Update team ELOs $team_a->changeElo($diff); $team_b->changeElo(-$diff); $match = self::create(array('team_a' => $a, 'team_b' => $b, 'team_a_points' => $a_points, 'team_b_points' => $b_points, 'team_a_players' => implode(',', $a_players), 'team_b_players' => implode(',', $b_players), 'team_a_elo_new' => $team_a->getElo(), 'team_b_elo_new' => $team_b->getElo(), 'elo_diff' => $diff, 'timestamp' => TimeDate::from($timestamp)->toMysql(), 'duration' => $duration, 'entered_by' => $entered_by, 'server' => $server, 'port' => $port, 'replay_file' => $replayFile, 'map_played' => $mapPlayed, 'status' => 'entered'), 'iiiissiiisiisisss', 'updated'); $match->updateMatchCount(); return $match; }
/** * Get the team a player was invited to * * @return Team */ public function getTeam() { return Team::get($this->team); }
/** * Enter a new match to the database * @param int $a Team A's ID * @param int $b Team B's ID * @param int $a_points Team A's match points * @param int $b_points Team B's match points * @param int $duration The match duration in minutes * @param int|null $entered_by The ID of the player reporting the match * @param string|DateTime $timestamp When the match was played * @param int[] $a_players The IDs of the first team's players * @param int[] $b_players The IDs of the second team's players * @param string|null $server The address of the server where the match was played * @param int|null $port The port of the server where the match was played * @param string $replayFile The name of the replay file of the match * @param int $map The ID of the map where the match was played, only for rotational leagues * @param string $matchType The type of match (e.g. official, fm, special) * @param string $a_color Team A's color * @param string $b_color Team b's color * @return Match An object representing the match that was just entered */ public static function enterMatch($a, $b, $a_points, $b_points, $duration, $entered_by, $timestamp = "now", $a_players = array(), $b_players = array(), $server = null, $replayFile = null, $map = null, $matchType = "official", $a_color = null, $b_color = null) { $matchData = array('team_a_color' => strtolower($a_color), 'team_b_color' => strtolower($b_color), 'team_a_points' => $a_points, 'team_b_points' => $b_points, 'team_a_players' => implode(',', $a_players), 'team_b_players' => implode(',', $b_players), 'timestamp' => TimeDate::from($timestamp)->toMysql(), 'duration' => $duration, 'entered_by' => $entered_by, 'server' => $server, 'replay_file' => $replayFile, 'map' => $map, 'status' => 'entered', 'match_type' => $matchType); if ($matchType === self::OFFICIAL) { $team_a = Team::get($a); $team_b = Team::get($b); $a_elo = $team_a->getElo(); $b_elo = $team_b->getElo(); $diff = self::calculateEloDiff($a_elo, $b_elo, $a_points, $b_points, $duration); // Update team ELOs $team_a->changeElo($diff); $team_b->changeElo(-$diff); $matchData = array_merge($matchData, array('team_a' => $a, 'team_b' => $b, 'team_a_elo_new' => $team_a->getElo(), 'team_b_elo_new' => $team_b->getElo(), 'elo_diff' => $diff)); } $match = self::create($matchData, 'updated'); if ($matchType === self::OFFICIAL) { $match->updateMatchCount(); } $players = $match->getPlayers(); Database::getInstance()->startTransaction(); foreach ($players as $player) { $player->setLastMatch($match->getId()); } Database::getInstance()->finishTransaction(); return $match; }
if ($season->getWeekDate($week) == $date) { $matches = Match::find('seasonid = ? and week = ?', [$season->seasonid, $week]); foreach ($matches as $match) { foreach ([$match->team1id, $match->team2id] as $teamid) { if ($match->result == 0) { // Falta resultado $team = Team::get($teamid); $msg = "Hola {$team->username}, falta por poner el resultado de tu combate de hoy."; echo "-> {$msg}\n"; TwitterAuth::botSendPrivateMessage($team->username, $msg); sleep(1); } $video = Video::findOne('matchid = ? and teamid = ? and type = ?', [$match->matchid, $teamid, 1]); if (!$video) { // Falta video $team = Team::get($teamid); $msg = "Hola {$team->username}, falta por poner el vídeo de tu combate de hoy."; echo "-> {$msg}\n"; TwitterAuth::botSendPrivateMessage($team->username, $msg); sleep(1); } } } } } } } if (date('H') * 1 == 17 && date('i') * 1 < 15) { // 17:00 - 17:15 // Videos foreach (Season::find('1=1') as $season) {
/** * @return void */ public function show() { $resultNames = [ ['Sin resultado', 'Sin resultado'], ]; for ($i=6; $i>=0; $i--) { $resultNames[] = ["Victoria $i-0", "Derrota 0-$i"]; } for ($i=0; $i<=6; $i++) { $resultNames[] = ["Derrota 0-$i", "Victoria $i-0"]; } $resultNames[] = ["Victoria 6-0 (sin jugar)", "Derrota 0-6 (sin jugar)"]; $resultNames[] = ["Derrota 0-6 (sin jugar)", "Victoria 6-0 (sin jugar)"]; $resultNames[] = ["Aplazado", "Aplazado"]; if (!($csrf = $_SESSION['csrf'])) { $_SESSION['csrf'] = $csrf = rand(1, 1000000) . ""; } $postCsrf = HTMLResponse::fromPOST('csrf', ''); if ($postCsrf == $csrf) { if (HTMLResponse::fromPOST('color') !== null) { $this->team->color = HTMLResponse::fromPOST('color'); $this->team->save(); } } $color = $this->team->color; ?> <div class="inblock" style="margin-right: 16px"> <a target="_blank" href="/<?=$this->team->getImageLink()?>"> <img src="/<?=$this->team->getImageLink(300, 200)?>" alt="Logo" class="teamlogo"><br> </a> <a href="https://twitter.com/hashtag/<?=$this->team->getHashtag()?>" target="_blank">#<?=$this->team->getHashtag()?></a> <div style="height:2px"></div> <a href="https://twitter.com/<?=$this->team->username?>" target="_blank">@<?=$this->team->username?></a> <div style="height: 6px"></div> <span style="text-decoration: underline;">Color oficial</span>: <? if (preg_match("'^#[abcdefABCDEF0-9]{6}$'", $color)) { ?><span id="teamcolor"><?= $color ?></span><? } else { ?><i id="teamcolor">Sin color</i><? $color = '#000000'; } ?> <div class="teamcolor" style="background: <?=$color?>"></div> <br><? if ($this->team->isManager()) { ?> <br>Eres el Manager del equipo. <form action="<?=HTMLResponse::getRoute()?>" method="post" id="colorform"> <input type="hidden" name="color" value="<?=$color?>"> <input type="hidden" name="csrf" value="<?=$csrf?>"> </form> <? $this->design->addJavaScript('/js/jquery-ui.min.js'); $this->design->addStyleSheet('/css/jquery-ui.min.css'); $this->design->addStyleSheet('/css/jquery.colorpicker.css'); $this->design->addJavaScript('/js/jquery.colorpicker.js'); $this->design->addJavaScript(" $('.teamcolor').colorpicker({ inline: false, color: '{$color}', colorFormat: '#HEX', closeOnOutside: false, closeOnEscape: false, ok: function(event, color) { $('#colorform input[name=\"color\"]').val(color.formatted); $('#colorform').submit(); } }).css('cursor', 'pointer'); ", false); } ?> </div> <div class="inblock"> <? ?> <h2>Calendario de enfrentamientos</h2> <table> <thead> <tr> <td>Jornada</td> <td>Fecha</td> <td>Oponentes</td> <td>Resultado</td> <td>Vídeos</td> </tr> </thead> <tbody> <? foreach(Match::find('(team1id = ? or team2id = ?) and seasonid = ? order by week asc', [$this->team->teamid, $this->team->teamid, $this->season->seasonid]) as $match) { if (!$this->team->isManager() && !$this->season->weekIsPublic($match->week)) { continue; } if (HTMLResponse::fromPOST('matchid', '') === $match->matchid && strlen($newResult = HTMLResponse::fromPOST('result', ''))) { $match->result = $newResult; $match->save(); HTMLResponse::exitWithRoute(HTMLResponse::getRoute()); } $date = $this->season->getPublishTimeForWeek($match->week); if ($match->team1id == $this->team->teamid) { $posIndex = 0; } else { $posIndex = 1; } $opponentsId = ($match->team1id != $this->team->teamid) ? $match->team1id : $match->team2id; $opponents = Team::get($opponentsId); ?> <tr> <td style="height:3em"> <? echo $this->season->getWeekName($match->week); ?> </td> <td><?= date("Y-m-d", $date) ?></td> <td style="text-align: center"> <!-- <?=htmlentities($this->team->name)?> VS --> <a href="/<?=$this->season->getLink()?>/equipos/<?=$opponents->getLink()?>/"> <?=htmlentities($opponents->name)?> </a> </td> <td> <i style="color: #666" <? if ($this->team->isManager()) { ?>class="editableResult"<?}?>> <?= ($this->team->isManager() || $match->isPublished()) ? $resultNames[$match->result][$posIndex] : $resultNames[0][0] ?> </i> <form class="editResult" method="POST" action="<?=HTMLResponse::getRoute()?>"> <select name="result"> <? foreach($resultNames as $index => $names) { ?><option <?=($index==$match->result?'selected':'')?> value="<?=$index?>"><?=$names[$posIndex]?></option><? } ?> </select> <input type="hidden" name="matchid" value="<?=$match->matchid?>"> </form> </td> <td> <? $this->showMatchVideo($this->team, $match, 2, "Ver Team Preview") ?> <? $this->showMatchVideo($this->team, $match, 1, "Ver Combate") ?> </td> </tr> <? } ?> </tbody> </table> <? $this->showFriendlyMatches(); if ($this->team->isManager()) { $this->checkPlayerChanges(); } $this->showPlayers(); if ($this->team->isManager()) { $this->showPlayersEditor(); } $sanctionLevels = Sanction::getLevelNames(); $sanctions = Sanction::find('seasonid = ? and teamid = ? order by dateline desc', [$this->season->seasonid, $this->team->teamid]); if ($sanctions && Team::isMember()) { ?> <h2>Sanciones recibidas</h2> <table style="min-width: 512px"> <thead> <tr> <!-- <td>Fecha</td> --> <td>Tipo</td> <td>Razón</td> </tr> </thead> <? foreach($sanctions as $sanction) { ?> <tr> <!-- <td style="font-style: italic"> <?= date("Y-m-d H:i:s", $sanction->dateline) ?> </td> --> <td> <?= $sanctionLevels[$sanction->level] ?> <? if (Team::isAdmin()) { ?> <i style="color: #666"> por </i> <?= htmlentities($sanction->adminname) ?> <? } ?> </td> <td> <?= htmlentities($sanction->reason) ?> </td> </tr> <? } ?> </table><br> <? } if (Team::isAdmin()) { $postCsrf = HTMLResponse::fromPOST('sanctioncsrf', ''); if ($postCsrf == $csrf) { if (strlen($reason = HTMLResponse::fromPOST('sanctionreason'))) { $sanction = Sanction::create(); $sanction->adminid = TwitterAuth::getUserId(); $sanction->adminname = TwitterAuth::getUserName(); $sanction->dateline = time(); $sanction->reason = $reason; $sanction->seasonid = $this->season->seasonid; $sanction->teamid = $this->team->teamid; $sanction->level = HTMLResponse::fromPOST('sanctionlevel', 0); $sanction->save(); HTMLResponse::exitWithRoute(HTMLResponse::getRoute()); } } ?> <h2>Añadir nueva sanción</h2> <form action="<?=HTMLResponse::getRoute()?>" method="post"> <table style="min-width: 512px"> <thead> <tr> <td>Tipo</td> <td>Razón</td> </tr> </thead> <tr> <td> <select name="sanctionlevel"> <? foreach ($sanctionLevels as $index => $label) { ?> <option value="<?=$index?>"> <?= $label ?> </option> <? } ?> </select> </td> <td> <textarea name="sanctionreason" style="width: 250px"></textarea> </td> </tr> </table> <input type="hidden" name="sanctioncsrf" value="<?=$csrf?>"> <div style="height: 6px"></div> <button type="submit">Añadir sanción</button> </form> <? } ?><br> <? $this->showTeamSeasons(); ?> </div> <? }
} else { ?> <script> var timePopup = setTimeout(function(){ window.parent.boss.removeClass('modal_dialog', 'active'); }, 100); window.parent.boss.popup("Esse(s) membro(s) já estão participando desta equipe."); </script> <?php die; } if ($team_member_set) { $model = new Team(); $sql = array('id_team' => $pk, 'id_admin' => $logado['id_member'], 'status' => 1); $model->fields = array('id_project'); $rs = $model->get($sql); $rs = $rs[0]; ?> <script> var timePopup = setTimeout(function(){ window.parent.boss.removeClass('modal_dialog', 'active'); }, 100); window.parent.boss.ajax.load('/app/team/view_team/?pk=<?php echo $rs["id_project"]; ?> ', '#app_pane_body'); window.parent.boss.popup("Membro(s) adicionados com sucesso."); </script> <?php } }
/** * Get a single team by its name * * @param string $name The team name to look for * @return Team */ public static function getFromName($name) { return Team::get(self::fetchIdFrom($name, 'name', 's')); }
/** * Returns leader team objects, false in case user is not a team leader * * @author Woxxy * @param int $team_id if NULL returns each team in which this user is leader * @return object Teams * */ function is_team_leader($team_id = NULL, $joint_id = NULL) { // not logged in? get booted if (!$this->is_logged_in()) { return FALSE; } // this calls another function in order to cycle each team in the joint with is_team if (!is_null($joint_id) && $joint_id != 0) { $teams = new Team(); return $this->is_team_leader_array($teams->get_teams(0, $joint_id)); } // let's get all the memberships if (!isset($this->cached['leaderships'])) { $memberships = new Membership(); $memberships->where('user_id', $this->get_user_id())->where('accepted', 1)->where('is_leader', 1)->get(); $this->cached['leaderships'] = $memberships->get_clone(); } else { $memberships = $this->cached['leaderships']; } // if not member of any team, return FALSE if ($memberships->result_count() < 1) { return FALSE; } // if a team is set, let's grab the team and return the data of the team if (is_numeric($team_id)) { foreach ($memberships->all as $membership) { if ($membership->team_id == $team_id) { return new Team($team_id); } } return FALSE; } $teams = new Team(); // Notice that if you remove the result count on $leaderships, this will not run and the user will be leader of any team! foreach ($memberships->all as $key => $membership) { $teams->or_where('id', $membership->team_id); } $teams->get(); return $teams; }
/** * {@inheritdoc} */ public function unserialize($data) { $data = unserialize($data); $this->__construct(\Team::get($data['team']), \Player::get($data['deleter'])); }
public function get_teams($team_id, $joint_id = 0) { if ($joint_id > 0) { $joint = new Joint(); $joint->where("joint_id", $joint_id)->get(); if ($joint->result_count() < 1) { log_message('error', 'get_teams: joint -> joint not found'); return false; } $teamarray = array(); $team = new Team(); foreach ($joint->all as $key => $join) { $team->where('id', $join->team_id); $team->get(); $teamarray[] = $team->get_clone(); } if ($team->result_count() < 1) { log_message('error', 'get_teams: joint -> no teams found'); return false; } return $teamarray; } $team = new Team($team_id); return array($team); }
public function testMiscMethods() { $this->team = Team::createTeam("Sample Team", $this->player->getId(), "Avatar", "Description"); $team = Team::get($this->team->getId()); $this->assertEquals("now", $team->getCreationDate()); }
/** * Returns leader team objects, false in case user is not a team leader * * @author Woxxy * @param int $team_id if NULL returns each team in which this user is leader * @return object Teams * */ function is_team_leader($team_id = NULL) { if (!$this->is_logged_in()) return FALSE; $leaderships = new Membership(); $leaderships->where('user_id', $this->get_user_id())->where('accepted', 1)->where('is_leader', 1); if (is_numeric($team_id)) { $leaderships->where('team_id', $team_id); $leaderships->get(); if ($leaderships->result_count() != 1) return FALSE; $team = new Team(); $team->where('id', $team_id)->get(); return $team; } $leaderships->get(); if ($leaderships->result_count() < 1) return FALSE; $teams = new Team(); // Notice that if you remove the result count on $leaderships, this will not run and the user will be leader of any team! foreach ($leaderships->all as $key => $leadership) { $teams->or_where('id', $leadership->team_id); } $teams->get(); return $teams; }
<?php require_once 'init.php'; use Agil\View\View; use Agil\Session\Session; $logado = Session::get('logado'); $request = View::route($_GET); $pk = $request['pk']; $sql = array("id_team" => $pk, "status" => 1); $fields = array("id_team", "id_admin", "name", "website", "slug"); $model = new Team(); $model->fields = $fields; $teams = $model->get($sql); $team = $teams[0]; $sql = array("id_team" => $team['id_team'], "status" => 1); $fields = array('id_member'); $model = new TeamMemberSet(); $model->fields = $fields; $rsTeamMembers = $model->get($sql); ?> <div class="modal-content"> <div class="modal-header"> <button class="close" onclick="boss.removeClass('modal_dialog', 'active')">x</button> <h3 class="modal-title font-open-sans"><?php echo $team['name']; ?> </h3> </div> <div class="modal-body"> <div class="container"> <label>Membros</label>
public function getTeams() { $teams = Team::get(); return $teams; }
function _submit($stationTag = null) { if ($stationTag === null) { trace("missing station id"); rest_sendBadRequestResponse(401, "missing stationId"); // doesn't return } $station = Station::getFromTag($stationTag); if ($station === false) { trace("can't find station from tag"); rest_sendBadRequestResponse(404, "can find station stationTag=" . $stationTag); // doesn't return } $team = new Team($station->get('teamAtStation'), -1); if ($team === false) { trace("can't find team", __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(404, "can find team at station stationTag=" . $stationTag . " teamId=" . $team->get('OID')); // doesn't return } $stationType = new StationType($station->get('typeId'), -1); if ($stationType === false) { trace("can't find station type stationTag = " . $stationTag, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "can't find station type stationTag=" . $stationTag); } $rpi = RPI::getFromStationId($station->get('OID')); if ($rpi === false) { trace("_start_challenge can't find RPI stationTag=" . $stationTag, __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "can't find RPI stationTag=" . $stationTag); } $json = json_getObjectFromRequest("POST"); // won't return if an error happens json_checkMembers("candidate_answer,is_correct,fail_message", $json); $count = $team->get('count'); $team->setChallengeData($json); trace("count=" . $count); $points = 3 - $count; if (!$json['is_correct']) { $count++; $team->set('count', $count); trace("count=" . $count); $challenge_complete = $count > 2; $team->_updateScore($stationType, 0); //TODO add legacy update score } else { $challenge_complete = true; } if ($challenge_complete) { switch ($stationType->get('typeCode')) { case StationType::STATION_TYPE_HMB: // Leave scoring up to brata submit for CPA and CTS but HMB needs it $team->_updateScore($stationType, $points); $station->endChallenge(); $team->endChallenge(); break; default: // FSL does not have pi, CPA and CTS not done until scan last qr // so technically challenge not complete until the brata submit break; } } if (Event::createEvent(Event::TYPE_SUBMIT, $team, $station, $points) === false) { trace("create event failed " . $team->get('OID') . " " . $station->get('OID'), __FILE__, __LINE__, __METHOD__); rest_sendBadRequestResponse(500, "database create failed"); } $json = array("message_version" => 0, "message_timestamp" => date("Y-m-d H:i:s"), "theatric_delay_ms" => $stationType->get('delay'), "challenge_complete" => $challenge_complete); json_sendObject($json); }
$totalPA = $team->nbOfPaUsed($gameId, $round); // register self action to gain PA foreach ($_GET as $t_teamId => $PA) { if (preg_match('/^t_[a-z]\\w{0,20}$/i', $t_teamId)) { $PA = intval($PA); // it's the sending team and it's a self targeted HP to gain PA if (substr($t_teamId, 2) == $team->getTeamId() && $PA < 0) { $totalPA = $totalPA + $PA; } } } foreach ($_GET as $t_teamId => $PA) { if (preg_match('/^t_[a-z]\\w{0,20}$/i', $t_teamId)) { $PA = intval($PA); // is the targeted team in the game? if (!$targetTeam->get($gameId, substr($t_teamId, 2))) { punishAndDie($team, $game); } // is the total PA used coherent? if ($PA > 0) { $totalPA = $totalPA + $PA; } if ($totalPA > $team->getPA()) { punishAndDie($team, $game); } // register action $team->addAction($gameId, $round, $targetTeam->getTeamId(), $PA); } } http_response_code(200); break;
/** * @return Team */ function getTeam2() { return Team::get($this->team2id); }
public function __construct($teamid) { $this->team = Team::get($teamid); }
public function teamExists($playerOne, $playerTwo) { return Team::get()->filter(array('PlayerOne' => $playerOne, 'PlayerTwo' => $playerTwo))->count() > 0 ? true : false; }