diff --git a/Admin/Install/db.json b/Admin/Install/db.json index e3b51c9..edd7e23 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -79,6 +79,11 @@ "foreignTable": "account", "foreignKey": "account_id" }, + "contractmgmt_contract_startoriginal": { + "name": "contractmgmt_contract_startoriginal", + "type": "DATETIME", + "null": false + }, "contractmgmt_contract_start": { "name": "contractmgmt_contract_start", "type": "DATETIME", diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 3bc7048..b356600 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -17,10 +17,8 @@ namespace Modules\ContractManagement\Controller; use Modules\Admin\Models\NullAccount; use Modules\ContractManagement\Models\Contract; use Modules\ContractManagement\Models\ContractMapper; -use Modules\ContractManagement\Models\ContractType; use Modules\ContractManagement\Models\ContractTypeL11nMapper; use Modules\ContractManagement\Models\ContractTypeMapper; -use Modules\ContractManagement\Models\NullContractType; use Modules\Media\Models\MediaMapper; use Modules\Media\Models\PathSettings; use Modules\Organization\Models\NullUnit; @@ -31,6 +29,8 @@ use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Message\FormValidation; +use phpOMS\Localization\NullBaseStringL11nType; +use phpOMS\Localization\BaseStringL11nType; /** * Api controller for the contracts module. @@ -121,7 +121,7 @@ final class ApiController extends Controller $contract = new Contract(); $contract->title = $request->getDataString('title') ?? ''; $contract->description = $request->getDataString('description') ?? ''; - $contract->type = new NullContractType($request->getDataInt('type') ?? 0); + $contract->type = new NullBaseStringL11nType($request->getDataInt('type') ?? 0); $contract->start = $request->getDataDateTime('start') ?? new \DateTime('now'); $contract->account = new NullAccount($request->getDataInt('account') ?? 0); $contract->renewal = $request->getDataInt('renewal') ?? 0; @@ -231,15 +231,15 @@ final class ApiController extends Controller * * @param RequestAbstract $request Request * - * @return ContractType + * @return BaseStringL11nType * * @since 1.0.0 */ - private function createContractTypeFromRequest(RequestAbstract $request) : ContractType + private function createContractTypeFromRequest(RequestAbstract $request) : BaseStringL11nType { - $contractType = new ContractType(); + $contractType = new BaseStringL11nType(); $contractType->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); - $contractType->name = $request->getDataString('name') ?? ''; + $contractType->title = $request->getDataString('name') ?? ''; return $contractType; } diff --git a/Models/Contract.php b/Models/Contract.php index 13938af..9d002cc 100755 --- a/Models/Contract.php +++ b/Models/Contract.php @@ -21,7 +21,7 @@ use Modules\Organization\Models\Unit; use phpOMS\Localization\Money; /** - * Account class. + * Contract class. * * @package Modules\ContractManagement\Models * @license OMS License 2.0 @@ -55,7 +55,7 @@ class Contract public string $description = ''; // The original start of the contract ignoring renewals - public \DateTime $originalStart; + public ?\DateTime $originalStart = null; // Start of the contract considering renewals public ?\DateTime $start = null; diff --git a/Models/ContractMapper.php b/Models/ContractMapper.php index 4553f74..f809566 100755 --- a/Models/ContractMapper.php +++ b/Models/ContractMapper.php @@ -52,6 +52,7 @@ final class ContractMapper extends DataMapperFactory 'contractmgmt_contract_autorenewal' => ['name' => 'contractmgmt_contract_autorenewal', 'type' => 'bool', 'internal' => 'autoRenewal'], 'contractmgmt_contract_duration' => ['name' => 'contractmgmt_contract_duration', 'type' => 'int', 'internal' => 'duration'], 'contractmgmt_contract_warning' => ['name' => 'contractmgmt_contract_warning', 'type' => 'int', 'internal' => 'warning'], + 'contractmgmt_contract_startoriginal' => ['name' => 'contractmgmt_contract_startoriginal', 'type' => 'DateTime', 'internal' => 'originalStart'], 'contractmgmt_contract_start' => ['name' => 'contractmgmt_contract_start', 'type' => 'DateTime', 'internal' => 'start'], 'contractmgmt_contract_end' => ['name' => 'contractmgmt_contract_end', 'type' => 'DateTime', 'internal' => 'end'], 'contractmgmt_contract_responsible' => ['name' => 'contractmgmt_contract_responsible', 'type' => 'int', 'internal' => 'responsible'], diff --git a/Models/ContractType.php b/Models/ContractType.php deleted file mode 100755 index 05bf4df..0000000 --- a/Models/ContractType.php +++ /dev/null @@ -1,132 +0,0 @@ -setL11n($name); - } - - /** - * Get id - * - * @return int - * - * @since 1.0.0 - */ - public function getId() : int - { - return $this->id; - } - - /** - * 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; - } else { - $this->l11n = new BaseStringL11n(); - $this->l11n->ref = $this->id; - $this->l11n->content = $l11n; - $this->l11n->setLanguage($lang); - } - } - - /** - * @return string - * - * @since 1.0.0 - */ - public function getL11n() : string - { - return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; - } - - /** - * {@inheritdoc} - */ - public function toArray() : array - { - return [ - 'id' => $this->id, - 'l11n' => $this->l11n, - 'name' => $this->name, - ]; - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return $this->toArray(); - } -} diff --git a/Models/ContractTypeMapper.php b/Models/ContractTypeMapper.php index 5257646..42bd689 100755 --- a/Models/ContractTypeMapper.php +++ b/Models/ContractTypeMapper.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace Modules\ContractManagement\Models; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; +use phpOMS\Localization\BaseStringL11nType; /** * Contract type mapper class. @@ -37,7 +38,7 @@ final class ContractTypeMapper extends DataMapperFactory */ public const COLUMNS = [ 'contractmgmt_type_id' => ['name' => 'contractmgmt_type_id', 'type' => 'int', 'internal' => 'id'], - 'contractmgmt_type_name' => ['name' => 'contractmgmt_type_name', 'type' => 'string', 'internal' => 'name'], + 'contractmgmt_type_name' => ['name' => 'contractmgmt_type_name', 'type' => 'string', 'internal' => 'title'], ]; /** @@ -62,7 +63,7 @@ final class ContractTypeMapper extends DataMapperFactory * @var class-string * @since 1.0.0 */ - public const MODEL = ContractType::class; + public const MODEL = BaseStringL11nType::class; /** * Primary table. diff --git a/Models/NullContractType.php b/Models/NullContractType.php deleted file mode 100755 index 65983e8..0000000 --- a/Models/NullContractType.php +++ /dev/null @@ -1,47 +0,0 @@ -id = $id; - parent::__construct(); - } - - /** - * {@inheritdoc} - */ - public function jsonSerialize() : mixed - { - return ['id' => $this->id]; - } -}