protected function retrievePerson($nefubId) { $url = NEFUB_API . '/person.php?id=' . $nefubId; $personDetails = $this->getNefubContentsParsed($url, MAX_AGE_PERSON_DETAILS); $oPerson = self::convertPerson($personDetails); self::put('Persoon ' . $oPerson->name . ' toegevoegd'); $oRetrieveLog = $this->retrieveLog; if (isset($personDetails->Teams) && is_array($personDetails->Teams)) { $teams = $personDetails->Teams; foreach ($teams as $team) { if (!($oTeam = Team::getByNefubId($team->ID))) { $oTeam = new Team(); $oTeam->nefub_id = $team->ID; $oTeam->name = $team->Name; $competition = $team->Competition; self::put('Team ' . $oTeam->name . ' toevoegen'); self::put('Team ' . $oTeam->name . ' toevoegen'); $newTeams++; if (!($oCompetition = Competition::getByNefubId($competition->ID))) { $oCompetition = new Competition(); $oCompetition->name = $competition->Name; $oCompetition->nefub_id = $competition->ID; $aSeasonYears = explode('-', $competition->Season); $oCompetition->season_nefub_id = Season::getInstance()->nefub_id; $oCompetition->save(); } $oGenre = $this->convertGenre($competition->Genre); $oGender = $this->convertGenre($competition->Gender); $oCompetitionType = $this->convertCompetitionType($competition->Type); $oCompetition->genre_id = $oGenre->getId(); $oCompetition->gender_id = $oGender->getId(); $oCompetition->competition_type_id = $oCompetitionType->getId(); $oCompetition->save(); $oTeam->season_nefub_id = Season::getInstance()->nefub_id; $oTeam->competition_nefub_id = $oCompetition->nefub_id; $oTeam->save(); self::put('Team ' . $oTeam->name . ' toegevoegd'); $newTeams++; } if (!($oTeamPerson = TeamPerson::getByNefubId($oPerson->nefub_id, $oTeam->nefub_id))) { $oTeamPerson = new TeamPerson(); $oTeamPerson->team_nefub_id = $oTeam->nefub_id; $oTeamPerson->person_nefub_id = $oPerson->nefub_id; $oTeamPerson->save(); self::put('Persoon ' . $oPerson->name . ' aan team ' . $oTeam->name . ' toegevoegd'); $newTeamPersons++; } } } else { self::put("API is aangepast"); self::put($personDetails); $data["msg"] = "Kon geen teams van persoon ophalen. API is aangepast: \n" . print_r($personDetails, true); $this->updateLog($data, true); exit; } $newData = array('teams' => $newTeams, 'personen' => $newPersons, 'teampersonen' => $newTeamPersons); $this->updateLog($newData); }
public function actionAdd() { if ($this->user->isOrganizer() && Competition::getUnpublicCount() >= 2) { Yii::app()->user->setFlash('danger', '仅可同时创建两场比赛,如有疑问,请与管理员联系 admin@cubingchina.com'); $this->redirect(array('/board/competition/index')); } $model = new Competition(); $model->date = $model->end_date = $model->reg_start = $model->reg_end = ''; $model->province_id = $model->city_id = ''; if (isset($_POST['Competition'])) { $model->attributes = $_POST['Competition']; if ($model->save()) { if ($this->user->isOrganizer()) { Yii::app()->mailer->sendAddCompetitionNotice($model); } Yii::app()->user->setFlash('success', '新加比赛成功'); $this->redirect(array('/board/competition/index')); } $model->formatSchedule(); } if ($this->user->isOrganizer()) { $organizer = new CompetitionOrganizer(); $organizer->organizer_id = $this->user->id; $organizer->user = $this->user; $model->organizer = array($organizer); } $model->formatEvents(); $model->formatDate(); $this->render('edit', $this->getCompetitionData($model)); }
public static function store() { self::check_admin_logged_in(); $attributes = self::get_attributes(); $competition = new Competition($attributes); $errors = $competition->errors(); if (count($competition->errors()) == 0) { $competition->save(); Redirect::to('/competition/' . $competition->id, array('message' => 'Kilpailu lisätty')); } else { View::make('/competition/new.html', array('errors' => $errors, 'attributes' => $attributes)); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { if ($this->CanAccess('create')) { $model = new Competition(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Competition'])) { $model->attributes = $_POST['Competition']; if ($model->CanUpdate() && $model->save()) { // if AJAX request , we should not redirect the browser if (!Yii::app()->request->isAjaxRequest) { $this->redirect(array('view', 'id' => $model->id)); } else { // UNCOMMENT THIS IF YOU WANT TO RETURN ID OF THE NEWLY CREATED // OBJECT (USEFUL WHEN CREATING NEW OBJECTS VIA AJAX AND INFO ABOUT // THEN NEWLY CREATED OBJECT MUST BE SENT TO THE BROWSER) // echo CJSON::encode(array('error' => '', 'id' => $model->id)); // die(); } } } if (!Yii::app()->request->isAjaxRequest) { $this->render('create', array('model' => $model)); // IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS, // USE THIS LINE AND DELETE THE LINE ABOVE // $this->render('create', array('model' => $model, 'ajaxRendering' => false)); } else { throw new CHttpException(400, Yii::t('app', 'Bad request. The request cannot be fulfilled.')); // IF YOU NEED DIFFERENT RENDERING FOR AJAX AND NON-AJAX CALLS, // USE THIS LINE AND DELETE THE LINE ABOVE // $this->renderPartial('create', array('model' => $model, 'ajaxRendering' => true)); } } else { throw new CHttpException(405, Yii::t('app', 'You do not have permissions to access this page.')); } }
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); } }