Skip to content
Merged
27 changes: 27 additions & 0 deletions app/Actions/ViewDataAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Actions;

use App\DTO\ContactDTO;
use App\Enums\ContactSectionEnum;
use App\Models\Contact;
use App\Models\News;
use App\Models\Product;
use App\Models\Service;
Expand Down Expand Up @@ -37,4 +40,28 @@ public function news(string $locale): Collection
return News::where('locale', $locale)->whereNotNull('published_at')->orderByDesc('published_at')->get();
});
}

public function contacts(string $locale): object
{
$key = Str::slug("contacts_published_{$locale}");

return Cache::rememberForever($key, function () use ($locale) {
return (object) collect([
ContactSectionEnum::EMPLOYEE_SERVICES,
ContactSectionEnum::EMPLOYEE_PRODUCTS,
ContactSectionEnum::EMPLOYEE_ADMINISTRATION,
ContactSectionEnum::COLLABORATIONS,
ContactSectionEnum::BOARD_MEMBERS,
])->mapWithKeys(function (string $section) use ($locale) {
$contacts = Contact::query()
->where('published', true)
->whereRaw("JSON_CONTAINS_PATH(sections, 'one', '$.\"$section\"')")
->orderBy('name')
->get()
->map(fn ($contact) => ContactDTO::fromModel($contact, $section, $locale));

return [$section => $contacts];
})->all();
});
}
}
32 changes: 32 additions & 0 deletions app/DTO/ContactDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace App\DTO;

use App\Models\Contact;
use Illuminate\Support\Arr;

class ContactDTO
{
public function __construct(
public readonly string $locale,
public readonly string $section,
public readonly string $name,
public readonly ?string $role,
public readonly string $image,
public readonly array $icons,
) {}

public static function fromModel(Contact $contact, string $section, string $locale): self
{
$role = Arr::get($contact->sections, "$section.role.$locale");

return new self(
name: $contact->name,
role: $role,
locale: $locale,
image: $contact->image,
icons: $contact->icons ?? [],
section: $section,
);
}
}
16 changes: 16 additions & 0 deletions app/Enums/ContactSectionEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Enums;

enum ContactSectionEnum: string
{
const string EMPLOYEE_SERVICES = 'employee_services';

const string EMPLOYEE_PRODUCTS = 'employee_products';

const string EMPLOYEE_ADMINISTRATION = 'employee_administration';

const string COLLABORATIONS = 'collaborations';

const string BOARD_MEMBERS = 'board_members';
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/AboutUs/AboutUsIndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\AboutUs;

use App\Actions\PageAction;
use App\Actions\ViewDataAction;
use App\Http\Controllers\Controller;
use Illuminate\View\View;

Expand All @@ -13,8 +14,11 @@ class AboutUsIndexController extends Controller
*/
public function __invoke(): View
{
$locale = app()->getLocale();

return view('app.about-us.index')->with([
'page' => (new PageAction(locale: null, routeName: 'about-us.index'))->default(),
'contacts' => (new ViewDataAction)->contacts($locale),
]);
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/Sitemap/SitemapController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SitemapController extends Controller

protected const array DEFAULT_ROUTES = [
'start.index',
'about-us.index',
'products.index',
'services.index',
'contact.index',
Expand Down
17 changes: 17 additions & 0 deletions app/Models/Contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Contact extends Model
{
use HasFactory;

protected $casts = [
'published' => 'boolean',
'sections' => 'json',
'icons' => 'json',
];
}
6 changes: 6 additions & 0 deletions app/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Traits\HasLocalizedRouteBinding;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Product extends Model
{
Expand All @@ -24,4 +25,9 @@ public function getRouteKeyName(): string
{
return 'slug';
}

public function productModules(): HasMany
{
return $this->hasMany(ProductModule::class);
}
}
33 changes: 33 additions & 0 deletions app/Models/ProductModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Models;

use App\Enums\LocaleEnum;
use App\Traits\HasLocalizedReferences;
use App\Traits\HasLocalizedRouteBinding;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class ProductModule extends Model
{
use HasFactory;
use HasLocalizedReferences;
use HasLocalizedRouteBinding;

protected $casts = [
'published' => 'boolean',
'locale' => LocaleEnum::class,
'tags' => 'json',
];

public function getRouteKeyName(): string
{
return 'slug';
}

public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
}
}
1 change: 1 addition & 0 deletions app/Security/Presets/MyCspPreset.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function configure(Policy $policy): void
$policy->add(Directive::IMG, [
Keyword::SELF,
'data:',
'res.cloudinary.com',
]);

$policy->add(Directive::FONT, Keyword::SELF);
Expand Down
Loading