public static function build($statistic) { $command = Yii::app()->wcaDb->createCommand()->select(array('r.*', 'rs.personName', 'rs.competitionId', 'c.cellName', 'c.cityName', 'c.year', 'c.month', 'c.day'))->leftJoin('Persons p', 'r.personId=p.id AND p.subid=1')->where('r.countryRank=1 AND rs.personCountryId="China"'); $rows = array(); foreach (Results::getRankingTypes() as $type) { $cmd = clone $command; $cmd->from(sprintf('Ranks%s r', ucfirst($type)))->leftJoin('Results rs', sprintf('r.best=rs.%s AND r.personId=rs.personId AND r.eventId=rs.eventId', $type == 'single' ? 'best' : $type))->leftJoin('Competitions c', 'rs.competitionId=c.id'); foreach ($cmd->queryAll() as $row) { $row['type'] = $type; if (isset($rows[$type][$row['eventId']])) { $temp = $rows[$type][$row['eventId']]; if ($temp['year'] > $row['year'] || $temp['month'] > $row['month'] || $temp['day'] > $row['day']) { continue; } } $row = self::getCompetition($row); $rows[$type][$row['eventId']] = $row; } } $rows = array_merge(array_values($rows['single']), array_values($rows['average'])); usort($rows, function ($rowA, $rowB) { $temp = $rowA['year'] - $rowB['year']; if ($temp == 0) { $temp = $rowA['month'] - $rowB['month']; } if ($temp == 0) { $temp = $rowA['day'] - $rowB['day']; } if ($temp == 0) { $temp = strcmp($rowA['personName'], $rowB['personName']); } return $temp; }); $rows = array_slice($rows, 0, self::$limit); //person days event type result record competition $columns = array(array('header' => 'Yii::t("statistics", "Person")', 'value' => 'Persons::getLinkByNameNId($data["personName"], $data["personId"])', 'type' => 'raw'), array('header' => 'Yii::t("statistics", "Days")', 'value' => 'CHtml::tag("b", array(), floor((time() - strtotime(sprintf("%s-%s-%s", $data["year"], $data["month"], $data["day"]))) / 86400))', 'type' => 'raw'), array('header' => 'Yii::t("common", "Event")', 'value' => 'Yii::t("event", Events::getFullEventName($data["eventId"]))'), array('header' => 'Yii::t("common", "Type")', 'value' => 'Yii::t("common", ucfirst($data["type"]))'), array('header' => 'Yii::t("common", "Result")', 'value' => 'Results::formatTime($data["best"], $data["eventId"])'), array('header' => 'Yii::t("common", "Records")', 'value' => '$data["worldRank"] == 1 ? "WR" : ($data["continentRank"] == 1 ? "AsR" : "NR")'), array('header' => 'Yii::t("common", "Competition")', 'value' => 'CHtml::link(ActiveRecord::getModelAttributeValue($data, "name"), $data["url"])', 'type' => 'raw')); return self::makeStatisticsData($statistic, $columns, $rows); }
</label> <?php echo CHtml::dropDownList('region', $region, Region::getWCARegions(), array('class' => 'form-control')); ?> </div> <div class="form-group"> <label for="Competition_year"><?php echo Yii::t('common', 'Gender'); ?> </label> <?php echo CHtml::dropDownList('gender', $gender, Persons::getGenders(), array('class' => 'form-control')); ?> </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 } ?> </div> <?php $this->endWidget(); ?> <?php $this->widget('RankGridView', array('dataProvider' => new NonSortArrayDataProvider($statistic['rows'], array('pagination' => array('pageSize' => Statistics::$limit, 'pageVar' => 'page'), 'sliceData' => false, 'totalItemCount' => $statistic['count'])), 'template' => '{items}{pager}', 'enableSorting' => false, 'front' => true, 'rankKey' => $statistic['rankKey'], 'rank' => $statistic['rank'], 'count' => ($page - 1) * 100, 'columns' => array_map(function ($column) { $column['header'] = Yii::app()->evaluateExpression($column['header']); return $column;
private function statTop100() { $region = $this->sGet('region', 'China'); $type = $this->sGet('type', 'single'); $event = $this->sGet('event', '333'); $gender = $this->sGet('gender', 'all'); if (!in_array($type, Results::getRankingTypes())) { $type = 'single'; } if (!array_key_exists($gender, Persons::getGenders())) { $gender = 'all'; } if (!array_key_exists($event, Events::getNormalEvents())) { $event = '333'; } if (!Region::isValidRegion($region)) { $region = 'China'; } $statistic = array('class' => 'Top100', 'type' => $type, 'event' => $event, 'gender' => $gender, 'region' => $region); $this->title = Yii::t('statistics', 'Chinese Top 100 Results'); $this->pageTitle = array('Fun Statistics', $this->title); $this->breadcrumbs = array('Results' => array('/results/index'), 'Statistics' => array('/results/statistics'), $this->title); $data = Statistics::buildRankings($statistic); extract($data); $this->render('stat/top100', array('statistic' => $statistic, 'time' => $time, 'region' => $region, 'gender' => $gender, 'event' => $event, 'type' => $type)); }