Backup #1047
| ID | 1047 |
| Dateipfad | /var/www/dev.campus.systemische-tools.de/src/Controller/TaxonomyController.php |
| Version | 12 |
| Typ |
modified |
| Größe | 4.4 KB |
| Hash | ac4c2f029056b9b2218169ea1d0da1313cd1901b9efb22a47a3fbfd055d8b2c8 |
| Datum | 2025-12-25 02:20:01 |
| Geändert von | claude-code-hook |
| Grund | Claude Code Pre-Hook Backup vor Edit-Operation |
| Datei existiert |
Ja
|
Dateiinhalt
<?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
{
$input = $this->getJsonInput();
$name = trim($input['name'] ?? '');
$parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;
if ($name === '') {
$this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);
return;
}
try {
$id = $this->repository->create($name, $parentId);
$this->json($this->apiFormatter->created($id, 'Taxonomie-Begriff erstellt'));
} catch (\Exception $e) {
$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
{
$input = $this->getJsonInput();
$name = trim($input['name'] ?? '');
$parentId = isset($input['parent_id']) && $input['parent_id'] !== '' ? (int) $input['parent_id'] : null;
if ($name === '') {
$this->json($this->apiFormatter->validationError('Name ist erforderlich', ['name' => 'Pflichtfeld']), 400);
return;
}
try {
$this->repository->updateTaxonomyTerm($id, $name, $parentId);
$this->json($this->apiFormatter->ok('Taxonomie-Begriff aktualisiert'));
} catch (\Exception $e) {
$this->json($this->apiFormatter->error($e->getMessage(), 'SERVER_ERROR'), 500);
}
}
/**
* POST /semantic-explorer/taxonomie/{id}/delete
*/
public function delete(int $id): void
{
try {
$success = $this->repository->deleteTaxonomyTerm($id);
if ($success) {
$this->json($this->apiFormatter->ok('Taxonomie-Begriff gelöscht'));
} else {
$this->json($this->apiFormatter->error('Begriff hat noch Unterbegriffe', 'HAS_CHILDREN'), 400);
}
} catch (\Exception $e) {
$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;
}
}
Vollständig herunterladen
Aktionen
Andere Versionen dieser Datei
| ID |
Version |
Typ |
Größe |
Datum |
| 1720 |
14 |
modified |
4.9 KB |
2025-12-27 12:31 |
| 1719 |
13 |
modified |
4.4 KB |
2025-12-27 12:30 |
| 1047 |
12 |
modified |
4.4 KB |
2025-12-25 02:20 |
| 1046 |
11 |
modified |
4.4 KB |
2025-12-25 02:19 |
| 1045 |
10 |
modified |
4.4 KB |
2025-12-25 02:19 |
| 1044 |
9 |
modified |
4.4 KB |
2025-12-25 02:19 |
| 1043 |
8 |
modified |
4.4 KB |
2025-12-25 02:19 |
| 1042 |
7 |
modified |
4.4 KB |
2025-12-25 02:19 |
| 692 |
6 |
modified |
4.5 KB |
2025-12-23 07:52 |
| 614 |
5 |
modified |
4.6 KB |
2025-12-23 04:42 |
| 518 |
4 |
modified |
4.4 KB |
2025-12-22 15:49 |
| 517 |
3 |
modified |
4.3 KB |
2025-12-22 15:49 |
| 516 |
2 |
modified |
4.1 KB |
2025-12-22 15:49 |
| 303 |
1 |
modified |
4.1 KB |
2025-12-22 08:04 |
← Zurück zur Übersicht