本文整理汇总了PHP中Region::isContinent方法的典型用法代码示例。如果您正苦于以下问题:PHP Region::isContinent方法的具体用法?PHP Region::isContinent怎么用?PHP Region::isContinent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Region
的用法示例。
在下文中一共展示了Region::isContinent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPenlties
public static function getPenlties($type, $countryId)
{
if (Region::isContinent($countryId)) {
$countryId = '_' . $countryId;
}
$ranksPenalties = self::model()->findAllByAttributes(array('type' => $type, 'countryId' => $countryId));
$penalties = array();
foreach ($ranksPenalties as $ranksPenalty) {
$penalties[$ranksPenalty->eventId] = $ranksPenalty->penalty;
}
//some countries dont' have penalty for some events
//because no person attend the events
foreach (Events::getNormalEvents() as $eventId => $eventName) {
if (!isset($penalties[$eventId])) {
$penalties[$eventId] = 1;
}
}
return $penalties;
}
示例2: build
public static function build($statistic, $page = 1)
{
$gender = isset($statistic['gender']) ? $statistic['gender'] : 'all';
$ranks = self::getRanks($statistic['type'], $statistic['region']);
$eventIds = !empty($statistic['eventIds']) ? $statistic['eventIds'] : array_keys(Events::getNormalEvents());
$eventIds = array_unique($eventIds);
$columns = array(array('header' => 'Yii::t("statistics", "Person")', 'value' => 'Persons::getLinkByNameNId($data["personName"], $data["personId"])', 'type' => 'raw'));
if (Region::isContinent($statistic['region']) || $statistic['region'] === 'World') {
$columns[] = array('header' => 'Yii::t("common", "Region")', 'value' => 'Region::getIconName($data["countryName"], $data["iso2"])', 'type' => 'raw', 'htmlOptions' => array('class' => 'region'));
}
$columns[] = array('header' => 'Yii::t("statistics", "Sum")', 'value' => 'CHtml::tag("b", array(), $data["sum"])', 'type' => 'raw');
//计算未参赛的项目应该排第几
$penalty = RanksPenalty::getPenlties($statistic['type'], $statistic['region']);
foreach ($eventIds as $key => $eventId) {
if (!isset($ranks[$eventId])) {
unset($eventIds[$key]);
continue;
}
}
$penalty = array_intersect_key($penalty, array_flip($eventIds));
$allPenalties = array_sum($penalty);
//计算每个人的排名
$rankSum = array();
foreach ($eventIds as $eventId) {
foreach ($ranks[$eventId] as $personId => $row) {
if (!isset($rankSum[$personId])) {
$rankSum[$personId] = $row;
$rankSum[$personId]['sum'] = $allPenalties;
}
$rankSum[$personId]['sum'] += $row['rank'] - $penalty[$eventId];
}
$columns[] = array('header' => "CHtml::tag('span', array(\r\n\t\t\t\t\t'class'=>'event-icon event-icon-white event-icon-{$eventId}'\r\n\t\t\t\t), ' ')", 'name' => $eventId, 'type' => 'raw');
}
uasort($rankSum, function ($rankA, $rankB) {
return $rankA['sum'] - $rankB['sum'];
});
switch ($gender) {
case 'female':
$rankSum = array_filter($rankSum, function ($row) {
return $row['gender'] == 'f';
});
break;
case 'male':
$rankSum = array_filter($rankSum, function ($row) {
return $row['gender'] == 'm';
});
break;
}
$count = count($rankSum);
if ($page > ceil($count / self::$limit)) {
$page = ceil($count / self::$limit);
}
$rows = array();
foreach (array_slice($rankSum, ($page - 1) * self::$limit, self::$limit) as $personId => $row) {
foreach ($eventIds as $eventId) {
$row[$eventId] = isset($ranks[$eventId][$personId]) ? $ranks[$eventId][$personId]['rank'] : $penalty[$eventId];
if (isset($ranks[$eventId][$personId]) && $ranks[$eventId][$personId]['rank'] <= 10) {
$row[$eventId] = CHtml::tag('span', array('class' => 'top10'), $row[$eventId]);
} elseif (!isset($ranks[$eventId][$personId])) {
$row[$eventId] = CHtml::tag('span', array('class' => 'penalty'), $row[$eventId]);
}
}
$rows[] = $row;
}
$statistic['count'] = $count;
$statistic['rank'] = isset($rows[0]) ? count(array_filter($rankSum, function ($row) use($rows) {
return $row['sum'] < $rows[0]['sum'];
})) : 0;
$statistic['rankKey'] = 'sum';
return self::makeStatisticsData($statistic, $columns, $rows);
}