| Server IP : 202.61.199.114 / Your IP : 216.73.217.139 Web Server : nginx/1.22.1 System : Linux de.arni-solutions.de 6.1.0-49-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.174-1 (2026-05-26) x86_64 User : web20 ( 1018) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/seaside2.pacim.de/web/app/models/ |
Upload File : |
<?php
class Organizer
{
private PDO $pdo;
public function __construct(Database $db)
{
$this->pdo = $db->getConnection();
}
public function all(): array
{
return $this->pdo->query("SELECT * FROM organizers ORDER BY name ASC")->fetchAll();
}
public function allActive(): array
{
return $this->pdo->query("SELECT * FROM organizers WHERE status = 'active' ORDER BY name ASC")->fetchAll();
}
public function find(int $id): ?array
{
$stmt = $this->pdo->prepare("SELECT * FROM organizers WHERE id = :id");
$stmt->execute(['id' => $id]);
$row = $stmt->fetch();
return $row !== false ? $row : null;
}
public function nameExists(string $name, ?int $excludeId = null): bool
{
if ($excludeId !== null) {
$stmt = $this->pdo->prepare("SELECT id FROM organizers WHERE name = :n AND id <> :id");
$stmt->execute(['n' => $name, 'id' => $excludeId]);
} else {
$stmt = $this->pdo->prepare("SELECT id FROM organizers WHERE name = :n");
$stmt->execute(['n' => $name]);
}
return (bool)$stmt->fetch();
}
public function create(array $data): int
{
$sql = "INSERT INTO organizers (name, contact_email, contact_phone, website, notes, status)
VALUES (:name, :email, :phone, :website, :notes, :status)";
$stmt = $this->pdo->prepare($sql);
$stmt->execute([
'name' => $data['name'],
'email' => $data['contact_email'] ?: null,
'phone' => $data['contact_phone'] ?: null,
'website' => $data['website'] ?: null,
'notes' => $data['notes'] ?: null,
'status' => $data['status'] ?? 'active',
]);
return (int)$this->pdo->lastInsertId();
}
public function update(int $id, array $data): bool
{
$sql = "UPDATE organizers SET
name = :name,
contact_email = :email,
contact_phone = :phone,
website = :website,
notes = :notes,
status = :status
WHERE id = :id";
$stmt = $this->pdo->prepare($sql);
return $stmt->execute([
'name' => $data['name'],
'email' => $data['contact_email'] ?: null,
'phone' => $data['contact_phone'] ?: null,
'website' => $data['website'] ?: null,
'notes' => $data['notes'] ?: null,
'status' => $data['status'] ?? 'active',
'id' => $id,
]);
}
public function delete(int $id): bool
{
$stmt = $this->pdo->prepare("DELETE FROM organizers WHERE id = :id");
return $stmt->execute(['id' => $id]);
}
/**
* Speichert die Logo-Pfade einer Skalierungs-Runde. Werte sind public-Pfade
* (relativ zu /public, beginnend mit /uploads/organizers/).
*/
public function updateLogoPaths(int $id, ?string $original, array $heightMap): bool
{
$stmt = $this->pdo->prepare("UPDATE organizers SET
logo_path = :p,
logo_path_32 = :p32,
logo_path_64 = :p64,
logo_path_128 = :p128,
logo_path_256 = :p256,
logo_uploaded_at = :ts
WHERE id = :id");
return $stmt->execute([
'p' => $original,
'p32' => $heightMap[32] ?? null,
'p64' => $heightMap[64] ?? null,
'p128' => $heightMap[128] ?? null,
'p256' => $heightMap[256] ?? null,
'ts' => $original ? date('Y-m-d H:i:s') : null,
'id' => $id,
]);
}
public function clearLogo(int $id): bool
{
return $this->updateLogoPaths($id, null, []);
}
/**
* Ergänzt eine Organizer-Zeile um eine `logo`-Map mit allen Größen,
* z.B. für API-Antworten. Liefert null wenn keine Logo-Pfade gesetzt sind.
*/
public static function logoUrls(array $row, ?string $baseUrl = null): ?array
{
if (empty($row['logo_path'])) return null;
$bu = rtrim($baseUrl ?? '', '/');
$abs = static fn(?string $p): ?string => $p ? ($bu . $p) : null;
return [
'original' => $abs((string)$row['logo_path']),
'32' => $abs($row['logo_path_32'] ?? null),
'64' => $abs($row['logo_path_64'] ?? null),
'128' => $abs($row['logo_path_128'] ?? null),
'256' => $abs($row['logo_path_256'] ?? null),
];
}
public function eventCount(int $id): int
{
$stmt = $this->pdo->prepare("SELECT COUNT(*) FROM events WHERE organizer_id = :id");
$stmt->execute(['id' => $id]);
return (int)$stmt->fetchColumn();
}
public static function validate(array $data): array
{
$errors = [];
if (empty(trim((string)($data['name'] ?? '')))) {
$errors['name'] = 'Name ist erforderlich.';
}
if (!empty($data['contact_email']) && !filter_var($data['contact_email'], FILTER_VALIDATE_EMAIL)) {
$errors['contact_email'] = 'Gültige E-Mail-Adresse angeben.';
}
return $errors;
}
}