TaxonomyController.php
- Pfad:
src/Controller/TaxonomyController.php - Namespace: Controller
- Zeilen: 215 | Größe: 6,022 Bytes
- Geändert: 2025-12-27 12:31:03 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 100
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 100 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Keine Issues gefunden.
Dependencies 6
- extends Framework\Controller
- constructor Domain\Repository\TaxonomyRepositoryInterface
- constructor Infrastructure\Formatter\ApiResponseFormatter
- use Domain\Repository\TaxonomyRepositoryInterface
- use Framework\Controller
- use Infrastructure\Formatter\ApiResponseFormatter
Klassen 1
-
TaxonomyControllerclass Zeile 13
Funktionen 8
-
__construct()public Zeile 18 -
index()public Zeile 30 -
create()public Zeile 47 -
store()public Zeile 58 -
edit()public Zeile 104 -
update()public Zeile 122 -
destroy()public Zeile 168 -
buildTaxonomyTree()private Zeile 202
Versionen 14
-
v14
2025-12-27 12:31 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v13
2025-12-27 12:30 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v12
2025-12-25 02:20 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v11
2025-12-25 02:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v10
2025-12-25 02:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v9
2025-12-25 02:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v8
2025-12-25 02:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v7
2025-12-25 02:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v6
2025-12-23 07:52 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v5
2025-12-23 04:42 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v4
2025-12-22 15:49 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v3
2025-12-22 15:49 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v2
2025-12-22 15:49 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation -
v1
2025-12-22 08:04 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Controller;
// @responsibility: HTTP-Endpunkte für Semantic Explorer Taxonomie (CRUD)
use Domain\Repository\TaxonomyRepositoryInterface;
use Framework\Controller;
use Infrastructure\Formatter\ApiResponseFormatter;
class TaxonomyController extends Controller
{
private TaxonomyRepositoryInterface $repository;
private ApiResponseFormatter $apiFormatter;
public function __construct(
TaxonomyRepositoryInterface $repository,
ApiResponseFormatter $apiFormatter
) {
$this->repository = $repository;
$this->apiFormatter = $apiFormatter;
}
/**
* GET /semantic-explorer/taxonomie
* Hierarchische Kategorisierung
*/
public function index(): void
{
$terms = $this->repository->findAll();
$hierarchy = $this->buildTaxonomyTree($terms);
$stats = $this->repository->getStats();
$this->view('semantic-explorer.taxonomie', [
'title' => 'Taxonomie',
'terms' => $terms,
'hierarchy' => $hierarchy,
'stats' => $stats,
]);
}
/**
* GET /semantic-explorer/taxonomie/new
*/
public function create(): void
{
$this->view('semantic-explorer.taxonomie.new', [
'title' => 'Neuer Taxonomie-Begriff',
'terms' => $this->repository->findForSelect(),
]);
}
/**
* POST /semantic-explorer/taxonomie
*/
public function store(): void
{
$this->requireCsrf();
$input = $this->getJsonInput();
if (empty($input)) {
$input = $_POST;
}
$name = trim($input['name'] ?? '');
$parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;
if ($name === '') {
if ($this->isHtmxRequest()) {
$this->htmxError('Name ist erforderlich');
return;
}
$this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);
return;
}
try {
$id = $this->repository->create($name, $parentId);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/taxonomie/' . $id);
return;
}
$this->json($this->apiFormatter->created($id, 'Taxonomie-Begriff erstellt'));
} catch (\Exception $e) {
if ($this->isHtmxRequest()) {
$this->htmxError($e->getMessage());
return;
}
$this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
}
}
/**
* GET /semantic-explorer/taxonomie/{id}/edit
*/
public function edit(int $id): void
{
$term = $this->repository->find($id);
if ($term === null) {
$this->notFound('Begriff nicht gefunden');
}
$this->view('semantic-explorer.taxonomie.edit', [
'title' => 'Begriff bearbeiten',
'term' => $term,
'terms' => $this->repository->findForSelect(),
]);
}
/**
* POST /semantic-explorer/taxonomie/{id}
*/
public function update(int $id): void
{
$this->requireCsrf();
$input = $this->getJsonInput();
if (empty($input)) {
$input = $_POST;
}
$name = trim($input['name'] ?? '');
$parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;
if ($name === '') {
if ($this->isHtmxRequest()) {
$this->htmxError('Name ist erforderlich');
return;
}
$this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);
return;
}
try {
$this->repository->update($id, $name, $parentId);
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/taxonomie/' . $id);
return;
}
$this->json($this->apiFormatter->ok('Taxonomie-Begriff aktualisiert'));
} catch (\Exception $e) {
if ($this->isHtmxRequest()) {
$this->htmxError($e->getMessage());
return;
}
$this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
}
}
/**
* POST /semantic-explorer/taxonomie/{id}/delete
*/
public function destroy(int $id): void
{
$this->requireCsrf();
try {
$success = $this->repository->delete($id);
if ($success) {
if ($this->isHtmxRequest()) {
$this->htmxRedirect('/semantic-explorer/taxonomie');
return;
}
$this->json($this->apiFormatter->ok('Taxonomie-Begriff gelöscht'));
} else {
if ($this->isHtmxRequest()) {
$this->htmxError('Begriff hat noch Unterbegriffe');
return;
}
$this->json($this->apiFormatter->error('Begriff hat noch Unterbegriffe', 'HAS_CHILDREN'), 400);
}
} catch (\Exception $e) {
if ($this->isHtmxRequest()) {
$this->htmxError($e->getMessage());
return;
}
$this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
}
}
/**
* Baut Baum aus flacher Liste
*/
private function buildTaxonomyTree(array $items, ?int $parentId = null): array
{
$tree = [];
foreach ($items as $item) {
if ($item['parent_id'] == $parentId) {
$item['children'] = $this->buildTaxonomyTree($items, $item['id']);
$tree[] = $item;
}
}
return $tree;
}
}