Updated Warehouse

This commit is contained in:
Luca Haid
2025-02-04 19:06:08 +01:00
parent 514d5d5d7e
commit 7c8af7aed4
24 changed files with 1126 additions and 99 deletions

View File

@@ -81,17 +81,13 @@ class TTCrudBaseModel {
}
public static function get($id, $die= false): TTCrudBaseModel {
public static function get($id): TTCrudBaseModel {
$FronkDB = FronkDB::singleton();
$db = $FronkDB->link;
$id = $db->real_escape_string($id);
$table = self::getTable();
$sql = "SELECT * FROM `$table` WHERE `id` = $id";
if($die) {
die($sql);
}
$result = $db->query($sql);
// as TTCRudBaseModel is abstract, we need to get the class name of the child class
$class = get_called_class();
@@ -109,16 +105,16 @@ class TTCrudBaseModel {
return $result->fetch_assoc()['count'];
}
public static function getSQLFilter($filter): string {
if (empty($filter)) {
return "";
}
public static function getSQLFilter(array $filter): string {
if (empty($filter)) return '';
$sql = 'WHERE 1=1';
$calledClass = get_called_class();
$sql = "WHERE 1=1";
foreach ($filter as $key => $value) {
if (!property_exists(get_called_class(), $key)) {
http_response_code(500);
throw new Exception("Field $key does not exist in " . get_called_class());
foreach (explode('|', $key) as $column) {
if (!property_exists($calledClass, $column)) {
throw new InvalidArgumentException("Field $column does not exist in $calledClass");
}
}
$sql .= Helper::generateFilterCondition($value, $key, gettype($value) === "integer");
}