Skip to content

Commit 8b410a3

Browse files
author
Sebastian Fix
committed
wip
1 parent 17f41e6 commit 8b410a3

21 files changed

Lines changed: 498 additions & 61 deletions

app/Actions/ViewDataAction.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace App\Actions;
44

5+
use App\DTO\ContactDTO;
6+
use App\Enums\ContactSectionEnum;
7+
use App\Models\Contact;
58
use App\Models\News;
69
use App\Models\Product;
710
use App\Models\Service;
@@ -37,4 +40,28 @@ public function news(string $locale): Collection
3740
return News::where('locale', $locale)->whereNotNull('published_at')->orderByDesc('published_at')->get();
3841
});
3942
}
43+
44+
public function contacts(string $locale): object
45+
{
46+
$key = Str::slug("contacts_published_{$locale}");
47+
48+
return Cache::rememberForever($key, function () use ($locale) {
49+
return (object) collect([
50+
ContactSectionEnum::EMPLOYEE_SERVICES,
51+
ContactSectionEnum::EMPLOYEE_PRODUCTS,
52+
ContactSectionEnum::EMPLOYEE_ADMINISTRATION,
53+
ContactSectionEnum::COLLABORATIONS,
54+
ContactSectionEnum::BOARD_MEMBERS,
55+
])->mapWithKeys(function (string $section) use ($locale) {
56+
$contacts = Contact::query()
57+
->where('published', true)
58+
->whereRaw("JSON_CONTAINS_PATH(sections, 'one', '$.\"$section\"')")
59+
->orderBy('name')
60+
->get()
61+
->map(fn ($contact) => ContactDTO::fromModel($contact, $section, $locale));
62+
63+
return [$section => $contacts];
64+
})->all();
65+
});
66+
}
4067
}

app/DTO/ContactDTO.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\DTO;
4+
5+
use App\Models\Contact;
6+
use Illuminate\Support\Arr;
7+
8+
class ContactDTO
9+
{
10+
public function __construct(
11+
public readonly string $locale,
12+
public readonly string $section,
13+
public readonly string $name,
14+
public readonly ?string $role,
15+
public readonly string $image,
16+
public readonly array $icons,
17+
) {}
18+
19+
public static function fromModel(Contact $contact, string $section, string $locale): self
20+
{
21+
$role = Arr::get($contact->sections, "$section.role.$locale");
22+
23+
return new self(
24+
name: $contact->name,
25+
role: $role,
26+
locale: $locale,
27+
image: $contact->image,
28+
icons: $contact->icons ?? [],
29+
section: $section,
30+
);
31+
}
32+
}

app/Enums/ContactSectionEnum.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace App\Enums;
4+
5+
enum ContactSectionEnum: string
6+
{
7+
const string EMPLOYEE_SERVICES = 'employee_services';
8+
9+
const string EMPLOYEE_PRODUCTS = 'employee_products';
10+
11+
const string EMPLOYEE_ADMINISTRATION = 'employee_administration';
12+
13+
const string COLLABORATIONS = 'collaborations';
14+
15+
const string BOARD_MEMBERS = 'board_members';
16+
}

app/Http/Controllers/AboutUs/AboutUsIndexController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Controllers\AboutUs;
44

55
use App\Actions\PageAction;
6+
use App\Actions\ViewDataAction;
67
use App\Http\Controllers\Controller;
78
use Illuminate\View\View;
89

@@ -13,8 +14,12 @@ class AboutUsIndexController extends Controller
1314
*/
1415
public function __invoke(): View
1516
{
17+
18+
$locale = app()->getLocale();
19+
1620
return view('app.about-us.index')->with([
1721
'page' => (new PageAction(locale: null, routeName: 'about-us.index'))->default(),
22+
'contacts' => (new ViewDataAction)->contacts($locale),
1823
]);
1924
}
2025
}

app/Models/Contact.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Contact extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $casts = [
13+
'published' => 'boolean',
14+
'sections' => 'json',
15+
'icons' => 'json',
16+
];
17+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::create('contacts', function (Blueprint $table) {
15+
$table->id();
16+
$table->boolean('published')->default(false);
17+
$table->string('name');
18+
$table->json('sections')->nullable();
19+
$table->string('image');
20+
$table->string('link')->nullable();
21+
$table->json('icons')->nullable();
22+
$table->timestamps();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*/
29+
public function down(): void
30+
{
31+
Schema::dropIfExists('contacts');
32+
}
33+
};

database/seeders/CodebarSeeder.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Database\Seeders;
4+
5+
use Illuminate\Cache\Console\ClearCommand;
6+
use Illuminate\Database\Seeder;
7+
use Illuminate\Support\Facades\Artisan;
8+
9+
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
10+
11+
class CodebarSeeder extends Seeder
12+
{
13+
/**
14+
* Seed the application's database.
15+
*/
16+
public function run(): void
17+
{
18+
if (app()->isLocal()) {
19+
Artisan::call(ClearCommand::class);
20+
}
21+
22+
}
23+
}

database/seeders/DatabaseSeeder.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
use App\Enums\LocaleEnum;
66
use App\Enums\RoleEnum;
77
use App\Models\User;
8-
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
9-
use Illuminate\Cache\Console\ClearCommand;
8+
use Database\Seeders\Paperflakes\RolesAndPermissionsSeeder;
109
use Illuminate\Database\Seeder;
11-
use Illuminate\Support\Facades\Artisan;
10+
11+
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
1212

1313
class DatabaseSeeder extends Seeder
1414
{
@@ -30,14 +30,8 @@ public function run(): void
3030

3131
$user->assignRole(RoleEnum::ADMINISTRATOR, RoleEnum::USER);
3232

33-
$this->call(PagesTableSeeder::class);
34-
$this->call(NewsTableSeeder::class);
35-
$this->call(ProductsTableSeeder::class);
36-
$this->call(ServicesTableSeeder::class);
37-
38-
if (app()->isLocal()) {
39-
Artisan::call(ClearCommand::class);
40-
}
33+
$this->call(PaperflakesSeeder::class);
34+
// $this->call(CodebarSeeder::class);
4135

4236
}
4337
}
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
namespace Database\Seeders\Paperflakes;
4+
5+
use App\Enums\ContactSectionEnum;
6+
use App\Models\Contact;
7+
use Illuminate\Database\Seeder;
8+
9+
class ContactsTableSeeder extends Seeder
10+
{
11+
public function run(): void
12+
{
13+
Contact::updateOrCreate(
14+
['name' => 'Sebastian Bürgin-Fix'],
15+
[
16+
'published' => true,
17+
'sections' => [
18+
ContactSectionEnum::EMPLOYEE_SERVICES => [
19+
'key' => ContactSectionEnum::EMPLOYEE_SERVICES,
20+
'role' => [
21+
'de_CH' => 'DMS/ECM Spezialist',
22+
'en_CH' => 'DMS/ECM Specialist',
23+
],
24+
],
25+
ContactSectionEnum::EMPLOYEE_PRODUCTS => [
26+
'key' => ContactSectionEnum::EMPLOYEE_PRODUCTS,
27+
'role' => [
28+
'de_CH' => 'Software-Architekt',
29+
'en_CH' => 'Software-Engineer',
30+
],
31+
],
32+
ContactSectionEnum::COLLABORATIONS => [
33+
'key' => ContactSectionEnum::COLLABORATIONS,
34+
'role' => [
35+
'de_CH' => 'codebar Solutions AG',
36+
],
37+
],
38+
ContactSectionEnum::BOARD_MEMBERS => [
39+
'key' => ContactSectionEnum::BOARD_MEMBERS,
40+
],
41+
],
42+
'icons' => [
43+
'email' => 'sebastian.buergin@paperflakes.ch',
44+
'linkedin' => 'https://www.linkedin.com/in/fix-sebastian/',
45+
],
46+
'link' => 'https://www.codebar.ch',
47+
'image' => 'https://res.cloudinary.com/codebar/image/upload/c_scale,dpr_2.0,f_auto,q_auto,w_500/www-codebar-ch/team/s_fix.webp',
48+
]
49+
);
50+
51+
Contact::updateOrCreate(
52+
['name' => 'Mischa Lanz'],
53+
[
54+
'published' => true,
55+
'sections' => [
56+
ContactSectionEnum::EMPLOYEE_SERVICES => [
57+
'key' => ContactSectionEnum::EMPLOYEE_SERVICES,
58+
'role' => [
59+
'de_CH' => 'zunscan.ch',
60+
],
61+
],
62+
ContactSectionEnum::BOARD_MEMBERS => [
63+
'key' => ContactSectionEnum::BOARD_MEMBERS,
64+
],
65+
],
66+
'icons' => [
67+
'email' => 'mischa.lanz@paperflakes.ch',
68+
'linkedin' => 'https://www.realestateclub.ch/images/REC_social_linkedin.svg',
69+
],
70+
'image' => 'https://www.realestateclub.ch/images/6528f7c6bddf8430fb5d154c_Mischa_Hemd.webp',
71+
]
72+
);
73+
74+
Contact::updateOrCreate(
75+
['name' => 'Dominique Ernst'],
76+
[
77+
'published' => true,
78+
'sections' => [
79+
ContactSectionEnum::BOARD_MEMBERS => [
80+
'key' => ContactSectionEnum::BOARD_MEMBERS,
81+
],
82+
],
83+
'icons' => [
84+
'email' => 'dominique.ernst@paperflakes.ch',
85+
'linkedin' => 'https://www.linkedin.com/in/dominique-ernst',
86+
],
87+
'image' => 'https://res.cloudinary.com/codebar/image/upload/c_scale,dpr_2.0,f_auto,q_auto,w_500/www-codebar-ch/team/d_ernst.webp',
88+
]
89+
);
90+
91+
Contact::updateOrCreate(
92+
['name' => 'Rhys Lees'],
93+
[
94+
'published' => true,
95+
'sections' => [
96+
ContactSectionEnum::EMPLOYEE_PRODUCTS => [
97+
'key' => ContactSectionEnum::EMPLOYEE_PRODUCTS,
98+
'role' => [
99+
'de_CH' => 'Entwickler',
100+
'en_CH' => 'Developer',
101+
],
102+
],
103+
],
104+
'icons' => [
105+
'email' => 'rhys.leess@paperflakes.ch',
106+
'linkedin' => 'https://www.linkedin.com/in/rhys-lees',
107+
],
108+
'image' => 'https://res.cloudinary.com/codebar/image/upload/c_scale,dpr_2.0,f_auto,q_auto,w_500/www-codebar-ch/team/r_lees.webp',
109+
]
110+
);
111+
112+
Contact::updateOrCreate(
113+
['name' => 'Katja Lanz'],
114+
[
115+
'published' => true,
116+
'sections' => [
117+
ContactSectionEnum::EMPLOYEE_ADMINISTRATION => [
118+
'key' => ContactSectionEnum::EMPLOYEE_ADMINISTRATION,
119+
'role' => [
120+
'de_CH' => 'Finanzen & HR',
121+
'en_CH' => 'Finance & HR',
122+
],
123+
],
124+
],
125+
'icons' => [
126+
'email' => 'katja.lanz@paperflakes.ch',
127+
'linkedin' => 'https://www.linkedin.com/in/katja-lanz-a92372149/',
128+
],
129+
'image' => 'https://www.realestateclub.ch/images/652d4179a3494dedacf6555a_Katja_Jacke.webp',
130+
]
131+
);
132+
133+
Contact::updateOrCreate(
134+
['name' => 'Dario Wieland'],
135+
[
136+
'published' => true,
137+
'sections' => [
138+
ContactSectionEnum::COLLABORATIONS => [
139+
'key' => ContactSectionEnum::COLLABORATIONS,
140+
'role' => [
141+
'de_CH' => 'Wieland Business Solutions GmbH',
142+
],
143+
],
144+
],
145+
'link' => 'https://www.business-solutions.gmbh',
146+
'image' => 'https://cdn.prod.website-files.com/6727978a2c75d658e43b75d5/67543ad5eb733f845bc34ba6_DarioWieland_Web.webp',
147+
]
148+
);
149+
}
150+
}

database/seeders/NewsTableSeeder.php renamed to database/seeders/Paperflakes/NewsTableSeeder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Database\Seeders;
3+
namespace Database\Seeders\Paperflakes;
44

55
use App\Models\News;
66
use Illuminate\Database\Seeder;

0 commit comments

Comments
 (0)