本文整理汇总了PHP中AppModel::_reindexInner方法的典型用法代码示例。如果您正苦于以下问题:PHP AppModel::_reindexInner方法的具体用法?PHP AppModel::_reindexInner怎么用?PHP AppModel::_reindexInner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppModel
的用法示例。
在下文中一共展示了AppModel::_reindexInner方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: status
function status()
{
// TODO
$id = $this->_arg('division');
if (!$id) {
$this->Session->setFlash(sprintf(__('Invalid %s', true), __('division', true)), 'default', array('class' => 'info'));
$this->redirect(array('controller' => 'leagues', 'action' => 'index'));
}
$this->Division->contain(array('Team' => array('order' => 'Team.name'), 'League'));
$division = $this->Division->read(null, $id);
if (!$division) {
$this->Session->setFlash(sprintf(__('Invalid %s', true), __('division', true)), 'default', array('class' => 'info'));
$this->redirect(array('controller' => 'leagues', 'action' => 'index'));
}
if (empty($division['Team'])) {
$this->Session->setFlash(__('Cannot generate status report for a division with no teams.', true), 'default', array('class' => 'info'));
$this->redirect(array('action' => 'view', 'division' => $id));
}
if (!in_array($division['Division']['schedule_type'], array('roundrobin', 'ratings_ladder'))) {
$this->Session->setFlash(__('Cannot generate status report for a division with this schedule type.', true), 'default', array('class' => 'info'));
$this->redirect(array('action' => 'view', 'division' => $id));
}
$this->Configuration->loadAffiliate($division['League']['affiliate_id']);
Configure::load("sport/{$division['League']['sport']}");
$league_obj = $this->_getComponent('LeagueType', $division['Division']['schedule_type'], $this);
// Find all games played by teams that are currently in this division.
AppModel::_reindexInner($division, 'Team', 'id');
$teams = array_keys($division['Team']);
$division['Game'] = $this->Division->Game->find('all', array('conditions' => array('OR' => array('Game.home_team' => $teams, 'Game.away_team' => $teams), 'NOT' => array('Game.status' => Configure::read('unplayed_status'))), 'contain' => array('GameSlot', 'ScoreEntry', 'SpiritEntry')));
if (empty($division['Game'])) {
$this->Session->setFlash(__('Cannot generate status report for a division with no schedule.', true), 'default', array('class' => 'info'));
$this->redirect(array('action' => 'view', 'division' => $id));
}
$regions = $this->Division->Game->GameSlot->Field->Facility->Region->find('list', array('conditions' => array('affiliate_id' => $division['League']['affiliate_id']), 'contain' => array()));
$fields = $this->Division->Game->GameSlot->Field->find('all', array('conditions' => array('Facility.region_id' => array_keys($regions)), 'contain' => array('Facility')));
AppModel::_reindexOuter($fields, 'Field', 'id');
$stats = array_fill_keys($teams, array('games' => 0, 'season_games' => 0, 'home_games' => 0, 'field_rank' => 0, 'region_games' => array(), 'opponents' => array()));
$regions_used = array();
$playoffs_included = false;
foreach ($division['Game'] as $game) {
$home_team_id = $game['Game']['home_team'];
$away_team_id = $game['Game']['away_team'];
// Only count regular-season games
if ($game['Game']['type'] == SEASON_GAME) {
++$stats[$home_team_id]['games'];
++$stats[$home_team_id]['home_games'];
if ($game['Game']['home_field_rank'] != NULL) {
$stats[$home_team_id]['field_rank'] += 1 / $game['Game']['home_field_rank'];
} else {
// A NULL home rank means that the home team had no preference at that time,
// which means we count it as being 100% satisfied.
++$stats[$home_team_id]['field_rank'];
}
++$stats[$away_team_id]['games'];
if ($game['Game']['away_field_rank'] != NULL) {
$stats[$away_team_id]['field_rank'] += 1 / $game['Game']['away_field_rank'];
}
$region_id = $fields[$game['GameSlot']['field_id']]['Facility']['region_id'];
$regions_used[$region_id] = true;
if (!array_key_exists($region_id, $stats[$home_team_id]['region_games'])) {
$stats[$home_team_id]['region_games'][$region_id] = 1;
} else {
++$stats[$home_team_id]['region_games'][$region_id];
}
if (!array_key_exists($region_id, $stats[$away_team_id]['region_games'])) {
$stats[$away_team_id]['region_games'][$region_id] = 1;
} else {
++$stats[$away_team_id]['region_games'][$region_id];
}
if (!array_key_exists($away_team_id, $stats[$home_team_id]['opponents'])) {
$stats[$home_team_id]['opponents'][$away_team_id] = 1;
} else {
++$stats[$home_team_id]['opponents'][$away_team_id];
}
if (!array_key_exists($home_team_id, $stats[$away_team_id]['opponents'])) {
$stats[$away_team_id]['opponents'][$home_team_id] = 1;
} else {
++$stats[$away_team_id]['opponents'][$home_team_id];
}
} else {
$playoffs_included = true;
}
}
// Skip the region column if there is only one
if (count($regions_used) == 1) {
$regions_used = array();
}
$this->set(compact('division', 'regions', 'regions_used', 'fields', 'stats', 'playoffs_included', 'league_obj'));
$this->_addDivisionMenuItems($division['Division'], $division['League']);
}
示例2: recalculateRatings
function recalculateRatings($id = null)
{
if ($id) {
$conditions = array('League.id' => $id);
} else {
$conditions = array('League.is_open' => true);
}
// Find any leagues that are currently open, and possibly recalculate ratings
$leagues = $this->find('all', array('conditions' => $conditions, 'contain' => array('Division' => array('Team')), 'order' => 'League.open'));
foreach ($leagues as $key => $league) {
AppModel::_reindexInner($league['Division'], 'Team', 'id');
// Find all games played by teams that are in this league
$games = $this->readFinalizedGames($league);
foreach ($league['Division'] as $dkey => $division) {
$ratings_obj = AppController::_getComponent('Ratings', $division['rating_calculator']);
$leagues[$key]['Division'][$dkey]['updates'] = $ratings_obj->recalculateRatings($league, $division, $games, true);
}
}
return $leagues;
}
示例3: full_list
function full_list()
{
if (!ini_get('safe_mode')) {
set_time_limit(1800);
}
$id = $this->_arg('event');
if (!$id) {
$this->Session->setFlash(sprintf(__('Invalid %s', true), __('event', true)), 'default', array('class' => 'info'));
$this->redirect('/');
}
$this->Registration->Event->contain(array('EventType', 'Questionnaire' => array('Question' => array('Answer')), 'Price', 'Division' => 'League'));
$event = $this->Registration->Event->read(null, $id);
if (!$event) {
$this->Session->setFlash(sprintf(__('Invalid %s', true), __('event', true)), 'default', array('class' => 'info'));
$this->redirect(array('controller' => 'events', 'action' => 'index'));
}
AppModel::_reindexInner($event, 'Price', 'id');
$this->Configuration->loadAffiliate($event['Event']['affiliate_id']);
$event_obj = $this->_getComponent('EventType', $event['EventType']['type'], $this);
$this->_mergeAutoQuestions($event, $event_obj, $event['Questionnaire'], null, true);
if ($this->params['url']['ext'] == 'csv') {
$contain = array('Person' => array($this->Auth->authenticate->name, 'Related' => $this->Auth->authenticate->name), 'Payment' => 'RegistrationAudit', 'Response');
if (!empty($event['Division']['League']['sport'])) {
$contain['Person']['Skill'] = array('conditions' => array('Skill.sport' => $event['Division']['League']['sport']));
} else {
if (count(Configure::read('options.sport')) == 1) {
$contain['Person']['Skill'] = array('conditions' => array('Skill.sport' => Configure::read('options.sport')));
}
}
$this->Registration->contain($contain);
$this->set('registrations', $this->Registration->find('all', array('conditions' => array('Registration.event_id' => $id), 'order' => array('Registration.payment' => 'DESC', 'Registration.created' => 'DESC'))));
$this->set('download_file_name', "Registrations - {$event['Event']['name']}");
Configure::write('debug', 0);
} else {
$this->paginate['Registration']['limit'] = Configure::read('feature.items_per_page');
$this->set('registrations', $this->paginate('Registration', array('event_id' => $id)));
}
$this->set(compact('event'));
}
示例4: assignFieldsByPreferences
/**
* Assign field based on home field or region preference.
*
* It uses the selectWeightedGameslot function, which first looks at home field
* designation, then at field region preferences.
*
* We first sort games in order of the home team's allocation preference ratio.
* Teams with a low ratio get first crack at a desired location. Games where the
* home team has a home field are first in the list, to prevent another team with
* a lower ratio from scooping another team's dedicated home field.
*
* Once sorted, we simply loop over all games and call selectWeightedGameslot(),
* which takes region preference into account.
*
*/
function assignFieldsByPreferences($date, $games, $remaining = 0)
{
/*
* We sort by ratio of getting their preference, from lowest to
* highest, so that teams who received their field preference least
* will have a better chance of it.
*/
AppModel::_reindexInner($this->division, 'Team', 'id');
usort($games, array($this, 'comparePreferredFieldRatio'));
while ($game = array_shift($games)) {
$slot = $this->selectWeightedGameslot($game, $date, count($games) + 1 + $remaining);
if (!$slot) {
return false;
}
$game['game_slot_id'] = $slot['id'];
$home = $this->division['Team'][$game['home_team']];
$away = !empty($game['away_team']) ? $this->division['Team'][$game['away_team']] : null;
$this->_controller->Division->Game->updateFieldRanking($game, $slot['Field'], $home, $away);
$this->games[] = $game;
}
return true;
}