All checks were successful
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m30s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m34s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m45s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 3m35s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 3m42s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 3m7s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 3m15s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m8s
- Organigramm: grafischer Baum (Linien, Zoom, Verschieben) und Fokus-Ansicht mit Vorgesetzten, Team und direkt Unterstellten - Dokumente: Übersicht mit Bereichen und „Zuletzt aktualisiert“, sortierbare Dateiliste oder Kacheln (Wahl wird gemerkt) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
115 lines
4.6 KiB
PHP
115 lines
4.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Collection;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
/**
|
|
* Organigramm aus den Vorgesetzten-Angaben (Entra ID oder Admin). Auch bei
|
|
* tausenden Personen schnell: angezeigt werden die oberste Ebene und der Weg
|
|
* zu einer gewählten Person; alles Weitere lädt beim Aufklappen nach.
|
|
*/
|
|
class OrganigramController extends Controller
|
|
{
|
|
public function index(Request $request): Response
|
|
{
|
|
$view = in_array($request->query('ansicht'), ['baum', 'fokus'], true) ? $request->query('ansicht') : 'baum';
|
|
$focus = $request->integer('person') ? User::query()->active()->find($request->integer('person')) : null;
|
|
|
|
// Oberste Ebene: aktive Personen ohne (aktive) Vorgesetzte, die selbst ein Team haben.
|
|
$roots = $this->nodes(User::query()->active()
|
|
->where(fn (Builder $q) => $q->whereNull('manager_id')->orWhereDoesntHave('manager', fn (Builder $m) => $m->where('is_active', true)))
|
|
->whereHas('reports', fn (Builder $r) => $r->where('is_active', true)));
|
|
|
|
// Die Fokus-Ansicht beginnt ohne Auswahl bei der Spitze.
|
|
if ($view === 'fokus' && ! $focus && $roots->isNotEmpty()) {
|
|
$focus = User::query()->find($roots[0]['id']);
|
|
}
|
|
|
|
// Weg von oben zur gewählten Person, samt Team jeder Ebene.
|
|
$path = [];
|
|
$teams = [];
|
|
|
|
if ($focus) {
|
|
$current = $focus;
|
|
|
|
for ($i = 0; $current && $i < 30; $i++) {
|
|
array_unshift($path, $current->id);
|
|
$current = $current->manager_id ? User::query()->active()->find($current->manager_id) : null;
|
|
}
|
|
|
|
foreach ($path as $id) {
|
|
$teams[$id] = $this->nodes(User::query()->active()->where('manager_id', $id));
|
|
}
|
|
|
|
// Wer oben im Weg steht, aber (z. B. ohne Team) nicht in der obersten Ebene ist, dazunehmen.
|
|
if (! $roots->contains('id', $path[0])) {
|
|
$roots = $roots->push(...$this->nodes(User::query()->whereKey($path[0])))->values();
|
|
}
|
|
} elseif ($roots->count() === 1) {
|
|
// Nur eine Spitze (z. B. die Geschäftsführung): erste Ebene gleich zeigen.
|
|
$path = [$roots[0]['id']];
|
|
$teams[$path[0]] = $this->nodes(User::query()->active()->where('manager_id', $path[0]));
|
|
}
|
|
|
|
return Inertia::render('People/Organigram', [
|
|
'roots' => $roots,
|
|
'path' => $path,
|
|
'teams' => (object) $teams,
|
|
'focus' => $focus?->id,
|
|
'details' => $focus ? [
|
|
'id' => $focus->id,
|
|
'name' => $focus->name,
|
|
'initials' => $focus->initials,
|
|
'job_title' => $focus->job_title,
|
|
'department' => $focus->department,
|
|
'location' => $focus->location,
|
|
'email' => $focus->email,
|
|
'phone' => $focus->phone,
|
|
'mobile' => $focus->mobile,
|
|
'avatar_url' => $focus->avatarUrl(192),
|
|
] : null,
|
|
'view' => $view,
|
|
'stats' => [
|
|
'people' => User::query()->active()->where(fn (Builder $q) => $q->whereNotNull('manager_id')->orWhereHas('reports', fn (Builder $r) => $r->where('is_active', true)))->count(),
|
|
'leaders' => User::query()->active()->whereHas('reports', fn (Builder $r) => $r->where('is_active', true))->count(),
|
|
],
|
|
'unassigned' => User::query()->active()->whereNull('manager_id')->whereDoesntHave('reports')->count(),
|
|
]);
|
|
}
|
|
|
|
public function team(User $user): JsonResponse
|
|
{
|
|
abort_unless($user->is_active, 404);
|
|
|
|
return response()->json(['team' => $this->nodes(User::query()->active()->where('manager_id', $user->id))]);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<User> $query
|
|
* @return Collection<int, array<string, mixed>>
|
|
*/
|
|
private function nodes(Builder $query): Collection
|
|
{
|
|
return $query->withCount(['reports' => fn (Builder $r) => $r->where('is_active', true)])
|
|
->orderBy('last_name')->orderBy('first_name')
|
|
->limit(500)
|
|
->get()
|
|
->map(fn (User $u) => [
|
|
'id' => $u->id,
|
|
'name' => $u->name,
|
|
'initials' => $u->initials,
|
|
'job_title' => $u->job_title,
|
|
'department' => $u->department,
|
|
'location' => $u->location,
|
|
'avatar_url' => $u->avatarUrl(96),
|
|
'reports' => $u->reports_count,
|
|
]);
|
|
}
|
|
}
|