Skip to content

Commit aae3967

Browse files
committed
coderdojo events import
1 parent 1f73709 commit aae3967

2 files changed

Lines changed: 52 additions & 11 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace App\Console\Commands\excel;
4+
5+
use App\Imports\CoderDojoEventsImport;
6+
use Illuminate\Console\Command;
7+
use Illuminate\Support\Facades\Log;
8+
use Maatwebsite\Excel\Facades\Excel;
9+
10+
class CoderDojoEvents extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'excel:coderdojo';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'Coder Dojo 2024 From Excel File';
25+
26+
/**
27+
* Create a new command instance.
28+
*
29+
* @return void
30+
*/
31+
public function __construct()
32+
{
33+
parent::__construct();
34+
}
35+
36+
/**
37+
* Execute the console command.
38+
*/
39+
public function handle(): void
40+
{
41+
Log::info('Loading Coder Dojo Excel File');
42+
43+
Excel::import(
44+
new CoderDojoEventsImport(),
45+
'20241024 CodeWeek activities NOVEMBER CoderDojo Belgium.xlsx',
46+
'excel'
47+
);
48+
}
49+
}

app/Imports/CoderDojoEventsImport.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ public function parseDate($date)
2323

2424
public function model(array $row): ?Model
2525
{
26-
27-
// dd($row["start_date"]);
28-
//dd(implode(",",$arr));
29-
(\PhpOffice\PhpSpreadsheet\Shared\Date::excelToDateTimeObject($row['start_date']));
30-
// dd(Carbon::parse($this->parseDate($row["start_date"]))->toDateTimeString());
31-
//dd(Carbon::createFromFormat("d/m/Y",$row["start_date"])->toDateTimeString());
32-
Log::info($row);
33-
3426
$event = new Event([
3527
'status' => 'APPROVED',
3628
'title' => $row['activity_title'],
@@ -42,9 +34,9 @@ public function model(array $row): ?Model
4234
'location' => isset($row['address']) ? $row['address'] : 'online',
4335
'event_url' => $row['organiser_website'],
4436
'user_email' => '',
45-
'creator_id' => $row['creator_id'],
37+
'creator_id' => 132942,
4638
'country_iso' => $row['country'],
47-
'picture' => $row['image_path'],
39+
'picture' => isset($row['image_path']) ? $row['image_path'] : '',
4840
'pub_date' => now(),
4941
'created' => now(),
5042
'updated' => now(),
@@ -54,7 +46,7 @@ public function model(array $row): ?Model
5446
'geoposition' => $row['latitude'].','.$row['longitude'],
5547
'longitude' => $row['longitude'],
5648
'latitude' => $row['latitude'],
57-
'language' => 'nl',
49+
'language' => isset($row['language']) ? $row['language'] : 'nl',
5850
'approved_by' => 19588,
5951
'mass_added_for' => 'Excel',
6052
]);

0 commit comments

Comments
 (0)