diff --git a/Admin/Install/db.json b/Admin/Install/db.json index ddda20c..f790e47 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -95,6 +95,54 @@ } } }, + "fleetmgmt_inspection_type": { + "name": "fleetmgmt_inspection_type", + "fields": { + "fleetmgmt_inspection_type_id": { + "name": "fleetmgmt_inspection_type_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "fleetmgmt_inspection_type_name": { + "name": "fleetmgmt_inspection_type_name", + "type": "VARCHAR(255)", + "null": false + } + } + }, + "fleetmgmt_inspection_type_l11n": { + "name": "fleetmgmt_inspection_type_l11n", + "fields": { + "fleetmgmt_inspection_type_l11n_id": { + "name": "fleetmgmt_inspection_type_l11n_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "fleetmgmt_inspection_type_l11n_title": { + "name": "fleetmgmt_inspection_type_l11n_title", + "type": "VARCHAR(255)", + "null": false + }, + "fleetmgmt_inspection_type_l11n_type": { + "name": "fleetmgmt_inspection_type_l11n_type", + "type": "INT(11)", + "null": false, + "foreignTable": "fleetmgmt_inspection_type", + "foreignKey": "fleetmgmt_inspection_type_id" + }, + "fleetmgmt_inspection_type_l11n_lang": { + "name": "fleetmgmt_inspection_type_l11n_lang", + "type": "VARCHAR(2)", + "null": false, + "foreignTable": "language", + "foreignKey": "language_639_1" + } + } + }, "fleetmgmt_vehicle": { "name": "fleetmgmt_vehicle", "fields": { @@ -155,6 +203,46 @@ } } }, + "fleetmgmt_vehicle_inspection": { + "name": "fleetmgmt_vehicle_inspection", + "fields": { + "fleetmgmt_vehicle_inspection_id": { + "name": "fleetmgmt_vehicle_inspection_id", + "type": "INT", + "null": false, + "primary": true, + "autoincrement": true + }, + "fleetmgmt_vehicle_inspection_description": { + "name": "fleetmgmt_vehicle_inspection_description", + "type": "TEXT", + "null": false + }, + "fleetmgmt_vehicle_inspection_status": { + "name": "fleetmgmt_vehicle_inspection_status", + "type": "TINYINT(1)", + "null": false + }, + "fleetmgmt_vehicle_inspection_interval": { + "name": "fleetmgmt_vehicle_inspection_interval", + "type": "TINYINT(3)", + "null": false + }, + "fleetmgmt_vehicle_inspection_next": { + "name": "fleetmgmt_vehicle_inspection_next", + "type": "DATETIME", + "null": true, + "default": null + }, + "fleetmgmt_vehicle_inspection_type": { + "name": "fleetmgmt_vehicle_inspection_type", + "type": "INT", + "null": false, + "foreignTable": "fleetmgmt_inspection_type", + "foreignKey": "fleetmgmt_inspection_type_id" + } + } + }, "fleetmgmt_vehicle_usage": { "name": "fleetmgmt_vehicle_usage", "fields": { diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 01553ae..5c2a874 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -20,11 +20,8 @@ use Modules\Attribute\Models\AttributeType; use Modules\Attribute\Models\AttributeValue; use Modules\Attribute\Models\NullAttributeType; use Modules\Attribute\Models\NullAttributeValue; -use Modules\FleetManagement\Models\FuelType; use Modules\FleetManagement\Models\FuelTypeL11nMapper; use Modules\FleetManagement\Models\FuelTypeMapper; -use Modules\FleetManagement\Models\NullFuelType; -use Modules\FleetManagement\Models\NullVehicleType; use Modules\FleetManagement\Models\Vehicle; use Modules\FleetManagement\Models\VehicleAttributeMapper; use Modules\FleetManagement\Models\VehicleAttributeTypeL11nMapper; @@ -33,7 +30,8 @@ use Modules\FleetManagement\Models\VehicleAttributeValueL11nMapper; use Modules\FleetManagement\Models\VehicleAttributeValueMapper; use Modules\FleetManagement\Models\VehicleMapper; use Modules\FleetManagement\Models\VehicleStatus; -use Modules\FleetManagement\Models\VehicleType; +use phpOMS\Localization\NullBaseStringL11nType; +use phpOMS\Localization\BaseStringL11nType; use Modules\FleetManagement\Models\VehicleTypeL11nMapper; use Modules\FleetManagement\Models\VehicleTypeMapper; use Modules\Media\Models\CollectionMapper; @@ -81,7 +79,7 @@ final class ApiController extends Controller return; } - /** @var VehicleType $vehicle */ + /** @var BaseStringL11nType $vehicle */ $vehicle = $this->createVehicleTypeFromRequest($request); $this->createModel($request->header->account, $vehicle, VehicleTypeMapper::class, 'vehicle_type', $request->getOrigin()); @@ -100,14 +98,14 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return VehicleType Returns the created vehicle from the request + * @return BaseStringL11nType Returns the created vehicle from the request * * @since 1.0.0 */ - public function createVehicleTypeFromRequest(RequestAbstract $request) : VehicleType + public function createVehicleTypeFromRequest(RequestAbstract $request) : BaseStringL11nType { - $type = new VehicleType(); - $type->name = $request->getDataString('name') ?? ''; + $type = new BaseStringL11nType(); + $type->title = $request->getDataString('name') ?? ''; $type->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); return $type; @@ -225,7 +223,7 @@ final class ApiController extends Controller return; } - /** @var FuelType $vehicle */ + /** @var BaseStringL11nType $vehicle */ $vehicle = $this->createFuelTypeFromRequest($request); $this->createModel($request->header->account, $vehicle, FuelTypeMapper::class, 'fuel_type', $request->getOrigin()); @@ -244,14 +242,14 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return FuelType Returns the created vehicle from the request + * @return BaseStringL11nType Returns the created vehicle from the request * * @since 1.0.0 */ - public function createFuelTypeFromRequest(RequestAbstract $request) : FuelType + public function createFuelTypeFromRequest(RequestAbstract $request) : BaseStringL11nType { - $type = new FuelType(); - $type->name = $request->getDataString('name') ?? ''; + $type = new BaseStringL11nType(); + $type->title = $request->getDataString('name') ?? ''; $type->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); return $type; @@ -403,8 +401,8 @@ final class ApiController extends Controller $vehicle = new Vehicle(); $vehicle->name = $request->getDataString('name') ?? ''; $vehicle->info = $request->getDataString('info') ?? ''; - $vehicle->type = new NullVehicleType((int) ($request->getDataInt('type') ?? 0)); - $vehicle->fuelType = new NullFuelType((int) ($request->getDataInt('fuel') ?? 0)); + $vehicle->type = new NullBaseStringL11nType((int) ($request->getDataInt('type') ?? 0)); + $vehicle->fuelType = new NullBaseStringL11nType((int) ($request->getDataInt('fuel') ?? 0)); $vehicle->status = (int) ($request->getDataInt('status') ?? VehicleStatus::INACTIVE); $vehicle->unit = $request->getDataInt('unit') ?? $this->app->unitId; diff --git a/Models/FuelType.php b/Models/FuelType.php deleted file mode 100644 index 2c7c5e2..0000000 --- a/Models/FuelType.php +++ /dev/null @@ -1,121 +0,0 @@ -name = $name; - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - if (!isset($this->l11n)) { - return ''; - } - - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'name' => $this->name, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/FuelTypeMapper.php b/Models/FuelTypeMapper.php index 10c16f0..0059b21 100644 --- a/Models/FuelTypeMapper.php +++ b/Models/FuelTypeMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\FleetManagement\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11nType; /** * Item mapper class. @@ -37,7 +38,7 @@ final class FuelTypeMapper extends DataMapperFactory */ public const COLUMNS = [ 'fleetmgmt_fuel_type_id' => ['name' => 'fleetmgmt_fuel_type_id', 'type' => 'int', 'internal' => 'id'], - 'fleetmgmt_fuel_type_name' => ['name' => 'fleetmgmt_fuel_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], + 'fleetmgmt_fuel_type_name' => ['name' => 'fleetmgmt_fuel_type_name', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], ]; /** @@ -62,7 +63,7 @@ final class FuelTypeMapper extends DataMapperFactory * @var class-string * @since 1.0.0 */ - public const MODEL = FuelType::class; + public const MODEL = BaseStringL11nType::class; /** * Primary table. diff --git a/Models/Inspection.php b/Models/Inspection.php index e69de29..3d90bb2 100644 --- a/Models/Inspection.php +++ b/Models/Inspection.php @@ -0,0 +1,54 @@ +type = new BaseStringL11nType(); + } + + use \Modules\Media\Models\MediaListTrait; +} diff --git a/Models/InspectionMapper.php b/Models/InspectionMapper.php new file mode 100644 index 0000000..66a798b --- /dev/null +++ b/Models/InspectionMapper.php @@ -0,0 +1,84 @@ + + */ +final class InspectionMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + 'fleetmgmt_vehicle_inspection_id' => ['name' => 'fleetmgmt_vehicle_inspection_id', 'type' => 'int', 'internal' => 'id'], + 'fleetmgmt_vehicle_inspection_description' => ['name' => 'fleetmgmt_vehicle_inspection_description', 'type' => 'string', 'internal' => 'description'], + 'fleetmgmt_vehicle_inspection_status' => ['name' => 'fleetmgmt_vehicle_inspection_status', 'type' => 'int', 'internal' => 'status'], + 'fleetmgmt_vehicle_inspection_interval' => ['name' => 'fleetmgmt_vehicle_inspection_interval', 'type' => 'int', 'internal' => 'interval'], + 'fleetmgmt_vehicle_inspection_next' => ['name' => 'fleetmgmt_vehicle_inspection_next', 'type' => 'DateTime', 'internal' => 'next'], + 'fleetmgmt_vehicle_inspection_type' => ['name' => 'fleetmgmt_vehicle_inspection_type', 'type' => 'int', 'internal' => 'type'], + ]; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + public const OWNS_ONE = [ + 'type' => [ + 'mapper' => InspectionTypeMapper::class, + 'external' => 'fleetmgmt_vehicle_inspection_type', + ], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'fleetmgmt_vehicle_inspection'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'fleetmgmt_vehicle_inspection_id'; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = Inspection::class; +} diff --git a/Models/InspectionMapper_.php b/Models/InspectionMapper_.php deleted file mode 100644 index e69de29..0000000 diff --git a/Models/NullFuelType.php b/Models/InspectionStatus.php similarity index 52% rename from Models/NullFuelType.php rename to Models/InspectionStatus.php index 9502384..c4a8921 100644 --- a/Models/NullFuelType.php +++ b/Models/InspectionStatus.php @@ -14,33 +14,23 @@ declare(strict_types=1); namespace Modules\FleetManagement\Models; +use phpOMS\Stdlib\Base\Enum; + /** - * Null model + * Inspection status enum. * * @package Modules\FleetManagement\Models * @license OMS License 2.0 * @link https://jingga.app * @since 1.0.0 */ -final class NullFuelType extends FuelType +abstract class InspectionStatus extends Enum { - /** - * Constructor - * - * @param int $id Model id - * - * @since 1.0.0 - */ - public function __construct(int $id = 0) - { - $this->id = $id; - } + public const DONE = 1; - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } + public const PASSED = 2; + + public const ONGOING = 4; + + public const TODO = 5; } diff --git a/Models/InspectionTypeL11nMapper.php b/Models/InspectionTypeL11nMapper.php new file mode 100644 index 0000000..f5485ff --- /dev/null +++ b/Models/InspectionTypeL11nMapper.php @@ -0,0 +1,69 @@ + + */ +final class InspectionTypeL11nMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + public const COLUMNS = [ + 'fleetmgmt_inspection_type_l11n_id' => ['name' => 'fleetmgmt_inspection_type_l11n_id', 'type' => 'int', 'internal' => 'id'], + 'fleetmgmt_inspection_type_l11n_title' => ['name' => 'fleetmgmt_inspection_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], + 'fleetmgmt_inspection_type_l11n_type' => ['name' => 'fleetmgmt_inspection_type_l11n_type', 'type' => 'int', 'internal' => 'ref'], + 'fleetmgmt_inspection_type_l11n_lang' => ['name' => 'fleetmgmt_inspection_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'fleetmgmt_inspection_type_l11n'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'fleetmgmt_inspection_type_l11n_id'; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11n::class; +} diff --git a/Models/InspectionTypeMapper.php b/Models/InspectionTypeMapper.php new file mode 100644 index 0000000..01ddbe5 --- /dev/null +++ b/Models/InspectionTypeMapper.php @@ -0,0 +1,83 @@ + + */ +final class InspectionTypeMapper extends DataMapperFactory +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + 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], + ]; + + /** + * Has many relation. + * + * @var array + * @since 1.0.0 + */ + public const HAS_MANY = [ + 'l11n' => [ + 'mapper' => FuelTypeL11nMapper::class, + 'table' => 'fleetmgmt_inspection_type_l11n', + 'self' => 'fleetmgmt_inspection_type_l11n_type', + 'column' => 'content', + 'external' => null, + ], + ]; + + /** + * Model to use by the mapper. + * + * @var class-string + * @since 1.0.0 + */ + public const MODEL = BaseStringL11nType::class; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + public const TABLE = 'fleetmgmt_inspection_type'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + public const PRIMARYFIELD = 'fleetmgmt_inspection_type_id'; +} diff --git a/Models/NullVehicleType.php b/Models/NullVehicleType.php deleted file mode 100644 index cee550b..0000000 --- a/Models/NullVehicleType.php +++ /dev/null @@ -1,46 +0,0 @@ -id = $id; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -} diff --git a/Models/Vehicle.php b/Models/Vehicle.php index eb010e7..d16c316 100644 --- a/Models/Vehicle.php +++ b/Models/Vehicle.php @@ -14,8 +14,10 @@ declare(strict_types=1); namespace Modules\FleetManagement\Models; +use phpOMS\Localization\BaseStringL11n; + /** - * class. + * Vehicle class. * * @package Modules\Attribute\Models * @license OMS License 2.0 @@ -30,7 +32,7 @@ class Vehicle implements \JsonSerializable public int $status = VehicleStatus::ACTIVE; - public VehicleType $type; + public BaseStringL11n $type; public FuelType $fuelType; @@ -53,7 +55,7 @@ class Vehicle implements \JsonSerializable public function __construct() { $this->createdAt = new \DateTimeImmutable('now'); - $this->type = new VehicleType(); + $this->type = new BaseStringL11n(); $this->fuelType = new FuelType(); } diff --git a/Models/VehicleType.php b/Models/VehicleType.php deleted file mode 100644 index c3c2bf9..0000000 --- a/Models/VehicleType.php +++ /dev/null @@ -1,121 +0,0 @@ -name = $name; - } - - /** - * Set l11n - * - * @param string|BaseStringL11n $l11n Tag article l11n - * @param string $lang Language - * - * @return void - * - * @since 1.0.0 - */ - public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void - { - if ($l11n instanceof BaseStringL11n) { - $this->l11n = $l11n; - } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - if (!isset($this->l11n)) { - return ''; - } - - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'name' => $this->name, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/VehicleTypeL11nMapper.php b/Models/VehicleTypeL11nMapper.php index 87ef2c8..48a6eb2 100644 --- a/Models/VehicleTypeL11nMapper.php +++ b/Models/VehicleTypeL11nMapper.php @@ -40,7 +40,6 @@ final class VehicleTypeL11nMapper extends DataMapperFactory 'fleetmgmt_vehicle_type_l11n_id' => ['name' => 'fleetmgmt_vehicle_type_l11n_id', 'type' => 'int', 'internal' => 'id'], 'fleetmgmt_vehicle_type_l11n_title' => ['name' => 'fleetmgmt_vehicle_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true], 'fleetmgmt_vehicle_type_l11n_type' => ['name' => 'fleetmgmt_vehicle_type_l11n_type', 'type' => 'int', 'internal' => 'ref'], - 'fleetmgmt_vehicle_type_l11n_lang' => ['name' => 'fleetmgmt_vehicle_type_l11n_lang', 'type' => 'string', 'internal' => 'language'], ]; /** diff --git a/Models/VehicleTypeMapper.php b/Models/VehicleTypeMapper.php index b188470..f222719 100644 --- a/Models/VehicleTypeMapper.php +++ b/Models/VehicleTypeMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\FleetManagement\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11nType; /** * Item mapper class. @@ -24,7 +25,7 @@ use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; * @link https://jingga.app * @since 1.0.0 * - * @template T of VehicleType + * @template T of BaseStringL11nType * @extends DataMapperFactory */ final class VehicleTypeMapper extends DataMapperFactory @@ -37,7 +38,8 @@ final class VehicleTypeMapper extends DataMapperFactory */ public const COLUMNS = [ 'fleetmgmt_vehicle_type_id' => ['name' => 'fleetmgmt_vehicle_type_id', 'type' => 'int', 'internal' => 'id'], - 'fleetmgmt_vehicle_type_name' => ['name' => 'fleetmgmt_vehicle_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], + 'fleetmgmt_vehicle_type_name' => ['name' => 'fleetmgmt_vehicle_type_name', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], + ]; /** @@ -62,7 +64,7 @@ final class VehicleTypeMapper extends DataMapperFactory * @var class-string * @since 1.0.0 */ - public const MODEL = VehicleType::class; + public const MODEL = BaseStringL11nType::class; /** * Primary table.