本文整理汇总了PHP中Statistics::getCompetition方法的典型用法代码示例。如果您正苦于以下问题:PHP Statistics::getCompetition方法的具体用法?PHP Statistics::getCompetition怎么用?PHP Statistics::getCompetition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statistics
的用法示例。
在下文中一共展示了Statistics::getCompetition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCompetitionLink
public function getCompetitionLink()
{
$competition = Statistics::getCompetition(array('competitionId' => $this->competitionId, 'cellName' => $this->competition->cellName, 'cityName' => $this->competition->cityName));
return CHtml::link(ActiveRecord::getModelAttributeValue($competition, 'name'), $competition['url']);
}
示例2: getResults
//.........这里部分代码省略.........
$sumOfRank->getRanks();
}
//奖牌数量
$command = $db->createCommand();
$command->select(array('eventId', 'sum(CASE WHEN pos=1 AND roundId IN ("c", "f") AND best>0 THEN 1 ELSE 0 END) AS gold', 'sum(CASE WHEN pos=2 AND roundId IN ("c", "f") AND best>0 THEN 1 ELSE 0 END) AS silver', 'sum(CASE WHEN pos=3 AND roundId IN ("c", "f") AND best>0 THEN 1 ELSE 0 END) AS bronze', 'sum(CASE WHEN value1>0 THEN 1 ELSE 0 END)
+sum(CASE WHEN value2>0 THEN 1 ELSE 0 END)
+sum(CASE WHEN value3>0 THEN 1 ELSE 0 END)
+sum(CASE WHEN value4>0 THEN 1 ELSE 0 END)
+sum(CASE WHEN value5>0 THEN 1 ELSE 0 END)
AS solve', 'sum(CASE WHEN value1>-2 AND value1!=0 THEN 1 ELSE 0 END)
+sum(CASE WHEN value2>-2 AND value2!=0 THEN 1 ELSE 0 END)
+sum(CASE WHEN value3>-2 AND value3!=0 THEN 1 ELSE 0 END)
+sum(CASE WHEN value4>-2 AND value4!=0 THEN 1 ELSE 0 END)
+sum(CASE WHEN value5>-2 AND value5!=0 THEN 1 ELSE 0 END)
AS attempt'))->from('Results')->where('personId=:personId', array(':personId' => $id))->group('eventId');
foreach ($command->queryAll() as $row) {
if (isset($personRanks[$row['eventId']])) {
$personRanks[$row['eventId']]->medals = $row;
}
}
//历史成绩
$competitions = array();
$personResults = array();
$eventId = '';
$best = $average = PHP_INT_MAX;
$results = Results::model()->with(array('competition', 'competition.country', 'round', 'event'))->findAllByAttributes(array('personId' => $id), array('order' => 'event.rank, competition.year, competition.month, competition.day, round.rank'));
foreach ($results as $result) {
if ($eventId != $result->eventId) {
//重置各值
$eventId = $result->eventId;
$best = $average = PHP_INT_MAX;
$personResults[$eventId] = array();
}
if ($result->best > 0 && $result->best <= $best) {
$result->newBest = true;
$best = $result->best;
}
if ($result->average > 0 && $result->average <= $average) {
$result->newAverage = true;
$average = $result->average;
}
$personResults[$eventId][] = $result;
$competitions[$result->competitionId] = $result->competition;
}
//世锦赛获奖记录
$wcPodiums = Results::model()->with(array('competition', 'event'))->findAllByAttributes(array('personId' => $id, 'roundId' => array('c', 'f'), 'pos' => array(1, 2, 3)), array('condition' => 'competitionId LIKE "WC%"', 'order' => 'competition.year DESC, event.rank ASC'));
//WR们
$historyWR = Results::model()->with(array('competition', 'event', 'round'))->findAllByAttributes(array('personId' => $id), array('condition' => 'regionalSingleRecord="WR" OR regionalAverageRecord="WR"', 'order' => 'event.rank ASC, competition.year DESC, competition.month DESC, competition.day DESC, round.rank DESC'));
//CR们
$historyCR = Results::model()->with(array('competition', 'event', 'round'))->findAllByAttributes(array('personId' => $id), array('condition' => 'regionalSingleRecord NOT IN ("WR", "NR", "") OR regionalAverageRecord NOT IN ("WR", "NR", "")', 'order' => 'event.rank ASC, competition.year DESC, competition.month DESC, competition.day DESC, round.rank DESC'));
//NR们
$historyNR = Results::model()->with(array('competition', 'event', 'round'))->findAllByAttributes(array('personId' => $id), array('condition' => 'regionalSingleRecord="NR" OR regionalAverageRecord="NR"', 'order' => 'event.rank ASC, competition.year DESC, competition.month DESC, competition.day DESC, round.rank DESC'));
//
$firstCompetitionResult = Results::model()->with(array('competition'))->findByAttributes(array('personId' => $id), array('order' => 'competition.year ASC, competition.month ASC, competition.day ASC'));
$lastCompetitionResult = Results::model()->with(array('competition'))->findByAttributes(array('personId' => $id), array('order' => 'competition.year DESC, competition.month DESC, competition.day DESC'));
$overAll = array('gold' => array_sum(array_map(function ($result) {
return $result->medals['gold'];
}, $personRanks)), 'silver' => array_sum(array_map(function ($result) {
return $result->medals['silver'];
}, $personRanks)), 'bronze' => array_sum(array_map(function ($result) {
return $result->medals['bronze'];
}, $personRanks)), 'WR' => count(array_filter($historyWR, function ($result) {
return $result->regionalSingleRecord == 'WR';
})) + count(array_filter($historyWR, function ($result) {
return $result->regionalAverageRecord == 'WR';
})), 'CR' => count(array_filter($historyCR, function ($result) {
return !in_array($result->regionalSingleRecord, array('WR', 'NR', ''));
})) + count(array_filter($historyCR, function ($result) {
return !in_array($result->regionalAverageRecord, array('WR', 'NR', ''));
})), 'NR' => count(array_filter($historyNR, function ($result) {
return $result->regionalSingleRecord == 'NR';
})) + count(array_filter($historyNR, function ($result) {
return $result->regionalAverageRecord == 'NR';
})));
usort($competitions, function ($competitionA, $competitionB) {
$temp = $competitionB->year - $competitionA->year;
if ($temp == 0) {
$temp = $competitionB->month - $competitionA->month;
}
if ($temp == 0) {
$temp = $competitionB->day - $competitionA->day;
}
return -$temp;
});
$temp = array('longitude' => 0, 'latitude' => 0);
$mapData = array();
foreach ($competitions as $key => $competition) {
$temp['longitude'] += $competition->longitude / 1000000.0;
$temp['latitude'] += $competition->latitude / 1000000.0;
$data = Statistics::getCompetition(array('competitionId' => $competition->id, 'cellName' => $competition->cellName, 'cityName' => $competition->cityName));
$data['longitude'] = $competition->longitude / 1000000.0;
$data['latitude'] = $competition->latitude / 1000000.0;
$data['url'] = CHtml::normalizeUrl($data['url']);
$data['date'] = $competition->getDate();
$competition->number = $key + 1;
$mapData[] = $data;
}
$mapCenter = array('longitude' => number_format($temp['longitude'] / count($competitions), 6, ',', ''), 'latitude' => number_format($temp['latitude'] / count($competitions), 6, ',', ''));
return array('id' => $id, 'personRanks' => $personRanks, 'sumOfRanks' => $sumOfRanks, 'personResults' => call_user_func_array('array_merge', array_map('array_reverse', $personResults)), 'wcPodiums' => $wcPodiums, 'historyWR' => $historyWR, 'historyCR' => $historyCR, 'historyNR' => $historyNR, 'overAll' => $overAll, 'score' => $overAll['WR'] * 10 + $overAll['CR'] * 5 + $overAll['NR'], 'firstCompetition' => $firstCompetitionResult->competition, 'lastCompetition' => $lastCompetitionResult->competition, 'mapData' => $mapData, 'mapCenter' => $mapCenter, 'competitions' => array_reverse($competitions), 'user' => User::model()->findByAttributes(array('wcaid' => $id, 'status' => User::STATUS_NORMAL)));
}