Add department_selfserve_tasks_o object for managing department self-serve tasks
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace objects;
|
||||
|
||||
use classes\db;
|
||||
use classes\object_property;
|
||||
use Exception;
|
||||
use traits\db_object_t;
|
||||
|
||||
class department_selfserve_tasks_o extends db
|
||||
{
|
||||
use db_object_t;
|
||||
|
||||
public object_property $department; // The department id
|
||||
public object_property $lane; // The lane id
|
||||
public object_property $product; // The product id
|
||||
public object_property $question; // The question id (if conditional task)
|
||||
public object_property $task; // The task
|
||||
public object_property $description; // The task description
|
||||
public object_property $order_priority; // The order priority of the question (lower numbers are shown first)
|
||||
public object_property $created_at;
|
||||
public object_property $updated_at;
|
||||
public object_property $deleted_at;
|
||||
|
||||
|
||||
public function structure(): void
|
||||
{
|
||||
$this->setTable('department_selfserve_tasks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a task
|
||||
* @param int $department The department id
|
||||
* @param int $lane The lane id
|
||||
* @param int $product The product id
|
||||
* @param int|null $question The question id (if conditional task)
|
||||
* @param string $task The task text
|
||||
* @param string $description The task description
|
||||
* @param int $order_priority The order priority of the task (lower numbers are shown first)
|
||||
* @return department_selfserve_tasks_o
|
||||
* @throws Exception If the object was not created successfully
|
||||
*/
|
||||
public function add(int $department, int $lane, int $product, int|null $question, string $task, string $description, int $order_priority = 0): department_selfserve_tasks_o
|
||||
{
|
||||
global /** @var db $db */
|
||||
$db;
|
||||
// Sanitize the input
|
||||
$department = (int)$department;
|
||||
$lane = (int)$lane;
|
||||
$product = (int)$product;
|
||||
if (!is_null($question)) {
|
||||
$question = (int)$question;
|
||||
}
|
||||
$task = $db->escape_string($task);
|
||||
$description = $db->escape_string($description);
|
||||
$order_priority = (int)$order_priority;
|
||||
// Add the object
|
||||
$tmp_id = self::add_object([
|
||||
'department' => $department,
|
||||
'lane' => $lane,
|
||||
'product' => $product,
|
||||
...(!is_null($question) ? ['question' => $question] : []), // If the question is null, it will be set to null in the database
|
||||
'task' => $task,
|
||||
'description' => $description,
|
||||
'order_priority' => $order_priority,
|
||||
]);
|
||||
$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->product = new object_property($this->table, $this->id, 'product', 'int', false);
|
||||
$this->question = new object_property($this->table, $this->id, 'question', 'int', true);
|
||||
$this->task = new object_property($this->table, $this->id, 'task', 'string', false);
|
||||
$this->description = new object_property($this->table, $this->id, 'description', 'string', false);
|
||||
$this->order_priority = new object_property($this->table, $this->id, 'order_priority', 'int', 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(),
|
||||
'product' => (int)$this->product->value(),
|
||||
'question' => is_null($this->question->value()) ? null : (int)$this->question->value(),
|
||||
'task' => (string)$this->task->value(),
|
||||
'description' => (string)$this->description->value(),
|
||||
'order_priority' => (int)$this->order_priority->value(),
|
||||
// Timestamps
|
||||
'created_at' => (string)$this->created_at->value(),
|
||||
'updated_at' => (string)$this->updated_at->value(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user