/** * Add all the links for a team to the menu. */ function _addTeamMenuItems($team, $id = null, $name = null) { if ($id) { $path = array(__('Teams', true), $name); } else { $path = array(__('Teams', true)); } $is_captain = in_array($team['Team']['id'], $this->UserCache->read('OwnedTeamIDs')); if (empty($team['Division']['id'])) { $affiliate_id = $team['Team']['affiliate_id']; } else { $affiliate_id = $team['Division']['League']['affiliate_id']; } $is_manager = $this->is_manager && in_array($affiliate_id, $this->UserCache->read('ManagedAffiliateIDs')); $this->_limitOverride($team['Team']['id']); $key = "{$team['Team']['name']}::{$team['Team']['id']}"; if (!empty($team['Team']['division_id'])) { $this->_addMenuItem($team['Team']['name'] . ' (' . $team['Division']['long_league_name'] . ')', array('controller' => 'teams', 'action' => 'view', 'team' => $team['Team']['id']), $path, $key); $this->_addMenuItem(__('Schedule', true), array('controller' => 'teams', 'action' => 'schedule', 'team' => $team['Team']['id']), array_merge($path, array($key))); $this->_addMenuItem(__('Standings', true), array('controller' => 'divisions', 'action' => 'standings', 'division' => $team['Division']['id'], 'team' => $team['Team']['id']), array_merge($path, array($key))); if ($team['Team']['track_attendance'] && in_array($team['Team']['id'], $this->UserCache->read('AllTeamIDs'))) { $this->_addMenuItem(__('Attendance', true), array('controller' => 'teams', 'action' => 'attendance', 'team' => $team['Team']['id']), array_merge($path, array($key))); } if ($this->is_logged_in && $team['Team']['open_roster'] && !Division::rosterDeadlinePassed($team['Division']) && !in_array($team['Team']['id'], $this->UserCache->read('TeamIDs'))) { $this->_addMenuItem(__('Join team', true), array('controller' => 'teams', 'action' => 'roster_request', 'team' => $team['Team']['id']), array_merge($path, array($key))); } $this->_addDivisionMenuItems($team['Division'], $team['Division']['League'], $id, $name); } else { $this->_addMenuItem($team['Team']['name'], array('controller' => 'teams', 'action' => 'view', 'team' => $team['Team']['id']), $path, $key); } if ($this->is_admin || $is_manager || $is_captain) { $this->_addMenuItem(__('Edit', true), array('controller' => 'teams', 'action' => 'edit', 'team' => $team['Team']['id']), array_merge($path, array($key))); $this->_addMenuItem(__('Player emails', true), array('controller' => 'teams', 'action' => 'emails', 'team' => $team['Team']['id']), array_merge($path, array($key))); $this->_addMenuItem(__('Delete', true), array('controller' => 'teams', 'action' => 'delete', 'team' => $team['Team']['id']), array_merge($path, array($key))); } if ($this->effective_admin || $is_manager || ($is_captain || $this->effective_coordinator) && !Division::rosterDeadlinePassed($team['Division'])) { $this->_addMenuItem(__('Add player', true), array('controller' => 'teams', 'action' => 'add_player', 'team' => $team['Team']['id']), array_merge($path, array($key))); } if ($this->effective_admin) { $this->_addMenuItem(__('Move', true), array('controller' => 'teams', 'action' => 'move', 'team' => $team['Team']['id']), array_merge($path, array($key))); } if (($this->is_admin || $is_manager) && League::hasSpirit($team)) { $this->_addMenuItem(__('Spirit', true), array('controller' => 'teams', 'action' => 'spirit', 'team' => $team['Team']['id']), array_merge($path, array($key))); } if ($this->is_logged_in && League::hasStats($team)) { $this->_addMenuItem(__('Stats', true), array('controller' => 'teams', 'action' => 'stats', 'team' => $team['Team']['id']), array_merge($path, array($key))); $this->_addMenuItem(__('Download', true), array('controller' => 'teams', 'action' => 'stats', 'team' => $team['Team']['id'], 'ext' => 'csv'), array_merge($path, array($key, 'Stats'))); } }
function _initTeamForRosterChange($person_id) { $team_id = $this->_arg('team'); if (!$team_id) { $this->Session->setFlash(sprintf(__('Invalid %s', true), __('team', true)), 'default', array('class' => 'info')); $this->redirect('/'); } // Read the team record $this->Team->contain(array('Person' => array($this->Auth->authenticate->name, 'fields' => array('Person.id', 'Person.user_id', 'Person.first_name', 'Person.last_name', 'Person.alternate_email', 'Person.gender', 'Person.status', 'Person.complete')), 'Franchise', 'Division' => array('Day', 'League'))); $team = $this->Team->read(null, $team_id); if (empty($team['Division']['id'])) { $this->Configuration->loadAffiliate($team['Team']['affiliate_id']); } else { $this->Configuration->loadAffiliate($team['Division']['League']['affiliate_id']); } $this->Team->Division->addPlayoffs($team); // Pull out the player record from the team, and make // it look as if we just read it $person = Set::extract("/Person[id={$person_id}]/.", $team); if (!empty($person)) { $person = array('Person' => reset($person)); } // To avoid abuses, whether intentional or accidental, we limit the permissions // of admins when managing teams they are on. $this->_limitOverride($team_id); if (!$this->effective_admin && Division::rosterDeadlinePassed($team['Division'])) { $this->Session->setFlash(__('The roster deadline for this division has already passed.', true), 'default', array('class' => 'info')); $this->redirect(array('action' => 'view', 'team' => $team_id)); } return array($team, $person); }