@@ -22,6 +22,7 @@ public function parseDate($date)
2222
2323 public function model (array $ row ): ?Model
2424 {
25+ // Validate required fields
2526 if (
2627 empty ($ row ['activity_title ' ]) ||
2728 empty ($ row ['name_of_organisation ' ]) ||
@@ -37,16 +38,7 @@ public function model(array $row): ?Model
3738 }
3839
3940 try {
40- $ latitude = !empty ($ row ['latitude ' ]) ? trim ($ row ['latitude ' ]) : '' ;
41- $ longitude = !empty ($ row ['longitude ' ]) ? trim ($ row ['longitude ' ]) : '' ;
42- $ start_date = \PhpOffice \PhpSpreadsheet \Shared \Date::excelToDateTimeObject ($ row ['start_date ' ]);
43-
44- // Check for existing event
45- $ existingEvent = Event::where ('title ' , trim ($ row ['activity_title ' ]))
46- ->where ('start_date ' , $ start_date )
47- ->first ();
48-
49- $ eventData = [
41+ $ event = new Event ([
5042 'status ' => 'APPROVED ' ,
5143 'title ' => trim ($ row ['activity_title ' ]),
5244 'slug ' => str_slug (trim ($ row ['activity_title ' ])),
@@ -62,35 +54,28 @@ public function model(array $row): ?Model
6254 'country_iso ' => trim ($ row ['country ' ]),
6355 'picture ' => !empty ($ row ['image_path ' ]) ? trim ($ row ['image_path ' ]) : '' ,
6456 'pub_date ' => now (),
57+ 'created ' => now (),
6558 'updated ' => now (),
6659 'codeweek_for_all_participation_code ' => 'cw20-coderdojo-eu ' ,
67- 'start_date ' => $ start_date ,
60+ 'start_date ' => \ PhpOffice \ PhpSpreadsheet \ Shared \Date:: excelToDateTimeObject ( $ row [ ' start_date ' ]) ,
6861 'end_date ' => \PhpOffice \PhpSpreadsheet \Shared \Date::excelToDateTimeObject ($ row ['end_date ' ]),
69- 'geoposition ' => ($ latitude && $ longitude) ? " $ longitude , $ latitude " : '' ,
70- 'longitude ' => $ longitude ,
71- 'latitude ' => $ latitude ,
62+ 'geoposition ' => (! empty ( $ row [ ' latitude ' ]) && ! empty ( $ row [ ' longitude ' ])) ? $ row [ ' latitude ' ] . ' , ' . $ row [ ' longitude ' ] : '' ,
63+ 'longitude ' => ! empty ( $ row [ ' longitude ' ]) ? trim ( $ row [ ' longitude ' ]) : '' ,
64+ 'latitude ' => ! empty ( $ row [ ' latitude ' ]) ? trim ( $ row [ ' latitude ' ]) : '' ,
7265 'language ' => !empty ($ row ['language ' ]) ? trim ($ row ['language ' ]) : 'nl ' ,
7366 'approved_by ' => 19588 ,
7467 'mass_added_for ' => 'Excel ' ,
75- ];
68+ ]) ;
7669
77- if ($ existingEvent ) {
78- Log::info ('Updating existing event: ' . $ existingEvent ->id );
79- $ existingEvent ->update ($ eventData );
80- $ event = $ existingEvent ;
81- } else {
82- $ eventData ['created ' ] = now ();
83- $ event = new Event ($ eventData );
84- $ event ->save ();
85- }
70+ $ event ->save ();
8671
8772 if (!empty ($ row ['audience_comma_separated_ids ' ])) {
8873 $ audiences = array_unique (array_map ('trim ' , explode (', ' , $ row ['audience_comma_separated_ids ' ])));
8974 $ audiences = array_filter ($ audiences , function ($ id ) {
9075 return is_numeric ($ id ) && $ id > 0 && $ id <= 100 ;
9176 });
9277 if (!empty ($ audiences )) {
93- $ event ->audiences ()->sync ($ audiences );
78+ $ event ->audiences ()->attach ($ audiences );
9479 }
9580 }
9681
@@ -100,7 +85,7 @@ public function model(array $row): ?Model
10085 return is_numeric ($ id ) && $ id > 0 && $ id <= 100 ;
10186 });
10287 if (!empty ($ themes )) {
103- $ event ->themes ()->sync ($ themes );
88+ $ event ->themes ()->attach ($ themes );
10489 }
10590 }
10691
@@ -110,4 +95,4 @@ public function model(array $row): ?Model
11095 return null ;
11196 }
11297 }
113- }
98+ }
0 commit comments