Exemplo n.º 1
0
 public function getHotel($city_id)
 {
     $cont = new Country();
     $data = $cont->getHotel($city_id);
     echo json_encode($data);
     die;
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $delimiter = ',';
     $csvFile = public_path() . '/gtd_70to91_0615dist.csv';
     if (($handle = fopen($csvFile, 'r')) !== FALSE) {
         $i = 0;
         while (($row = fgetcsv($handle, 8192, $delimiter)) !== FALSE) {
             if ($i != 0) {
                 /* Creating the where entry */
                 $when = new When();
                 $when->year = $row[1];
                 $when->month = $row[2];
                 $when->day = $row[3];
                 $when->approxdate = $row[4];
                 $when->extended = $row[5];
                 $when->resolution = $row[6];
                 $when->save();
                 /* Check if Countyr, provstate and city exist.
                  * If no, creating them */
                 $country = Country::where('txt', $row[8])->first();
                 if ($country == null) {
                     $country = new Country();
                     $country->txt = $row[8];
                     $country->save();
                 }
                 $provstate = Provstate::where('txt', $row[11])->first();
                 if ($provstate == null) {
                     $provstate = new Provstate();
                     $provstate->txt = $row[11];
                     $provstate->save();
                 }
                 $city = City::where('txt', $row[12])->first();
                 if ($city == null) {
                     $city = new City();
                     $city->txt = $row[12];
                     $city->save();
                 }
                 /* Creating the where entry */
                 $where = new Where();
                 $where->country_id = $country->id;
                 $where->provstate_id = $provstate->id;
                 $where->city_id = $city->id;
                 $where->latitude = $row[13];
                 $where->longitude = $row[14];
                 $where->specificity_id = $row[15];
                 $where->vicinity = $row[16];
                 $where->txt = $row[17];
                 $where->save();
                 /* Creating the what entry */
                 $what = new What();
                 $what->crit1 = $row[19];
                 $what->crit2 = $row[20];
                 $what->crit3 = $row[21];
                 $what->success = $row[26];
                 $what->suicide = $row[27];
                 $what->attacktype1 = $row[28];
                 $what->attacktype2 = $row[30];
                 $what->attacktype3 = $row[32];
                 $what->save();
                 /* Creating the target entry */
                 $target = new Target();
                 $target->targettype1 = $row[34];
                 $target->targetsubtype1 = $row[36];
                 $target->corp1 = $row[38];
                 $target->target1 = $row[39];
                 $target->natlty1 = $row[40];
                 $target->targettype2 = $row[42];
                 $target->targetsubtype2 = $row[44];
                 $target->corp2 = $row[46];
                 $target->target2 = $row[47];
                 $target->natlty2 = $row[48];
                 $target->targettype3 = $row[50];
                 $target->targetsubtype3 = $row[52];
                 $target->corp3 = $row[54];
                 $target->target3 = $row[55];
                 $target->natlty3 = $row[56];
                 $target->save();
                 /* Check if perpetrator groups and sub groups exist.
                  * If no, creating them */
                 $perpetrator_group1 = PerpetratorGroup::where('txt', $row[58])->first();
                 if ($perpetrator_group1 == null) {
                     $perpetrator_group1 = new PerpetratorGroup();
                     $perpetrator_group1->txt = $row[58];
                     $perpetrator_group1->save();
                 }
                 $perpetrator_sub_group1 = PerpetratorSubGroup::where('txt', $row[59])->first();
                 if ($perpetrator_sub_group1 == null) {
                     $perpetrator_sub_group1 = new PerpetratorSubGroup();
                     $perpetrator_sub_group1->txt = $row[59];
                     $perpetrator_sub_group1->save();
                 }
                 $perpetrator_group2 = PerpetratorGroup::where('txt', $row[60])->first();
                 if ($perpetrator_group2 == null) {
                     $perpetrator_group2 = new PerpetratorGroup();
                     $perpetrator_group2->txt = $row[60];
                     $perpetrator_group2->save();
                 }
                 $perpetrator_sub_group2 = PerpetratorSubGroup::where('txt', $row[61])->first();
                 if ($perpetrator_sub_group2 == null) {
                     $perpetrator_sub_group2 = new PerpetratorSubGroup();
                     $perpetrator_sub_group2->txt = $row[61];
                     $perpetrator_sub_group2->save();
                 }
                 $perpetrator_group3 = PerpetratorGroup::where('txt', $row[62])->first();
                 if ($perpetrator_group3 == null) {
                     $perpetrator_group3 = new PerpetratorGroup();
                     $perpetrator_group3->txt = $row[62];
                     $perpetrator_group3->save();
                 }
                 $perpetrator_sub_group3 = PerpetratorSubGroup::where('txt', $row[63])->first();
                 if ($perpetrator_sub_group3 == null) {
                     $perpetrator_sub_group3 = new PerpetratorSubGroup();
                     $perpetrator_sub_group3->txt = $row[63];
                     $perpetrator_sub_group3->save();
                 }
                 /* Creating the who entry */
                 $who = new Who();
                 $who->perpetrator_group1 = $perpetrator_group1->id;
                 $who->perpetrator_sub_group1 = $perpetrator_sub_group1->id;
                 $who->perpetrator_group2 = $perpetrator_group2->id;
                 $who->perpetrator_sub_group2 = $perpetrator_sub_group2->id;
                 $who->perpetrator_group3 = $perpetrator_group3->id;
                 $who->perpetrator_sub_group3 = $perpetrator_sub_group3->id;
                 $who->motive = $row[64];
                 $who->perpetrator_1confirmed = $row[65];
                 $who->perpetrator_2confirmed = $row[66];
                 $who->perpetrator_3confirmed = $row[67];
                 $who->nperps = $row[68];
                 $who->nperpscap = $row[69];
                 $who->claimed1 = $row[70];
                 $who->claimed_mode1 = $row[71];
                 $who->claimed2 = $row[73];
                 $who->claimed_mode2 = $row[74];
                 $who->claimed3 = $row[76];
                 $who->claimed_mode3 = $row[77];
                 $who->compclaim = $row[79];
                 $who->save();
                 /* Creating the how entry */
                 $how = new How();
                 $how->weaptype1 = $row[80];
                 $how->weapsubtype1 = $row[82];
                 $how->weaptype2 = $row[84];
                 $how->weapsubtype2 = $row[86];
                 $how->weaptype3 = $row[88];
                 $how->weapsubtype3 = $row[90];
                 $how->weaptype4 = $row[92];
                 $how->weapsubtype4 = $row[94];
                 $how->weapdetail = $row[96];
                 $how->save();
                 /* Creating the victim entry */
                 $victims = new Victims();
                 $victims->total_killed = $row[97];
                 $victims->us_killed = $row[98];
                 $victims->perpetrators_killed = $row[99];
                 $victims->total_injured = $row[100];
                 $victims->us_injured = $row[101];
                 $victims->perpetrators_injured = $row[102];
                 $victims->property_damage = $row[103];
                 $victims->property_damage_id = $row[104];
                 $victims->property_value = $row[106];
                 $victims->property_comment = $row[107];
                 $victims->hostages_kidnapping = $row[108];
                 $victims->hostages_kidnapping_victims = $row[109];
                 $victims->us_hostages_kidnapping_victims = $row[110];
                 $victims->hours_of_kidnapping = $row[111];
                 $victims->days_of_kidnapping = $row[112];
                 $victims->divert = $row[113];
                 $victims->kidhijcountry = $row[114];
                 $victims->ransom_demanded = $row[115];
                 $victims->ransom_amount = $row[116];
                 $victims->ransom_us_amount = $row[117];
                 $victims->ransom_paied = $row[118];
                 $victims->ransom_us_paied = $row[119];
                 $victims->ransom_note = $row[120];
                 $victims->kidnapping_hostage_outcome = $row[121];
                 $victims->nb_released = $row[122];
                 $victims->save();
                 /* Creating the event */
                 $event = new Event();
                 $event->where_id = $where->id;
                 $event->when_id = $when->id;
                 $event->what_id = $what->id;
                 $event->who_id = $who->id;
                 $event->how_id = $how->id;
                 $event->target_id = $target->id;
                 $event->victims_id = $victims->id;
                 $event->alternative_id = $row[23];
                 $event->summary = $row[18];
                 $event->multiple = $row[25];
                 $event->related = $row[133];
                 $event->add_informations = $row[124];
                 $event->INT_LOG = $row[129];
                 $event->INT_IDEO = $row[130];
                 $event->INT_MISC = $row[131];
                 $event->INT_ANY = $row[132];
                 $event->source1 = $row[125];
                 $event->source2 = $row[126];
                 $event->source3 = $row[127];
                 $event->db_source = $row[128];
                 $event->doubtter = $row[22];
                 $event->save();
                 /* Updating the event id into the several fields */
                 $where->event_id = $event->id;
                 $where->save();
                 $when->event_id = $event->id;
                 $when->save();
                 $what->event_id = $event->id;
                 $what->save();
                 $who->event_id = $event->id;
                 $who->save();
                 $how->event_id = $event->id;
                 $how->save();
                 $target->event_id = $event->id;
                 $target->save();
                 $victims->event_id = $event->id;
                 $victims->save();
                 dd([$event, $when, $where, $what, $who, $how, $target, $victims]);
             }
             $i++;
         }
         fclose($handle);
     }
     return $data;
 }