protected function _init() { parent::_init(); $this->team = Teams::find($this->request->id); if ($this->team) { $this->set(array('team' => $this->team)); } }
public function getOpponent($entity, $team_id) { $team_list = $entity->teams->export(); $team_list = $team_list['data']; $opp_id = null; foreach ($team_list as $t) { if ($t == $team_id) { continue; } if (!is_null($opp_id)) { return null; } $opp_id = $t; } $opp_team = Teams::find((string) $opp_id); return $opp_team; }
?> <?php if (is_object($g->game_time) and $g->game_time->sec <= time() and $g->canReport($CURRENT_USER)) { $reportScoreLink = $this->html->link('<i title="Report Score" class="hasTooltip icon-edit"></i>', array('Leagues::reportScore', 'id' => $g->_id), array('escape' => false)); } else { $reportScoreLink = ''; } $fs = $g->getFieldsite(); $teams = $g->teams; for ($i = 0; $i < 2; $i++) { $t = isset($teams[$i]) ? (string) $teams[$i] : null; $thisTeam = null; if (isset($t) and isset($teamCache[$t])) { $thisTeam = $teamCache[$t]; } elseif (isset($t)) { $thisTeam = Teams::find($t); $teamCache[$t] = $thisTeam; } if (isset($thisTeam)) { echo "<td>" . $this->html->link($thisTeam->name, array('Teams::view', 'id' => $thisTeam->_id)) . "</td>"; $team_id = $thisTeam->_id; if (isset($g->scores->{$team_id})) { $scoreVar = "score_{$i}"; ${$scoreVar} = $g->scores->{$team_id}; } } else { echo "<td>n/a</td>"; } } ?>
public function importRoster() { if (!isset($this->CURRENT_USER) or !$this->league->isManager($this->CURRENT_USER)) { $redirectUrl = $this->request->env('HTTP_REFERER') ?: '/'; $this->flashMessage('You do not have permission to check this league\'s schedule.', array('alertType' => 'error')); return $this->redirect($redirectUrl); } $lineErrors = array(); $errors = array(); $playerList = array(); $rosters = array(); if (isset($this->request->data['draft_results'])) { $draft_results = $this->request->data['draft_results']; $draftLines = explode("\n", trim($draft_results)); $line = 0; foreach ($draftLines as $l) { $line++; $fields = explode(",", $l); // Check field count if (count($fields) != 2) { $errors["{$line}"] = 'Wrong number of fields'; continue; } $team_id = trim($fields[0]); $user_id = trim($fields[1]); if (!isset($rosters[$team_id])) { $team = Teams::find($team_id); if (!isset($team) or !$team->exists()) { $errors["{$line}"] = "Team with the ID '{$team_id}' not found."; continue; } if ($team->league_id != $this->league->_id) { $errors["{$line}"] = "Team with the ID '{$team_id}' is not in this league."; continue; } $rosters[$team_id] = array(); } if (isset($playerList[$user_id])) { $errors["{$line}"] = "User with ID '{$user_id}' has been assigned multiple times."; continue; } $user = Users::find($user_id); if (!isset($user) or !$user->exists()) { $errors["{$line}"] = "User with the ID '{$user_id}' not found."; continue; } $playerList[$user_id] = new \MongoId($team_id); $rosters[$team_id][] = new \MongoId($user_id); } if (empty($errors)) { // Assign Team Rosters foreach ($rosters as $team_id => $roster) { $conditions = array('_id' => new \MongoId($team_id)); $query = array('$set' => array('players' => $roster)); Teams::update($query, $conditions); } // Assign Player Teams foreach ($playerList as $user_id => $team_id) { $conditions = array('_id' => new \MongoId($user_id)); $query = array('$addToSet' => array('teams' => $team_id)); Users::update($query, $conditions); } $this->flashMessage('Roster Imported Successfully!', array('alertType' => 'success')); return $this->redirect(array('Leagues::view', 'id' => $this->league->_id)); } } else { $draft_results = ''; } return compact('draft_results', 'errors', 'rosters'); }