本文整理汇总了PHP中AppModel::_reindexOuter方法的典型用法代码示例。如果您正苦于以下问题:PHP AppModel::_reindexOuter方法的具体用法?PHP AppModel::_reindexOuter怎么用?PHP AppModel::_reindexOuter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppModel
的用法示例。
在下文中一共展示了AppModel::_reindexOuter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initializeRatings
/**
* Initialize for ratings recalculation.
*/
function _initializeRatings($league, &$division, $games)
{
AppModel::_reindexOuter($division['Team'], 'Team', 'id');
foreach (array_keys($division['Team']) as $team_id) {
$division['Team'][$team_id]['current_rating'] = $division['Team'][$team_id]['initial_rating'];
}
}
示例2: edit
function edit($section)
{
$affiliate = $this->_arg('affiliate');
$affiliates = $this->_applicableAffiliates();
if (!empty($this->data)) {
$to_delete = array();
foreach ($this->data['Setting'] as $key => $value) {
$this->data['Setting'][$key]['affiliate_id'] = $affiliate;
if (is_array($value['value'])) {
// There may be dates that need to be deconstructed
if ($affiliate && (empty($value['value']['day']) || empty($value['value']['month']))) {
// If we're editing affiliate settings, anything blank should be removed so the system default applies
unset($this->data['Setting'][$key]);
if ($key < MIN_FAKE_ID) {
$to_delete[] = $key;
}
} else {
if (array_key_exists('year', $value['value'])) {
$this->data['Setting'][$key]['value'] = $value['value']['year'] . '-' . $value['value']['month'] . '-' . $value['value']['day'];
} else {
if (array_key_exists('month', $value['value'])) {
$this->data['Setting'][$key]['value'] = '0-' . $value['value']['month'] . '-' . $value['value']['day'];
}
}
}
} else {
if ($affiliate && (empty($value['value']) && $value['value'] !== '0' || $value['value'] == MIN_FAKE_ID)) {
// If we're editing affiliate settings, anything blank should be removed so the system default applies
unset($this->data['Setting'][$key]);
if ($key < MIN_FAKE_ID) {
$to_delete[] = $key;
}
}
}
}
if ((empty($this->data['Setting']) || $this->Setting->saveAll($this->data['Setting'], array('validate' => false))) && (empty($to_delete) || $this->Setting->deleteAll(array('id' => $to_delete)))) {
$this->Session->setFlash(sprintf(__('The %s have been saved', true), __('settings', true)), 'default', array('class' => 'success'));
// Reload the configuration right away, so it affects any rendering we do now,
// and rebuild the menu based on any changes.
if ($affiliate) {
$this->Configuration->loadAffiliate($affiliate);
} else {
$this->Configuration->load($this->UserCache->currentId());
}
$this->_initMenu();
} else {
$this->Session->setFlash(__('Failed to save the settings', true), 'default', array('class' => 'warning'));
}
}
$this->data = $this->Setting->find('all', array('conditions' => array('person_id' => null, 'affiliate_id' => $affiliate)));
$this->_loadAddressOptions();
$defaults = $this->Setting->find('all', array('conditions' => array('person_id' => null, 'affiliate_id' => null)));
AppModel::_reindexOuter($defaults, 'Setting', 'id');
if (Configure::read('feature.tiny_mce')) {
$this->helpers[] = 'TinyMce.TinyMce';
}
$this->set(compact('affiliate', 'affiliates', 'defaults'));
$this->render($section);
}
示例3: 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']);
}
示例4: cron
function cron()
{
$this->layout = 'bare';
if (!$this->Lock->lock('cron')) {
return false;
}
if (Configure::read('feature.generate_roster_email')) {
$this->Roster = ClassRegistry::init('TeamsPerson');
$people = $this->Roster->find('all', array('conditions' => array('TeamsPerson.status' => array(ROSTER_INVITED, ROSTER_REQUESTED), 'TeamsPerson.created < DATE_ADD(CURDATE(), INTERVAL -7 DAY)'), 'contain' => array('Person' => array($this->Auth->authenticate->name, 'fields' => array('Person.id', 'Person.user_id', 'Person.first_name', 'Person.last_name', 'Person.alternate_email')))));
// Read all required team records
$teams = $this->Team->find('all', array('conditions' => array('Team.id' => array_unique(Set::extract('/TeamsPerson/team_id', $people))), 'contain' => array('Division' => array('Day', 'League'), 'Person' => array($this->Auth->authenticate->name, 'conditions' => array('TeamsPerson.role' => Configure::read('privileged_roster_roles')), 'order' => 'TeamsPerson.id'))));
AppModel::_reindexOuter($teams, 'Team', 'id');
$log = ClassRegistry::init('ActivityLog');
$emailed = $reminded = $expired = $outstanding = 0;
$activity = array();
// Second reminder for people that have had reminders sent more than 5.5 days ago
$second = 5.5 * DAY;
// Expire invites that have had reminders sent more than 7.5 days ago
$expire = 7.5 * DAY;
foreach ($people as $person) {
$team_id = $person['TeamsPerson']['team_id'];
$conditions = array('type' => $person['TeamsPerson']['status'] == ROSTER_INVITED ? 'roster_invite_reminder' : 'roster_request_reminder', 'team_id' => $team_id, 'person_id' => $person['Person']['id']);
$sent = $log->find('all', array('conditions' => $conditions, 'order' => 'ActivityLog.created'));
if (!empty($sent)) {
$age = time() - strtotime($sent[0]['ActivityLog']['created']);
if ($age > $expire) {
$success = $this->_rosterExpire($person['Person'], $teams[$team_id]['Person'], $teams[$team_id]['Team'], $teams[$team_id]['Division'], $person['TeamsPerson']);
if ($success) {
$activity[] = $conditions;
++$expired;
}
} else {
if ($age > $second && count($sent) < 2) {
$success = $this->_rosterRemind($person['Person'], $teams[$team_id]['Person'], $teams[$team_id]['Team'], $teams[$team_id]['Division'], $person['TeamsPerson'], true);
if ($success) {
$activity[] = $conditions;
++$reminded;
}
} else {
++$outstanding;
}
}
} else {
$success = $this->_rosterRemind($person['Person'], $teams[$team_id]['Person'], $teams[$team_id]['Team'], $teams[$team_id]['Division'], $person['TeamsPerson']);
if ($success) {
$activity[] = $conditions;
++$emailed;
}
}
}
$this->set(compact('emailed', 'reminded', 'expired', 'outstanding'));
// Update the activity log
if (!empty($activity)) {
$log->saveAll($activity);
}
}
$this->Lock->unlock();
}
示例5: presort
/**
* Do any calculations that will make the comparisons more efficient, such
* as determining wins, losses, spirit, etc.
*
* @param mixed $division Division to perform calculations on
*
*/
function presort(&$teams, &$division, $league, $games, $spirit_obj)
{
// Different read methods create arrays in different formats.
// This puts them all in the same format. At the same time,
// we split them into various groupings.
$bracket_games = array();
foreach ($games as $game) {
if (array_key_exists('Game', $game)) {
$game = array_merge($game['Game'], $game);
unset($game['Game']);
}
switch ($game['type']) {
case SEASON_GAME:
$division['Season']['Game'][] = $game;
break;
case POOL_PLAY_GAME:
$division['Pools'][$game['HomePoolTeam']['Pool']['stage']][$game['pool_id']]['Game'][] = $game;
break;
case BRACKET_GAME:
$bracket_games[] = $game;
break;
}
}
// Process each group of games to generate interim results
if (!empty($division['Season'])) {
$division['Season']['Results'] = $this->roundRobinResults($division, $league, $division['Season']['Game'], $spirit_obj);
}
if (!empty($division['Pools'])) {
ksort($division['Pools']);
foreach ($division['Pools'] as $stage_num => $stage) {
foreach ($stage as $pool_num => $pool) {
$division['Pools'][$stage_num][$pool_num]['Results'] = $this->roundRobinResults($division, $league, $pool['Game'], $spirit_obj);
}
}
}
if (!empty($bracket_games)) {
$division['Bracket']['Results'] = $this->bracketResults($bracket_games, $spirit_obj);
AppModel::_reindexOuter($bracket_games, 'Game', 'id');
ksort($bracket_games);
while (!empty($bracket_games)) {
$bracket = Game::_extractBracket($bracket_games);
ksort($bracket);
// For the class names to format this correctly, we need the rounds in
// this bracket to be numbered from 0, regardless of what their real
// round number is.
$bracket = array_values($bracket);
// Find the bracket's pool id
$pool_id = null;
foreach ($bracket[0] as $game) {
if (!empty($game['pool_id'])) {
$pool_id = $game['pool_id'];
break;
}
}
$division['Bracket']['Game'][] = compact('pool_id', 'bracket');
}
}
// Put the results into the top team records for easy access.
// Also, put teams into arrays for each grouping and sort them.
foreach ($teams as $key => $team) {
if (!empty($division['Season']['Results'][$team['id']])) {
$teams[$key]['Season'] = $division['Season']['Results'][$team['id']];
$division['Season']['Team'][] = $teams[$key];
}
if (!empty($division['Pools'])) {
foreach ($division['Pools'] as $stage_num => $stage) {
foreach ($stage as $pool_num => $pool) {
if (!empty($pool['Results'][$team['id']])) {
$x = $teams[$key];
unset($x['Season']);
unset($x['Pools']);
$x += $pool['Results'][$team['id']];
$division['Pools'][$stage_num][$pool_num]['Team'][] = $x;
$teams[$key]['Pools'][$stage_num][$pool_num] = $pool['Results'][$team['id']];
}
}
}
}
if (!empty($division['Bracket']['Results'][$team['id']])) {
$teams[$key]['Bracket'] = $division['Bracket']['Results'][$team['id']];
$x = $teams[$key];
unset($x['Season']);
unset($x['Pools']);
$division['Bracket']['Team'][] = $x;
}
}
$this->division_for_sort = $division;
$this->league_for_sort = $league;
if (!empty($division['Season']['Team'])) {
usort($division['Season']['Team'], array($this, 'compareTeams'));
}
if (!empty($division['Pools'])) {
foreach ($division['Pools'] as $stage_num => $stage) {
//.........这里部分代码省略.........