Slim API deployment - composer install + full CRUD endpoints
This commit is contained in:
@@ -79,4 +79,41 @@ final class InstructorRepository extends BaseRepository
|
||||
|
||||
return $statement->fetch() ?: null;
|
||||
}
|
||||
|
||||
public function findById(int $id): ?array
|
||||
{
|
||||
$statement = $this->db->prepare('SELECT * FROM instructors WHERE id = :id');
|
||||
$statement->execute(['id' => $id]);
|
||||
|
||||
return $statement->fetch() ?: null;
|
||||
}
|
||||
|
||||
public function listForTenant(int $tenantId): array
|
||||
{
|
||||
$statement = $this->db->prepare('SELECT * FROM instructors WHERE tenant_id = :tenant_id AND is_active = 1 ORDER BY last_name, first_name');
|
||||
$statement->execute(['tenant_id' => $tenantId]);
|
||||
|
||||
return $statement->fetchAll();
|
||||
}
|
||||
|
||||
public function updateSettings(int $instructorId, array $settings): bool
|
||||
{
|
||||
$allowed = ['max_daily_units', 'max_daily_override', 'max_weekly_units', 'max_weekly_override', 'booking_enabled'];
|
||||
$sets = [];
|
||||
$params = ['id' => $instructorId];
|
||||
foreach ($allowed as $key) {
|
||||
if (array_key_exists($key, $settings)) {
|
||||
$sets[] = "{$key} = :{$key}";
|
||||
$params[$key] = $settings[$key];
|
||||
}
|
||||
}
|
||||
if (empty($sets)) {
|
||||
return false;
|
||||
}
|
||||
$sql = 'UPDATE instructors SET ' . implode(', ', $sets) . ', updated_at = :updated_at WHERE id = :id';
|
||||
$params['updated_at'] = $this->now();
|
||||
$statement = $this->db->prepare($sql);
|
||||
$statement->execute($params);
|
||||
return (bool) $statement->rowCount();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user