Add department_selfserve_vehicle_conditions_o class and standardize_registration method to manage vehicle conditions and standardize registration input
This commit is contained in:
@@ -34,6 +34,13 @@ class selfserve implements universal_module_i
|
||||
return new self();
|
||||
}
|
||||
|
||||
public static function standardize_registration(string $reg): string
|
||||
{
|
||||
// Remove spaces and convert to uppercase
|
||||
// Return the standardized registration
|
||||
return strtoupper(str_replace(' ', '', $reg));
|
||||
}
|
||||
|
||||
public function lane(int $lane_id): selfserve_lane
|
||||
{
|
||||
return new selfserve_lane($lane_id);
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace objects;
|
||||
|
||||
use classes\db;
|
||||
use classes\object_property;
|
||||
use classes\selfserve;
|
||||
use Exception;
|
||||
use traits\db_object_t;
|
||||
|
||||
class department_selfserve_vehicle_conditions_o extends db
|
||||
{
|
||||
use db_object_t;
|
||||
|
||||
public object_property $department; // The department id
|
||||
public object_property $lane; // The lane id
|
||||
public object_property $customer_id; // The customer id
|
||||
public object_property $reg; // The vehicle registration number
|
||||
public object_property $question; // The question id
|
||||
public object_property $value; // The answer value
|
||||
public object_property $created_at;
|
||||
public object_property $updated_at;
|
||||
public object_property $deleted_at;
|
||||
|
||||
|
||||
public function structure(): void
|
||||
{
|
||||
$this->setTable('department_selfserve_vehicle_conditions');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a department lane
|
||||
* @param int $department The department id
|
||||
* @param int $lane The lane id
|
||||
* @param string $reg The vehicle registration number
|
||||
* @param int $question The question id
|
||||
* @param bool $value The answer value
|
||||
* @return department_selfserve_vehicle_conditions_o
|
||||
* @throws Exception If the object was not created successfully
|
||||
*/
|
||||
public function add(int $department, int $lane, string $reg, int $question, bool $value): department_selfserve_vehicle_conditions_o
|
||||
{
|
||||
global /** @var db $db */
|
||||
$db;
|
||||
// Sanitize the input
|
||||
$department = (int)$department;
|
||||
$lane = (int)$lane;
|
||||
$reg = $db->escape_string($reg);
|
||||
// Standardize the registration number
|
||||
$reg = selfserve::standardize_registration($reg);
|
||||
$question = (int)$question;
|
||||
$value = (bool)$value;
|
||||
// Add the object
|
||||
$tmp_id = self::add_object([
|
||||
'department' => $department,
|
||||
'lane' => $lane,
|
||||
'reg' => $reg,
|
||||
'question' => $question,
|
||||
'value' => $value,
|
||||
]);
|
||||
$this->id = $tmp_id;
|
||||
self::getObjectProperties();
|
||||
self::objectChanged();
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getObjectProperties(): void
|
||||
{
|
||||
$this->department = new object_property($this->table, $this->id, 'department', 'int', false);
|
||||
$this->lane = new object_property($this->table, $this->id, 'lane', 'int', false);
|
||||
$this->customer_id = new object_property($this->table, $this->id, 'customer_id', 'int', false);
|
||||
$this->reg = new object_property($this->table, $this->id, 'reg', 'string', false);
|
||||
$this->question = new object_property($this->table, $this->id, 'question', 'int', false);
|
||||
$this->value = new object_property($this->table, $this->id, 'value', 'bool', 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);
|
||||
}
|
||||
|
||||
public function objectChanged(): void
|
||||
{
|
||||
//TODO: Add cache invalidation
|
||||
}
|
||||
|
||||
public function asArray(): array
|
||||
{
|
||||
return [
|
||||
'id' => (int)$this->id,
|
||||
'department' => (int)$this->department->value(),
|
||||
'lane' => (int)$this->lane->value(),
|
||||
'customer_id' => (int)$this->customer_id->value(),
|
||||
'reg' => (string)$this->reg->value(),
|
||||
'question' => (int)$this->question->value(),
|
||||
'value' => (bool)$this->value->value(),
|
||||
'created_at' => (string)$this->created_at->value(),
|
||||
'updated_at' => (string)$this->updated_at->value(),
|
||||
'deleted_at' => (string)$this->deleted_at->value(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user