Veranstalter strikt von Lieferanten trennen
This commit is contained in:
1 parent
0e71aca89b
commit
36fb17ac32
9 files changed
+114
-152
No files matched your search
@@ -166,76 +166,6 @@ function get_party_options(PDO $pdo): array
|
||||
);
|
||||
}
|
||||
|
||||
function get_market_organizer_options(PDO $pdo): array
|
||||
{
|
||||
$stmt = $pdo->query(
|
||||
"SELECT p.id, p.name, p.email, p.phone
|
||||
FROM party p
|
||||
INNER JOIN party_role pr ON pr.party_id = p.id AND pr.role_code = 'market_organizer'
|
||||
WHERE p.status = 'active'
|
||||
ORDER BY p.name ASC, p.id ASC"
|
||||
);
|
||||
|
||||
return $stmt->fetchAll() ?: [];
|
||||
}
|
||||
|
||||
function get_market_organizer_reference(PDO $pdo, int $partyId): ?array
|
||||
{
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT p.id, p.name, p.email, p.phone
|
||||
FROM party p
|
||||
INNER JOIN party_role pr ON pr.party_id = p.id AND pr.role_code = 'market_organizer'
|
||||
WHERE p.id = :id AND p.status = 'active'"
|
||||
);
|
||||
$stmt->execute([':id' => $partyId]);
|
||||
$party = $stmt->fetch();
|
||||
|
||||
return is_array($party) ? $party : null;
|
||||
}
|
||||
|
||||
function create_market_organizer(PDO $pdo, string $name, ?string $email = null, ?string $phone = null): array
|
||||
{
|
||||
$name = trim($name);
|
||||
$email = $email !== null ? trim($email) : null;
|
||||
$phone = $phone !== null ? trim($phone) : null;
|
||||
if ($name === '') {
|
||||
throw new InvalidArgumentException('Veranstaltername fehlt.');
|
||||
}
|
||||
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
$stmt = $pdo->prepare(
|
||||
"SELECT id, name, email, phone FROM party WHERE LOWER(TRIM(name)) = LOWER(:name) LIMIT 1 FOR UPDATE"
|
||||
);
|
||||
$stmt->execute([':name' => $name]);
|
||||
$party = $stmt->fetch();
|
||||
if (!is_array($party)) {
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO party (type, name, email, phone, status, created_at, updated_at)
|
||||
VALUES ('customer', :name, :email, :phone, 'active', NOW(), NOW())
|
||||
RETURNING id, name, email, phone"
|
||||
);
|
||||
$stmt->execute([':name' => $name, ':email' => $email ?: null, ':phone' => $phone ?: null]);
|
||||
$party = $stmt->fetch();
|
||||
}
|
||||
if (!is_array($party)) {
|
||||
throw new RuntimeException('Veranstalter konnte nicht angelegt werden.');
|
||||
}
|
||||
$role = $pdo->prepare(
|
||||
"INSERT INTO party_role (party_id, role_code) VALUES (:party_id, 'market_organizer')
|
||||
ON CONFLICT (party_id, role_code) DO NOTHING"
|
||||
);
|
||||
$role->execute([':party_id' => (int) $party['id']]);
|
||||
$pdo->commit();
|
||||
return (array) $party;
|
||||
} catch (Throwable $error) {
|
||||
if ($pdo->inTransaction()) {
|
||||
$pdo->rollBack();
|
||||
}
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
function get_contact_options(PDO $pdo): array
|
||||
{
|
||||
$stmt = $pdo->query(
|
||||
|
||||
Reference in new issue
Block a user