protected function _init() { parent::_init(); $this->league = Leagues::find($this->request->id); if ($this->league) { $this->set(array('league' => $this->league)); } // Keep empty fields from being converted to zeros. if ($this->request->data and isset($this->request->data['player_limit'])) { if ($this->request->data['player_limit']['male'] === '') { unset($this->request->data['player_limit']['male']); } if ($this->request->data['player_limit']['female'] === '') { unset($this->request->data['player_limit']['female']); } } }
protected function edit() { $league = Leagues::find((string) $this->game->league_id); if (!$this->CURRENT_USER or !$league->isManager($this->CURRENT_USER)) { $this->flashMessage('You don\'t have permission to view that page.', array('alertType' => 'error')); return $this->redirect('/'); } if (!isset($this->game)) { $this->flashMessage('Game not found.', array('alertType' => 'error')); $this->redirect('/'); return; } if ($this->game->game_time->sec < time()) { $this->flashMessage('This game is in the past! Any reported scores will be erased if this game is edited.', array('alertType' => 'warning')); } if ($this->request->data) { $gameStartTime = $this->request->data['game_date'] . ' ' . $this->request->data['game_time']; unset($this->request->data['game_date']); unset($this->request->data['game_time']); $this->request->data['game_time'] = strtotime($gameStartTime); $this->game->set($this->request->data); if ($this->game->save()) { // Handle game with scores already if ($this->game->scores) { $old_score_report = $this->game->scores->export(); $old_score_report = $old_score_report['data']; if (!empty($old_score_report)) { // Log the previously-reported score $conditions = array('_id' => $this->game->_id); $query = array('$push' => array('old_scores' => $old_score_report)); Games::update($query, $conditions); // Remove the scores and winner $query = array('$unset' => array('scores' => 1, 'winner' => 1)); Games::update($query, $conditions); } } $this->flashMessage('The game has been updated successfully.', array('alertType' => 'success')); return $this->redirect(array('Leagues::view', 'id' => $league->_id)); } } return compact('league'); }
<?php if (isset($CURRENT_USER) and $CURRENT_USER->can('leagues.edit')) { echo '<p>' . $this->html->link('<i class="icon-plus icon-white"></i> Create a new league', 'Leagues::create', array('class' => 'btn btn-primary', 'escape' => false)) . '</p>'; } $league_types = array('future' => 'Upcoming Leagues', 'present' => 'Current Leagues', 'past' => 'Past Leagues'); foreach ($league_types as $key => $label) { if (count($leagues[$key]) <= 0) { continue; } echo "<h2>{$label}</h2>\n"; echo '<table class="table table-striped tablesorter">'; echo '<thead><tr><th width="7%">Action</th><th>League Name</th><th width="15%">Season</th><th width="15%">Sport</th><th width="15%">Commissioners</th><th width="15%">Start</th><th width="15%">End</th></tr></thead>'; echo '<tbody>'; foreach ($leagues[$key] as $l) { $this_league = Leagues::find($l['_id']); $league_link = $this->html->link($l['name'], array('Leagues::view', 'id' => $l['_id'])); $actionLinks = array(); if (isset($CURRENT_USER)) { $actionLinks[] = $this->html->link('<i class="icon-list"></i>', "/leagues/{$l['_id']}/registrations", array('escape' => false, 'class' => 'hasTooltip', 'title' => 'Participant List')); } else { $actionLinks[] = '<i class="icon-list hasTooltip" title="Please log in to view the participant list."></i>'; } if (isset($CURRENT_USER) and $this_league->isManager($CURRENT_USER)) { $actionLinks[] = $this->html->link('<i class="icon-pencil"></i>', array('Leagues::edit', 'id' => $l['_id']), array('escape' => false, 'class' => 'hasTooltip', 'title' => 'Edit League')); } if ($l['meta']['registration_open'] and isset($CURRENT_USER) and $CURRENT_USER->can('leagues.register')) { $actionLinks[] = $this->html->link('<i class="icon-shopping-cart"></i>', "/leagues/" . $l['_id'] . "/register/", array('escape' => false, 'class' => 'hasTooltip', 'title' => 'Register')); } echo '<tr>'; echo '<td>' . implode(' ', $actionLinks) . '</td>';