/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     //Empty the countries table
     DB::table('countries')->delete();
     if (DB::table('countries')->count() == 0) {
         //Get all of the countries
         $countries = Countries::getList();
         foreach ($countries as $countryId => $country) {
             DB::table('countries')->insert(array('id' => $countryId, 'capital' => isset($country['capital']) ? $country['capital'] : null, 'citizenship' => isset($country['citizenship']) ? $country['citizenship'] : null, 'country_code' => $country['country-code'], 'currency' => isset($country['currency']) ? $country['currency'] : null, 'currency_code' => isset($country['currency_code']) ? $country['currency_code'] : null, 'currency_sub_unit' => isset($country['currency_sub_unit']) ? $country['currency_sub_unit'] : null, 'full_name' => isset($country['full_name']) ? $country['full_name'] : null, 'iso_3166_2' => $country['iso_3166_2'], 'iso_3166_3' => $country['iso_3166_3'], 'name' => $country['name'], 'region_code' => $country['region-code'], 'sub_region_code' => $country['sub-region-code'], 'eea' => (bool) $country['eea']));
         }
     }
     // Source: http://www.bitboost.com/ref/international-address-formats.html
     // Source: https://en.wikipedia.org/wiki/Linguistic_issues_concerning_the_euro
     $countries = ['AR' => ['swap_postal_code' => true], 'AT' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'BE' => ['swap_postal_code' => true], 'BG' => ['swap_currency_symbol' => true], 'CH' => ['swap_postal_code' => true], 'CZ' => ['swap_currency_symbol' => true], 'DE' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'DK' => ['swap_postal_code' => true], 'EE' => ['swap_currency_symbol' => true], 'ES' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'FI' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'FR' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'GR' => ['swap_currency_symbol' => true], 'HR' => ['swap_currency_symbol' => true], 'HU' => ['swap_currency_symbol' => true], 'GL' => ['swap_postal_code' => true], 'IE' => ['thousand_separator' => ',', 'decimal_separator' => '.'], 'IL' => ['swap_postal_code' => true], 'IS' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'IT' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'JP' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'LT' => ['swap_currency_symbol' => true], 'LU' => ['swap_postal_code' => true], 'MY' => ['swap_postal_code' => true], 'MX' => ['swap_postal_code' => true], 'NL' => ['swap_postal_code' => true], 'PL' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'PT' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'RO' => ['swap_currency_symbol' => true], 'SE' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'SI' => ['swap_currency_symbol' => true], 'SK' => ['swap_currency_symbol' => true], 'UY' => ['swap_postal_code' => true]];
     foreach ($countries as $code => $data) {
         $country = Country::where('iso_3166_2', '=', $code)->first();
         if (isset($data['swap_postal_code'])) {
             $country->swap_postal_code = true;
         }
         if (isset($data['swap_currency_symbol'])) {
             $country->swap_currency_symbol = true;
         }
         if (isset($data['thousand_separator'])) {
             $country->thousand_separator = $data['thousand_separator'];
         }
         if (isset($data['decimal_separator'])) {
             $country->decimal_separator = $data['decimal_separator'];
         }
         $country->save();
     }
 }
 /**
  * Create a new User.
  *
  * @param array $attributes
  * @return mixed
  */
 public function create($attributes = array())
 {
     $country = Country::where('id', array_get($attributes, 'country'));
     if ($country->exists()) {
         array_set($attributes, 'country', $country->first()->id);
         $user = User::create($attributes);
         Event::fire(new EmailUpdatedEvent($user));
         return $user;
     }
     return false;
 }
Exemple #3
0
 public function issue()
 {
     // 1 byte = 2^8 bits = 16^2 bits = 2 hex characters
     $key = bin2hex(random_bytes(config('osu.user.verification_key_length_hex') / 2));
     $user = $this->user;
     $email = $user->user_email;
     $to = $user->user_email;
     $this->request->session()->put('verification_key', $key);
     $this->request->session()->put('verification_expire_date', Carbon::now()->addHours(5));
     $this->request->session()->put('verification_tries', 0);
     $requestCountry = Country::where('acronym', $this->request->header('CF_IPCOUNTRY'))->pluck('name')->first();
     Mail::queue(['text' => i18n_view('emails.user_verification')], compact('key', 'user', 'requestCountry'), function ($message) use($to) {
         $message->to($to);
         $message->subject(trans('user_verification.email.subject'));
     });
 }
 public function handle(UserCreateCommand $command)
 {
     $reader = new Reader(storage_path() . '/geolite2city.mmdb');
     $ip = null;
     if (isset($_SERVER['REMOTE_ADDR'])) {
         $ip = $_SERVER['REMOTE_ADDR'];
     }
     if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
     }
     $country = null;
     $timezone = null;
     if (!is_null($ip)) {
         $record = $reader->get($ip);
         $timezone = Timezone::firstOrCreate(['name' => $record["location"]["time_zone"]]);
         $countryCode = $record["country"]["iso_code"];
         $country = Country::where('iso_3166_2', $countryCode)->first();
     }
     $user = new User(['username' => $command->username, 'email' => $command->email, 'country_id' => is_null($country) ? null : $country->id, 'timezone_id' => is_null($timezone) ? null : $timezone->id]);
     $user->password = $command->password;
     $user->save();
     \Event::fire(new UserCreatedEvent($user));
     return $user->id;
 }
 private function updateLocalization()
 {
     // Source: http://www.bitboost.com/ref/international-address-formats.html
     // Source: https://en.wikipedia.org/wiki/Linguistic_issues_concerning_the_euro
     $countries = ['AR' => ['swap_postal_code' => true], 'AT' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'BE' => ['swap_postal_code' => true], 'BG' => ['swap_currency_symbol' => true], 'CH' => ['swap_postal_code' => true], 'CZ' => ['swap_currency_symbol' => true], 'DE' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'DK' => ['swap_postal_code' => true], 'EE' => ['swap_currency_symbol' => true], 'ES' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'FI' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'FR' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'GR' => ['swap_currency_symbol' => true], 'HR' => ['swap_currency_symbol' => true], 'HU' => ['swap_currency_symbol' => true], 'GL' => ['swap_postal_code' => true], 'IE' => ['thousand_separator' => ',', 'decimal_separator' => '.'], 'IL' => ['swap_postal_code' => true], 'IS' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'IT' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'LT' => ['swap_currency_symbol' => true], 'LU' => ['swap_postal_code' => true], 'MY' => ['swap_postal_code' => true], 'MX' => ['swap_postal_code' => true], 'NL' => ['swap_postal_code' => true], 'PL' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'PT' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'RO' => ['swap_currency_symbol' => true], 'SE' => ['swap_postal_code' => true, 'swap_currency_symbol' => true], 'SI' => ['swap_currency_symbol' => true], 'SK' => ['swap_currency_symbol' => true], 'UY' => ['swap_postal_code' => true]];
     foreach ($countries as $code => $data) {
         $country = Country::where('iso_3166_2', '=', $code)->first();
         if (isset($data['swap_postal_code'])) {
             $country->swap_postal_code = true;
         }
         if (isset($data['swap_currency_symbol'])) {
             $country->swap_currency_symbol = true;
         }
         if (isset($data['thousand_separator'])) {
             $country->thousand_separator = $data['thousand_separator'];
         }
         if (isset($data['decimal_separator'])) {
             $country->decimal_separator = $data['decimal_separator'];
         }
         $country->save();
     }
 }
 public static function getCountryId($country)
 {
     $id = Country::where('country_name', 'like', $country)->firstOrFail();
     return $id['id'];
 }
 private function updateSwapPostalCode()
 {
     // Source: http://www.bitboost.com/ref/international-address-formats.html
     $countries = ['AR', 'AT', 'CH', 'BE', 'DE', 'DK', 'ES', 'FI', 'FR', 'GL', 'IL', 'IS', 'IT', 'LU', 'MY', 'MX', 'NL', 'PL', 'PT', 'SE', 'UY'];
     for ($i = 0; $i < count($countries); $i++) {
         $code = $countries[$i];
         $country = Country::where('iso_3166_2', '=', $code)->first();
         $country->swap_postal_code = true;
         $country->save();
     }
 }
 public function listing($page, $limit)
 {
     $response = array('data' => array(), 'paginator' => '');
     if (!empty($limit)) {
         $countries = Country::paginate($limit);
     } else {
         $countries = Country::where('id', '>', '0')->get();
     }
     if (!empty($countries)) {
         foreach ($countries as $key => $country) {
             $response['data'][] = $this->get($country->id, false);
         }
     }
     if (!empty($limit)) {
         $response = Utility::paginator($response, $countries, $limit);
     }
     return $response;
 }
Exemple #9
0
$router->post('/questions/upload', 'QuestionsController@store');
$router->post('/questions/{id}', 'QuestionsController@show');
$router->bind('pagename', function ($id) {
    return \AppAdmin\Models\PageName::find($id);
});
$router->bind('categories', function ($id) {
    return \App\Models\Category::find($id);
});
$router->bind('tags', function ($id) {
    return \App\Models\Tags::find($id);
});
$router->bind('ads', function ($id) {
    return \App\Models\Advertisement::find($id);
});
$router->bind('country', function ($title) {
    return \App\Models\Country::where('title', '=', $title)->first();
});
/**
 * PROFILE
 */
$router->bind('profile', function ($user_name) {
    $user = \App\Models\User::where('user_name', $user_name)->first();
    if (!$user) {
        $user = \App\Models\User::where('user_name', Auth::user()->user_name)->first();
    }
    return \ZaWeb\Profile\Models\Profile::where('user_id', $user->id)->first();
});
/**
 * COMMENTS
 */
Route::model('comments', 'App\\Models\\Comments');
Exemple #10
0
 public function getCountry()
 {
     //return $this->hasOne('App\Models\Country', 'id_Country', 'id_Country');
     return Country::where("id_Country", "=", $this->id_Country)->first();
 }
 protected function parseTenders(Client $client, Crawler $crawler)
 {
     $repeatSensor = 0;
     $contractsNum = 0;
     $crawler->filter('div.registerBox')->each(function (Crawler $node, $i) use($client, &$repeatSensor, &$contractsNum) {
         $systemId = str_replace('№ ', '', trim($node->filter('td.descriptTenderTd > dl > dt > a')->text()));
         $organizationNode = $node->filter('dd.nameOrganization > a');
         $organizationName = trim($organizationNode->text());
         $organizationUrl = trim($organizationNode->attr('href'));
         //Log::info('Node data', [$node->html()]);
         $contractName = trim($node->filter('td.descriptTenderTd > dl > dd')->eq(1)->text());
         $contractUrl = $node->filter('td.descriptTenderTd > dl > dt > a')->attr('href');
         $contractType = trim($node->filter('td.tenderTd > dl > dt')->eq(0)->text());
         $contractStatus = '';
         /*Log::info('Обработка нового контракта', [
               'org_name' => $organizationName,
               'org_url' => $organizationUrl,
               'name' => $contractName,
               'url' => $contractUrl
           ]);*/
         $contract = Contract::where('system_id', $systemId)->first();
         if (!$contract) {
             $repeatSensor = 0;
             // Search organization in database
             $organization = Organization::where('url', $organizationUrl)->first();
             if (!$organization) {
                 //Log::info('Организация не найдена, добавляем в базу.');
                 $organization = new Organization();
                 $organization->name = $organizationName;
                 $organization->url = $organizationUrl;
                 $this->info($organizationUrl);
                 $organizationResponse = $client->get($organizationUrl);
                 $organizationCrawler = new Crawler((string) $organizationResponse->getBody());
                 //Log::info('Информация по организации загружена.');
                 // Federal Law 223
                 if (preg_match("/223\\/ppa/", $organizationUrl)) {
                     $organizationCrawler->filter('div.noticeTabBoxWrapper > table tr')->each(function (Crawler $row, $j) use(&$organization) {
                         if ($row->children('td')->count() > 1) {
                             $nameColumn = trim($row->children('td')->eq(0)->text());
                             $valueColumn = trim($row->children('td')->eq(1)->text());
                             if ($valueColumn) {
                                 switch ($nameColumn) {
                                     case 'Уровень организации':
                                         $organization->level = $valueColumn;
                                         break;
                                     case 'ИНН':
                                         $organization->inn = $valueColumn;
                                         break;
                                     case 'КПП':
                                         $organization->kpp = $valueColumn;
                                         break;
                                     case 'ОГРН':
                                         $organization->ogrn = $valueColumn;
                                         break;
                                     case 'ОКАТО':
                                         $organization->okato = $valueColumn;
                                         break;
                                     case 'Адрес (место нахождения)':
                                         $addresses = array_map(function ($value) {
                                             return trim($value);
                                         }, explode(',', $valueColumn));
                                         $address = collect($addresses);
                                         $address->forget('Российская Федерация');
                                         $organization->postal_code = $address[0];
                                         $organization->country_id = 1;
                                         $country = Country::find(1);
                                         if (isset($address[3])) {
                                             $region = Region::where('name', $address[2])->where('country_id', $country->id)->first();
                                             if (!$region) {
                                                 $region = Region::create(['country_id' => $country->id, 'name' => $address[2]]);
                                             }
                                             $town = Town::where('name', $address[3])->where('region_id', $region->id)->first();
                                             if (!$town) {
                                                 $town = Town::create(['region_id' => $region->id, 'name' => $address[3]]);
                                             }
                                             $organization->region_id = $region->id;
                                             $organization->town_id = $town->id;
                                         }
                                         $organization->address = $valueColumn;
                                         break;
                                     case 'Телефон':
                                         $organization->contact_phone = $valueColumn;
                                         break;
                                     case 'Факс':
                                         $organization->contact_fax = $valueColumn;
                                         break;
                                     case 'Почтовый адрес':
                                         $organization->contact_address = $valueColumn;
                                         break;
                                     case 'Контактное лицо':
                                         $organization->contact_name = $valueColumn;
                                         break;
                                     case 'Адрес электронной почты для системных уведомлений':
                                         $organization->contact_email = $valueColumn;
                                         break;
                                 }
                             }
                         }
                     });
                 } else {
                     $organizationCrawler->filter('td.icePnlTbSetCnt table tr')->each(function (Crawler $row, $j) use($organization) {
                         if ($row->children('td')->count() > 1) {
                             $nameColumn = trim($row->children('td')->eq(0)->text());
                             $valueColumn = trim($row->children('td')->eq(1)->text());
                             if ($valueColumn) {
                                 switch ($nameColumn) {
                                     case 'Уровень организации':
                                         $organization->level = $valueColumn;
                                         break;
                                     case 'ИНН':
                                         $organization->inn = $valueColumn;
                                         break;
                                     case 'КПП':
                                         $organization->kpp = $valueColumn;
                                         break;
                                     case 'ОГРН':
                                         $organization->ogrn = $valueColumn;
                                         break;
                                     case 'ОКАТО':
                                         $organization->okato = $valueColumn;
                                         break;
                                     case 'Место нахождения':
                                         $address = array_map(function ($value) {
                                             return trim($value);
                                         }, explode(',', $valueColumn));
                                         $this->info($valueColumn);
                                         $organization->postal_code = $address[1];
                                         $country = Country::where('name', 'Российская Федерация')->first();
                                         $region = Region::where('name', $address[2])->where('country_id', $country->id)->first();
                                         if (!$region) {
                                             $region = Region::create(['country_id' => $country->id, 'name' => $address[2]]);
                                         }
                                         if (isset($address[3])) {
                                             $town = Town::where('name', $address[3])->where('region_id', $region->id)->first();
                                             if (!$town) {
                                                 $town = Town::create(['region_id' => $region->id, 'name' => $address[3]]);
                                             }
                                         }
                                         $organization->country_id = $country->id;
                                         $organization->region_id = $region->id;
                                         $organization->town_id = isset($town) ? $town->id : null;
                                         $organization->address = $valueColumn;
                                         break;
                                     case 'Телефон':
                                         $organization->contact_phone = $valueColumn;
                                         break;
                                     case 'Факс':
                                         $organization->contact_fax = $valueColumn;
                                         break;
                                     case 'Почтовый адрес':
                                         $organization->contact_address = $valueColumn;
                                         break;
                                     case 'Контактное лицо':
                                         $organization->contact_name = $valueColumn;
                                         break;
                                     case 'Контактный адрес электронной почты':
                                         $organization->contact_email = $valueColumn;
                                         break;
                                 }
                             }
                         }
                     });
                 }
                 //dd($organization);
                 $organization->save();
                 //Log::info('Организация добавлена в базу.');
                 $this->info('Organization ' . $organizationName);
             } else {
                 //Log::info('Организация найдена в базе.');
             }
             //Log::info('Переходим на страницу контракта.');
             $contractResponse = $client->get($contractUrl);
             $contractCrawler = new Crawler((string) $contractResponse->getBody());
             //Log::info('Страница контракта загружена.');
             $contract = new Contract();
             $contract->organization_id = $organization->id;
             $contract->system_id = $systemId;
             $contract->name = $contractName;
             $contract->link = $contractUrl;
             $contract->status = $contractStatus;
             $contract->type = $contractType;
             $price = str_replace(',', '.', preg_replace("/([^0-9\\.\\,]*)/", '', trim($node->filter('td.tenderTd > dl > dd')->eq(1)->text())));
             $contract->price = $price;
             // Federal Law 223
             $contractCrawler->filter('div.noticeTabBoxWrapper > table tr')->each(function (Crawler $row, $j) use($contract, $contractUrl) {
                 if ($row->filter('td')->count() > 1) {
                     $nameColumn = trim($row->filter('td')->eq(0)->text());
                     $valueColumn = trim($row->filter('td')->eq(1)->text());
                     if (!$valueColumn) {
                         return;
                     }
                     if (preg_match("/223\\/purchase/", $contractUrl)) {
                         if (preg_match('/подачи заявок/i', $nameColumn)) {
                             preg_match("/(\\d{2}\\.\\d{2}\\.\\d{4}\\sв\\s\\d{2}:\\d{2})/ui", $valueColumn, $date);
                             if (!isset($date[1])) {
                                 return;
                             }
                             $valueColumn = str_replace('в', '', $date[1]);
                             $finishDate = new Carbon($valueColumn);
                             $contract->finished_at = $finishDate;
                         } elseif (preg_match('/подведения итогов/i', $nameColumn)) {
                             preg_match("/(\\d{2}[\\.]{1}\\d{2}[\\.]{1}\\d{4}[ ]{1}[в]{1}[ ]{1}\\d{2}:\\d{2})/ui", $valueColumn, $date);
                             if (!isset($date[1])) {
                                 return;
                             }
                             $valueColumn = str_replace('в', '', $date[1]);
                             $resultDate = new Carbon($valueColumn);
                             $contract->results_at = $resultDate;
                         }
                     } else {
                         if (preg_match('/Дата и время окончания подачи заявок/i', $nameColumn) || preg_match('/Дата и время окончания подачи котировочных заявок/i', $nameColumn)) {
                             $valueColumn = str_replace('в', '', $valueColumn);
                             $finishDate = new Carbon($valueColumn);
                             $contract->finished_at = $finishDate;
                         } elseif (preg_match('/Дата проведения аукциона в электронной форме/i', $nameColumn) || preg_match('/Дата и время вскрытия конвертов с заявками/i', $nameColumn)) {
                             // Не ставим точную дату, так как скрипт проверять будет на следующий день
                             $valueColumn = str_replace('в', '', $valueColumn);
                             $resultDate = new Carbon($valueColumn);
                             $contract->results_at = $resultDate;
                         }
                     }
                 }
             });
             $contract->save();
             $contractsNum++;
             $this->info('Контракт ' . $systemId . ' ' . $contractName);
             Log::info('Контракт сохранен в базу.');
         } else {
             $repeatSensor++;
             Log::info('Контракт найден в базе.');
         }
         usleep(rand(200, 2000) * 1000);
         // sleep for random time
     });
     return $contractsNum;
 }