public static function getFullRoundName($round) { if (self::$_allRounds === null) { self::$_allRounds = CHtml::listData(self::model()->cache(86400 * 7)->findAll(), 'id', 'cellName'); } return isset(self::$_allRounds[$round]) ? self::$_allRounds[$round] : $round; }
public function rounds() { return Rounds::Instance(); }
public function export($competition, $exportFormsts, $all = false, $xlsx = false, $extra = false, $order = 'date') { $registrations = $this->getRegistrations($competition, $all, $order); $template = PHPExcel_IOFactory::load(Yii::getPathOfAlias('application.data.results') . '.xls'); $export = new PHPExcel(); $export->getProperties()->setCreator(Yii::app()->params->author)->setLastModifiedBy(Yii::app()->params->author)->setTitle($competition->wca_competition_id ?: $competition->name)->setSubject($competition->name); $export->removeSheetByIndex(0); //注册页 $sheet = $template->getSheet(0); $sheet->setCellValue('A1', $competition->wca_competition_id ?: $competition->name); $events = $competition->getRegistrationEvents(); $col = 'J'; $cubecompsEvents = array('333' => '3x3', '444' => '4x4', '555' => '5x5', '666' => '6x6', '777' => '7x7', '222' => '2x2', '333bf' => '333bld', '333fm' => 'fmc', 'minx' => 'mega', 'pyram' => 'pyra', '444bf' => '444bld', '555bf' => '555bld', '333mbf' => '333mlt'); foreach ($events as $event => $data) { $sheet->setCellValue($col . 2, "=SUM({$col}4:{$col}" . (count($registrations) + 4) . ')'); $sheet->setCellValue($col . 3, isset($cubecompsEvents[$event]) ? $cubecompsEvents[$event] : $event); $sheet->getColumnDimension($col)->setWidth(5.5); $col++; } foreach ($registrations as $key => $registration) { $user = $registration->user; $row = $key + 4; $sheet->setCellValue('A' . $row, $registration->number)->setCellValue('B' . $row, $user->getCompetitionName())->setCellValue('C' . $row, $user->country->name)->setCellValue('D' . $row, $user->wcaid)->setCellValue('E' . $row, $user->getWcaGender())->setCellValue('F' . $row, PHPExcel_Shared_Date::FormattedPHPToExcel(date('Y', $user->birthday), date('m', $user->birthday), date('d', $user->birthday))); $col = 'J'; foreach ($events as $event => $data) { if (in_array("{$event}", $registration->events)) { $sheet->setCellValue($col . $row, 1); } $col++; } if ($extra) { $col++; $fee = $registration->getTotalFee(); if ($registration->isPaid()) { $fee .= Yii::t('common', ' (paid)'); } $sheet->setCellValue($col . $row, $fee); $col++; $sheet->setCellValue($col . $row, $user->mobile); $col++; $sheet->setCellValue($col . $row, $user->email); $col++; $sheet->setCellValue($col . $row, $registration->comments); } if (!$registration->isAccepted()) { $sheet->getStyle("A{$row}:D{$row}")->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('argb' => 'FFFFFF00')))); } } $export->addExternalSheet($sheet); //各个项目 foreach ($exportFormsts as $event => $rounds) { $count = count($rounds); foreach ($rounds as $round => $format) { if ($round == $count - 1) { $round = 'f'; } else { $round++; } $sheet = $template->getSheetByName($format); if ($sheet === null) { continue; } $sheet = clone $sheet; $sheet->setTitle("{$event}-{$round}"); $template->addSheet($sheet); $sheet->setCellValue('A1', Events::getFullEventName($event) . ' - ' . Rounds::getFullRoundName($round)); if ($round == 1 || $count == 1) { $row = 5; foreach ($registrations as $registration) { if (!in_array("{$event}", $registration->events)) { continue; } $user = $registration->user; $sheet->setCellValue('B' . $row, $user->getCompetitionName())->setCellValue('C' . $row, $user->country->name)->setCellValue('D' . $row, $user->wcaid); if ($row > 5) { $formula = $sheet->getCell('A' . ($row - 1))->getValue(); $formula = strtr($formula, array('-4' => '_temp_', $row - 1 => $row, $row - 2 => $row - 1, $row => $row + 1)); $formula = str_replace('_temp_', '-4', $formula); $sheet->setCellValue('A' . $row, $formula); } if (!$registration->isAccepted()) { $sheet->getStyle("A{$row}:D{$row}")->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('argb' => 'FFFFFF00')))); } $row++; } } $export->addExternalSheet($sheet); } } $this->exportToExcel($export, 'php://output', $competition->name, $xlsx); }
public function run() { $htmlOptions = $this->htmlOptions; $tableOptions = $this->tableOptions; $model = $this->model; $name = $this->name; if (!isset($htmlOptions['class'])) { $htmlOptions['class'] = 'table-responsive'; } else { $htmlOptions['class'] .= ' table-responsive'; } $htmlOptions['id'] = 'schedules'; if (!isset($tableOptions['class'])) { $tableOptions['class'] = 'table table-condensed'; } else { $tableOptions['class'] .= ' table table-condensed'; } echo CHtml::openTag('div', $htmlOptions); echo CHtml::openTag('table', $tableOptions); echo CHtml::openTag('thead'); echo CHtml::openTag('tr'); echo CHtml::tag('th', array(), '第几天'); echo CHtml::tag('th', array(), '赛区'); echo CHtml::tag('th', array(), '开始时间'); echo CHtml::tag('th', array(), '结束时间'); echo CHtml::tag('th', array(), '项目'); echo CHtml::tag('th', array(), '分组'); echo CHtml::tag('th', array(), '轮次'); echo CHtml::tag('th', array(), '赛制'); echo CHtml::tag('th', array(), '及格线(秒)'); echo CHtml::tag('th', array(), '还原时限(秒)'); echo CHtml::tag('th', array(), '人数'); echo CHtml::closeTag('tr'); echo CHtml::closeTag('thead'); $schedules = $model->{$name}; $schedules[] = Schedule::model()->attributes; $events = Events::getScheduleEvents(); foreach ($events as $key => $value) { $events[$key] = Yii::t('event', $value); } $formats = Formats::getAllFormats(); foreach ($formats as $key => $value) { $formats[$key] = Yii::t('common', $value); } $rounds = Rounds::getAllRounds(); foreach ($rounds as $key => $value) { $rounds[$key] = Yii::t('Rounds', $value); } $stages = Schedule::getStages(); echo CHtml::openTag('tbody'); foreach ($schedules as $key => $value) { extract($value); echo CHtml::openTag('tr'); echo CHtml::tag('td', array(), CHtml::activeNumberField($model, "{$name}[day][]", array('value' => $day ?: 1, 'min' => 1, 'max' => 4))); echo CHtml::tag('td', array(), CHtml::dropDownList(CHtml::activeName($model, "{$name}[stage][]"), $stage, $stages)); echo CHtml::tag('td', array(), CHtml::activeTextField($model, "{$name}[start_time][]", array('value' => $start_time ? date('H:i', $start_time) : '', 'class' => 'datetime-picker', 'data-date-format' => 'hh:ii', 'data-max-view' => '1', 'data-start-view' => '1'))); echo CHtml::tag('td', array(), CHtml::activeTextField($model, "{$name}[end_time][]", array('value' => $end_time ? date('H:i', $end_time) : '', 'class' => 'datetime-picker', 'data-date-format' => 'hh:ii', 'data-max-view' => '1', 'data-start-view' => '1'))); echo CHtml::tag('td', array(), CHtml::dropDownList(CHtml::activeName($model, "{$name}[event][]"), $event, $events, array('prompt' => ''))); echo CHtml::tag('td', array(), CHtml::activeTextField($model, "{$name}[group][]", array('value' => $group))); echo CHtml::tag('td', array(), CHtml::dropDownList(CHtml::activeName($model, "{$name}[round][]"), $round, $rounds, array('prompt' => ''))); echo CHtml::tag('td', array(), CHtml::dropDownList(CHtml::activeName($model, "{$name}[format][]"), $format, $formats, array('prompt' => ''))); echo CHtml::tag('td', array(), CHtml::activeNumberField($model, "{$name}[cut_off][]", array('value' => $cut_off, 'max' => 3600))); echo CHtml::tag('td', array(), CHtml::activeNumberField($model, "{$name}[time_limit][]", array('value' => $time_limit, 'max' => 3600))); echo CHtml::tag('td', array(), CHtml::activeNumberField($model, "{$name}[number][]", array('value' => $number))); echo CHtml::closeTag('tr'); } echo CHtml::closeTag('tbody'); echo CHtml::closeTag('table'); echo CHtml::closeTag('div'); Yii::app()->clientScript->registerScript('SchedulesForm', <<<EOT \$(document).on('focus', '#schedules table tbody tr:last-child', function() { \$(this).clone().insertAfter(this); \$('.datetime-picker').datetimepicker({ autoclose: true }); }); EOT ); }
/** * Desqualify a rival. Knight win combat by desqualify */ public function actionDesqualifyRival() { $output = array('errno' => 1, 'html' => '', 'isDesqualify' => false); //Check session is enable if (!Yii::app()->user->isGuest) { //Check input if (isset($_GET['combat']) && is_numeric($_GET['combat']) && $_GET['combat'] > 0) { //Check combat if ($combat = Combats::model()->with(array('combatsPrecombat', 'rounds', array('fromKnight' => array('with' => array('knightsCard'))), array('toKnight' => array('with' => 'knightsCard'))))->findByPk($_GET['combat'])) { //Check if user is in combat if ($combat->fromKnight->id == Yii::app()->user->knights_id || $combat->toKnight->id == Yii::app()->user->knights_id) { //Check if combat is enable if ($combat->status == Combats::STATUS_ENABLE) { //Check last round if ($round_data = RoundsData::model()->find('rounds_combats_id = :combats_id AND rounds_number = :rounds_id AND knights_id = :knights_id', array(':combats_id' => $combat->id, ':rounds_id' => count($combat->rounds), ':knights_id' => Yii::app()->user->knights_id))) { //Check time of desqualify $timeLimit = strtotime($round_data->date) + Yii::app()->params['desqualifyTime']; $requestTime = strtotime('now'); Yii::trace('[CHARACTER][actionDesqualifyRival] Check limit time of desqualify request (' . $requestTime . ') > $timelimit (' . $timeLimit . ') '); if ($requestTime >= $timeLimit) { //Finish combat Yii::trace('[CHARACTER][actionDesqualifyRival] FINISH COMBAT '); $output['isDesqualified'] = true; $combat->status = Combats::STATUS_FINISHED; $combat->result_by = Combats::RESULT_BY_DESQUALIFY; //Load round and knights $round = Rounds::model()->find('combats_id=:combats_id AND number=:number', array(':combats_id' => $combat->id, ':number' => count($combat->rounds))); if (Yii::app()->user->knights_id == $combat->from_knight) { $combat->result = Combats::RESULT_FROM_KNIGHT_WIN; $round->status = Rounds::STATUS_FROM_KNIGHT_WIN; $fromKnight =& $this->user_data['knights']; $toKnight = Knights::model()->findByPk($combat->toKnight->id); } else { $combat->result = Combats::RESULT_TO_KNIGHT_WIN; $round->status = Rounds::STATUS_TO_KNIGHT_WIN; $fromKnight = Knights::model()->findByPk($combat->fromKnight->id); $toKnight =& $this->user_data['knights']; } /* * Update round and combat */ Yii::trace('[CHARACTER][actionDesqualifyRival] update round and combat '); if (!$round->save()) { Yii::trace('[CHARACTER][actionDesqualifyRival] No se ha podido salvar el round'); } if ($combat->save()) { //Update combat cache Yii::app()->cache->set(Yii::app()->params['cacheKeys']['combat'] . $combat->id, $combat, Yii::app()->params['cachetime']['combat']); } else { Yii::trace('[CHARACTER][actionDesqualifyRival] No se ha podido salvar el combate'); } /* * Update knights to ready to challenge */ $fromKnight->endurance = ($combat->fromKnight->knightsCard->will + $combat->fromKnight->knightsCard->constitution) * 3; $fromKnight->life = $combat->fromKnight->knightsCard->constitution * 2; $fromKnight->status = Knights::STATUS_ENABLE; $toKnight->endurance = ($combat->toKnight->knightsCard->will + $combat->toKnight->knightsCard->constitution) * 3; $toKnight->life = $combat->toKnight->knightsCard->constitution * 2; $toKnight->status = Knights::STATUS_ENABLE; /* *Calcula postcombat */ //Calculate experience Yii::trace('[CHARACTER][actionDesqualifyRival] CALCULATE EXPERIENCE'); $precombat = $combat->combatsPrecombat; $postcombatData = CombatsPostcombat::calculateEarnedExperience($combat, $combat->fromKnight->level, $combat->toKnight->level); Yii::trace('[CHARACTER][actionDesqualifyRival] SAVE POSTCOMBATS'); $from_knight_post_combat = new CombatsPostcombat(); $from_knight_post_combat->attributes = array('combats_id' => $combat->id, 'knights_id' => $combat->fromKnight->id, 'knight_rival_level' => $combat->fromKnight->level, 'experience_generate' => $postcombatData['from_knight_experience_generate'], 'percent_by_result' => $postcombatData['from_knight_percent_by_result'], 'percent_by_injury' => $postcombatData['from_knight_percent_by_injury'], 'earned_experience' => $postcombatData['from_knight_earned_experience'], 'total_experience' => $combat->fromKnight->experiencie_earned + $postcombatData['from_knight_earned_experience'], 'total_coins' => $precombat->from_knight_gate + $combat->fromKnight->coins, 'earned_coins' => $precombat->from_knight_gate, 'injury_type' => null); if (!$from_knight_post_combat->save()) { Yii::trace('[CHARACTER][actionDesqualifyRival] se ha producido un error al salvar postcombate para from knight', 'error'); } $to_knight_post_combat = new CombatsPostcombat(); $to_knight_post_combat->attributes = array('combats_id' => $combat->id, 'knights_id' => $combat->toKnight->id, 'knight_rival_level' => $combat->toKnight->level, 'experience_generate' => $postcombatData['to_knight_experience_generate'], 'percent_by_result' => $postcombatData['to_knight_percent_by_result'], 'percent_by_injury' => $postcombatData['to_knight_percent_by_injury'], 'earned_experience' => $postcombatData['to_knight_earned_experience'], 'total_experience' => $combat->toKnight->experiencie_earned + $postcombatData['to_knight_earned_experience'], 'total_coins' => $precombat->to_knight_gate + $combat->toKnight->coins, 'earned_coins' => $precombat->to_knight_gate, 'injury_type' => null); if (!$to_knight_post_combat->save()) { Yii::trace('[CHARACTER][actionDesqualifyRival] se ha producido un error al salvar postcombate para to knight', 'error'); } //Update experience of knights Yii::trace('[CHARACTER][actionSetCombatPoints] UPDATE EXPERIECE'); $fromKknight->experiencie_earned = $from_knight_post_combat->total_experience; $toKnight->experiencie_earned = $to_knight_post_combat->total_experience; /* * Calculate repair prize equipment */ Yii::trace('[CHARACTER][actionDesqualifyRival]CALCULATE REPAIR PRIZE'); $from_knight_autorepair = CombatsPostcombat::autorepairObjectsEquipment($combat, $combat->fromKnight); if ($from_knight_autorepair['errno'] > 0) { Yii::trace('[CHARACTER][actionDesqualifyRival] FROM KNIGHT AUTOREPAIR FAIL', 'error'); } $to_knight_autorepair = CombatsPostcombat::autorepairObjectsEquipment($combat, $combat->toKnight); if ($to_knight_autorepair['errno'] > 0) { Yii::trace('[CHARACTER][actionDesqualifyRival] TO KNIGHT AUTOREPAIR FAIL', 'error'); } /* * Update coins of knights */ Yii::trace('[CHARACTER][actionDesqualifyRival] UPDATE COINS OF KNIGHTS'); Yii::trace('[CHARACTER][actionDesqualifyRival] FROM_KNIGHT earned coins: current coinds(' . $combat->fromKnight->coins . ') + gate coins (' . $precombat->from_knight_gate . ') - autorrepair coins (' . $from_knight_autorepair['repair_cost'] . ') '); $fromKnight->coins += $precombat->from_knight_gate - $from_knight_autorepair['repair_cost']; Yii::trace('[CHARACTER][actionDesqualifyRival] TO_KNIGHT earned coins: current coinds(' . $toKnight->coins . ') + gate coins (' . $precombat->to_knight_gate . ') - autorrepair coins (' . $to_knight_autorepair['repair_cost'] . ') '); $toKnight->coins += $precombat->to_knight_gate - $to_knight_autorepair['repair_cost']; /* * Update healings of knights */ if ($combat->fromKnight->pain > 0) { Yii::trace('[CHARACTER][actionDesqualifyRival] Healing schule for from knigth'); $healing = Healings::model()->findByPk($combat->fromKnight->id); $healing->next_healing_date = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' +' . Yii::app()->params['healingTime'] . ' seconds')); if (!$healing->save()) { Yii::trace('[CHARACTER][actionDesqualifyRival] Error to update from knight next healing date', 'error'); } } if ($combat->toKnight->pain > 0) { Yii::trace('[CHARACTER][actionDesqualifyRival] Healing schule for to knigth'); $healing = Healings::model()->findByPk($combat->toKnight->id); $healing->next_healing_date = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' +' . Yii::app()->params['healingTime'] . ' seconds')); if (!$healing->save()) { Yii::trace('[CHARACTER][actionDesqualifyRival] Error to update to knight next healing date', 'error'); } } /* * STATS * Update stats of knights and platform */ Yii::trace('[CHARACTER][actionDesqualifyRival] update stats'); $from_knight_stats = KnightsStats::model()->findByPk($combat->fromKnight->id); $to_knight_stats = KnightsStats::model()->findByPk($combat->toKnight->id); $from_knight_stats_vs = KnightsStatsVs::model()->find('knights_id = :knights_id AND opponent = :opponent', array(':knights_id' => $fromKnight->id, ':opponent' => $toKnight->id)); $to_knight_stats_vs = KnightsStatsVs::model()->find('knights_id = :knights_id AND opponent = :opponent', array(':knights_id' => $toKnight->id, ':opponent' => $fromKnight->id)); if (!$from_knight_stats_vs) { $from_knight_stats_vs = new KnightsStatsVs(); $from_knight_stats_vs->attributes = array('knights_id' => $combat->fromKnight->id, 'opponent' => $combat->toKnight->id, 'money_total_earned' => 0); } if (!$to_knight_stats_vs) { $to_knight_stats_vs = new KnightsStatsVs(); $to_knight_stats_vs->attributes = array('knights_id' => $combat->toKnight->id, 'opponent' => $combat->fromKnight->id, 'money_total_earned' => 0); } $from_knight_stats_by_date = KnightsStatsByDate::model()->find('knights_id = :knights_id AND date = :date', array(':knights_id' => $fromKnight->id, ':date' => substr($combat->date, 0, 10))); $to_knight_stats_by_date = KnightsStatsByDate::model()->find('knights_id = :knights_id AND date = :date', array(':knights_id' => $toKnight->id, ':date' => substr($combat->date, 0, 10))); if (!$from_knight_stats_by_date) { $from_knight_stats_by_date = new KnightsStatsByDate(); $from_knight_stats_by_date = array('knights_id' => $combat->fromKnight->id, 'date' => date('Y-m-d')); } if (!$to_knight_stats_by_date) { $to_knight_stats_by_date = new KnightsStatsByDate(); $to_knight_stats_by_date = array('knights_id' => $combat->toKnight->id, 'date' => date('Y-m-d')); } if ($combat->result == Combats::RESULT_FROM_KNIGHT_WIN) { $from_knight_stats->combats_wins += 1; $from_knight_stats_vs->combats_wins += 1; $from_knight_stats_by_date->combats_wins += 1; $to_knight_stats->combats_loose += 1; $to_knight_stats_vs->combats_loose += 1; $to_knight_stats_by_date->combats_loose += 1; } else { if ($combat->result == Combats::RESULT_TO_KNIGHT_WIN) { $to_knight_stats->combats_wins += 1; $to_knight_stats_vs->combats_wins += 1; $to_knight_stats_by_date->combats_wins += 1; $from_knight_stats->combats_loose += 1; $from_knight_stats_vs->combats_loose += 1; $from_knight_stats_by_date->combats_loose += 1; } else { $to_knight_stats->combats_draw += 1; $to_knight_stats_vs->combats_draw += 1; $to_knight_stats_by_date->combats_draw += 1; $from_knight_stats->combats_draw += 1; $from_knight_stats_vs->combats_draw += 1; $from_knight_stats_by_date->combats_draw += 1; } } //stats desquality if (Yii::app()->user->knights_id == $combat->fromKnight->id) { $from_knight_stats->desquality_produced += 1; $to_knight_stats->desquality_received += 1; } else { $from_knight_stats->desquality_received += 1; $to_knight_stats->desquality_produced += 1; } //stats money $from_knight_stats->money_total_earned += $precombat->from_knight_gate; $to_knight_stats->money_total_earned += $precombat->to_knight_gate; Yii::trace('[CHARACTER][actionDesqualifyRival] UPDATE STATS '); if (!$from_knight_stats->save()) { trace('[CHARACTER][actionDesqualifyRival] No se puede salvar las estadística de from knight', 'error'); } if (!$from_knight_stats_vs->save()) { trace('[CHARACTER][actionDesqualifyRival] No se puede salvar las estadística vs de from knight stats', 'error'); } if (!$from_knight_stats_by_date->save()) { trace('[CHARACTER][actionDesqualifyRival] No se puede salvar las estadística por dia de from knight stats', 'error'); } if (!$to_knight_stats->save()) { trace('[CHARACTER][actionDesqualifyRival] No se puede salvar las estadística de to knight', 'error'); } if (!$to_knight_stats_vs->save()) { trace('[CHARACTER][actionDesqualifyRival] No se puede salvar las estadística vs de to knight', 'error'); } if (!$to_knight_stats_by_date->save()) { trace('[CHARACTER][actionDesqualifyRival] No se puede salvar las estadística diarias de to knight', 'error'); } //UPDATE knights Yii::trace('[CHARACTER][actionDesqualifyRival] update knights '); if (!$fromKnight->save()) { Yii::trace('[CHARACTER][actionDesqualifyRival] No se ha podido salvar el caballero from knight'); } else { Yii::app()->cache->set(Yii::app()->params['cacheKeys']['knights'] . $fromKnight->id, $fromKnight, Yii::app()->params['cachetime']['knight']); Yii::app()->cache->set(Yii::app()->params['cacheKeys']['knights_by_name'] . $fromKnight->name, $fromKnight, Yii::app()->params['cachetime']['knight']); } if (!$toKnight->save()) { Yii::trace('[CHARACTER][actionDesqualifyRival] No se ha podido salvar el caballero to knight'); } else { Yii::app()->cache->set(Yii::app()->params['cacheKeys']['knights'] . $fromKnight->id, $fromKnight, Yii::app()->params['cachetime']['knight']); Yii::app()->cache->set(Yii::app()->params['cacheKeys']['knights_by_name'] . $fromKnight, $fromKnight, Yii::app()->params['cachetime']['knight']); } //Show desqualify $desqualifyKnight = Yii::app()->user->knights_id == $combat->fromKnight->id ? $combat->fromKnight->name : $combat->toKnight->name; $output['html'] = $this->renderFile(Yii::app()->basePath . '/views/character/dialog_round_desqualified_by.php', array('desqualifiedKnight' => $desqualifyKnight), true); $output['errno'] = 0; } else { $output['html'] = 'Todavía no ha pasado el tiempo para que le puedas descalificar. Faltan ' . ($timeLimit - $requestTime) . ' segundos.'; } } else { $output['html'] = 'No puedes descalificar a tu adversario si no has enviado los datos para la última ronda.'; } } else { $output['html'] = 'Este combate no está en curso.'; } } else { $output['html'] = 'No puedes toquetear combates que no son tuyos.'; } } else { $output['html'] = 'No se ha encontrado el combate.'; } } else { $output['html'] = 'El identificador del combate no es válido.'; } } else { $output['html'] = 'La sesión ha expirado. Necesitas volver a hacer login.'; } //Show output echo CJSON::encode($output); }
public function getListableSchedules() { $listableSchedules = array(); $schedules = $this->schedule; usort($schedules, array($this, 'sortSchedules')); $hasGroup = false; $hasNumber = false; $specialEvents = array('333fm' => array(), '333mbf' => array()); foreach ($schedules as $key => $schedule) { if (trim($schedule->group) != '') { $hasGroup = true; } if ($schedule->number > 0) { $hasNumber = true; } else { $schedule->number = ''; } if (isset($specialEvents[$schedule->event])) { $specialEvents[$schedule->event][$schedule->round][] = $key; } } $scheduleEvents = Events::getOnlyScheduleEvents(); foreach ($schedules as $key => $schedule) { if (isset($scheduleEvents[$schedule->event])) { $schedule->round = $schedule->group = $schedule->format = ''; $schedule->cut_off = $schedule->time_limit = 0; } $event = Yii::t('event', Events::getFullEventName($schedule->event)); if (isset($specialEvents[$schedule->event][$schedule->round]) && count($specialEvents[$schedule->event][$schedule->round]) > 1) { $times = array_search($key, $specialEvents[$schedule->event][$schedule->round]); switch ($times + 1) { case 1: $event .= Yii::t('common', '(1st attempt)'); break; case 2: $event .= Yii::t('common', '(2nd attempt)'); break; case 3: $event .= Yii::t('common', '(3rd attempt)'); break; default: $event .= Yii::t('common', '({times}th attempt)', array('{times}' => $times)); break; } } $temp = array('Start Time' => date('H:i', $schedule->start_time), 'End Time' => date('H:i', $schedule->end_time), 'Event' => $event, 'Group' => $schedule->group, 'Round' => Yii::t('Rounds', Rounds::getFullRoundName($schedule->round)), 'Format' => Yii::t('common', Formats::getFullFormatName($schedule->format)), 'Cut Off' => self::formatTime($schedule->cut_off), 'Time Limit' => self::formatTime($schedule->time_limit), 'Competitors' => $schedule->number, 'id' => $schedule->id, 'event' => $schedule->event, 'round' => $schedule->round); if ($hasGroup === false) { unset($temp['Group']); } if ($hasNumber === false) { unset($temp['Competitors']); } $listableSchedules[$schedule->day][$schedule->stage][] = $temp; } return $listableSchedules; }