ContentConfigRepository.php
- Pfad:
src/Infrastructure/Persistence/ContentConfigRepository.php
- Namespace: Infrastructure\Persistence
- Zeilen: 240 | Größe: 7,396 Bytes
- Geändert: 2025-12-30 20:30:05 | Gescannt: 2025-12-31 10:22:15
Code Hygiene Score: 80
- Dependencies: 100 (25%)
- LOC: 100 (20%)
- Methods: 0 (20%)
- Secrets: 100 (15%)
- Classes: 100 (10%)
- Magic Numbers: 100 (10%)
Issues 1
| Zeile |
Typ |
Beschreibung |
| - |
srp |
Klasse hat 21 Methoden (max: 20) |
Dependencies 3
- implements Domain\Repository\ContentConfigRepositoryInterface
- constructor PDO
- use Domain\Repository\ContentConfigRepositoryInterface
Klassen 1
-
ContentConfigRepository
class
Zeile 11
Funktionen 21
-
__construct()
public
Zeile 15
-
findById()
public
Zeile 20
-
findByIdAndType()
public
Zeile 34
-
findAll()
public
Zeile 47
-
findAllByType()
public
Zeile 73
-
create()
public
Zeile 86
-
update()
public
Zeile 107
-
delete()
public
Zeile 127
-
saveHistory()
public
Zeile 133
-
deleteHistory()
public
Zeile 142
-
countChildren()
public
Zeile 148
-
getChildren()
public
Zeile 156
-
getHistory()
public
Zeile 164
-
getParentOptions()
public
Zeile 176
-
getStatistics()
public
Zeile 192
-
getAuthorProfiles()
public
Zeile 210
-
getSystemPrompts()
public
Zeile 215
-
getAuthorProfile()
public
Zeile 220
-
getSystemPrompt()
public
Zeile 225
-
getStructures()
public
Zeile 230
-
getStructure()
public
Zeile 235
Verwendet von 5
Versionen 8
-
v8
2025-12-30 20:30 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v7
2025-12-30 20:29 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v6
2025-12-25 18:19 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v5
2025-12-25 10:35 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v4
2025-12-25 10:32 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v3
2025-12-23 08:05 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v2
2025-12-23 02:37 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
-
v1
2025-12-22 10:17 | claude-code-hook | modified
Claude Code Pre-Hook Backup vor Edit-Operation
Code
<?php
declare(strict_types=1);
namespace Infrastructure\Persistence;
// @responsibility: Persistenz für Content-Konfiguration (Profile, Contracts, Strukturen)
use Domain\Repository\ContentConfigRepositoryInterface;
class ContentConfigRepository implements ContentConfigRepositoryInterface
{
private \PDO $pdo;
public function __construct(\PDO $pdo)
{
$this->pdo = $pdo;
}
public function findById(int $id): ?array
{
$stmt = $this->pdo->prepare(
'SELECT c.*, p.name as parent_name
FROM content_config c
LEFT JOIN content_config p ON c.parent_id = p.id
WHERE c.id = ?'
);
$stmt->execute([$id]);
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
return $result !== false ? $result : null;
}
public function findByIdAndType(int $id, string $type): ?array
{
$stmt = $this->pdo->prepare(
"SELECT id, name, slug, content, type, status
FROM content_config
WHERE id = ? AND type = ? AND status = 'active'"
);
$stmt->execute([$id, $type]);
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
return $result !== false ? $result : null;
}
public function findAll(?string $typeFilter = null, ?string $statusFilter = null): array
{
$sql = 'SELECT c.*, p.name as parent_name
FROM content_config c
LEFT JOIN content_config p ON c.parent_id = p.id
WHERE 1=1';
$params = [];
if ($typeFilter !== null && $typeFilter !== '') {
$sql .= ' AND c.type = ?';
$params[] = $typeFilter;
}
if ($statusFilter !== null && $statusFilter !== '') {
$sql .= ' AND c.status = ?';
$params[] = $statusFilter;
}
$sql .= ' ORDER BY c.type, c.name';
$stmt = $this->pdo->prepare($sql);
$stmt->execute($params);
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
public function findAllByType(string $type): array
{
$stmt = $this->pdo->prepare(
"SELECT id, name, slug, content, type, status
FROM content_config
WHERE type = ? AND status = 'active'
ORDER BY name"
);
$stmt->execute([$type]);
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
public function create(
string $type,
string $name,
string $slug,
?string $description,
string $content,
string $version,
string $status,
?int $parentId,
?int $promptId = null,
int $sortOrder = 0
): int {
$stmt = $this->pdo->prepare(
'INSERT INTO content_config (type, name, slug, description, content, version, status, parent_id, prompt_id, sort_order)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
);
$stmt->execute([$type, $name, $slug, $description, $content, $version, $status, $parentId, $promptId, $sortOrder]);
return (int) $this->pdo->lastInsertId();
}
public function update(
int $id,
string $name,
string $slug,
?string $description,
string $content,
string $version,
string $status,
?int $parentId,
?int $promptId = null,
int $sortOrder = 0
): void {
$stmt = $this->pdo->prepare(
'UPDATE content_config
SET name = ?, slug = ?, description = ?, content = ?, version = ?, status = ?, parent_id = ?, prompt_id = ?, sort_order = ?
WHERE id = ?'
);
$stmt->execute([$name, $slug, $description, $content, $version, $status, $parentId, $promptId, $sortOrder, $id]);
}
public function delete(int $id): void
{
$stmt = $this->pdo->prepare('DELETE FROM content_config WHERE id = ?');
$stmt->execute([$id]);
}
public function saveHistory(int $configId, string $content, string $version, string $changedBy, string $changeDescription): void
{
$stmt = $this->pdo->prepare(
'INSERT INTO content_config_history (config_id, content, version, changed_by, change_description)
VALUES (?, ?, ?, ?, ?)'
);
$stmt->execute([$configId, $content, $version, $changedBy, $changeDescription]);
}
public function deleteHistory(int $configId): void
{
$stmt = $this->pdo->prepare('DELETE FROM content_config_history WHERE config_id = ?');
$stmt->execute([$configId]);
}
public function countChildren(int $parentId): int
{
$stmt = $this->pdo->prepare('SELECT COUNT(*) FROM content_config WHERE parent_id = ?');
$stmt->execute([$parentId]);
return (int) $stmt->fetchColumn();
}
public function getChildren(int $parentId): array
{
$stmt = $this->pdo->prepare('SELECT * FROM content_config WHERE parent_id = ? ORDER BY name');
$stmt->execute([$parentId]);
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
public function getHistory(int $configId, int $limit = 10): array
{
$stmt = $this->pdo->prepare(
'SELECT * FROM content_config_history WHERE config_id = ? ORDER BY created_at DESC LIMIT ?'
);
$stmt->bindValue(1, $configId, \PDO::PARAM_INT);
$stmt->bindValue(2, $limit, \PDO::PARAM_INT);
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
public function getParentOptions(?int $excludeId = null): array
{
$stmt = $this->pdo->query(
'SELECT id, type, name FROM content_config WHERE type IN ("contract", "organization") ORDER BY type, name'
);
$parents = [];
foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
if ($excludeId !== null && (int) $row['id'] === $excludeId) {
continue;
}
$parents[] = $row;
}
return $parents;
}
public function getStatistics(): array
{
$stats = ['total' => 0, 'by_type' => [], 'by_status' => []];
$stmt = $this->pdo->query('SELECT type, COUNT(*) as cnt FROM content_config GROUP BY type');
foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$stats['by_type'][$row['type']] = (int) $row['cnt'];
$stats['total'] += (int) $row['cnt'];
}
$stmt = $this->pdo->query('SELECT status, COUNT(*) as cnt FROM content_config GROUP BY status');
foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
$stats['by_status'][$row['status']] = (int) $row['cnt'];
}
return $stats;
}
public function getAuthorProfiles(): array
{
return $this->findAllByType('author_profile');
}
public function getSystemPrompts(): array
{
return $this->findAllByType('system_prompt');
}
public function getAuthorProfile(int $id): ?array
{
return $this->findByIdAndType($id, 'author_profile');
}
public function getSystemPrompt(int $id): ?array
{
return $this->findByIdAndType($id, 'system_prompt');
}
public function getStructures(): array
{
return $this->findAllByType('structure');
}
public function getStructure(int $id): ?array
{
return $this->findByIdAndType($id, 'structure');
}
}