Add relay_machine_id property to department_lanes_o object and extend related functionality
- Introduced `relay_machine_id` to `department_lanes_o` for managing Shelly relay associated with machines. - Updated `add` method and database interactions to support the new property. - Included `relay_machine_id` in `asArray` and field initialization logic. - Enhanced `departmentLanesRoute` to handle `relay_machine_id` via API for creation and updates.
This commit is contained in:
@@ -15,6 +15,7 @@ class department_lanes_o extends db
|
||||
public object_property $name; // The lane name
|
||||
public object_property $relay_in_id; // The Shelly relay for the entrance port (if applicable)
|
||||
public object_property $relay_out_id; // The Shelly relay for the exit port (if applicable)
|
||||
public object_property $relay_machine_id; // The Shelly relay for the machine (if applicable)
|
||||
public object_property $created_at;
|
||||
public object_property $updated_at;
|
||||
public object_property $deleted_at;
|
||||
@@ -31,10 +32,11 @@ class department_lanes_o extends db
|
||||
* @param string $name The lane name
|
||||
* @param string|null $relay_in_id The Shelly relay for the entrance port (if applicable)
|
||||
* @param string|null $relay_out_id The Shelly relay for the exit port (if applicable)
|
||||
* @param string|null $relay_machine_id The Shelly relay for the machine (if applicable)
|
||||
* @return department_lanes_o
|
||||
* @throws Exception If the object was not created successfully
|
||||
*/
|
||||
public function add(int $department, string $name, string $relay_in_id = null, string $relay_out_id = null): self
|
||||
public function add(int $department, string $name, string $relay_in_id = null, string $relay_out_id = null, string $relay_machine_id = null): department_lanes_o
|
||||
{
|
||||
global /** @var db $db */
|
||||
$db;
|
||||
@@ -47,12 +49,16 @@ class department_lanes_o extends db
|
||||
if (!is_null($relay_out_id)) {
|
||||
$relay_out_id = $db->escape_string($relay_out_id);
|
||||
}
|
||||
if (!is_null($relay_machine_id)) {
|
||||
$relay_machine_id = $db->escape_string($relay_machine_id);
|
||||
}
|
||||
// Add the object
|
||||
$tmp_id = self::add_object([
|
||||
'department' => $department,
|
||||
'name' => $name,
|
||||
...(!is_null($relay_in_id) ? ['relay_in_id' => $relay_in_id] : []), // If the relay_in_id is null, it will be set to null in the database
|
||||
...(!is_null($relay_out_id) ? ['relay_out_id' => $relay_out_id] : []), // If the relay_out_id is null, it will be set to null in the database
|
||||
...(!is_null($relay_machine_id) ? ['relay_machine_id' => $relay_machine_id] : []), // If the relay_machine_id is null, it will be set to null in the database
|
||||
]);
|
||||
$this->id = $tmp_id;
|
||||
self::getObjectProperties();
|
||||
@@ -66,6 +72,7 @@ class department_lanes_o extends db
|
||||
$this->name = new object_property($this->table, $this->id, 'name', 'string', false);
|
||||
$this->relay_in_id = new object_property($this->table, $this->id, 'relay_in_id', 'string', false);
|
||||
$this->relay_out_id = new object_property($this->table, $this->id, 'relay_out_id', 'string', false);
|
||||
$this->relay_machine_id = new object_property($this->table, $this->id, 'relay_machine_id', 'string', false);
|
||||
$this->created_at = new object_property($this->table, $this->id, 'created_at', 'timestamp', false);
|
||||
$this->updated_at = new object_property($this->table, $this->id, 'updated_at', 'timestamp', false);
|
||||
$this->deleted_at = new object_property($this->table, $this->id, 'deleted_at', 'timestamp', false);
|
||||
@@ -84,6 +91,7 @@ class department_lanes_o extends db
|
||||
'name' => (string)$this->name->value(),
|
||||
'relay_in_id' => (string)$this->relay_in_id->value(),
|
||||
'relay_out_id' => (string)$this->relay_out_id->value(),
|
||||
'relay_machine_id' => (string)$this->relay_machine_id->value(),
|
||||
'created_at' => (string)$this->created_at->value(),
|
||||
'updated_at' => (string)$this->updated_at->value(),
|
||||
];
|
||||
|
||||
@@ -35,6 +35,7 @@ class departmentLanesRoute
|
||||
'department',
|
||||
'relay_in_id',
|
||||
'relay_out_id',
|
||||
'relay_machine_id',
|
||||
])
|
||||
->listObjectsWithPaginationIfSet(
|
||||
function ($department_lane) use ($user) {
|
||||
@@ -45,6 +46,7 @@ class departmentLanesRoute
|
||||
'name' => (string)$department_lane['name'],
|
||||
'relay_in_id' => (string)$department_lane['relay_in_id'],
|
||||
'relay_out_id' => (string)$department_lane['relay_out_id'],
|
||||
'relay_machine_id' => (string)$department_lane['relay_machine_id'],
|
||||
'created_at' => (string)$department_lane['created_at'],
|
||||
'updated_at' => (string)$department_lane['updated_at'],
|
||||
];
|
||||
@@ -79,11 +81,12 @@ class departmentLanesRoute
|
||||
$department = $response->getRequestParameter('department') ?? null;
|
||||
$relay_in_id = $response->getRequestParameter('relay_in_id') ?? null;
|
||||
$relay_out_id = $response->getRequestParameter('relay_out_id') ?? null;
|
||||
$relay_machine_id = $response->getRequestParameter('relay_machine_id') ?? null;
|
||||
// Remove spaces from the relay_in_id and relay_out_id
|
||||
// Check if the required fields are set
|
||||
if ($name && $department) {
|
||||
// Add the department lane
|
||||
(new department_lanes_o())->add((int)$department, (string)$name, $relay_in_id, $relay_out_id);
|
||||
(new department_lanes_o())->add((int)$department, (string)$name, $relay_in_id, $relay_out_id, $relay_machine_id);
|
||||
// Return a success message
|
||||
$response->success('Department lane added');
|
||||
} else {
|
||||
@@ -120,6 +123,7 @@ class departmentLanesRoute
|
||||
$department = $response->getRequestParameter('department') ?? null;
|
||||
$relay_in_id = $response->getRequestParameter('relay_in_id') ?? null;
|
||||
$relay_out_id = $response->getRequestParameter('relay_out_id') ?? null;
|
||||
$relay_machine_id = $response->getRequestParameter('relay_machine_id') ?? null;
|
||||
|
||||
// Check what fields are set
|
||||
self::requireParameters(['id']);
|
||||
@@ -143,6 +147,9 @@ class departmentLanesRoute
|
||||
if (self::isParametersSet(['relay_out_id'])) {
|
||||
$department_lane->relay_out_id->set((string)$relay_out_id);
|
||||
}
|
||||
if (self::isParametersSet(['relay_machine_id'])) {
|
||||
$department_lane->relay_machine_id->set((string)$relay_machine_id);
|
||||
}
|
||||
// Return a success message
|
||||
$response->success('Department lane updated');
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user