mirror of
https://github.com/Karaka-Management/oms-ContractManagement.git
synced 2026-02-06 05:38:43 +00:00
Change to BaseStringL11nType
This commit is contained in:
parent
6aef562cdb
commit
bd67834189
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
|
|
|
|||
|
|
@ -1,132 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\ContractManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\ContractManagement\Models;
|
||||
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* Contract Type class.
|
||||
*
|
||||
* @package Modules\ContractManagement\Models
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ContractType implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Id
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $id = 0;
|
||||
|
||||
/**
|
||||
* Name.
|
||||
*
|
||||
* Name used for additional identification, doesn't have to be unique.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $name = '';
|
||||
|
||||
/**
|
||||
* Localization
|
||||
*
|
||||
* @var BaseStringL11n
|
||||
*/
|
||||
protected string | BaseStringL11n $l11n;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $name Name
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(string $name = '')
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
|
|
@ -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<T>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = ContractType::class;
|
||||
public const MODEL = BaseStringL11nType::class;
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
|
|
|
|||
|
|
@ -1,47 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\ContractManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 2.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\ContractManagement\Models;
|
||||
|
||||
/**
|
||||
* Contract model.
|
||||
*
|
||||
* @package Modules\ContractManagement\Models
|
||||
* @license OMS License 2.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullContractType extends ContractType
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param int $id Model id
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(int $id = 0)
|
||||
{
|
||||
$this->id = $id;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return ['id' => $this->id];
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user