| 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
/**
* Mitarbeiter-Stammdaten für die Zeiterfassung (?page=reports/worktime).
*/
class WorkEmployee
{
private PDO $pdo;
public function __construct(Database $db)
{
$this->pdo = $db->getConnection();
}
/**
* Aktive Mitarbeiter, alphabetisch nach Nachname/Vorname.
*/
public function allActive(): array
{
$sql = "SELECT id, first_name, last_name, max_hours, is_active, created_at
FROM work_employees
WHERE is_active = 1
ORDER BY last_name ASC, first_name ASC";
$stmt = $this->pdo->prepare($sql);
$stmt->execute();
return $stmt->fetchAll();
}
/**
* Alle Mitarbeiter inkl. inaktiver — für Admin-Listen.
*/
public function all(): array
{
$sql = "SELECT id, first_name, last_name, max_hours, is_active, created_at
FROM work_employees
ORDER BY is_active DESC, last_name ASC, first_name ASC";
$stmt = $this->pdo->prepare($sql);
$stmt->execute();
return $stmt->fetchAll();
}
public function find(int $id): ?array
{
$stmt = $this->pdo->prepare(
"SELECT id, first_name, last_name, max_hours, is_active, created_at
FROM work_employees WHERE id = :id"
);
$stmt->execute(['id' => $id]);
$row = $stmt->fetch();
return $row !== false ? $row : null;
}
public function create(array $data): int
{
$stmt = $this->pdo->prepare(
"INSERT INTO work_employees (first_name, last_name, max_hours, is_active)
VALUES (:first_name, :last_name, :max_hours, :is_active)"
);
$stmt->execute([
'first_name' => trim((string)($data['first_name'] ?? '')),
'last_name' => trim((string)($data['last_name'] ?? '')),
'max_hours' => (float)($data['max_hours'] ?? 0),
'is_active' => !empty($data['is_active']) ? 1 : 0,
]);
return (int)$this->pdo->lastInsertId();
}
public function update(int $id, array $data): void
{
$stmt = $this->pdo->prepare(
"UPDATE work_employees
SET first_name = :first_name,
last_name = :last_name,
max_hours = :max_hours,
is_active = :is_active
WHERE id = :id"
);
$stmt->execute([
'first_name' => trim((string)($data['first_name'] ?? '')),
'last_name' => trim((string)($data['last_name'] ?? '')),
'max_hours' => (float)($data['max_hours'] ?? 0),
'is_active' => !empty($data['is_active']) ? 1 : 0,
'id' => $id,
]);
}
public function delete(int $id): void
{
$stmt = $this->pdo->prepare("DELETE FROM work_employees WHERE id = :id");
$stmt->execute(['id' => $id]);
}
}