Files
thetool/application/AssetManagementReservation/AssetManagementReservationModel.php
2025-06-29 10:43:06 +00:00

31 lines
814 B
PHP

<?php
class AssetManagementReservationModel extends TTCrudBaseModel {
public int $id;
public int $assetId;
public int $userId;
public int $startDate;
public ?int $endDate;
public ?string $notes;
public int $createBy;
public int $create;
public static function getConflictingReservations($assetId): array
{
$db = self::getDB();
$table = self::getFullyQualifiedTable();
$now = time();
$sql = "SELECT * FROM $table
WHERE assetId = $assetId AND startDate <= $now AND (endDate IS NULL OR endDate >= $now)
";
$result = $db->query($sql);
$reservations = [];
while ($row = $result->fetch_assoc()) {
$reservations[] = new self($row);
}
return $reservations;
}
}