public function actionRecords() { $type = $this->sGet('type', 'current'); $region = $this->sGet('region', 'China'); $event = $this->sGet('event', '333'); if (!in_array($type, array('current', 'history'))) { $type = 'current'; } if (!array_key_exists($event, Events::getNormalEvents())) { $event = '333'; } if ($type !== 'history') { $event = ''; } if (!Region::isValidRegion($region)) { $region = 'China'; } $records = Results::getRecords($type, $region, $event); $this->title = 'Official Records'; $pageTitle = array('Official Records', Yii::t('Region', $region)); if ($type === 'history') { $pageTitle[] = Yii::t('event', Events::getFullEventName($event)); } $pageTitle[] = Yii::t('Results', ucfirst($type)); $this->pageTitle = $pageTitle; $this->description = Yii::t('statistics', 'Regional records are displayed on the page, based on the official WCA records.'); $this->setWeiboShareDefaultText('世界魔方协会(WCA)所有官方项目的纪录展示'); $this->render('records', array('records' => $records, 'type' => $type, 'region' => $region, 'event' => $event)); }
echo $competition->secondStageFee($competition->entry_fee); ?> </td> <?php } ?> </tr> <?php foreach ($competition->events as $key => $value) { ?> <?php if ($value['round'] > 0) { ?> <tr> <td><?php echo Yii::t('event', Events::getFullEventName($key)); ?> </td> <td> +<i class="fa fa-rmb"></i><?php echo $value['fee']; ?> </td> <?php if ($competition->hasSecondStage) { ?> <td> +<i class="fa fa-rmb"></i><?php echo $competition->secondStageFee($value['fee'], $competition->second_stage_all); ?> </td> <?php }
private function makeRecords($records, $isNR = false) { $rec = array('en' => array(), 'zh' => array()); foreach ($records as $type => $recs) { foreach ($recs as $result) { $eventName = Events::getFullEventName($result->eventId); $temp = $this->makePerson($result, true, $type); $enRec = sprintf('%s %s %s (%s)', $temp->link, $eventName, $temp->score, $type); $zhRec = sprintf('%s的%s纪录(%s),创造者%s', Yii::t('event', $eventName), $type === 'average' ? '平均' : '单次', $temp->score_zh, $temp->link_zh); if ($isNR) { $rec['en'][$result->personCountryId][] = $enRec; $rec['zh'][$result->personCountryId][] = $zhRec; } else { $rec['en'][] = $enRec; $rec['zh'][] = $zhRec; } } } if (!$isNR) { $rec['en'] = implode(', ', $rec['en']); $rec['zh'] = implode(';', $rec['zh']); } return $rec; }
public function exportScoreCard($competition, $all = false, $order = 'date') { $registrations = $this->getRegistrations($competition, $all, $order); $tempPath = Yii::app()->runtimePath; $templatePath = APP_PATH . '/public/static/score-card.xlsx'; $scoreCard = PHPExcel_IOFactory::load($templatePath); $scoreCard->getProperties()->setCreator(Yii::app()->params->author)->setLastModifiedBy(Yii::app()->params->author)->setTitle($competition->wca_competition_id ?: $competition->name)->setSubject($competition->name); $sheet = $scoreCard->getSheet(0); //修复图片宽高及偏移 $imageStyle = array('width' => 65, 'height' => 63, 'offsetX' => 2, 'offsetY' => 1); $drawingCollection = $sheet->getDrawingCollection(); foreach ($drawingCollection as $drawing) { $drawing->setWidth($imageStyle['width'])->setHeight($imageStyle['height']); $drawing->setOffsetX($imageStyle['offsetX'])->setOffsetY($imageStyle['offsetY']); } $title = "{$competition->name_zh} ({$competition->name}) - 成绩记录单 (Score Card)"; $rowHeights = array(); $xfIndexes = array(); $oneCardRow = 13; for ($row = 1; $row <= $oneCardRow; $row++) { $height = $sheet->getRowDimension($row)->getRowHeight(); if ($height === -1) { $height = isset($rowHeights[$row - 1]) ? $rowHeights[$row - 1] - 1 : 10; } $rowHeights[$row] = $height; $xfIndexes[$row] = array(); for ($col = 'A'; strcmp($col, 'AL') != 0; $col++) { $xfIndexes[$row][$col] = $sheet->getCell($col . $row)->getXfIndex(); } } $staticCells = array('A3', 'K3', 'O3', 'S3', 'Z3', 'AK3', 'A5', 'B5', 'G5', 'G6', 'S5', 'S6', 'AE5', 'AJ5', 'A8', 'A9', 'A10', 'A11', 'A12', 'AJ8', 'AJ9', 'AJ10', 'AJ11', 'AJ12', 'A13', 'S13'); $values = array(); foreach ($staticCells as $cell) { $value = $sheet->getCell($cell)->getValue(); $template = preg_replace('{\\d+}', '{row}', $cell); $row = preg_replace('{[A-Z]}', '', $cell); $values[] = array('value' => $value, 'template' => $template, 'row' => $row); } $i = 0; $count = 0; foreach ($registrations as $registration) { foreach ($registration->events as $event) { if ($event === '333fm') { continue; } //合并单元格 //标题 $sheet->mergeCells(sprintf('A%d:AK%d', $i * $oneCardRow + 2, $i * $oneCardRow + 2)); //项目、轮次等 $sheet->mergeCells(sprintf('A%d:B%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('C%d:J%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('K%d:L%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('M%d:N%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('O%d:P%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('Q%d:R%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('S%d:T%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('U%d:Y%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('Z%d:AA%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('AB%d:AJ%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); $sheet->mergeCells(sprintf('AK%d:AK%d', $i * $oneCardRow + 3, $i * $oneCardRow + 4)); //表头 $sheet->mergeCells(sprintf('A%d:A%d', $i * $oneCardRow + 5, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('B%d:F%d', $i * $oneCardRow + 5, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('G%d:R%d', $i * $oneCardRow + 5, $i * $oneCardRow + 5)); $sheet->mergeCells(sprintf('S%d:AD%d', $i * $oneCardRow + 5, $i * $oneCardRow + 5)); $sheet->mergeCells(sprintf('G%d:R%d', $i * $oneCardRow + 6, $i * $oneCardRow + 6)); $sheet->mergeCells(sprintf('S%d:AD%d', $i * $oneCardRow + 6, $i * $oneCardRow + 6)); $sheet->mergeCells(sprintf('G%d:I%d', $i * $oneCardRow + 7, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('J%d:L%d', $i * $oneCardRow + 7, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('M%d:O%d', $i * $oneCardRow + 7, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('P%d:R%d', $i * $oneCardRow + 7, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('S%d:U%d', $i * $oneCardRow + 7, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('V%d:X%d', $i * $oneCardRow + 7, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('Y%d:AA%d', $i * $oneCardRow + 7, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('AB%d:AD%d', $i * $oneCardRow + 7, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('AE%d:AI%d', $i * $oneCardRow + 5, $i * $oneCardRow + 7)); $sheet->mergeCells(sprintf('AJ%d:AJ%d', $i * $oneCardRow + 5, $i * $oneCardRow + 7)); //表身 $sheet->mergeCells(sprintf('B%d:F%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('B%d:F%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('B%d:F%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('B%d:F%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('B%d:F%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('G%d:I%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('J%d:L%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('M%d:O%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('P%d:R%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('S%d:U%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('V%d:X%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('Y%d:AA%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('AB%d:AD%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('G%d:I%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('J%d:L%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('M%d:O%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('P%d:R%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('S%d:U%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('V%d:X%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('Y%d:AA%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('AB%d:AD%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('G%d:I%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('J%d:L%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('M%d:O%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('P%d:R%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('S%d:U%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('V%d:X%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('Y%d:AA%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('AB%d:AD%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('G%d:I%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('J%d:L%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('M%d:O%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('P%d:R%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('S%d:U%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('V%d:X%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('Y%d:AA%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('AB%d:AD%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('G%d:I%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('J%d:L%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('M%d:O%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('P%d:R%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('S%d:U%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('V%d:X%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('Y%d:AA%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('AB%d:AD%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); $sheet->mergeCells(sprintf('AE%d:AI%d', $i * $oneCardRow + 8, $i * $oneCardRow + 8)); $sheet->mergeCells(sprintf('AE%d:AI%d', $i * $oneCardRow + 9, $i * $oneCardRow + 9)); $sheet->mergeCells(sprintf('AE%d:AI%d', $i * $oneCardRow + 10, $i * $oneCardRow + 10)); $sheet->mergeCells(sprintf('AE%d:AI%d', $i * $oneCardRow + 11, $i * $oneCardRow + 11)); $sheet->mergeCells(sprintf('AE%d:AI%d', $i * $oneCardRow + 12, $i * $oneCardRow + 12)); //表尾 $sheet->mergeCells(sprintf('A%d:R%d', $i * $oneCardRow + 13, $i * $oneCardRow + 13)); $sheet->mergeCells(sprintf('S%d:AJ%d', $i * $oneCardRow + 13, $i * $oneCardRow + 13)); //调整各行高度及样式 for ($j = 1; $j <= $oneCardRow; $j++) { $row = $i * $oneCardRow + $j; $sheet->getRowDimension($row)->setRowHeight($rowHeights[$j]); foreach ($xfIndexes[$j] as $col => $xfIndex) { $sheet->getCell($col . $row)->setXfIndex($xfIndex); } } //填写固定内容 foreach ($values as $value) { $row = $i * $oneCardRow + $value['row']; $cell = str_replace('{row}', $row, $value['template']); $sheet->setCellValue($cell, $value['value']); } //比赛名字 $row = $i * $oneCardRow + 2; $sheet->setCellValue("A{$row}", $title); //项目、轮次、编号等 $row = $i * $oneCardRow + 3; $eventName = Events::getFullEventName($event); $eventName = sprintf('%s (%s)', Yii::t('event', $eventName), $eventName); $sheet->setCellValue("C{$row}", $eventName); $sheet->setCellValue("M{$row}", '1st'); $sheet->setCellValue("Q{$row}", $registration->number); $sheet->setCellValue("U{$row}", $registration->user->wcaid); $sheet->setCellValue("AB{$row}", $registration->user->getCompetitionName()); //8个图片 $row = $i * $oneCardRow + 7; $col = 'G'; for ($j = 0; $j < 8; $j++) { $drawing = new PHPExcelDrawing(); $drawing->setImageIndex($drawingCollection[$j]->getImageIndex()); $drawing->setWorksheet($sheet); $drawing->setPath($drawingCollection[$j]->getPath(), false); $drawing->setResizeProportional(false); $drawing->setCoordinates("{$col}{$row}"); $drawing->setWidth($imageStyle['width'])->setHeight($imageStyle['height']); $drawing->setOffsetX($imageStyle['offsetX'])->setOffsetY($imageStyle['offsetY']); $col++; $col++; $col++; } $i++; //400张一个表 if ($i == 400) { $path = $tempPath . '/' . $competition->name . ".{$count}.xlsx"; $sheet->getRowDimension(4)->setRowHeight($rowHeights[4]); $this->exportToExcel($scoreCard, $path); //释放内存 $scoreCard->disconnectWorksheets(); unset($scoreCard, $sheet); $count++; $i = 0; //新开excel $scoreCard = PHPExcel_IOFactory::load($templatePath); $scoreCard->getProperties()->setCreator(Yii::app()->params->author)->setLastModifiedBy(Yii::app()->params->author)->setTitle($competition->wca_competition_id ?: $competition->name)->setSubject($competition->name); $sheet = $scoreCard->getSheet(0); //修复图片宽高及偏移 $drawingCollection = $sheet->getDrawingCollection(); foreach ($drawingCollection as $drawing) { $drawing->setWidth($imageStyle['width'])->setHeight($imageStyle['height']); $drawing->setOffsetX($imageStyle['offsetX'])->setOffsetY($imageStyle['offsetY']); } } } } if ($count == 0) { //修复第四行高度 $sheet->getRowDimension(4)->setRowHeight($rowHeights[4]); $this->exportToExcel($scoreCard, 'php://output', $competition->name); } else { //压缩成zip $path = $tempPath . '/' . $competition->name . ".{$count}.xlsx"; $sheet->getRowDimension(4)->setRowHeight($rowHeights[4]); $this->exportToExcel($scoreCard, $path); //释放内存 $scoreCard->disconnectWorksheets(); unset($scoreCard, $sheet); $count++; $zip = new ZipArchive(); $tempName = tempnam($tempPath, 'scoreCardTmp'); if ($zip->open($tempName, ZipArchive::CREATE) !== true) { throw new CHttpException(500, '创建压缩文件失败'); } $dir = 'score-card'; $zip->addEmptyDir($dir); for ($i = 0; $i < $count; $i++) { $path = $tempPath . '/' . $competition->name . ".{$i}.xlsx"; $zip->addFile($path, $dir . '/' . basename($path)); } $zip->close(); header('Content-Type: application/zip'); header('Content-Disposition: attachment;filename="' . $competition->name . '.zip"'); readfile($tempName); //删除临时文件 for ($i = 0; $i < $count; $i++) { $path = $tempPath . '/' . $competition->name . ".{$i}.xlsx"; unlink($path); } unlink($tempName); exit; } }
<div class="panel-collapse collapse in"> <div class="portlet-body"> <?php $form = $this->beginWidget('ActiveForm', array('htmlOptions' => array('class' => 'form-horizontal'), 'enableClientValidation' => true)); ?> <?php foreach ($competition->events as $event => $data) { ?> <?php if ($data['round'] <= 0) { continue; } ?> <div class="form-group"> <?php echo $form->labelEx($model, 'name_zh', array('class' => 'col-lg-2 control-label', 'label' => Yii::t('event', Events::getFullEventName($event)))); ?> <div class="col-lg-10 checkbox"> <?php for ($i = 0; $i < $data['round']; $i++) { ?> <div class="export-round"> 第<?php echo $i + 1; ?> 轮:<?php echo CHtml::dropDownList("event[{$event}][{$i}]", Events::getDefaultExportFormat($event), $exportFormsts, array()); ?> </div> <?php }
</div> <?php foreach (Results::getRankingTypes() as $_type) { ?> <?php echo CHtml::tag('button', array('type' => 'submit', 'name' => 'type', 'value' => $_type, 'class' => 'btn btn-' . ($type == $_type ? 'warning' : 'theme')), Yii::t('common', ucfirst($_type))); ?> <?php } ?> <?php $this->endWidget(); ?> <div class="event-title"> <?php echo CHtml::tag('span', array('class' => 'event-icon event-icon-' . $event), Yii::t('event', Events::getFullEventName($event))); ?> <?php echo Yii::t('Region', $region); ?> <?php echo Yii::t('common', ucfirst($gender)); ?> <?php echo Yii::t('common', ucfirst($type)); ?> </div> <?php
public function getEventsColumns($headerText = false) { $region = 'Yii::t("Region", $data->user->country->getAttributeValue("name"))'; if (Yii::app()->language == 'zh_cn') { $region .= '.$data->user->getRegionName($data->user->province). (in_array($data->user->province_id, array(215, 525, 567, 642)) ? "" : $data->user->getRegionName($data->user->city))'; } $columns = array(array('headerHtmlOptions' => array('class' => 'battle-checkbox'), 'header' => Yii::t('common', 'Battle'), 'value' => 'Persons::getBattleCheckBox($data->user->getCompetitionName(), $data->user->wcaid)', 'type' => 'raw'), array('name' => 'number', 'header' => 'No.', 'value' => '$data->number'), array('name' => 'name', 'header' => Yii::t('Competition', 'Name'), 'headerHtmlOptions' => array('class' => 'header-username'), 'type' => 'raw', 'value' => '$data->user->getWcaLink()'), array('name' => 'gender', 'header' => Yii::t('common', 'Gender'), 'headerHtmlOptions' => array('class' => 'header-gender'), 'type' => 'raw', 'value' => '$data->user->getGenderText()'), array('name' => 'country_id', 'header' => Yii::t('common', 'Region'), 'headerHtmlOptions' => array('class' => 'header-region'), 'type' => 'raw', 'value' => $region)); if ($this->isMultiLocation()) { $columns[] = array('name' => 'location_id', 'header' => Yii::t('common', 'Competition Site'), 'headerHtmlOptions' => array('class' => 'header-location'), 'type' => 'raw', 'value' => '$data->location->getFullAddress(false)'); } foreach ($this->events as $event => $value) { if ($value['round'] > 0) { $columns[] = array('name' => (string) $event, 'header' => CHtml::tag('span', array('class' => 'event-icon event-icon-white event-icon-' . $event, 'title' => Yii::t('event', Events::getFullEventName($event))), $headerText ? $event : ''), 'headerHtmlOptions' => array('class' => 'header-event'), 'htmlOptions' => Yii::app()->controller->sGet('sort') === "{$event}" ? array('class' => 'hover') : array(), 'type' => 'raw', 'value' => "\$data->getEventsString('{$event}')"); } } return $columns; }