Add department_selfserve_conditions_o and department_selfserve_condition_rules_o for managing self-serve conditions and rules

This commit is contained in:
Jeppe Bundgaard
2026-01-09 12:34:14 +01:00
parent e4c4c9c76d
commit b4eda9ed9c
2 changed files with 197 additions and 0 deletions
@@ -0,0 +1,101 @@
<?php
namespace objects;
use classes\db;
use classes\object_property;
use Exception;
use traits\db_object_t;
class department_selfserve_condition_rules_o extends db
{
use db_object_t;
public object_property $condition_id; // The condition object id
public object_property $type; // The condition type (e.g., true/false, equals, greater than, etc.)
public object_property $object_type; // The object type to which the condition applies (e.g., question, task, etc.)
public object_property $object_id; // The object id to which the condition applies
public object_property $name; // The condition name
public object_property $description; // The task description
public object_property $created_at;
public object_property $updated_at;
public object_property $deleted_at;
public function structure(): void
{
$this->setTable('department_selfserve_condition_rules');
}
/**
* Add a condition rule
* @param int $condition_id The condition object id
* @param string $type The condition type (e.g., IS_TRUE, IS_FALSE)
* @param string $object_type The object type to which the condition applies (e.g., question, task, etc.)
* @param int $object_id The object id to which the condition applies
* @param string $name The condition name
* @param string $description The condition description
* @return department_selfserve_condition_rules_o
* @throws Exception If the object was not created successfully
*/
public function add(int $condition_id, string $type, string $object_type, int $object_id, string $name, string $description): department_selfserve_condition_rules_o
{
global /** @var db $db */
$db;
// Sanitize the input
$condition_id = (int)$condition_id;
$type = $db->escape_string($type);
$object_type = $db->escape_string($object_type);
$object_id = (int)$object_id;
$name = $db->escape_string($name);
$description = $db->escape_string($description);
// Add the object
$tmp_id = self::add_object([
'condition_id' => $condition_id,
'type' => $type,
'object_type' => $object_type,
'object_id' => $object_id,
'name' => $name,
'description' => $description,
]);
$this->id = $tmp_id;
self::getObjectProperties();
self::objectChanged();
return $this;
}
public function getObjectProperties(): void
{
$this->condition_id = new object_property($this->table, $this->id, 'condition_id', 'int', false);
$this->type = new object_property($this->table, $this->id, 'type', 'string', false);
$this->object_type = new object_property($this->table, $this->id, 'object_type', 'string', false);
$this->object_id = new object_property($this->table, $this->id, 'object_id', 'int', false);
$this->name = new object_property($this->table, $this->id, 'name', 'string', false);
$this->description = new object_property($this->table, $this->id, 'description', '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);
}
public function objectChanged(): void
{
//TODO: Add cache invalidation
}
public function asArray(): array
{
return [
'condition_id' => (int)$this->condition_id->value(),
'type' => (string)$this->type->value(),
'object_type' => (string)$this->object_type->value(),
'object_id' => (int)$this->object_id->value(),
'name' => (string)$this->name->value(),
'description' => (string)$this->description->value(),
// Timestamps
'created_at' => (string)$this->created_at->value(),
'updated_at' => (string)$this->updated_at->value(),
];
}
}
@@ -0,0 +1,96 @@
<?php
namespace objects;
use classes\db;
use classes\object_property;
use Exception;
use traits\db_object_t;
class department_selfserve_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 $product; // The product id
public object_property $name; // The condition name
public object_property $description; // The task description
public object_property $created_at;
public object_property $updated_at;
public object_property $deleted_at;
public function structure(): void
{
$this->setTable('department_selfserve_conditions');
}
/**
* Add a condition
* @param int $department The department id
* @param int $lane The lane id
* @param int $product The product id
* @param string $name The condition name
* @param string $description The condition description
* @return department_selfserve_conditions_o
* @throws Exception If the object was not created successfully
*/
public function add(int $department, int $lane, int $product, string $name, string $description): department_selfserve_conditions_o
{
global /** @var db $db */
$db;
// Sanitize the input
$department = (int)$department;
$lane = (int)$lane;
$product = (int)$product;
$name = $db->escape_string($name);
$description = $db->escape_string($description);
// Add the object
$tmp_id = self::add_object([
'department' => $department,
'lane' => $lane,
'product' => $product,
'name' => $name,
'description' => $description,
]);
$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->name = new object_property($this->table, $this->id, 'name', 'string', false);
$this->description = new object_property($this->table, $this->id, 'description', '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);
}
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(),
'name' => (string)$this->name->value(),
'description' => (string)$this->description->value(),
// Timestamps
'created_at' => (string)$this->created_at->value(),
'updated_at' => (string)$this->updated_at->value(),
];
}
}