designtopack/public/site/controllers/site.php

46 lines
1.4 KiB
PHP
Raw Normal View History

2024-07-11 12:42:29 +02:00
<?php
2024-10-29 11:20:31 +01:00
return function ($page, $kirby, $site) {
if (!$kirby->user() && $page->uri() !== 'login') {
go('/login');
}
$data = $page->toArray();
$data['template'] = (string) $page->template();
$data['newInspirations'] = (bool) page('inspirations')->children()->findBy('new', 'true');
2024-10-28 15:33:52 +01:00
if ($kirby->user()) {
$userData = [
2025-05-02 17:58:50 +02:00
"name" => (string) $kirby->user()->name()->or(null),
"email" => (string) $kirby->user()->email(),
"role" => (string) $kirby->user()->role(),
"uuid" => (string) $kirby->user()->uuid()
];
if ($kirby->user()->client()->exists() && $kirby->user()->client()->isNotEmpty()) {
$userData['client'] = [
"name" => (string) $kirby->user()->client()->toPage()->title(),
"uuid" => (string) $kirby->user()->client()->toPage()->uuid()
2025-04-30 15:27:01 +02:00
];
if ($kirby->user()->client()->toPage()->logo()->isNotEmpty()) {
$userData['client']["logo"] = $kirby->user()->client()->toPage()->logo()->toFile()->url();
}
2025-04-30 15:27:01 +02:00
}
2025-05-02 17:58:50 +02:00
if ($kirby->user()->projects()->exists() && $kirby->user()->projects()->isNotEmpty()) {
$userData['projects'] = $kirby->user()->projects()->toPages()->map(function ($project) {
return [
"title" => (string) $project->title(),
"uri" => (string) $project->uri(),
"step" => (string) $project->getStepLabel(),
];
})->data;
}
2024-10-28 15:33:52 +01:00
}
return [
'genericData' => $data,
'userData' => $userData ?? null
];
2024-07-11 12:42:29 +02:00
};