Add getLaneProducts method to department_selfserve_tasks_o and implement lane product retrieval in related objects and routes; enhance object validation with requireSelected method
This commit is contained in:
@@ -28,12 +28,22 @@ class object_property
|
||||
return $this->value();
|
||||
}
|
||||
|
||||
public function requireSelected(): void
|
||||
{
|
||||
// Check if the object is selected
|
||||
// This is a placeholder function. In a real implementation, this would check if the object
|
||||
if (!isset($this->id)) {
|
||||
throw new \RuntimeException("Object not selected");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the field in the database table
|
||||
* @return mixed The value of the field in the database table
|
||||
*/
|
||||
public function value(): mixed
|
||||
{
|
||||
self::requireSelected();
|
||||
if ($this->id < 0) {
|
||||
// If the object id is less than 0, return the fake value
|
||||
return $this->fake_value ?? $this->default;
|
||||
|
||||
@@ -29,6 +29,7 @@ class department_lanes_o extends db
|
||||
|
||||
public function getLaneStatus(): \modules\selfserve\helpers\selfserve_lane_status
|
||||
{
|
||||
self::requireSelected();
|
||||
$selfserve = new selfserve();
|
||||
$lane = $selfserve->lane((int)$this->id);
|
||||
return $lane->getLaneStatus();
|
||||
@@ -108,6 +109,17 @@ class department_lanes_o extends db
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the self-serve lane products available for this lane
|
||||
* @return array An array of product ids available for this lane
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getSelfServeLaneProducts(): array
|
||||
{
|
||||
self::requireSelected();
|
||||
return department_selfserve_tasks_o::getLaneProducts((int)$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @return department_lanes_o[] An array of department lane objects for the specified department
|
||||
|
||||
@@ -22,6 +22,22 @@ class department_selfserve_tasks_o extends db
|
||||
public object_property $updated_at;
|
||||
public object_property $deleted_at;
|
||||
|
||||
public static function getLaneProducts(int $lane_id): array
|
||||
{
|
||||
global /** @var db $db */
|
||||
$db;
|
||||
// Sanitize the input
|
||||
$lane_id = (int)$lane_id;
|
||||
// Get the products for the lane
|
||||
$sql = "SELECT DISTINCT product FROM department_selfserve_tasks WHERE lane = $lane_id AND deleted_at IS NULL ORDER BY product DESC";
|
||||
$result = $db->query($sql);
|
||||
$products = [];
|
||||
while ($row = $db->fetch_assoc($result)) {
|
||||
$products[] = (int)$row['product'];
|
||||
}
|
||||
return $products;
|
||||
}
|
||||
|
||||
|
||||
public function structure(): void
|
||||
{
|
||||
|
||||
@@ -73,6 +73,7 @@ class guestRoute
|
||||
'id' => (int)$lane->id,
|
||||
'name' => (string)$lane->name->value(),
|
||||
'status' => (string)$lane->getLaneStatus()->name,
|
||||
'products' => $lane->getSelfServeLaneProducts(),
|
||||
];
|
||||
}, $department->getLanes());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user