diff --git a/app/Console/Commands/ExcelImporter.php b/app/Console/Commands/ExcelImporter.php index 32e8bffed..0621c2f56 100644 --- a/app/Console/Commands/ExcelImporter.php +++ b/app/Console/Commands/ExcelImporter.php @@ -41,7 +41,7 @@ public function __construct() public function handle() { Log::info("Read excel file"); - Excel::import(new EventsImport, 'dutch.xlsx','excel'); + Excel::import(new EventsImport, 'apple.xlsx','excel'); // Read the xls file // For each line: // Create en event diff --git a/app/Imports/EventsImport.php b/app/Imports/EventsImport.php index 81bdfccce..fb9fd5dfc 100644 --- a/app/Imports/EventsImport.php +++ b/app/Imports/EventsImport.php @@ -15,35 +15,43 @@ class EventsImport extends DefaultValueBinder implements WithCustomValueBinder, ToModel, WithHeadingRow { - + public function parseDate($date){ + $arr = explode(",", $date); + array_shift($arr); + return implode($arr); + } /** - * @param array $row - * - * @return \Illuminate\Database\Eloquent\Model|null - */ + * @param array $row + * + * @return \Illuminate\Database\Eloquent\Model|null + */ public function model(array $row) { + + //dd(implode(",",$arr)); + //dd(Carbon::parse($this->parseDate($row["start_date"]))->toDateTimeString()); //dd(Carbon::createFromFormat("d/m/Y",$row["start_date"])->toDateTimeString()); //Log::info($row["Address"]); $event = new Event([ 'status' => "APPROVED", - 'title' => $row["activity_title"], - 'slug' => str_slug($row["activity_title"]), - 'organizer' => $row["name_of_organisation"], - 'description' => $row["description"], - 'organizer_type' => $row["type_of_organisation"], - 'location' => $row["address"], - 'event_url' => $row["organiser_website"], - 'user_email' => $row["contact_email"], - 'creator_id' => 19588, - 'country_iso' => "NL", + 'title' => $row["activity_title"], + 'slug' => str_slug($row["activity_title"]), + 'organizer' => $row["name_of_organisation"], + 'description' => $row["description"], + 'organizer_type' => $row["type_of_organisation"], + 'location' => $row["address"], + 'event_url' => $row["organiser_website"], + 'user_email' => "", + 'creator_id' => $row["creator_id"], + 'country_iso' => $row["country"], 'picture' => $row["image_path"], "pub_date" => now(), "created" => now(), "updated" => now(), - "start_date" => Carbon::createFromFormat("!d/m/Y",$row["start_date"])->toDateTimeString(), - "end_date" => Carbon::createFromFormat("!d/m/Y",$row["end_date"])->toDateTimeString(), + "codeweek_for_all_participation_code" => "cw18-apple-eu", + "start_date" => Carbon::parse($this->parseDate($row["start_date"]))->toDateTimeString(), + "end_date" => Carbon::parse($this->parseDate($row["end_date"]))->toDateTimeString(), "geoposition" => $row["latitude"] . "," . $row["longitude"], "longitude" => $row["longitude"], "latitude" => $row["latitude"] @@ -51,13 +59,11 @@ public function model(array $row) $event->save(); - $event->audiences()->attach(explode(",",$row["audience_comma_separated_ids"])); - $event->themes()->attach(explode(",",$row["theme_comma_separated_ids"])); + $event->audiences()->attach(explode(",", $row["audience_comma_separated_ids"])); + $event->themes()->attach(explode(",", $row["theme_comma_separated_ids"])); return $event; } - - } diff --git a/resources/excel/apple.xlsx b/resources/excel/apple.xlsx new file mode 100644 index 000000000..fa538756f Binary files /dev/null and b/resources/excel/apple.xlsx differ