mirror of
https://github.com/Karaka-Management/oms-FleetManagement.git
synced 2026-02-07 17:08:40 +00:00
Quick backup before crash
This commit is contained in:
parent
f3ff7eec1f
commit
364626bf85
|
|
@ -156,7 +156,7 @@
|
|||
"pid": "/",
|
||||
"type": 2,
|
||||
"subtype": 1,
|
||||
"name": "Attributes",
|
||||
"name": "VehicleAttributes",
|
||||
"uri": "{/base}/fleet/vehicle/attribute/type/list?{?}",
|
||||
"target": "self",
|
||||
"icon": null,
|
||||
|
|
@ -196,6 +196,52 @@
|
|||
"children": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 1003506001,
|
||||
"pid": "/",
|
||||
"type": 2,
|
||||
"subtype": 1,
|
||||
"name": "DriverAttributes",
|
||||
"uri": "{/base}/fleet/driver/attribute/type/list?{?}",
|
||||
"target": "self",
|
||||
"icon": null,
|
||||
"order": 5,
|
||||
"from": "FleetManagement",
|
||||
"permission": { "permission": 2, "category": null, "element": null },
|
||||
"parent": 1003501001,
|
||||
"children": [
|
||||
{
|
||||
"id": 1003506101,
|
||||
"pid": "/fleet/driver/attribute",
|
||||
"type": 3,
|
||||
"subtype": 1,
|
||||
"name": "Types",
|
||||
"uri": "{/base}/fleet/driver/attribute/type/list?{?}",
|
||||
"target": "self",
|
||||
"icon": null,
|
||||
"order": 15,
|
||||
"from": "FleetManagement",
|
||||
"permission": { "permission": 2, "category": null, "element": null },
|
||||
"parent": 1003506001,
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"id": 1003506201,
|
||||
"pid": "/fleet/driver/attribute",
|
||||
"type": 3,
|
||||
"subtype": 1,
|
||||
"name": "Values",
|
||||
"uri": "{/base}/fleet/driver/attribute/value/list?{?}",
|
||||
"target": "self",
|
||||
"icon": null,
|
||||
"order": 15,
|
||||
"from": "FleetManagement",
|
||||
"permission": { "permission": 2, "category": null, "element": null },
|
||||
"parent": 1003506001,
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -243,6 +243,119 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_inspection_type": {
|
||||
"name": "fleetmgmt_driver_inspection_type",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_inspection_type_id": {
|
||||
"name": "fleetmgmt_driver_inspection_type_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_inspection_type_name": {
|
||||
"name": "fleetmgmt_driver_inspection_type_name",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_inspection_type_l11n": {
|
||||
"name": "fleetmgmt_driver_inspection_type_l11n",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_inspection_type_l11n_id": {
|
||||
"name": "fleetmgmt_driver_inspection_type_l11n_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_inspection_type_l11n_title": {
|
||||
"name": "fleetmgmt_driver_inspection_type_l11n_title",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_inspection_type_l11n_type": {
|
||||
"name": "fleetmgmt_driver_inspection_type_l11n_type",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_driver_inspection_type",
|
||||
"foreignKey": "fleetmgmt_driver_inspection_type_id"
|
||||
},
|
||||
"fleetmgmt_driver_inspection_type_l11n_lang": {
|
||||
"name": "fleetmgmt_driver_inspection_type_l11n_lang",
|
||||
"type": "VARCHAR(2)",
|
||||
"null": false,
|
||||
"foreignTable": "language",
|
||||
"foreignKey": "language_639_1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver": {
|
||||
"name": "fleetmgmt_driver",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_id": {
|
||||
"name": "fleetmgmt_driver_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_status": {
|
||||
"name": "fleetmgmt_driver_status",
|
||||
"type": "TINYINT(1)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_account": {
|
||||
"name": "fleetmgmt_driver_account",
|
||||
"type": "INT",
|
||||
"null": true,
|
||||
"default": true,
|
||||
"foreignTable": "account",
|
||||
"foreignKey": "account_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_inspection": {
|
||||
"name": "fleetmgmt_driver_inspection",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_inspection_id": {
|
||||
"name": "fleetmgmt_driver_inspection_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_inspection_description": {
|
||||
"name": "fleetmgmt_driver_inspection_description",
|
||||
"type": "TEXT",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_inspection_status": {
|
||||
"name": "fleetmgmt_driver_inspection_status",
|
||||
"type": "TINYINT(1)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_inspection_interval": {
|
||||
"name": "fleetmgmt_driver_inspection_interval",
|
||||
"type": "TINYINT(3)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_inspection_next": {
|
||||
"name": "fleetmgmt_driver_inspection_next",
|
||||
"type": "DATETIME",
|
||||
"null": true,
|
||||
"default": null
|
||||
},
|
||||
"fleetmgmt_driver_inspection_type": {
|
||||
"name": "fleetmgmt_driver_inspection_type",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_driver_inspection_type",
|
||||
"foreignKey": "fleetmgmt_driver_inspection_type_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_vehicle_usage": {
|
||||
"name": "fleetmgmt_vehicle_usage",
|
||||
"fields": {
|
||||
|
|
@ -563,5 +676,286 @@
|
|||
"foreignKey": "editor_doc_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_attr_type": {
|
||||
"name": "fleetmgmt_driver_attr_type",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_attr_type_id": {
|
||||
"name": "fleetmgmt_driver_attr_type_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_name": {
|
||||
"name": "fleetmgmt_driver_attr_type_name",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false,
|
||||
"unique": true
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_datatype": {
|
||||
"name": "fleetmgmt_driver_attr_type_datatype",
|
||||
"type": "INT(11)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_fields": {
|
||||
"name": "fleetmgmt_driver_attr_type_fields",
|
||||
"type": "INT(11)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_custom": {
|
||||
"name": "fleetmgmt_driver_attr_type_custom",
|
||||
"type": "TINYINT(1)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_required": {
|
||||
"description": "Every item must have this attribute type if set to true.",
|
||||
"name": "fleetmgmt_driver_attr_type_required",
|
||||
"type": "TINYINT(1)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_pattern": {
|
||||
"description": "This is a regex validation pattern.",
|
||||
"name": "fleetmgmt_driver_attr_type_pattern",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_l11n": {
|
||||
"name": "fleetmgmt_driver_attr_type_l11n",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_attr_type_l11n_id": {
|
||||
"name": "fleetmgmt_driver_attr_type_l11n_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_l11n_title": {
|
||||
"name": "fleetmgmt_driver_attr_type_l11n_title",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_l11n_type": {
|
||||
"name": "fleetmgmt_driver_attr_type_l11n_type",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_driver_attr_type",
|
||||
"foreignKey": "fleetmgmt_driver_attr_type_id"
|
||||
},
|
||||
"fleetmgmt_driver_attr_type_l11n_lang": {
|
||||
"name": "fleetmgmt_driver_attr_type_l11n_lang",
|
||||
"type": "VARCHAR(2)",
|
||||
"null": false,
|
||||
"foreignTable": "language",
|
||||
"foreignKey": "language_639_1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_attr_value": {
|
||||
"name": "fleetmgmt_driver_attr_value",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_attr_value_id": {
|
||||
"name": "fleetmgmt_driver_attr_value_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_default": {
|
||||
"name": "fleetmgmt_driver_attr_value_default",
|
||||
"type": "TINYINT(1)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_valueStr": {
|
||||
"name": "fleetmgmt_driver_attr_value_valueStr",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": true,
|
||||
"default": null
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_valueInt": {
|
||||
"name": "fleetmgmt_driver_attr_value_valueInt",
|
||||
"type": "INT(11)",
|
||||
"null": true,
|
||||
"default": null
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_valueDec": {
|
||||
"name": "fleetmgmt_driver_attr_value_valueDec",
|
||||
"type": "DECIMAL(19,5)",
|
||||
"null": true,
|
||||
"default": null
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_valueDat": {
|
||||
"name": "fleetmgmt_driver_attr_value_valueDat",
|
||||
"type": "DATETIME",
|
||||
"null": true,
|
||||
"default": null
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_unit": {
|
||||
"name": "fleetmgmt_driver_attr_value_unit",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_deptype": {
|
||||
"name": "fleetmgmt_driver_attr_value_deptype",
|
||||
"type": "INT(11)",
|
||||
"null": true,
|
||||
"default": null,
|
||||
"foreignTable": "fleetmgmt_driver_attr_type",
|
||||
"foreignKey": "fleetmgmt_driver_attr_type_id"
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_depvalue": {
|
||||
"name": "fleetmgmt_driver_attr_value_depvalue",
|
||||
"type": "INT(11)",
|
||||
"null": true,
|
||||
"default": null,
|
||||
"foreignTable": "fleetmgmt_driver_attr_value",
|
||||
"foreignKey": "fleetmgmt_driver_attr_value_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_l11n": {
|
||||
"name": "fleetmgmt_driver_attr_value_l11n",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_attr_value_l11n_id": {
|
||||
"name": "fleetmgmt_driver_attr_value_l11n_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_l11n_title": {
|
||||
"name": "fleetmgmt_driver_attr_value_l11n_title",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_l11n_value": {
|
||||
"name": "fleetmgmt_driver_attr_value_l11n_value",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_driver_attr_value",
|
||||
"foreignKey": "fleetmgmt_driver_attr_value_id"
|
||||
},
|
||||
"fleetmgmt_driver_attr_value_l11n_lang": {
|
||||
"name": "fleetmgmt_driver_attr_value_l11n_lang",
|
||||
"type": "VARCHAR(2)",
|
||||
"null": false,
|
||||
"foreignTable": "language",
|
||||
"foreignKey": "language_639_1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_attr_default": {
|
||||
"name": "fleetmgmt_driver_attr_default",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_attr_default_id": {
|
||||
"name": "fleetmgmt_driver_attr_default_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_attr_default_type": {
|
||||
"name": "fleetmgmt_driver_attr_default_type",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_attr_type",
|
||||
"foreignKey": "fleetmgmt_attr_type_id"
|
||||
},
|
||||
"fleetmgmt_driver_attr_default_value": {
|
||||
"name": "fleetmgmt_driver_attr_default_value",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_attr_value",
|
||||
"foreignKey": "fleetmgmt_attr_value_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_attr": {
|
||||
"name": "fleetmgmt_driver_attr",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_attr_id": {
|
||||
"name": "fleetmgmt_driver_attr_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_attr_item": {
|
||||
"name": "fleetmgmt_driver_attr_item",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_driver",
|
||||
"foreignKey": "fleetmgmt_driver_id"
|
||||
},
|
||||
"fleetmgmt_driver_attr_type": {
|
||||
"name": "fleetmgmt_driver_attr_type",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_attr_type",
|
||||
"foreignKey": "fleetmgmt_attr_type_id"
|
||||
},
|
||||
"fleetmgmt_driver_attr_value": {
|
||||
"name": "fleetmgmt_driver_attr_value",
|
||||
"type": "INT(11)",
|
||||
"null": true,
|
||||
"default": null,
|
||||
"foreignTable": "fleetmgmt_attr_value",
|
||||
"foreignKey": "fleetmgmt_attr_value_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_media": {
|
||||
"name": "fleetmgmt_driver_media",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_media_id": {
|
||||
"name": "fleetmgmt_driver_media_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_media_vehicle": {
|
||||
"name": "fleetmgmt_driver_media_vehicle",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_driver",
|
||||
"foreignKey": "fleetmgmt_driver_id"
|
||||
},
|
||||
"fleetmgmt_driver_media_media": {
|
||||
"name": "fleetmgmt_driver_media_media",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "media",
|
||||
"foreignKey": "media_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"fleetmgmt_driver_note": {
|
||||
"name": "fleetmgmt_driver_note",
|
||||
"fields": {
|
||||
"fleetmgmt_driver_note_id": {
|
||||
"name": "fleetmgmt_driver_note_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"fleetmgmt_driver_note_driver": {
|
||||
"name": "fleetmgmt_driver_note_driver",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "fleetmgmt_driver",
|
||||
"foreignKey": "fleetmgmt_driver_id"
|
||||
},
|
||||
"fleetmgmt_driver_note_doc": {
|
||||
"name": "fleetmgmt_driver_note_doc",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "editor_doc",
|
||||
"foreignKey": "editor_doc_id"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -68,7 +68,7 @@ final class Installer extends InstallerAbstract
|
|||
$types = \json_decode($fileContent, true);
|
||||
$fuelTypes = self::createFuelTypes($app, $types);
|
||||
|
||||
/* Fuel types */
|
||||
/* Vehicle types */
|
||||
$fileContent = \file_get_contents(__DIR__ . '/Install/vehicletype.json');
|
||||
if ($fileContent === false) {
|
||||
return;
|
||||
|
|
@ -77,15 +77,25 @@ final class Installer extends InstallerAbstract
|
|||
/** @var array $types */
|
||||
$types = \json_decode($fileContent, true);
|
||||
$vehicleTypes = self::createVehicleTypes($app, $types);
|
||||
|
||||
/* Inspection types */
|
||||
$fileContent = \file_get_contents(__DIR__ . '/Install/inspectiontype.json');
|
||||
if ($fileContent === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var array $types */
|
||||
$types = \json_decode($fileContent, true);
|
||||
$inspectionTypes = self::createInspectionTypes($app, $types);
|
||||
}
|
||||
|
||||
/**
|
||||
* Install fuel type
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array<array{name:string, l11n?:array<string, string>, is_required?:bool, is_custom_allowed?:bool, validation_pattern?:string, value_type?:string, values?:array<string, mixed>}> $attributes Attribute definition
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array $types Attribute definition
|
||||
*
|
||||
* @return array<string, array>
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
@ -94,8 +104,8 @@ final class Installer extends InstallerAbstract
|
|||
/** @var array<string, array> $fuelTypes */
|
||||
$fuelTypes = [];
|
||||
|
||||
/** @var \Modules\FleetManagement\Controller\ApiController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement');
|
||||
/** @var \Modules\FleetManagement\Controller\ApiVehicleController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement', 'ApiVehicle');
|
||||
|
||||
/** @var array $type */
|
||||
foreach ($types as $type) {
|
||||
|
|
@ -141,22 +151,22 @@ final class Installer extends InstallerAbstract
|
|||
}
|
||||
|
||||
/**
|
||||
* Install fuel type
|
||||
* Install vehicle type
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array<array{name:string, l11n?:array<string, string>, is_required?:bool, is_custom_allowed?:bool, validation_pattern?:string, value_type?:string, values?:array<string, mixed>}> $attributes Attribute definition
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array $types Attribute definition
|
||||
*
|
||||
* @return array<string, array>
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createVehicleTypes(ApplicationAbstract $app, array $types) : array
|
||||
{
|
||||
/** @var array<string, array> $fuelTypes */
|
||||
/** @var array<string, array> $vehicleTypes */
|
||||
$vehicleTypes = [];
|
||||
|
||||
/** @var \Modules\FleetManagement\Controller\ApiController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement');
|
||||
/** @var \Modules\FleetManagement\Controller\ApiVehicleController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement', 'ApiVehicle');
|
||||
|
||||
/** @var array $type */
|
||||
foreach ($types as $type) {
|
||||
|
|
@ -201,13 +211,74 @@ final class Installer extends InstallerAbstract
|
|||
return $vehicleTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install inspection type
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array $types Attribute definition
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function createInspectionTypes(ApplicationAbstract $app, array $types) : array
|
||||
{
|
||||
/** @var array<string, array> $inspectionTypes */
|
||||
$inspectionTypes = [];
|
||||
|
||||
/** @var \Modules\FleetManagement\Controller\ApiVehicleController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement', 'ApiVehicle');
|
||||
|
||||
/** @var array $type */
|
||||
foreach ($types as $type) {
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('name', $type['name'] ?? '');
|
||||
$request->setData('title', \reset($type['l11n']));
|
||||
$request->setData('language', \array_keys($type['l11n'])[0] ?? 'en');
|
||||
|
||||
$module->apiInspectionTypeCreate($request, $response);
|
||||
|
||||
$responseData = $response->get('');
|
||||
if (!\is_array($responseData)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$inspectionTypes[$type['name']] = !\is_array($responseData['response'])
|
||||
? $responseData['response']->toArray()
|
||||
: $responseData['response'];
|
||||
|
||||
$isFirst = true;
|
||||
foreach ($type['l11n'] as $language => $l11n) {
|
||||
if ($isFirst) {
|
||||
$isFirst = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', $l11n);
|
||||
$request->setData('language', $language);
|
||||
$request->setData('type', $inspectionTypes[$type['name']]['id']);
|
||||
|
||||
$module->apiInspectionTypeL11nCreate($request, $response);
|
||||
}
|
||||
}
|
||||
|
||||
return $inspectionTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install default attribute types
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array<array{name:string, l11n?:array<string, string>, is_required?:bool, is_custom_allowed?:bool, validation_pattern?:string, value_type?:string, values?:array<string, mixed>}> $attributes Attribute definition
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array $attributes Attribute definition
|
||||
*
|
||||
* @return array<string, array>
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
@ -216,8 +287,8 @@ final class Installer extends InstallerAbstract
|
|||
/** @var array<string, array> $itemAttrType */
|
||||
$itemAttrType = [];
|
||||
|
||||
/** @var \Modules\FleetManagement\Controller\ApiController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement');
|
||||
/** @var \Modules\FleetManagement\Controller\ApiVehicleAttributeController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement', 'ApiVehicleAttribute');
|
||||
|
||||
/** @var array $attribute */
|
||||
foreach ($attributes as $attribute) {
|
||||
|
|
@ -273,7 +344,7 @@ final class Installer extends InstallerAbstract
|
|||
* @param array $itemAttrType Attribute types
|
||||
* @param array<array{name:string, l11n?:array<string, string>, is_required?:bool, is_custom_allowed?:bool, validation_pattern?:string, value_type?:string, values?:array<string, mixed>}> $attributes Attribute definition
|
||||
*
|
||||
* @return array<string, array>
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
|
@ -282,8 +353,8 @@ final class Installer extends InstallerAbstract
|
|||
/** @var array<string, array> $itemAttrValue */
|
||||
$itemAttrValue = [];
|
||||
|
||||
/** @var \Modules\FleetManagement\Controller\ApiController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement');
|
||||
/** @var \Modules\FleetManagement\Controller\ApiVehicleAttributeController $module */
|
||||
$module = $app->moduleManager->getModuleInstance('FleetManagement', 'ApiVehicleAttribute');
|
||||
|
||||
foreach ($attributes as $attribute) {
|
||||
$itemAttrValue[$attribute['name']] = [];
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
use Modules\FleetManagement\Controller\ApiController;
|
||||
use Modules\FleetManagement\Controller\Controller;
|
||||
use Modules\FleetManagement\Models\PermissionCategory;
|
||||
use phpOMS\Account\PermissionType;
|
||||
use phpOMS\Router\RouteVerb;
|
||||
|
|
@ -20,30 +20,52 @@ use phpOMS\Router\RouteVerb;
|
|||
return [
|
||||
'^.*/fleet/vehicle/find.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\FleetManagement\Controller\ApiController:apiVehicleFind',
|
||||
'dest' => '\Modules\FleetManagement\Controller\ApiVehicleController:apiVehicleFind',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => ApiController::NAME,
|
||||
'module' => Controller::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::VEHICLE,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'^.*/fleet/vehicle/attribute.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\FleetManagement\Controller\ApiController:apiVehicleAttributeCreate',
|
||||
'dest' => '\Modules\FleetManagement\Controller\ApiVehicleAttributeController:apiVehicleAttributeCreate',
|
||||
'verb' => RouteVerb::PUT,
|
||||
'permission' => [
|
||||
'module' => ApiController::NAME,
|
||||
'module' => Controller::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::VEHICLE,
|
||||
],
|
||||
],
|
||||
[
|
||||
'dest' => '\Modules\FleetManagement\Controller\ApiController:apiVehicleAttributeUpdate',
|
||||
'dest' => '\Modules\FleetManagement\Controller\ApiVehicleAttributeController:apiVehicleAttributeUpdate',
|
||||
'verb' => RouteVerb::SET,
|
||||
'permission' => [
|
||||
'module' => ApiController::NAME,
|
||||
'module' => Controller::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::VEHICLE,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'^.*/fleet/driver/attribute.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\FleetManagement\Controller\ApiDriverAttributeController:apiDriverAttributeCreate',
|
||||
'verb' => RouteVerb::PUT,
|
||||
'permission' => [
|
||||
'module' => Controller::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::VEHICLE,
|
||||
],
|
||||
],
|
||||
[
|
||||
'dest' => '\Modules\FleetManagement\Controller\ApiDriverAttributeController:apiDriverAttributeUpdate',
|
||||
'verb' => RouteVerb::SET,
|
||||
'permission' => [
|
||||
'module' => Controller::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::VEHICLE,
|
||||
],
|
||||
|
|
|
|||
|
|
@ -75,6 +75,29 @@ return [
|
|||
],
|
||||
],
|
||||
|
||||
'^.*/fleet/driver/attribute/type/list.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\FleetManagement\Controller\BackendController:viewFleetManagementDriverAttributeTypeList',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => BackendController::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::VEHICLE,
|
||||
],
|
||||
],
|
||||
],
|
||||
'^.*/fleet/driver/attribute/type\?.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\FleetManagement\Controller\BackendController:viewFleetManagementDriverAttributeType',
|
||||
'verb' => RouteVerb::GET,
|
||||
'permission' => [
|
||||
'module' => BackendController::NAME,
|
||||
'type' => PermissionType::READ,
|
||||
'state' => PermissionCategory::VEHICLE,
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
'^.*/fleet/driver/list.*$' => [
|
||||
[
|
||||
'dest' => '\Modules\FleetManagement\Controller\BackendController:viewFleetManagementDriverList',
|
||||
|
|
|
|||
534
Controller/ApiDriverAttributeController.php
Normal file
534
Controller/ApiDriverAttributeController.php
Normal file
|
|
@ -0,0 +1,534 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Controller;
|
||||
|
||||
use Modules\Attribute\Models\Attribute;
|
||||
use Modules\Attribute\Models\AttributeType;
|
||||
use Modules\Attribute\Models\AttributeValue;
|
||||
use Modules\Attribute\Models\NullAttributeType;
|
||||
use Modules\Attribute\Models\NullAttributeValue;
|
||||
use Modules\FleetManagement\Models\Driver\DriverAttributeMapper;
|
||||
use Modules\FleetManagement\Models\Driver\DriverAttributeTypeL11nMapper;
|
||||
use Modules\FleetManagement\Models\Driver\DriverAttributeTypeMapper;
|
||||
use Modules\FleetManagement\Models\Driver\DriverAttributeValueL11nMapper;
|
||||
use Modules\FleetManagement\Models\Driver\DriverAttributeValueMapper;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\Message\NotificationLevel;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Message\FormValidation;
|
||||
|
||||
/**
|
||||
* FleetManagement class.
|
||||
*
|
||||
* @package Modules\FleetManagement
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class ApiDriverAttributeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Api method to create driver attribute
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverAttributeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverAttributeCreate($request))) {
|
||||
$response->data['attribute_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attribute = $this->createDriverAttributeFromRequest($request);
|
||||
$this->createModel($request->header->account, $attribute, DriverAttributeMapper::class, 'attribute', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully created', $attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return Attribute
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createDriverAttributeFromRequest(RequestAbstract $request) : Attribute
|
||||
{
|
||||
$attribute = new Attribute();
|
||||
$attribute->ref = (int) $request->getData('driver');
|
||||
$attribute->type = new NullAttributeType((int) $request->getData('type'));
|
||||
|
||||
if ($request->hasData('value')) {
|
||||
$attribute->value = new NullAttributeValue((int) $request->getData('value'));
|
||||
} else {
|
||||
$newRequest = clone $request;
|
||||
$newRequest->setData('value', $request->getData('custom'), true);
|
||||
|
||||
$value = $this->createAttributeValueFromRequest($newRequest);
|
||||
|
||||
$attribute->value = $value;
|
||||
}
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverAttributeCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['type'] = !$request->hasData('type'))
|
||||
|| ($val['value'] = (!$request->hasData('value') && !$request->hasData('custom')))
|
||||
|| ($val['driver'] = !$request->hasData('driver'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create driver attribute
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverAttributeUpdate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverAttributeUpdate($request))) {
|
||||
$response->data['attribute_update'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$old = DriverAttributeMapper::get()
|
||||
->with('type')
|
||||
->with('type/defaults')
|
||||
->with('value')
|
||||
->where('id', (int) $request->getData('id'))
|
||||
->execute();
|
||||
|
||||
$new = $this->updateDriverAttributeFromRequest($request, $old->deepClone());
|
||||
$this->updateModel($request->header->account, $old, $new, DriverAttributeMapper::class, 'attribute', $request->getOrigin());
|
||||
|
||||
if ($new->value->getValue() !== $old->value->getValue()) {
|
||||
$this->updateModel($request->header->account, $old->value, $new->value, DriverAttributeValueMapper::class, 'attribute_value', $request->getOrigin());
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully updated', $new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return Attribute
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function updateDriverAttributeFromRequest(RequestAbstract $request, Attribute $attribute) : Attribute
|
||||
{
|
||||
if ($attribute->type->custom) {
|
||||
if ($request->hasData('value')) {
|
||||
// @question: we are overwriting the old value, could there be a use case where we want to create a new value and keep the old one?
|
||||
$attribute->value->setValue($request->getData('value'), $attribute->type->datatype);
|
||||
}
|
||||
} else {
|
||||
if ($request->hasData('value')) {
|
||||
// @todo: fix by only accepting the value id to be used
|
||||
// this is a workaround for now because the front end doesn't allow to dynamically show default values.
|
||||
$value = $attribute->type->getDefaultByValue($request->getData('value'));
|
||||
|
||||
if ($value->id !== 0) {
|
||||
$attribute->value = $attribute->type->getDefaultByValue($request->getData('value'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverAttributeUpdate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['id'] = !$request->hasData('id'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create driver attribute l11n
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverAttributeTypeL11nCreate($request))) {
|
||||
$response->data['attr_type_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createDriverAttributeTypeL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, DriverAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver attribute l11n from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return BaseStringL11n
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createDriverAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = $request->getDataInt('type') ?? 0;
|
||||
$attrL11n->setLanguage(
|
||||
$request->getDataString('language') ?? $request->header->l11n->language
|
||||
);
|
||||
$attrL11n->content = $request->getDataString('title') ?? '';
|
||||
|
||||
return $attrL11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver attribute l11n create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverAttributeTypeL11nCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['type'] = !$request->hasData('type'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create driver attribute type
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverAttributeTypeCreate($request))) {
|
||||
$response->data['attr_type_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrType = $this->createAttributeTypeFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrType, DriverAttributeTypeMapper::class, 'attr_type', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return AttributeType
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeTypeFromRequest(RequestAbstract $request) : AttributeType
|
||||
{
|
||||
$attrType = new AttributeType($request->getDataString('name') ?? '');
|
||||
$attrType->datatype = $request->getDataInt('datatype') ?? 0;
|
||||
$attrType->custom = $request->getDataBool('custom') ?? false;
|
||||
$attrType->isRequired = (bool) ($request->getData('is_required') ?? false);
|
||||
$attrType->validationPattern = $request->getDataString('validation_pattern') ?? '';
|
||||
$attrType->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
|
||||
$attrType->setFields($request->getDataInt('fields') ?? 0);
|
||||
|
||||
return $attrType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverAttributeTypeCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['name'] = !$request->hasData('name'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create driver attribute value
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverAttributeValueCreate($request))) {
|
||||
$response->data['attr_value_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrValue = $this->createAttributeValueFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrValue, DriverAttributeValueMapper::class, 'attr_value', $request->getOrigin());
|
||||
|
||||
if ($attrValue->isDefault) {
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
(int) $request->getData('type'),
|
||||
$attrValue->id,
|
||||
DriverAttributeTypeMapper::class, 'defaults', '', $request->getOrigin()
|
||||
);
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute value', 'Attribute value successfully created', $attrValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver attribute value from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return AttributeValue
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeValueFromRequest(RequestAbstract $request) : AttributeValue
|
||||
{
|
||||
/** @var AttributeType $type */
|
||||
$type = DriverAttributeTypeMapper::get()
|
||||
->where('id', $request->getDataInt('type') ?? 0)
|
||||
->execute();
|
||||
|
||||
$attrValue = new AttributeValue();
|
||||
$attrValue->isDefault = $request->getDataBool('default') ?? false;
|
||||
$attrValue->setValue($request->getData('value'), $type->datatype);
|
||||
|
||||
if ($request->hasData('title')) {
|
||||
$attrValue->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
|
||||
}
|
||||
|
||||
return $attrValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver attribute value create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverAttributeValueCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['type'] = !$request->hasData('type'))
|
||||
|| ($val['value'] = !$request->hasData('value'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create driver attribute l11n
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverAttributeValueL11nCreate($request))) {
|
||||
$response->data['attr_value_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createAttributeValueL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, DriverAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver attribute l11n from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return BaseStringL11n
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = $request->getDataInt('value') ?? 0;
|
||||
$attrL11n->setLanguage(
|
||||
$request->getDataString('language') ?? $request->header->l11n->language
|
||||
);
|
||||
$attrL11n->content = $request->getDataString('title') ?? '';
|
||||
|
||||
return $attrL11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver attribute l11n create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverAttributeValueL11nCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['value'] = !$request->hasData('value'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to handle api driver attributes
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverAttribute(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverAttributeValueL11nCreate($request))) {
|
||||
$response->data['attr_value_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createAttributeValueL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, DriverAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
}
|
||||
588
Controller/ApiDriverController.php
Normal file
588
Controller/ApiDriverController.php
Normal file
|
|
@ -0,0 +1,588 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Controller;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\FleetManagement\Models\Driver\DriverInspectionTypeL11nMapper;
|
||||
use Modules\FleetManagement\Models\Driver\DriverInspectionTypeMapper;
|
||||
use Modules\FleetManagement\Models\Driver\Driver;
|
||||
use Modules\FleetManagement\Models\Driver\DriverMapper;
|
||||
use Modules\FleetManagement\Models\Driver\DriverStatus;
|
||||
use Modules\Media\Models\CollectionMapper;
|
||||
use Modules\Media\Models\MediaMapper;
|
||||
use Modules\Media\Models\NullMedia;
|
||||
use Modules\Media\Models\PathSettings;
|
||||
use Modules\Media\Models\Reference;
|
||||
use Modules\Media\Models\ReferenceMapper;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\BaseStringL11nType;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\Message\NotificationLevel;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Message\FormValidation;
|
||||
|
||||
/**
|
||||
* FleetManagement class.
|
||||
*
|
||||
* @package Modules\FleetManagement
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class ApiDriverController extends Controller
|
||||
{
|
||||
/**
|
||||
* Api method to create a driver
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverCreate($request))) {
|
||||
$response->data[$request->uri->__toString()] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var Driver $driver */
|
||||
$driver = $this->createDriverFromRequest($request);
|
||||
$this->createModel($request->header->account, $driver, DriverMapper::class, 'driver', $request->getOrigin());
|
||||
|
||||
if (!empty($request->files)
|
||||
|| !empty($request->getDataJson('media'))
|
||||
) {
|
||||
$this->createDriverMedia($driver, $request);
|
||||
}
|
||||
|
||||
$this->fillJsonResponse(
|
||||
$request,
|
||||
$response,
|
||||
NotificationLevel::OK,
|
||||
'',
|
||||
$this->app->l11nManager->getText($response->header->l11n->language, '0', '0', 'SucessfulCreate'),
|
||||
$driver
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return Driver Returns the created driver from the request
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function createDriverFromRequest(RequestAbstract $request) : Driver
|
||||
{
|
||||
$driver = new Driver();
|
||||
$driver->account = new NullAccount($request->getDataInt('account') ?? 1);
|
||||
$driver->status = (int) ($request->getDataInt('status') ?? DriverStatus::INACTIVE);
|
||||
|
||||
return $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create media files for driver
|
||||
*
|
||||
* @param Driver $driver Driver
|
||||
* @param RequestAbstract $request Request incl. media do upload
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createDriverMedia(Driver $driver, RequestAbstract $request) : void
|
||||
{
|
||||
$path = $this->createDriverDir($driver);
|
||||
|
||||
if (!empty($uploadedFiles = $request->files)) {
|
||||
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
|
||||
names: [],
|
||||
fileNames: [],
|
||||
files: $uploadedFiles,
|
||||
account: $request->header->account,
|
||||
basePath: __DIR__ . '/../../../Modules/Media/Files' . $path,
|
||||
virtualPath: $path,
|
||||
pathSettings: PathSettings::FILE_PATH
|
||||
);
|
||||
|
||||
$collection = null;
|
||||
foreach ($uploaded as $media) {
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$driver->id,
|
||||
$media->id,
|
||||
DriverMapper::class,
|
||||
'media',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
|
||||
if ($collection === null) {
|
||||
/** @var \Modules\Media\Models\Collection $collection */
|
||||
$collection = MediaMapper::getParentCollection($path)->limit(1)->execute();
|
||||
|
||||
if ($collection->id === 0) {
|
||||
$collection = $this->app->moduleManager->get('Media')->createRecursiveMediaCollection(
|
||||
$path,
|
||||
$request->header->account,
|
||||
__DIR__ . '/../../../Modules/Media/Files' . $path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$collection->id,
|
||||
$media->id,
|
||||
CollectionMapper::class,
|
||||
'sources',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($mediaFiles = $request->getDataJson('media'))) {
|
||||
$collection = null;
|
||||
|
||||
foreach ($mediaFiles as $file) {
|
||||
/** @var \Modules\Media\Models\Media $media */
|
||||
$media = MediaMapper::get()->where('id', (int) $file)->limit(1)->execute();
|
||||
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$driver->id,
|
||||
$media->id,
|
||||
DriverMapper::class,
|
||||
'media',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
|
||||
$ref = new Reference();
|
||||
$ref->name = $media->name;
|
||||
$ref->source = new NullMedia($media->id);
|
||||
$ref->createdBy = new NullAccount($request->header->account);
|
||||
$ref->setVirtualPath($path);
|
||||
|
||||
$this->createModel($request->header->account, $ref, ReferenceMapper::class, 'media_reference', $request->getOrigin());
|
||||
|
||||
if ($collection === null) {
|
||||
/** @var \Modules\Media\Models\Collection $collection */
|
||||
$collection = MediaMapper::getParentCollection($path)->limit(1)->execute();
|
||||
|
||||
if ($collection->id === 0) {
|
||||
$collection = $this->app->moduleManager->get('Media')->createRecursiveMediaCollection(
|
||||
$path,
|
||||
$request->header->account,
|
||||
__DIR__ . '/../../../Modules/Media/Files' . $path
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$collection->id,
|
||||
$ref->id,
|
||||
CollectionMapper::class,
|
||||
'sources',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool> Returns the validation array of the request
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['account'] = !$request->hasData('account'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create a bill
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiMediaAddToDriver(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateMediaAddToDriver($request))) {
|
||||
$response->data[$request->uri->__toString()] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var \Modules\FleetManagement\Models\Driver\Driver $driver */
|
||||
$driver = DriverMapper::get()->where('id', (int) $request->getData('driver'))->execute();
|
||||
$path = $this->createDriverDir($driver);
|
||||
|
||||
$uploaded = [];
|
||||
if (!empty($uploadedFiles = $request->files)) {
|
||||
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
|
||||
names: [],
|
||||
fileNames: [],
|
||||
files: $uploadedFiles,
|
||||
account: $request->header->account,
|
||||
basePath: __DIR__ . '/../../../Modules/Media/Files' . $path,
|
||||
virtualPath: $path,
|
||||
pathSettings: PathSettings::FILE_PATH,
|
||||
hasAccountRelation: false,
|
||||
readContent: (bool) ($request->getData('parse_content') ?? false)
|
||||
);
|
||||
|
||||
$collection = null;
|
||||
foreach ($uploaded as $media) {
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$driver->id,
|
||||
$media->id,
|
||||
DriverMapper::class,
|
||||
'files',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
|
||||
if ($request->hasData('type')) {
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$media->id,
|
||||
$request->getDataInt('type'),
|
||||
MediaMapper::class,
|
||||
'types',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
}
|
||||
|
||||
if ($collection === null) {
|
||||
/** @var \Modules\Media\Models\Collection $collection */
|
||||
$collection = MediaMapper::getParentCollection($path)->limit(1)->execute();
|
||||
|
||||
if ($collection->id === 0) {
|
||||
$collection = $this->app->moduleManager->get('Media')->createRecursiveMediaCollection(
|
||||
$path,
|
||||
$request->header->account,
|
||||
__DIR__ . '/../../../Modules/Media/Files' . $path,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$collection->id,
|
||||
$media->id,
|
||||
CollectionMapper::class,
|
||||
'sources',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($mediaFiles = $request->getDataJson('media'))) {
|
||||
foreach ($mediaFiles as $media) {
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$driver->id,
|
||||
(int) $media,
|
||||
DriverMapper::class,
|
||||
'files',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Media', 'Media added to driver.', [
|
||||
'upload' => $uploaded,
|
||||
'media' => $mediaFiles,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create media directory path
|
||||
*
|
||||
* @param Driver $driver Driver
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createDriverDir(Driver $driver) : string
|
||||
{
|
||||
return '/Modules/FleetManagement/Driver/'
|
||||
. $this->app->unitId . '/'
|
||||
. $driver->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to validate bill creation from request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateMediaAddToDriver(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['media'] = (!$request->hasData('media') && empty($request->files)))
|
||||
|| ($val['driver'] = !$request->hasData('driver'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create a driver
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverInspectionTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverInspectionTypeCreate($request))) {
|
||||
$response->data[$request->uri->__toString()] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var BaseStringL11nType $driver */
|
||||
$driver = $this->createDriverInspectionTypeFromRequest($request);
|
||||
$this->createModel($request->header->account, $driver, DriverInspectionTypeMapper::class, 'inspection_type', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse(
|
||||
$request,
|
||||
$response,
|
||||
NotificationLevel::OK,
|
||||
'',
|
||||
$this->app->l11nManager->getText($response->header->l11n->language, '0', '0', 'SucessfulCreate'),
|
||||
$driver
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return BaseStringL11nType Returns the created driver from the request
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function createDriverInspectionTypeFromRequest(RequestAbstract $request) : BaseStringL11nType
|
||||
{
|
||||
$type = new BaseStringL11nType();
|
||||
$type->title = $request->getDataString('name') ?? '';
|
||||
$type->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
|
||||
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool> Returns the validation array of the request
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverInspectionTypeCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['name'] = !$request->hasData('name'))
|
||||
|| ($val['title'] = !$request->hasData('title'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create driver attribute l11n
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiDriverInspectionTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateDriverInspectionTypeL11nCreate($request))) {
|
||||
$response->data['inspection_type_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$typeL11n = $this->createDriverInspectionTypeL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $typeL11n, DriverInspectionTypeL11nMapper::class, 'inspection_type_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $typeL11n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create driver attribute l11n from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return BaseStringL11n
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createDriverInspectionTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$typeL11n = new BaseStringL11n();
|
||||
$typeL11n->ref = $request->getDataInt('type') ?? 0;
|
||||
$typeL11n->setLanguage(
|
||||
$request->getDataString('language') ?? $request->header->l11n->language
|
||||
);
|
||||
$typeL11n->content = $request->getDataString('title') ?? '';
|
||||
|
||||
return $typeL11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate driver attribute l11n create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateDriverInspectionTypeL11nCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['type'] = !$request->hasData('type'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create item files
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiNoteCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateNoteCreate($request))) {
|
||||
$response->data['driver_note_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$request->setData('virtualpath', '/Modules/FleetManagement/Items/' . $request->getData('id'), true);
|
||||
$this->app->moduleManager->get('Editor', 'Api')->apiEditorCreate($request, $response, $data);
|
||||
|
||||
if ($response->header->status !== RequestStatusCode::R_200) {
|
||||
return;
|
||||
}
|
||||
|
||||
$responseData = $response->get($request->uri->__toString());
|
||||
if (!\is_array($responseData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$model = $responseData['response'];
|
||||
$this->createModelRelation($request->header->account, (int) $request->getData('id'), $model->id, DriverMapper::class, 'notes', '', $request->getOrigin());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate item note create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateNoteCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['id'] = !$request->hasData('id'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
534
Controller/ApiVehicleAttributeController.php
Normal file
534
Controller/ApiVehicleAttributeController.php
Normal file
|
|
@ -0,0 +1,534 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Controller;
|
||||
|
||||
use Modules\Attribute\Models\Attribute;
|
||||
use Modules\Attribute\Models\AttributeType;
|
||||
use Modules\Attribute\Models\AttributeValue;
|
||||
use Modules\Attribute\Models\NullAttributeType;
|
||||
use Modules\Attribute\Models\NullAttributeValue;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeMapper;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeTypeL11nMapper;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeTypeMapper;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeValueL11nMapper;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeValueMapper;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
use phpOMS\Message\Http\RequestStatusCode;
|
||||
use phpOMS\Message\NotificationLevel;
|
||||
use phpOMS\Message\RequestAbstract;
|
||||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Message\FormValidation;
|
||||
|
||||
/**
|
||||
* FleetManagement class.
|
||||
*
|
||||
* @package Modules\FleetManagement
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class ApiVehicleAttributeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Api method to create vehicle attribute
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeCreate($request))) {
|
||||
$response->data['attribute_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attribute = $this->createVehicleAttributeFromRequest($request);
|
||||
$this->createModel($request->header->account, $attribute, VehicleAttributeMapper::class, 'attribute', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully created', $attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return Attribute
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createVehicleAttributeFromRequest(RequestAbstract $request) : Attribute
|
||||
{
|
||||
$attribute = new Attribute();
|
||||
$attribute->ref = (int) $request->getData('vehicle');
|
||||
$attribute->type = new NullAttributeType((int) $request->getData('type'));
|
||||
|
||||
if ($request->hasData('value')) {
|
||||
$attribute->value = new NullAttributeValue((int) $request->getData('value'));
|
||||
} else {
|
||||
$newRequest = clone $request;
|
||||
$newRequest->setData('value', $request->getData('custom'), true);
|
||||
|
||||
$value = $this->createAttributeValueFromRequest($newRequest);
|
||||
|
||||
$attribute->value = $value;
|
||||
}
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['type'] = !$request->hasData('type'))
|
||||
|| ($val['value'] = (!$request->hasData('value') && !$request->hasData('custom')))
|
||||
|| ($val['vehicle'] = !$request->hasData('vehicle'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeUpdate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeUpdate($request))) {
|
||||
$response->data['attribute_update'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$old = VehicleAttributeMapper::get()
|
||||
->with('type')
|
||||
->with('type/defaults')
|
||||
->with('value')
|
||||
->where('id', (int) $request->getData('id'))
|
||||
->execute();
|
||||
|
||||
$new = $this->updateVehicleAttributeFromRequest($request, $old->deepClone());
|
||||
$this->updateModel($request->header->account, $old, $new, VehicleAttributeMapper::class, 'attribute', $request->getOrigin());
|
||||
|
||||
if ($new->value->getValue() !== $old->value->getValue()) {
|
||||
$this->updateModel($request->header->account, $old->value, $new->value, VehicleAttributeValueMapper::class, 'attribute_value', $request->getOrigin());
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully updated', $new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return Attribute
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function updateVehicleAttributeFromRequest(RequestAbstract $request, Attribute $attribute) : Attribute
|
||||
{
|
||||
if ($attribute->type->custom) {
|
||||
if ($request->hasData('value')) {
|
||||
// @question: we are overwriting the old value, could there be a use case where we want to create a new value and keep the old one?
|
||||
$attribute->value->setValue($request->getData('value'), $attribute->type->datatype);
|
||||
}
|
||||
} else {
|
||||
if ($request->hasData('value')) {
|
||||
// @todo: fix by only accepting the value id to be used
|
||||
// this is a workaround for now because the front end doesn't allow to dynamically show default values.
|
||||
$value = $attribute->type->getDefaultByValue($request->getData('value'));
|
||||
|
||||
if ($value->id !== 0) {
|
||||
$attribute->value = $attribute->type->getDefaultByValue($request->getData('value'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeUpdate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['id'] = !$request->hasData('id'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute l11n
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeTypeL11nCreate($request))) {
|
||||
$response->data['attr_type_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createVehicleAttributeTypeL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, VehicleAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute l11n from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return BaseStringL11n
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createVehicleAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = $request->getDataInt('type') ?? 0;
|
||||
$attrL11n->setLanguage(
|
||||
$request->getDataString('language') ?? $request->header->l11n->language
|
||||
);
|
||||
$attrL11n->content = $request->getDataString('title') ?? '';
|
||||
|
||||
return $attrL11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute l11n create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeTypeL11nCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['type'] = !$request->hasData('type'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute type
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeTypeCreate($request))) {
|
||||
$response->data['attr_type_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrType = $this->createAttributeTypeFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrType, VehicleAttributeTypeMapper::class, 'attr_type', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return AttributeType
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeTypeFromRequest(RequestAbstract $request) : AttributeType
|
||||
{
|
||||
$attrType = new AttributeType($request->getDataString('name') ?? '');
|
||||
$attrType->datatype = $request->getDataInt('datatype') ?? 0;
|
||||
$attrType->custom = $request->getDataBool('custom') ?? false;
|
||||
$attrType->isRequired = (bool) ($request->getData('is_required') ?? false);
|
||||
$attrType->validationPattern = $request->getDataString('validation_pattern') ?? '';
|
||||
$attrType->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
|
||||
$attrType->setFields($request->getDataInt('fields') ?? 0);
|
||||
|
||||
return $attrType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeTypeCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['name'] = !$request->hasData('name'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute value
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeValueCreate($request))) {
|
||||
$response->data['attr_value_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrValue = $this->createAttributeValueFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrValue, VehicleAttributeValueMapper::class, 'attr_value', $request->getOrigin());
|
||||
|
||||
if ($attrValue->isDefault) {
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
(int) $request->getData('type'),
|
||||
$attrValue->id,
|
||||
VehicleAttributeTypeMapper::class, 'defaults', '', $request->getOrigin()
|
||||
);
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute value', 'Attribute value successfully created', $attrValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute value from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return AttributeValue
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeValueFromRequest(RequestAbstract $request) : AttributeValue
|
||||
{
|
||||
/** @var AttributeType $type */
|
||||
$type = VehicleAttributeTypeMapper::get()
|
||||
->where('id', $request->getDataInt('type') ?? 0)
|
||||
->execute();
|
||||
|
||||
$attrValue = new AttributeValue();
|
||||
$attrValue->isDefault = $request->getDataBool('default') ?? false;
|
||||
$attrValue->setValue($request->getData('value'), $type->datatype);
|
||||
|
||||
if ($request->hasData('title')) {
|
||||
$attrValue->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
|
||||
}
|
||||
|
||||
return $attrValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute value create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeValueCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['type'] = !$request->hasData('type'))
|
||||
|| ($val['value'] = !$request->hasData('value'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute l11n
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeValueL11nCreate($request))) {
|
||||
$response->data['attr_value_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createAttributeValueL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, VehicleAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute l11n from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return BaseStringL11n
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = $request->getDataInt('value') ?? 0;
|
||||
$attrL11n->setLanguage(
|
||||
$request->getDataString('language') ?? $request->header->l11n->language
|
||||
);
|
||||
$attrL11n->content = $request->getDataString('title') ?? '';
|
||||
|
||||
return $attrL11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute l11n create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeValueL11nCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['value'] = !$request->hasData('value'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to handle api vehicle attributes
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttribute(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeValueL11nCreate($request))) {
|
||||
$response->data['attr_value_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createAttributeValueL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, VehicleAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,21 +15,11 @@ declare(strict_types=1);
|
|||
namespace Modules\FleetManagement\Controller;
|
||||
|
||||
use Modules\Admin\Models\NullAccount;
|
||||
use Modules\Attribute\Models\Attribute;
|
||||
use Modules\Attribute\Models\AttributeType;
|
||||
use Modules\Attribute\Models\AttributeValue;
|
||||
use Modules\Attribute\Models\NullAttributeType;
|
||||
use Modules\Attribute\Models\NullAttributeValue;
|
||||
use Modules\FleetManagement\Models\FuelTypeL11nMapper;
|
||||
use Modules\FleetManagement\Models\FuelTypeMapper;
|
||||
use Modules\FleetManagement\Models\InspectionTypeL11nMapper;
|
||||
use Modules\FleetManagement\Models\InspectionTypeMapper;
|
||||
use Modules\FleetManagement\Models\Vehicle;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeMapper;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeTypeL11nMapper;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeTypeMapper;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeValueL11nMapper;
|
||||
use Modules\FleetManagement\Models\VehicleAttributeValueMapper;
|
||||
use Modules\FleetManagement\Models\VehicleMapper;
|
||||
use Modules\FleetManagement\Models\VehicleStatus;
|
||||
use Modules\FleetManagement\Models\VehicleTypeL11nMapper;
|
||||
|
|
@ -39,6 +29,7 @@ use Modules\Media\Models\MediaMapper;
|
|||
use Modules\Media\Models\NullMedia;
|
||||
use Modules\Media\Models\PathSettings;
|
||||
use Modules\Media\Models\Reference;
|
||||
use Modules\Media\Models\ReferenceMapper;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\BaseStringL11nType;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
|
@ -57,7 +48,7 @@ use phpOMS\Model\Message\FormValidation;
|
|||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class ApiController extends Controller
|
||||
final class ApiVehicleController extends Controller
|
||||
{
|
||||
/**
|
||||
* Api method to create a vehicle
|
||||
|
|
@ -449,7 +440,7 @@ final class ApiController extends Controller
|
|||
);
|
||||
|
||||
if ($collection === null) {
|
||||
/** @var \Modules\Media\Models\Media $media */
|
||||
/** @var \Modules\Media\Models\Collection $collection */
|
||||
$collection = MediaMapper::getParentCollection($path)->limit(1)->execute();
|
||||
|
||||
if ($collection->id === 0) {
|
||||
|
|
@ -499,7 +490,7 @@ final class ApiController extends Controller
|
|||
$this->createModel($request->header->account, $ref, ReferenceMapper::class, 'media_reference', $request->getOrigin());
|
||||
|
||||
if ($collection === null) {
|
||||
/** @var \Modules\Media\Models\Media $media */
|
||||
/** @var \Modules\Media\Models\Collection $collection */
|
||||
$collection = MediaMapper::getParentCollection($path)->limit(1)->execute();
|
||||
|
||||
if ($collection->id === 0) {
|
||||
|
|
@ -545,496 +536,6 @@ final class ApiController extends Controller
|
|||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeCreate($request))) {
|
||||
$response->data['attribute_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attribute = $this->createVehicleAttributeFromRequest($request);
|
||||
$this->createModel($request->header->account, $attribute, VehicleAttributeMapper::class, 'attribute', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully created', $attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return Attribute
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createVehicleAttributeFromRequest(RequestAbstract $request) : Attribute
|
||||
{
|
||||
$attribute = new Attribute();
|
||||
$attribute->ref = (int) $request->getData('vehicle');
|
||||
$attribute->type = new NullAttributeType((int) $request->getData('type'));
|
||||
|
||||
if ($request->hasData('value')) {
|
||||
$attribute->value = new NullAttributeValue((int) $request->getData('value'));
|
||||
} else {
|
||||
$newRequest = clone $request;
|
||||
$newRequest->setData('value', $request->getData('custom'), true);
|
||||
|
||||
$value = $this->createAttributeValueFromRequest($newRequest);
|
||||
|
||||
$attribute->value = $value;
|
||||
}
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['type'] = !$request->hasData('type'))
|
||||
|| ($val['value'] = (!$request->hasData('value') && !$request->hasData('custom')))
|
||||
|| ($val['vehicle'] = !$request->hasData('vehicle'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeUpdate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeUpdate($request))) {
|
||||
$response->data['attribute_update'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$old = VehicleAttributeMapper::get()
|
||||
->with('type')
|
||||
->with('type/defaults')
|
||||
->with('value')
|
||||
->where('id', (int) $request->getData('id'))
|
||||
->execute();
|
||||
|
||||
$new = $this->updateVehicleAttributeFromRequest($request, $old->deepClone());
|
||||
$this->updateModel($request->header->account, $old, $new, VehicleAttributeMapper::class, 'attribute', $request->getOrigin());
|
||||
|
||||
if ($new->value->getValue() !== $old->value->getValue()) {
|
||||
$this->updateModel($request->header->account, $old->value, $new->value, VehicleAttributeValueMapper::class, 'attribute_value', $request->getOrigin());
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully updated', $new);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return Attribute
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function updateVehicleAttributeFromRequest(RequestAbstract $request, Attribute $attribute) : Attribute
|
||||
{
|
||||
if ($attribute->type->custom) {
|
||||
if ($request->hasData('value')) {
|
||||
// @question: we are overwriting the old value, could there be a use case where we want to create a new value and keep the old one?
|
||||
$attribute->value->setValue($request->getData('value'), $attribute->type->datatype);
|
||||
}
|
||||
} else {
|
||||
if ($request->hasData('value')) {
|
||||
// @todo: fix by only accepting the value id to be used
|
||||
// this is a workaround for now because the front end doesn't allow to dynamically show default values.
|
||||
$value = $attribute->type->getDefaultByValue($request->getData('value'));
|
||||
|
||||
if ($value->id !== 0) {
|
||||
$attribute->value = $attribute->type->getDefaultByValue($request->getData('value'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeUpdate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['id'] = !$request->hasData('id'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute l11n
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeTypeL11nCreate($request))) {
|
||||
$response->data['attr_type_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createVehicleAttributeTypeL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, VehicleAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute l11n from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return BaseStringL11n
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createVehicleAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = $request->getDataInt('type') ?? 0;
|
||||
$attrL11n->setLanguage(
|
||||
$request->getDataString('language') ?? $request->header->l11n->language
|
||||
);
|
||||
$attrL11n->content = $request->getDataString('title') ?? '';
|
||||
|
||||
return $attrL11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute l11n create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeTypeL11nCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['type'] = !$request->hasData('type'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute type
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeTypeCreate($request))) {
|
||||
$response->data['attr_type_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrType = $this->createAttributeTypeFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrType, VehicleAttributeTypeMapper::class, 'attr_type', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return AttributeType
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeTypeFromRequest(RequestAbstract $request) : AttributeType
|
||||
{
|
||||
$attrType = new AttributeType($request->getDataString('name') ?? '');
|
||||
$attrType->datatype = $request->getDataInt('datatype') ?? 0;
|
||||
$attrType->custom = $request->getDataBool('custom') ?? false;
|
||||
$attrType->isRequired = (bool) ($request->getData('is_required') ?? false);
|
||||
$attrType->validationPattern = $request->getDataString('validation_pattern') ?? '';
|
||||
$attrType->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
|
||||
$attrType->setFields($request->getDataInt('fields') ?? 0);
|
||||
|
||||
return $attrType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeTypeCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['name'] = !$request->hasData('name'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute value
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeValueCreate($request))) {
|
||||
$response->data['attr_value_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrValue = $this->createAttributeValueFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrValue, VehicleAttributeValueMapper::class, 'attr_value', $request->getOrigin());
|
||||
|
||||
if ($attrValue->isDefault) {
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
(int) $request->getData('type'),
|
||||
$attrValue->id,
|
||||
VehicleAttributeTypeMapper::class, 'defaults', '', $request->getOrigin()
|
||||
);
|
||||
}
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute value', 'Attribute value successfully created', $attrValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute value from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return AttributeValue
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeValueFromRequest(RequestAbstract $request) : AttributeValue
|
||||
{
|
||||
/** @var AttributeType $type */
|
||||
$type = VehicleAttributeTypeMapper::get()
|
||||
->where('id', $request->getDataInt('type') ?? 0)
|
||||
->execute();
|
||||
|
||||
$attrValue = new AttributeValue();
|
||||
$attrValue->isDefault = $request->getDataBool('default') ?? false;
|
||||
$attrValue->setValue($request->getData('value'), $type->datatype);
|
||||
|
||||
if ($request->hasData('title')) {
|
||||
$attrValue->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN);
|
||||
}
|
||||
|
||||
return $attrValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute value create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeValueCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['type'] = !$request->hasData('type'))
|
||||
|| ($val['value'] = !$request->hasData('value'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create vehicle attribute l11n
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeValueL11nCreate($request))) {
|
||||
$response->data['attr_value_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createAttributeValueL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, VehicleAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create vehicle attribute l11n from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return BaseStringL11n
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = $request->getDataInt('value') ?? 0;
|
||||
$attrL11n->setLanguage(
|
||||
$request->getDataString('language') ?? $request->header->l11n->language
|
||||
);
|
||||
$attrL11n->content = $request->getDataString('title') ?? '';
|
||||
|
||||
return $attrL11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate vehicle attribute l11n create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateVehicleAttributeValueL11nCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = !$request->hasData('title'))
|
||||
|| ($val['value'] = !$request->hasData('value'))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to handle api vehicle attributes
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiVehicleAttribute(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateVehicleAttributeValueL11nCreate($request))) {
|
||||
$response->data['attr_value_l11n_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$attrL11n = $this->createAttributeValueL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $attrL11n, VehicleAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create a bill
|
||||
*
|
||||
|
|
@ -1100,6 +601,7 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
if ($collection === null) {
|
||||
/** @var \Modules\Media\Models\Collection $collection */
|
||||
$collection = MediaMapper::getParentCollection($path)->limit(1)->execute();
|
||||
|
||||
if ($collection->id === 0) {
|
||||
|
|
@ -1202,9 +704,9 @@ final class ApiController extends Controller
|
|||
return;
|
||||
}
|
||||
|
||||
/** @var BaseStringL11nType $vehicle */
|
||||
$vehicle = $this->createInspectionTypeFromRequest($request);
|
||||
$this->createModel($request->header->account, $vehicle, InspectionTypeMapper::class, 'inspection_type', $request->getOrigin());
|
||||
/** @var BaseStringL11nType $inspection */
|
||||
$inspection = $this->createInspectionTypeFromRequest($request);
|
||||
$this->createModel($request->header->account, $inspection, InspectionTypeMapper::class, 'inspection_type', $request->getOrigin());
|
||||
|
||||
$this->fillJsonResponse(
|
||||
$request,
|
||||
|
|
@ -1212,7 +714,7 @@ final class ApiController extends Controller
|
|||
NotificationLevel::OK,
|
||||
'',
|
||||
$this->app->l11nManager->getText($response->header->l11n->language, '0', '0', 'SucessfulCreate'),
|
||||
$vehicle
|
||||
$inspection
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -1341,7 +843,7 @@ final class ApiController extends Controller
|
|||
{
|
||||
if (!empty($val = $this->validateNoteCreate($request))) {
|
||||
$response->data['vehicle_note_create'] = new FormValidation($val);
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
@ -159,10 +159,10 @@ final class BackendController extends Controller
|
|||
SettingsEnum::DEFAULT_LOCALIZATION,
|
||||
]);
|
||||
|
||||
$view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response);
|
||||
$view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response);
|
||||
$view->data['attributeView']->data['defaultlocalization'] = LocalizationMapper::get()->where('id', (int) $settings->id)->execute();
|
||||
|
||||
$view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response);
|
||||
$view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response);
|
||||
$view->data['vehicle-notes'] = new \Modules\Editor\Theme\Backend\Components\Compound\BaseView($this->app->l11nManager, $request, $response);
|
||||
|
||||
return $view;
|
||||
|
|
@ -193,6 +193,8 @@ final class BackendController extends Controller
|
|||
->with('attributes/type')
|
||||
->with('attributes/value')
|
||||
->with('attributes/type/l11n')
|
||||
->with('files')
|
||||
->with('files/types')
|
||||
->with('type')
|
||||
->with('type/l11n')
|
||||
->with('fuelType')
|
||||
|
|
@ -236,6 +238,7 @@ final class BackendController extends Controller
|
|||
|
||||
$units = UnitMapper::getAll()
|
||||
->execute();
|
||||
|
||||
$view->data['units'] = $units;
|
||||
|
||||
/** @var \Model\Setting $settings */
|
||||
|
|
@ -243,10 +246,10 @@ final class BackendController extends Controller
|
|||
SettingsEnum::DEFAULT_LOCALIZATION,
|
||||
]);
|
||||
|
||||
$view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response);
|
||||
$view->data['attributeView'] = new \Modules\Attribute\Theme\Backend\Components\AttributeView($this->app->l11nManager, $request, $response);
|
||||
$view->data['attributeView']->data['defaultlocalization'] = LocalizationMapper::get()->where('id', (int) $settings->id)->execute();
|
||||
|
||||
$view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response);
|
||||
$view->data['media-upload'] = new \Modules\Media\Theme\Backend\Components\Upload\BaseView($this->app->l11nManager, $request, $response);
|
||||
$view->data['vehicle-notes'] = new \Modules\Editor\Theme\Backend\Components\Compound\BaseView($this->app->l11nManager, $request, $response);
|
||||
|
||||
return $view;
|
||||
|
|
|
|||
79
Models/Driver/Driver.php
Normal file
79
Models/Driver/Driver.php
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use Modules\Admin\Models\Account;
|
||||
|
||||
/**
|
||||
* Driver class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Driver
|
||||
{
|
||||
/**
|
||||
* ID value.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $id = 0;
|
||||
|
||||
/**
|
||||
* Status value.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $status = DriverStatus::ACTIVE;
|
||||
|
||||
/**
|
||||
* Account associated with the client.
|
||||
*
|
||||
* @var Account
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public Account $account;
|
||||
|
||||
public array $licenses = [];
|
||||
|
||||
public array $inspections = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'status' => $this->status,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
use \Modules\Media\Models\MediaListTrait;
|
||||
use \Modules\Editor\Models\EditorDocListTrait;
|
||||
use \Modules\Attribute\Models\AttributeHolderTrait;
|
||||
}
|
||||
86
Models/Driver/DriverAttributeMapper.php
Normal file
86
Models/Driver/DriverAttributeMapper.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use Modules\Attribute\Models\Attribute;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Fleet mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of Attribute
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverAttributeMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_attr_id' => ['name' => 'fleetmgmt_driver_attr_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_attr_item' => ['name' => 'fleetmgmt_driver_attr_item', 'type' => 'int', 'internal' => 'ref'],
|
||||
'fleetmgmt_driver_attr_type' => ['name' => 'fleetmgmt_driver_attr_type', 'type' => 'int', 'internal' => 'type'],
|
||||
'fleetmgmt_driver_attr_value' => ['name' => 'fleetmgmt_driver_attr_value', 'type' => 'int', 'internal' => 'value'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has one relation.
|
||||
*
|
||||
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const OWNS_ONE = [
|
||||
'type' => [
|
||||
'mapper' => DriverAttributeTypeMapper::class,
|
||||
'external' => 'fleetmgmt_driver_attr_type',
|
||||
],
|
||||
'value' => [
|
||||
'mapper' => DriverAttributeValueMapper::class,
|
||||
'external' => 'fleetmgmt_driver_attr_value',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var class-string<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = Attribute::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver_attr';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_attr_id';
|
||||
}
|
||||
69
Models/Driver/DriverAttributeTypeL11nMapper.php
Normal file
69
Models/Driver/DriverAttributeTypeL11nMapper.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
|
||||
/**
|
||||
* Driver mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of BaseStringL11n
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverAttributeTypeL11nMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_attr_type_l11n_id' => ['name' => 'fleetmgmt_driver_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_attr_type_l11n_title' => ['name' => 'fleetmgmt_driver_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
|
||||
'fleetmgmt_driver_attr_type_l11n_type' => ['name' => 'fleetmgmt_driver_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'],
|
||||
'fleetmgmt_driver_attr_type_l11n_lang' => ['name' => 'fleetmgmt_driver_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver_attr_type_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_attr_type_l11n_id';
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var class-string<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = BaseStringL11n::class;
|
||||
}
|
||||
94
Models/Driver/DriverAttributeTypeMapper.php
Normal file
94
Models/Driver/DriverAttributeTypeMapper.php
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use Modules\Attribute\Models\AttributeType;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Driver mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of AttributeType
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverAttributeTypeMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_attr_type_id' => ['name' => 'fleetmgmt_driver_attr_type_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_attr_type_name' => ['name' => 'fleetmgmt_driver_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
|
||||
'fleetmgmt_driver_attr_type_datatype' => ['name' => 'fleetmgmt_driver_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'],
|
||||
'fleetmgmt_driver_attr_type_fields' => ['name' => 'fleetmgmt_driver_attr_type_fields', 'type' => 'int', 'internal' => 'fields'],
|
||||
'fleetmgmt_driver_attr_type_custom' => ['name' => 'fleetmgmt_driver_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'],
|
||||
'fleetmgmt_driver_attr_type_pattern' => ['name' => 'fleetmgmt_driver_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'],
|
||||
'fleetmgmt_driver_attr_type_required' => ['name' => 'fleetmgmt_driver_attr_type_required', 'type' => 'bool', 'internal' => 'isRequired'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const HAS_MANY = [
|
||||
'l11n' => [
|
||||
'mapper' => DriverAttributeTypeL11nMapper::class,
|
||||
'table' => 'fleetmgmt_driver_attr_type_l11n',
|
||||
'self' => 'fleetmgmt_driver_attr_type_l11n_type',
|
||||
'column' => 'content',
|
||||
'external' => null,
|
||||
],
|
||||
'defaults' => [
|
||||
'mapper' => DriverAttributeValueMapper::class,
|
||||
'table' => 'fleetmgmt_driver_attr_default',
|
||||
'self' => 'fleetmgmt_driver_attr_default_type',
|
||||
'external' => 'fleetmgmt_driver_attr_default_value',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var class-string<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = AttributeType::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver_attr_type';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_attr_type_id';
|
||||
}
|
||||
69
Models/Driver/DriverAttributeValueL11nMapper.php
Normal file
69
Models/Driver/DriverAttributeValueL11nMapper.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
|
||||
/**
|
||||
* Driver mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of BaseStringL11n
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverAttributeValueL11nMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_attr_value_l11n_id' => ['name' => 'fleetmgmt_driver_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_attr_value_l11n_title' => ['name' => 'fleetmgmt_driver_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
|
||||
'fleetmgmt_driver_attr_value_l11n_value' => ['name' => 'fleetmgmt_driver_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'],
|
||||
'fleetmgmt_driver_attr_value_l11n_lang' => ['name' => 'fleetmgmt_driver_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver_attr_value_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_attr_value_l11n_id';
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var class-string<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = BaseStringL11n::class;
|
||||
}
|
||||
89
Models/Driver/DriverAttributeValueMapper.php
Normal file
89
Models/Driver/DriverAttributeValueMapper.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use Modules\Attribute\Models\AttributeValue;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Driver mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of AttributeValue
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverAttributeValueMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_attr_value_id' => ['name' => 'fleetmgmt_driver_attr_value_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_attr_value_default' => ['name' => 'fleetmgmt_driver_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
|
||||
'fleetmgmt_driver_attr_value_valueStr' => ['name' => 'fleetmgmt_driver_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'],
|
||||
'fleetmgmt_driver_attr_value_valueInt' => ['name' => 'fleetmgmt_driver_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'],
|
||||
'fleetmgmt_driver_attr_value_valueDec' => ['name' => 'fleetmgmt_driver_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'],
|
||||
'fleetmgmt_driver_attr_value_valueDat' => ['name' => 'fleetmgmt_driver_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'],
|
||||
'fleetmgmt_driver_attr_value_unit' => ['name' => 'fleetmgmt_driver_attr_value_unit', 'type' => 'string', 'internal' => 'unit'],
|
||||
'fleetmgmt_driver_attr_value_deptype' => ['name' => 'fleetmgmt_driver_attr_value_deptype', 'type' => 'int', 'internal' => 'dependingAttributeType'],
|
||||
'fleetmgmt_driver_attr_value_depvalue' => ['name' => 'fleetmgmt_driver_attr_value_depvalue', 'type' => 'int', 'internal' => 'dependingAttributeValue'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const HAS_MANY = [
|
||||
'l11n' => [
|
||||
'mapper' => DriverAttributeValueL11nMapper::class,
|
||||
'table' => 'fleetmgmt_driver_attr_value_l11n',
|
||||
'self' => 'fleetmgmt_driver_attr_value_l11n_value',
|
||||
'external' => null,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var class-string<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = AttributeValue::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver_attr_value';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_attr_value_id';
|
||||
}
|
||||
78
Models/Driver/DriverInspection.php
Normal file
78
Models/Driver/DriverInspection.php
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use phpOMS\Localization\BaseStringL11nType;
|
||||
|
||||
/**
|
||||
* Inspection class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class DriverInspection implements \JsonSerializable
|
||||
{
|
||||
public int $id = 0;
|
||||
|
||||
public string $description = '';
|
||||
|
||||
public BaseStringL11nType $type;
|
||||
|
||||
public int $status = DriverInspectionStatus::TODO;
|
||||
|
||||
// Automatically get's filled from the previous inspection if available
|
||||
// Alternatively define default interval from inspection type?
|
||||
public ?\DateTime $next = null;
|
||||
|
||||
/**
|
||||
* Inspectio interval in months
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $interval = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->type = new BaseStringL11nType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
use \Modules\Media\Models\MediaListTrait;
|
||||
}
|
||||
84
Models/Driver/DriverInspectionMapper.php
Normal file
84
Models/Driver/DriverInspectionMapper.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
|
||||
/**
|
||||
* mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of DriverInspection
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverInspectionMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_inspection_id' => ['name' => 'fleetmgmt_driver_inspection_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_inspection_description' => ['name' => 'fleetmgmt_driver_inspection_description', 'type' => 'string', 'internal' => 'description'],
|
||||
'fleetmgmt_driver_inspection_status' => ['name' => 'fleetmgmt_driver_inspection_status', 'type' => 'int', 'internal' => 'status'],
|
||||
'fleetmgmt_driver_inspection_interval' => ['name' => 'fleetmgmt_driver_inspection_interval', 'type' => 'int', 'internal' => 'interval'],
|
||||
'fleetmgmt_driver_inspection_next' => ['name' => 'fleetmgmt_driver_inspection_next', 'type' => 'DateTime', 'internal' => 'next'],
|
||||
'fleetmgmt_driver_inspection_type' => ['name' => 'fleetmgmt_driver_inspection_type', 'type' => 'int', 'internal' => 'type'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has one relation.
|
||||
*
|
||||
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const OWNS_ONE = [
|
||||
'type' => [
|
||||
'mapper' => DriverInspectionTypeMapper::class,
|
||||
'external' => 'fleetmgmt_driver_inspection_type',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver_inspection';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_inspection_id';
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var class-string<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = DriverInspection::class;
|
||||
}
|
||||
36
Models/Driver/DriverInspectionStatus.php
Normal file
36
Models/Driver/DriverInspectionStatus.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use phpOMS\Stdlib\Base\Enum;
|
||||
|
||||
/**
|
||||
* Inspection status enum.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class DriverInspectionStatus extends Enum
|
||||
{
|
||||
public const DONE = 1;
|
||||
|
||||
public const PASSED = 2;
|
||||
|
||||
public const ONGOING = 4;
|
||||
|
||||
public const TODO = 5;
|
||||
}
|
||||
69
Models/Driver/DriverInspectionTypeL11nMapper.php
Normal file
69
Models/Driver/DriverInspectionTypeL11nMapper.php
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
|
||||
/**
|
||||
* mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of BaseStringL11n
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverInspectionTypeL11nMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_inspection_type_l11n_id' => ['name' => 'fleetmgmt_driver_inspection_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_inspection_type_l11n_title' => ['name' => 'fleetmgmt_driver_inspection_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
|
||||
'fleetmgmt_driver_inspection_type_l11n_type' => ['name' => 'fleetmgmt_driver_inspection_type_l11n_type', 'type' => 'int', 'internal' => 'ref'],
|
||||
'fleetmgmt_driver_inspection_type_l11n_lang' => ['name' => 'fleetmgmt_driver_inspection_type_l11n_lang', 'type' => 'string', 'internal' => 'language'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver_inspection_type_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_inspection_type_l11n_id';
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var class-string<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = BaseStringL11n::class;
|
||||
}
|
||||
83
Models/Driver/DriverInspectionTypeMapper.php
Normal file
83
Models/Driver/DriverInspectionTypeMapper.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\Localization\BaseStringL11nType;
|
||||
|
||||
/**
|
||||
* Item mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of BaseStringL11nType
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverInspectionTypeMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_inspection_type_id' => ['name' => 'fleetmgmt_driver_inspection_type_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_inspection_type_name' => ['name' => 'fleetmgmt_driver_inspection_type_name', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const HAS_MANY = [
|
||||
'l11n' => [
|
||||
'mapper' => DriverInspectionTypeL11nMapper::class,
|
||||
'table' => 'fleetmgmt_driver_inspection_type_l11n',
|
||||
'self' => 'fleetmgmt_driver_inspection_type_l11n_type',
|
||||
'column' => 'content',
|
||||
'external' => null,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var class-string<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = BaseStringL11nType::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver_inspection_type';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_inspection_type_id';
|
||||
}
|
||||
102
Models/Driver/DriverMapper.php
Normal file
102
Models/Driver/DriverMapper.php
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use Modules\Media\Models\MediaMapper;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use Modules\Editor\Models\EditorDocMapper;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @template T of Driver
|
||||
* @extends DataMapperFactory<T>
|
||||
*/
|
||||
final class DriverMapper extends DataMapperFactory
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_driver_id' => ['name' => 'fleetmgmt_driver_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_driver_status' => ['name' => 'fleetmgmt_driver_status', 'type' => 'int', 'internal' => 'status'],
|
||||
'fleetmgmt_driver_account' => ['name' => 'fleetmgmt_driver_account', 'type' => 'int', 'internal' => 'account'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const HAS_MANY = [
|
||||
'files' => [
|
||||
'mapper' => MediaMapper::class,
|
||||
'table' => 'fleetmgmt_driver_media',
|
||||
'external' => 'fleetmgmt_driver_media_media',
|
||||
'self' => 'fleetmgmt_driver_media_vehicle',
|
||||
],
|
||||
'attributes' => [
|
||||
'mapper' => DriverAttributeMapper::class,
|
||||
'table' => 'fleetmgmt_driver_attr',
|
||||
'self' => 'fleetmgmt_driver_attr_item',
|
||||
'external' => null,
|
||||
],
|
||||
'notes' => [
|
||||
'mapper' => EditorDocMapper::class, /* mapper of the related object */
|
||||
'table' => 'fleetmgmt_driver_note', /* table of the related object, null if no relation table is used (many->1) */
|
||||
'external' => 'fleetmgmt_driver_note_doc',
|
||||
'self' => 'fleetmgmt_driver_note_driver',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has one relation.
|
||||
*
|
||||
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const OWNS_ONE = [
|
||||
'account' => [
|
||||
'mapper' => AccountMapper::class,
|
||||
'external' => 'fleetmgmt_driver_account',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'fleetmgmt_driver';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD = 'fleetmgmt_driver_id';
|
||||
}
|
||||
34
Models/Driver/DriverStatus.php
Normal file
34
Models/Driver/DriverStatus.php
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
use phpOMS\Stdlib\Base\Enum;
|
||||
|
||||
/**
|
||||
* Driver status enum.
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
abstract class DriverStatus extends Enum
|
||||
{
|
||||
public const ACTIVE = 1;
|
||||
|
||||
public const INACTIVE = 2;
|
||||
|
||||
public const SUSPENDED = 3;
|
||||
}
|
||||
46
Models/Driver/NullDriver.php
Normal file
46
Models/Driver/NullDriver.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullDriver extends Driver
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return ['id' => $this->id];
|
||||
}
|
||||
}
|
||||
46
Models/Driver/NullDriverInspection.php
Normal file
46
Models/Driver/NullDriverInspection.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models\Driver;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\FleetManagement\Models\Driver
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullDriverInspection extends DriverInspection
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return ['id' => $this->id];
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\FleetManagement\Models;
|
||||
|
||||
use phpOMS\Localization\BaseStringL11nType;
|
||||
|
||||
/**
|
||||
* Inspection class.
|
||||
*
|
||||
|
|
@ -38,16 +40,39 @@ class Inspection implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Inspectio interval in months
|
||||
*
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $interval = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->type = new BaseStringL11nType();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
use \Modules\Media\Models\MediaListTrait;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ final class InspectionTypeMapper extends DataMapperFactory
|
|||
*/
|
||||
public const COLUMNS = [
|
||||
'fleetmgmt_inspection_type_id' => ['name' => 'fleetmgmt_inspection_type_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'fleetmgmt_inspection_type_name' => ['name' => 'fleetmgmt_inspection_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
|
||||
'fleetmgmt_inspection_type_name' => ['name' => 'fleetmgmt_inspection_type_name', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
|
|||
0
Models/License.php
Normal file
0
Models/License.php
Normal file
0
Models/LicenseType.php
Normal file
0
Models/LicenseType.php
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\FleetManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\FleetManagement\Models;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\FleetManagement\Models
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullInspection extends Inspection
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return ['id' => $this->id];
|
||||
}
|
||||
}
|
||||
|
|
@ -50,6 +50,11 @@ class Vehicle implements \JsonSerializable
|
|||
|
||||
public \DateTimeImmutable $createdAt;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTimeImmutable('now');
|
||||
|
|
@ -74,7 +79,7 @@ class Vehicle implements \JsonSerializable
|
|||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
|
||||
|
||||
use \Modules\Media\Models\MediaListTrait;
|
||||
use \Modules\Editor\Models\EditorDocListTrait;
|
||||
use \Modules\Attribute\Models\AttributeHolderTrait;
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ final class VehicleMapper extends DataMapperFactory
|
|||
],
|
||||
'notes' => [
|
||||
'mapper' => EditorDocMapper::class, /* mapper of the related object */
|
||||
'table' => 'bizexpenses_expense_note', /* table of the related object, null if no relation table is used (many->1) */
|
||||
'external' => 'bizexpenses_expense_note_doc',
|
||||
'self' => 'bizexpenses_expense_note_expense',
|
||||
'table' => 'fleetmgmt_vehicle_note', /* table of the related object, null if no relation table is used (many->1) */
|
||||
'external' => 'fleetmgmt_vehicle_note_doc',
|
||||
'self' => 'fleetmgmt_vehicle_note_vehicle',
|
||||
],
|
||||
];
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user