本文整理汇总了PHP中Results::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Results::model方法的具体用法?PHP Results::model怎么用?PHP Results::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Results
的用法示例。
在下文中一共展示了Results::model方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResults
public static function getResults($id)
{
//比赛成绩
$winners = Results::model()->with(array('person', 'person.country', 'round', 'event', 'format'))->findAllByAttributes(array('competitionId' => $id, 'pos' => 1, 'roundId' => array('c', 'f')), array('order' => 'event.rank, round.rank, t.pos'));
$top3 = Results::model()->with(array('person', 'person.country', 'round', 'event', 'format'))->findAllByAttributes(array('competitionId' => $id, 'pos' => array(1, 2, 3), 'roundId' => array('c', 'f')), array('order' => 'event.rank, round.rank, t.pos'));
$all = Results::model()->with(array('person', 'person.country', 'round', 'event', 'format'))->findAllByAttributes(array('competitionId' => $id), array('order' => 'event.rank, round.rank, t.pos'));
$scrambles = Scrambles::model()->with(array('round', 'event'))->findAllByAttributes(array('competitionId' => $id), array('order' => 'event.rank, round.rank, t.groupId, t.isExtra, t.scrambleNum'));
return array('winners' => $winners, 'top3' => $top3, 'all' => $all, 'scrambles' => $scrambles);
}
示例2: getCompetitionNum
public function getCompetitionNum()
{
return Results::model()->countByAttributes(array('personId' => $this->id), array('select' => 'COUNT(DISTINCT competitionId)'));
}
示例3: actionCompetition
public function actionCompetition()
{
$provinces = CHtml::listData(Region::getRegionsByPid(1), 'id', 'name_zh');
$cities = Yii::app()->db->cache(86400)->createCommand()->select('*')->from('region')->where('pid>1')->order('id')->queryAll();
$allCities = array();
foreach ($cities as $city) {
if (!isset($allCities[$city['pid']])) {
$allCities[$city['pid']] = array();
}
$allCities[$city['pid']][$city['id']] = $city['name_zh'];
}
$cities = $allCities;
$db = Yii::app()->db;
$db->createCommand()->truncateTable('old_competition');
$oldEvents = $db->createCommand()->select('*')->from('cubingchina_mf8.比赛项目')->order('项目顺序')->queryAll();
$oldEvents = array_combine(array_map(function ($event) {
return $event['项目顺序'];
}, $oldEvents), $oldEvents);
$oldCompetitions = $db->createCommand()->select('*')->from('cubingchina_mf8.比赛事件')->order('比赛id')->queryAll();
foreach ($oldCompetitions as $oldCompetition) {
$competition = new Competition();
//基本信息
$competition->name_zh = str_replace(' ', '', $oldCompetition['比赛名称']);
$competition->date = strtotime($oldCompetition['比赛日期']);
if ($oldCompetition['天数'] > 1) {
$competition->end_date = $competition->date + 86400 * ($oldCompetition['天数'] - 1);
}
$competition->reg_end = $competition->date - 86400;
$competition->old_competition_id = $oldCompetition['比赛id'];
//地点
$location = new CompetitionLocation();
$detected = false;
$address = $oldCompetition['地址'] . $oldCompetition['比赛名称'];
foreach ($provinces as $provinceId => $province) {
if (strpos($address, $province) !== false) {
$location->province_id = $provinceId;
$location->city_id = $this->_cityId;
foreach ($cities[$provinceId] as $cityId => $city) {
if (mb_strlen($city, 'utf-8') > 2) {
$city = mb_substr($city, 0, -1, 'utf-8');
}
if (strpos($address, $city) !== false) {
$location->city_id = $cityId;
break;
}
}
$detected = true;
break;
}
}
if (!$detected) {
$location->province_id = $this->_provinceId;
$location->city_id = $this->_cityId;
}
$location->venue_zh = $oldCompetition['地址'];
$competition->location = array($location);
if ($oldCompetition['是否wca']) {
$competition->type = Competition::TYPE_WCA;
$wcaCompetitions = Competitions::model()->findAllByAttributes(array('countryId' => 'China', 'year' => date('Y', $competition->date), 'month' => date('m', $competition->date), 'day' => date('d', $competition->date)));
$wcaCompetition = null;
if (count($wcaCompetitions) == 1) {
$wcaCompetition = $wcaCompetitions[0];
} else {
foreach ($wcaCompetitions as $value) {
if (strpos($value->website, '=' . $competition->old_competition_id) !== false) {
$wcaCompetition = $value;
break;
}
}
}
if ($wcaCompetition !== null) {
$competition->name = $wcaCompetition->name;
$competition->wca_competition_id = $wcaCompetition->id;
$location->venue = $wcaCompetition->venueDetails . ', ' . $wcaCompetition->venueAddress;
}
} else {
$competition->type = Competition::TYPE_OTHER;
}
//代表和主办
$oldComp = new OldCompetition();
$oldComp->id = $oldCompetition['比赛id'];
$oldComp->delegate_zh = OldCompetition::generateInfo($this->makeInfo($oldCompetition['监督代表']));
$organizer = $this->makeInfo($oldCompetition['主办方']);
if ($oldCompetition['主办电邮']) {
$organizer[0]['email'] = $oldCompetition['主办电邮'];
}
$oldComp->organizer_zh = OldCompetition::generateInfo($organizer);
$oldComp->save(false);
//项目
$events = array();
$resultEvents = $db->createCommand()->select('*')->from('cubingchina_mf8.比赛成绩')->leftJoin('cubingchina_mf8.比赛项目', '比赛项目.项目id=比赛成绩.项目id')->where('比赛成绩.事件id=' . $oldCompetition['比赛id'])->group('比赛成绩.项目id, 比赛成绩.第N轮')->queryAll();
if ($resultEvents !== array()) {
foreach ($resultEvents as $value) {
$eventName = $value['项目名'];
$event = isset($this->_eventsMap[$eventName]) ? $this->_eventsMap[$eventName] : 'funny';
if (!isset($events[$event])) {
$events[$event] = array('round' => 0, 'fee' => 0);
}
$events[$event]['round']++;
}
//.........这里部分代码省略.........
示例4: generateTemplateData
private function generateTemplateData($competition)
{
$data = array('competition' => $competition);
if ($competition->wca_competition_id == '') {
return $data;
}
$events = CHtml::listData(Results::model()->findAllByAttributes(array('competitionId' => $competition->wca_competition_id), array('group' => 'eventId', 'select' => 'eventId,COUNT(1) AS average')), 'eventId', 'average');
if ($events === array()) {
return $data;
}
arsort($events);
$eventId = array_keys($events)[0];
$primaryEvents = array('333', '777', '666', '555', '444', '222', '333fm', '333oh', '333ft', '333bf', '444bf', '555bf');
foreach ($primaryEvents as $event) {
if (isset($events[$event])) {
$eventId = $event;
break;
}
}
$results = Results::model()->findAllByAttributes(array('competitionId' => $competition->wca_competition_id, 'roundId' => array('c', 'f'), 'eventId' => $eventId, 'pos' => array(1, 2, 3)), array('order' => 'eventId, pos'));
if (count($results) < 3) {
return $data;
}
$event = new stdClass();
$event->name = Events::getFullEventName($eventId);
$event->name_zh = Yii::t('event', $event->name);
$data['event'] = $event;
$winners = array('winner', 'runnerUp', 'secondRunnerUp');
foreach ($winners as $key => $top3) {
$data[$top3] = $this->makePerson($results[$key]);
}
$data['records'] = array();
$data['records_zh'] = array();
$recordResults = Results::model()->with('event')->findAllByAttributes(array('competitionId' => $competition->wca_competition_id), array('condition' => 'regionalSingleRecord !="" OR regionalAverageRecord !=""', 'order' => 'event.rank ASC, best ASC, average ASC'));
$records = array();
foreach ($recordResults as $record) {
if ($record->regionalSingleRecord) {
$records[$record->regionalSingleRecord]['single'][] = $record;
}
if ($record->regionalAverageRecord) {
$records[$record->regionalAverageRecord]['average'][] = $record;
}
}
foreach ($records as $region => $record) {
if (isset($record['single'])) {
$records[$region]['single'] = $this->filterRecords($record['single'], 'best', $region);
}
if (isset($record['average'])) {
$records[$region]['average'] = $this->filterRecords($record['average'], 'average', $region);
}
}
if (isset($records['WR'])) {
$rec = $this->makeRecords($records['WR']);
$data['records'][] = sprintf('World records: %s.', $rec['en']);
$data['records_zh'][] = sprintf('世界纪录:%s。', $rec['zh']);
}
$continents = array('AfR' => array('en' => 'Africa', 'zh' => '非洲'), 'AsR' => array('en' => 'Asia', 'zh' => '亚洲'), 'OcR' => array('en' => 'Oceania', 'zh' => '大洋洲'), 'ER' => array('en' => 'Europe', 'zh' => '欧洲'), 'NAR' => array('en' => 'North America', 'zh' => '北美洲'), 'SAR' => array('en' => 'South America', 'zh' => '南美洲'));
foreach ($continents as $cr => $continent) {
if (isset($records[$cr])) {
$rec = $this->makeRecords($records[$cr]);
$data['records'][] = sprintf('%s records: %s.', $continent['en'], $rec['en']);
$data['records_zh'][] = sprintf('%s纪录:%s。', $continent['zh'], $rec['zh']);
}
}
if (isset($records['NR'])) {
$rec = $this->makeRecords($records['NR'], true);
foreach ($rec['en'] as $country => $re) {
$re = implode(', ', $re);
$data['records'][] = sprintf('%s records: %s.', $country, $re);
}
foreach ($rec['zh'] as $country => $re) {
$re = implode(';', $re);
$country = Yii::t('Region', $country);
$data['records_zh'][] = sprintf('%s纪录:%s。', $country, $re);
}
}
$data['records'] = implode('<br>', $data['records']);
$data['records_zh'] = implode('<br>', $data['records_zh']);
if (!empty($data['records'])) {
$data['records'] = '<br>' . $data['records'];
$data['records_zh'] = '<br>' . $data['records_zh'];
}
return $data;
}
示例5: getHasResults
public function getHasResults()
{
return $this->type == self::TYPE_WCA && Results::model()->countByAttributes(array('competitionId' => $this->wca_competition_id)) > 0;
}