public function createRegion($name, $attr = []) { if (!($model = $this->findRegion($name))) { $model = new Region(); $model->name = $name; $model->setAttributes($attr); $model->save(false); } return $model; }
public function setup() { $options = ContractSearchCriteria::where('user_id', Auth::user()->id)->first(); $criterias = $options ? json_decode($options->criterias, true) : []; $regions = Region::orderBy('name')->lists('name', 'id'); return view('admin.contracts.setup', compact('criterias', 'regions')); }
private function passData($id = null) { $people = new \App\Models\People(); $address = new \App\Models\Addresses(); $employee = new \App\Models\Employee(); if (!is_null($id)) { $people = People::findOrNew($id); $universityHisttory = $people->universityHistory()->get(); $careerHistory = $people->careerHistory()->get(); $employee = $people->employee()->first(); if ($people->address()->first()) { $address = $people->address()->get()->first(); } } else { if (!Session::has('UniversityHistory')) { Session::set('UniversityHistory', $people->universityHistory()->get()); } if (!Session::has('CareerHistory')) { Session::set('CareerHistory', $people->careerHistory()->get()); } $universityHisttory = Session::get('UniversityHistory'); $careerHistory = Session::get('CareerHistory'); } $pTitle = PeopleTitle::all()->sortBy("Title_Name")->toArray(); foreach ($pTitle as $peopTitle) { $peopleTitle[$peopTitle["id_People_Title"]] = $peopTitle["Title_Name"]; } $employeeType = EmployeeType::getEmployeeTypeOptions(); $countryModel = $address->getCountry(); $regionsOptions = Region::getRegionsOptions(); $countryOptions = Country::getCountriesOptionsByRegion($countryModel->id_Region); return compact("countryOptions", "regionsOptions", "employeeType", "people", "peopleTitle", "universityHisttory", "careerHistory", "employee", "address"); }
public function actionUpdate($region, $number) { $transaction = Yii::$app->db->beginTransaction(); if (!($region = Region::findOne(['key' => $region]))) { printf("Unknown region: %s\n", $region); return 1; } if (!($fest = Splatfest::findOne(['region_id' => $region->id, '[[order]]' => $number]))) { printf("Unknown number: %s (region = %s)\n", $number, $region->key); return 1; } printf("Target #%d (Region=%s, Number=%d)\n", $fest->id, $region->key, $fest->order); $alpha = SplatfestTeam::findOne(['fest_id' => $fest->id, 'team_id' => 1]); $bravo = SplatfestTeam::findOne(['fest_id' => $fest->id, 'team_id' => 2]); if (!$alpha || !$bravo || $alpha->color_hue === null || $bravo->color_hue === null) { printf(" > Team information is not ready\n"); return 1; } printf(" > cleanup ...\n"); SplatfestBattleSummary::deleteAll(['fest_id' => $fest->id]); $this->createBattleSummaryTmpTimestamp($fest); $this->createBattleSummaryTmpTable('tmp_summary_a', $fest, $alpha->color_hue, $bravo->color_hue); $this->createBattleSummaryTmpTable('tmp_summary_b', $fest, $bravo->color_hue, $alpha->color_hue); $this->createBattleSummary($fest); $transaction->commit(); return 0; }
/** * Run the database seeds. * * @return void */ public function run() { $regions = ['', '---', 'sev', 'simf', 'ubk', 'evp', 'feo']; foreach ($regions as $region) { Region::create(['id' => $region]); } }
public function run() { // Suppression de la table 'terrains' de la base de données DB::table('terrains')->delete(); // Chargement de la liste des sports existants $sports = Sport::all(); // Création d'une liste de valeurs par défaut $items = [["Football 1 Cégep de Drummondville", "960 Rue Saint-Georges", "Drummondville", [0, 1, 2]], ["Football 2 Cégep de Drummondville", "960 Rue Saint-Georges", "Drummondville", [0, 1, 2]], ["Football 3 Cégep de Drummondville", "960 Rue Saint-Georges", "Drummondville", [0, 1, 2]], ["Soccer 1 Cégep de Drummondville", "960 Rue Saint-Georges", "Drummondville", [0, 1, 2]], ["Soccer 2 Cégep de Drummondville", "960 Rue Saint-Georges", "Drummondville", [0, 1, 2]], ["Football 1 Marie-Rivier", "265 Rue Saint Félix", "Drummondville", [0, 1, 2]], ["Football 2 Marie-Rivier", "265 Rue Saint Félix", "Drummondville", [0, 1, 2]], ["Football 3 Marie-Rivier", "265 Rue Saint Félix", "Drummondville", [0, 1, 2]], ["Soccer 1 Marie-Rivier", "265 Rue Saint Félix", "Drummondville", [0, 1, 2]], ["Soccer 2 Marie-Rivier", "265 Rue Saint Félix", "Drummondville", [0, 1, 2]], ["Football 1 Jean-Raimbault", "175 Rue Pelletier", "Drummondville", [0, 1, 2]], ["Football 2 Jean-Raimbault", "175 Rue Pelletier", "Drummondville", [0, 1, 2]], ["Football 3 Jean-Raimbault", "175 Rue Pelletier", "Drummondville", [0, 1, 2]], ["Soccer 1 Jean-Raimbault", "175 Rue Pelletier", "Drummondville", [0, 1, 2]], ["Soccer 2 Jean-Raimbault", "177 Rue Pelletier", "Drummondville", [0, 1, 2]]]; // Création d'objet 'terrain' et sauvegarde de ceux-ci dans la base de données foreach ($items as $item) { $terrain = new Terrain(); $terrain->nom = $item[0]; $terrain->adresse = $item[1]; $terrain->ville = $item[2]; $terrain->region_id = Region::where("nom_court", "=", "CDQ")->first()->id; //un peu de favoritisme pour le Centre du Québec. $terrain->save(); // Ajout de l'association entre les terrains et les sports $index_sports = array(); for ($x = 0; $x < count($item[3]); $x++) { array_push($index_sports, $sports[$x]->id); } $terrain->sports()->sync($index_sports); } }
/** * Crée les entrées de la table Participants correspondant aux équipes */ public function creerEquipes() { $entrees = [["Grizzlis effarouchés", 1, 1, 1, [1, 2, 3]], ["Opossums déchaînés", 2, 1, 2, [4, 5, 6]], ["Antilopes frustrées", 3, 1, 3, [7, 8, 9]], ["Nasiques offensés", 4, 2, 1, []], ["Renards désinhibés", 5, 2, 1, [13, 14, 15]], ["Escargots enragés", 6, 2, 3, [16, 18, 19]], ["Méduses surexcitées", 7, 3, 2, [20, 21, 22]], ["Gousses d'aïl en furie", 8, 3, 1, [24, 25, 26]], ["Levures passives-agressives", 9, 5, 3, [1, 2, 3]], ["Streptocoques désagréables", 10, 4, 3, [4, 5, 6]]]; $sports = Sport::all(); $regions = Region::all(); $participants = Participant::all(); Equipe::where('equipe', '=', 1)->delete(); foreach ($entrees as $entree) { $equipe = new Equipe(); $equipe->nom = $entree[0]; $equipe->numero = $entree[1]; $equipe->region_id = $regions[$entree[2]]->id; $equipe->prenom = ""; $equipe->equipe = true; $equipe->sexe = $entree[1] % 2; $equipe->naissance = new DateTime(); $equipe->save(); $equipe->sports()->attach([$sports[$entree[3]]->id]); $index_membres = array(); for ($x = 0; $x < count($entree[4]); $x++) { array_push($index_membres, $participants[$entree[4][$x] - 1]->id); } $equipe->membres()->sync($index_membres); } }
/** * Création d'arbitres dans la base de données */ public function run() { DB::table('arbitre_epreuve')->delete(); DB::table("arbitres")->delete(); $epreuves = Epreuve::all(); $entrees = [["Benoit", "Desrosiers", "1", "AQSFR", "819-578-6489", 0], ["Guy", "Bernard", "1", "OSQ", "450-715-6915", 0], ["Jonathan", "Gareau", "1", "ASSQ", "514-763-2485", 0], ["Stéphane", "Janvier", "2", "ASAQ", "450-571-1203", 0]]; $regions = Region::all(); foreach ($entrees as $entree) { $arbitre = new Arbitre(); $arbitre->prenom = $entree[0]; $arbitre->nom = $entree[1]; $arbitre->region_id = $regions->random()->id; $arbitre->numero_accreditation = $entree[2]; $arbitre->association = $entree[3]; $arbitre->numero_telephone = $entree[4]; $arbitre->sexe = $entree[5]; $date_temp = new DateTime(); $date_temp->setDate(1994, 1, 1); $arbitre->date_naissance = $date_temp; $arbitre->save(); for ($j = 0; $j < rand(1, 4); $j++) { $epreuves->random()->arbitres()->attach($arbitre->id); } } }
private function passData($id = null) { $jobs = new \App\Models\Jobs(); if (!is_null($id)) { $jobs = Jobs::findOrNew($id); } $companyPreference = $jobs->getCompanyPreference() ? $jobs->getCompanyPreference() : new \App\Models\CompanyPreference(); $address = $jobs->address()->first() ? $jobs->address()->first() : new \App\Models\Addresses(); $commOrBon = CommisionOrBonus::all()->sortBy("Commission_Or_Bonus")->toArray(); $lns = SupportedLanguages::all()->sortBy("Language_Name")->toArray(); if (sizeof($commOrBon) == 0) { $commOrBon = new \App\Models\CommisionOrBonus(); } $tEndUser = TargetEndUser::all()->sortBy("Target_End_User")->toArray(); foreach ($commOrBon as $commisionOrBonusVal) { $commisionOrBonus[$commisionOrBonusVal["id_Commission_Or_Bonus"]] = $commisionOrBonusVal["Commission_Or_Bonus"]; } foreach ($tEndUser as $tgEndUser) { $targetEndUser[$tgEndUser["id_Target_End_User"]] = $tgEndUser["Target_End_User"]; } foreach ($lns as $langs) { $languages[$langs["id_Language"]] = $langs["Language_Name"]; } $companies = Companies::SelectOptionsModel(); $jobType = $jobs->getJobType(); $jobFamilyOptions = JobFamily::getJobsFamilyOptions(); $jobTypesOptions = JobType::getJobsTypesByJobFamilyOptions($jobType->id_Job_Family); $countryModel = $address->getCountry(); $regionsOptions = Region::getRegionsOptions(); $countryOptions = Country::getCountriesOptionsByRegion($countryModel->id_Region); return compact("companies", "commisionOrBonus", "targetEndUser", "jobFamilyOptions", "regionsOptions", "countryOptions", "languages", "jobs", "companyPreference", "address", "jobTypesOptions"); }
public function up() { $this->createTable('splatfest', ['id' => $this->primaryKey(), 'region_id' => $this->integer()->notNull(), 'name' => $this->string(64)->notNull(), 'start_at' => 'TIMESTAMP(0) WITH TIME ZONE NOT NULL', 'end_at' => 'TIMESTAMP(0) WITH TIME ZONE NOT NULL']); $this->addForeignKey('fk_splatfest_1', 'splatfest', 'region_id', 'region', 'id'); $jp = Region::findOne(['key' => 'jp'])->id; $this->batchInsert('splatfest', ['region_id', 'name', 'start_at', 'end_at'], [[$jp, 'ごはん vs パン', '2015-06-13 18:00:00+09', '2015-06-14 18:00:00+09'], [$jp, '赤いきつね vs 緑のたぬき', '2015-07-03 15:00:00+09', '2015-07-04 15:00:00+09'], [$jp, 'レモンティー vs ミルクティー', '2015-07-25 15:00:00+09', '2015-07-26 15:00:00+09'], [$jp, 'キリギリス vs アリ', '2015-08-22 12:00:00+09', '2015-08-23 12:00:00+09'], [$jp, 'ボケ vs ツッコミ', '2015-09-12 12:00:00+09', '2015-09-13 12:00:00+09'], [$jp, 'イカ vs タコ', '2015-10-10 09:00:00+09', '2015-10-11 09:00:00+09'], [$jp, '愛 vs おカネ', '2015-10-31 09:00:00+09', '2015-11-01 09:00:00+09'], [$jp, '山の幸 vs 海の幸', '2015-11-21 12:00:00+09', '2015-11-22 12:00:00+09'], [$jp, '赤いきつね vs 緑のたぬき', '2015-12-26 09:00:00+09', '2015-12-27 09:00:00+09']]); }
/** * Display a listing of the resource. * * @return Response */ public function index(Region $region, TrainRoad $trainRoad, Stantion $stantion) { $regionsCount = $region->count(); $tRoadsCount = $trainRoad->count(); $stationsCount = $stantion->count(); $condCount = Condition::count(); $productsCount = Product::count(); $servicesCount = Service::count(); $catCount = Category::count(); $statusesCount = Status::count(); $serviceStatusesCount = ServiceStatus::count(); $newOrdersCount = Order::where('is_new', 1)->count(); $newServiceOrdersCount = ServiceOrder::where('is_new', 1)->count(); $customers = Firm::where('accountant_fio', null)->get(); return view('admin.adminArea', ['regionsCount' => $regionsCount, 'tRoadsCount' => $tRoadsCount, 'stationsCount' => $stationsCount, 'condCount' => $condCount, 'catCount' => $catCount, 'productsCount' => $productsCount, 'servicesCount' => $servicesCount, 'statusesCount' => $statusesCount, 'newOrdersCount' => $newOrdersCount, 'serviceStatusesCount' => $serviceStatusesCount, 'newServiceOrdersCount' => $newServiceOrdersCount, 'customers' => $customers]); }
public function run() { DB::table('regions')->delete(); $regions = $this->api('database.getRegions', ['country_id' => 2]); foreach ($regions['response'] as $region) { Region::create(['name' => $region['title']]); } }
public function getOfficeOrRegion(Request $request) { if ($request->input('id') == 'reg') { $office_region = Region::select(\DB::raw("CONCAT(code,'-',name) AS full_name, id"))->lists('full_name', 'id'); } else { $office_region = Office::select(\DB::raw("CONCAT(code,'-',name) AS full_name, id"))->lists('full_name', 'id'); } return Response::json($office_region); }
public function actionDeleteRegion($region_id, $user_id) { $user = User::findOne($user_id); $region = Region::findOne($region_id); if (!$user) { throw new NotFoundHttpException('Данный пользователь не существует.'); } $user->unlinkRegion($region_id); $user->save(); }
public function safeUp() { $regionNA = Region::findOne(['key' => 'na'])->id; $this->batchInsert('timezone', ['identifier', 'name', 'order', 'region_id'], [['America/St_Johns', 'North America (Newfoundland)', 10001, $regionNA], ['America/Halifax', 'North America (AT)', 10002, $regionNA], ['America/Regina', 'North America (Saskatchewan)', 10003, $regionNA]]); $newOrder = ['America/St_Johns', 'America/Halifax', 'America/New_York', 'America/Chicago', 'America/Regina', 'America/Denver', 'America/Phoenix', 'America/Los_Angeles', 'America/Anchorage', 'America/Adak', 'Pacific/Honolulu']; $order = 20 + count($newOrder); foreach (array_reverse($newOrder) as $ident) { $this->update('timezone', ['order' => $order--], ['identifier' => $ident]); } }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { try { $tRoad = TrainRoad::findOrFail($id); } catch (ModelNotFoundException $e) { abort(404); } $regions = Region::all(); return view('trainRoads.edit', ['tRoadName' => $tRoad->tr_name, 'id' => $tRoad->id, 'regions' => $regions, 'regID' => $tRoad->region_id]); }
/** * Affiche les participants associés au sport sélectionné par région. * * @param[in] int $id l'id du sport qu'on sélectionne. */ public function index($id) { try { $sport = Sport::findOrFail($id); $regions = Region::all()->sortby('nom'); $participants = $sport->participants->sortby('nom'); return View::make('sportParticipant.index', compact('regions', 'participants', 'sport')); } catch (ModelNotFoundException $e) { App::abort(404); } }
public function up() { $this->createTable('team', ['id' => 'INTEGER NOT NULL PRIMARY KEY', 'name' => 'VARCHAR(8) NOT NULL', 'leader' => 'VARCHAR(8) NOT NULL']); $this->batchInsert('team', ['id', 'name', 'leader'], [[1, 'Alpha', 'Callie'], [2, 'Bravo', 'Marie']]); $this->createTable('splatfest_team', ['fest_id' => 'INTEGER NOT NULL', 'team_id' => 'INTEGER NOT NULL', 'name' => 'VARCHAR(32) NOT NULL', 'color_hue' => 'INTEGER NULL']); $this->addPrimaryKey('pk_splatfest_team', 'splatfest_team', ['fest_id', 'team_id']); $this->addForeignKey('fk_splatfest_team_1', 'splatfest_team', 'fest_id', 'splatfest', 'id'); $this->addForeignKey('fk_splatfest_team_2', 'splatfest_team', 'team_id', 'team', 'id'); $jp = Region::findOne(['key' => 'jp'])->id; $this->batchInsert('splatfest_team', ['fest_id', 'team_id', 'name', 'color_hue'], [[$this->fest($jp, 7), 1, '愛', 332], [$this->fest($jp, 7), 2, 'おカネ', 34], [$this->fest($jp, 8), 1, '山の幸', 346], [$this->fest($jp, 8), 2, '海の幸', 166], [$this->fest($jp, 9), 1, '赤いきつね', 335], [$this->fest($jp, 9), 2, '緑のたぬき', 155]]); }
/** * Displays a single Profile model. * @param integer $id * @return mixed */ public function actionView() { $model = $this->findModel(Yii::$app->user->id); $modelRegion = Region::find()->where(['id' => $model->region_id])->one(); $model->region = $modelRegion->name; // echo '<pre>'; // print_r($model->region); // echo '</pre>'; // exit; return $this->render('view', ['model' => $model]); }
public function up() { $this->execute('ALTER TABLE {{timezone}} ADD COLUMN [[region_id]] INTEGER'); $this->addForeignKey('fk_timezone_1', 'timezone', 'region_id', 'region', 'id'); // Japan $this->update('timezone', ['region_id' => Region::findOne(['key' => 'jp'])->id], ['identifier' => 'Asia/Tokyo']); // Europe/Oceania $this->update('timezone', ['region_id' => Region::findOne(['key' => 'eu'])->id], ['or like', 'identifier', ['Etc/UTC', 'Europe/%', 'Australia/%'], false]); // North America $this->update('timezone', ['region_id' => Region::findOne(['key' => 'na'])->id], ['or like', 'identifier', ['America/%', 'Pacific/Honolulu'], false]); $this->execute('ALTER TABLE {{timezone}} ALTER COLUMN [[region_id]] SET NOT NULL'); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Region::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); return $dataProvider; }
public function up() { $this->execute('ALTER TABLE {{splatfest}} ADD COLUMN [[order]] INTEGER'); $transaction = \Yii::$app->db->beginTransaction(); $jp = Region::findOne(['key' => 'jp'])->id; $jpStarts = ['2015-06-13 18:00:00+09', '2015-07-03 15:00:00+09', '2015-07-25 15:00:00+09', '2015-08-22 12:00:00+09', '2015-09-12 12:00:00+09', '2015-10-10 09:00:00+09', '2015-10-31 09:00:00+09', '2015-11-21 12:00:00+09', '2015-12-26 09:00:00+09']; foreach ($jpStarts as $i => $startAt) { $this->update('splatfest', ['order' => $i + 1], ['region_id' => $jp, 'start_at' => $startAt]); } $transaction->commit(); $this->execute('ALTER TABLE {{splatfest}} ALTER COLUMN [[order]] SET NOT NULL'); $this->createIndex('ix_splatfest_1', 'splatfest', ['region_id', 'order'], true); }
/** * Execute the console command. * * @return mixed */ public function fire() { $client = new HttpClient(); $provinces = json_decode('[{"children":[],"diji":"","quHuaDaiMa":"110000","quhao":"","shengji":"北京市(京)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"120000","quhao":"","shengji":"天津市(津)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"130000","quhao":"","shengji":"河北省(冀)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"140000","quhao":"","shengji":"山西省(晋)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"150000","quhao":"","shengji":"内蒙古自治区(内蒙古)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"210000","quhao":"","shengji":"辽宁省(辽)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"220000","quhao":"","shengji":"吉林省(吉)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"230000","quhao":"","shengji":"黑龙江省(黑)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"310000","quhao":"","shengji":"上海市(沪)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"320000","quhao":"","shengji":"江苏省(苏)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"330000","quhao":"","shengji":"浙江省(浙)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"340000","quhao":"","shengji":"安徽省(皖)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"350000","quhao":"","shengji":"福建省(闽)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"360000","quhao":"","shengji":"江西省(赣)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"370000","quhao":"","shengji":"山东省(鲁)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"410000","quhao":"","shengji":"河南省(豫)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"420000","quhao":"","shengji":"湖北省(鄂)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"430000","quhao":"","shengji":"湖南省(湘)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"440000","quhao":"","shengji":"广东省(粤)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"450000","quhao":"","shengji":"广西壮族自治区(桂)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"460000","quhao":"","shengji":"海南省(琼)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"500000","quhao":"","shengji":"重庆市(渝)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"510000","quhao":"","shengji":"四川省(川、蜀)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"520000","quhao":"","shengji":"贵州省(黔、贵)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"530000","quhao":"","shengji":"云南省(滇、云)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"540000","quhao":"","shengji":"西藏自治区(藏)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"610000","quhao":"","shengji":"陕西省(陕、秦)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"620000","quhao":"","shengji":"甘肃省(甘、陇)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"630000","quhao":"","shengji":"青海省(青)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"640000","quhao":"","shengji":"宁夏回族自治区(宁)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"650000","quhao":"","shengji":"新疆维吾尔自治区(新)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"810000","quhao":"0852","shengji":"香港特别行政区(港)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"820000","quhao":"0853","shengji":"澳门特别行政区(澳)","xianji":""},{"children":[],"diji":"","quHuaDaiMa":"710000","quhao":"","shengji":"台湾省(台)","xianji":""}]', true); foreach ($provinces as $province) { preg_match_all('/(.*?)\\((.*?)\\)/', $province['shengji'], $matched); $region = new Region(array('region_name' => $matched[1][0], 'region_code' => $province['quHuaDaiMa'], 'parent_id' => 0, 'extra_attrs' => array('shortened' => $matched[2][0]))); $region->save(); echo $region->region_name . "...\r\n"; $cities = json_decode($client->post('http://202.108.98.30/selectJson', array('headers' => ['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'], 'body' => 'shengji=' . $province['shengji']))->getBody()->read(10240000), true); foreach ($cities as $c) { $city = new Region(array('region_name' => $c['diji'], 'region_code' => $c['quHuaDaiMa'])); $city = $region->children()->save($city); $dists = json_decode($client->post('http://202.108.98.30/selectJson', array('headers' => ['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8'], 'body' => 'shengji=' . $province['shengji'] . '&diji=' . $c['diji']))->getBody()->read(10240000), true); foreach ($dists as $d) { $dist = new Region(array('region_name' => $d['xianji'], 'region_code' => $d['quHuaDaiMa'], 'extra_attrs' => array('area_code' => $d['quhao']))); $city->children()->save($dist); } } } echo 'done'; }
/** * List Region Children for select * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionAjaxListChild($id) { //'visible' => Yii::$app->user->can('deleteYourAuth'), $countChild = Region::find()->where(['parent_id' => $id])->count(); $children = Region::find()->where(['parent_id' => $id])->all(); if ($countChild > 0) { echo "<option>" . Yii::t('app', 'Please Select') . "</option>"; foreach ($children as $child) { echo "<option value='" . $child->id . "'>" . $child->name . "</option>"; } } else { echo "<option>" . Yii::t('app', 'No Option') . "</option>"; } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Region::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'rec_status_id' => $this->rec_status_id, 'user_id' => $this->user_id, 'dc' => $this->dc]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'note', $this->note]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Region::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'lat' => $this->lat, 'lng' => $this->lng, 'zoom' => $this->zoom, 'radius' => $this->radius, 'provincia_id' => $this->provincia_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'codigo_postal', $this->codigo_postal]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find()->joinWith('profile.region'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['region'] = ['asc' => [Region::tableName() . '.name' => SORT_ASC], 'desc' => [Region::tableName() . '.name' => SORT_DESC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, Region::tableName() . '.id' => $this->region]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email]); return $dataProvider; }
public function excel($params) { $query = Mon1str::find()->joinWith('monitoring1.user.profile.region'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => array('pageSize' => 10000)]); $dataProvider->sort->attributes['region'] = ['asc' => [Region::tableName() . '.name' => SORT_ASC], 'desc' => [Region::tableName() . '.name' => SORT_DESC]]; $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // $query->andFilterWhere([Monitoring1::tableName() . '.date' => $this->date, Region::tableName() . '.id' => $this->region]); return $dataProvider; }
public function syncRegions($geonameId, $parent = null, $level = 1) { if ($level > 2) { return; } $geonames = $this->request('childrenJSON', ['geonameId' => $geonameId]); if (empty($geonames['geonames'])) { return; } foreach ($geonames['geonames'] as $geoname) { $data = ['name' => $geoname['name'], 'short' => $geoname['fcode'] == 'ADM1' ? $geoname['adminCode1'] : '', 'parent_id' => $parent ? $parent->id : 0]; $region = Region::updateOrCreate($data); $this->info("Inserted {$region->name}"); $this->syncRegions($geoname['geonameId'], $region, $level + 1); } }
public function run() { ini_set('max_execution_time', 0); //300 seconds = 5 minutes DB::table('areas')->delete(); DB::table('towns')->delete(); $regions = $this->api('database.getRegions', ['country_id' => 2]); foreach ($regions['response'] as $region) { $towns = $this->api('database.getCities', ['country_id' => 2, 'region_id' => $region['region_id'], 'count' => 1000]); foreach ($towns['response'] as $town) { $area = Area::firstOrCreate(['name' => isset($town['area']) ? $town['area'] : $town['title'], 'region_id' => isset(Region::where('name', '=', $town['region'])->first()->id) ? Region::where('name', '=', $town['region'])->first()->id : 0]); Town::create(['name' => $town['title'], 'area_id' => $area->id]); } sleep(10); } }