Пример #1
0
 public function renderList()
 {
     $this->articles->where('ad', '1');
     $this->template->setFile(__DIR__ . "/CompetitionsList.latte");
     $this->headline = true;
     $this->render();
 }
Пример #2
0
 public function actionCompetitionHistory()
 {
     if ($this->user->id === '') {
         $this->redirect(array('/user/competitions'));
     }
     $model = new Competitions('search');
     $model->unsetAttributes();
     $this->render('competitionHistory', array('model' => $model));
 }
Пример #3
0
 /**
  * @param null $args
  */
 public function render($args = NULL)
 {
     parent::render($args);
     // TODO: Change the autogenerated stub
     $articles = $this->articles->where('published < NOW()')->order('created DESC')->limit(10)->fetchPairs('created');
     $venues = $this->venues->fetchVisible()->order('created DESC')->limit(10)->fetchPairs('created');
     $competitions = $this->competitions->order('created DESC')->limit(10)->fetchPairs('created');
     $output = $articles + $venues + $competitions;
     krsort($output);
     $this->template->items = $output;
     $this->template->setFile(__DIR__ . "/StreamControl.basic.latte");
     $this->template->render();
 }
Пример #4
0
 public function onSuccess(\Nette\Application\UI\Form $form)
 {
     try {
         $vars = $form->getValues();
         $this->items->competition = $vars;
         $this->items->save();
         $this->cleanCache('', array('competitions', 'competition'));
         $this->flashMessage('Competition has been saved successfully!', 'ok');
         $this->redirect('default');
     } catch (Exception $e) {
         $this->flashMessage('Ooops! Something bad happend! ' . $e->getMessage(), 'err');
     }
 }
Пример #5
0
 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']++;
             }
         }
         if ($events === array() && $competition->wca_competition_id !== '') {
             $resultEvents = Results::model()->findAllByAttributes(array('competitionId' => $competition->wca_competition_id), array('group' => 'eventId,roundId'));
             if ($resultEvents !== array()) {
                 foreach ($resultEvents as $value) {
                     $event = $value->eventId;
                     if (!isset($events[$event])) {
                         $events[$event] = array('round' => 0, 'fee' => 0);
                     }
                     $events[$event]['round']++;
                 }
             }
         }
         if ($events === array()) {
             for ($i = 0; $i < strlen($oldCompetition['比赛项目']); $i++) {
                 if ($oldCompetition['比赛项目'][$i]) {
                     $eventName = $oldEvents[$i + 1]['项目名'];
                     $event = isset($this->_eventsMap[$eventName]) ? $this->_eventsMap[$eventName] : 'funny';
                     $events[$event] = array('round' => 1, 'fee' => 0);
                 }
             }
         }
         $competition->events = $events;
         $competition->handleEvents();
         $ret = $competition->save(false);
         $location->competition_id = $competition->id;
         $location->save(false);
     }
 }
Пример #6
0
 public function actionC()
 {
     $id = $this->sGet('id');
     $type = $this->sGet('type', 'winners');
     $types = Competitions::getResultsTypes();
     $competition = Competitions::model()->findByAttributes(array('id' => $id));
     if ($competition == null) {
         $this->redirect(array('/results/competition'));
     }
     if (!array_key_exists($type, $types)) {
         $type = 'winners';
     }
     if (($c = Competition::model()->findByAttributes(array('wca_competition_id' => $id))) !== null) {
         $competition->name = $c->getAttributeValue('name');
         $competition->location = $c->isMultiLocation() ? $c->getLocationInfo('venue') : $c->location[0]->getFullAddress(false);
         $competition->c = $c;
     }
     $data = Yii::app()->cache->getData(array('Competitions', 'getResults'), $id);
     if (empty($data['scrambles']) && $type !== 'scrambles') {
         unset($types['scrambles']);
     }
     $data['competition'] = $competition;
     $data['type'] = $type;
     $data['types'] = $types;
     $this->breadcrumbs = array('Results' => array('/results/index'), 'Competitions' => array('/results/competition'), $competition->name);
     $this->pageTitle = array($competition->name, 'Competition Results');
     $this->title = $competition->name;
     // $this->setWeiboShareDefaultText($competition->name . '选手的魔方速拧成绩页 - 粗饼·中国魔方赛事网', false);
     $this->render('c', $data);
 }
Пример #7
0
<div class="col-lg-12">
  <?php 
$form = $this->beginWidget('ActiveForm', array('htmlOptions' => array('role' => 'form', 'class' => 'form-inline'), 'method' => 'get', 'action' => array('/results/competition')));
?>
    <div class="form-group">
      <label for="year"><?php 
echo Yii::t('common', 'Year');
?>
</label>
      <?php 
echo CHtml::dropDownList('year', $model->year, Competitions::getYears(), array('class' => 'form-control', 'prompt' => Yii::t('common', 'All')));
?>
    </div>
    <div class="form-group">
      <label for="region"><?php 
echo Yii::t('common', 'Region');
?>
</label>
      <?php 
echo CHtml::dropDownList('region', $model->region, Region::getWCARegions(), array('class' => 'form-control'));
?>
    </div>
    <div class="form-group">
      <label for="event"><?php 
echo Yii::t('common', 'Event');
?>
</label>
      <?php 
echo CHtml::dropDownList('event', $model->event, Events::getNormalTranslatedEvents(), array('class' => 'form-control', 'prompt' => Yii::t('common', 'All')));
?>
    </div>
Пример #8
0
 public function getDisplayDate()
 {
     return Competitions::getDisplayDate($this->date, $this->end_date);
 }