too many changes

This commit is contained in:
Dennis Eichhorn 2023-03-11 23:38:19 +01:00
parent db96540155
commit 8dab18e60c
26 changed files with 2082 additions and 45 deletions

View File

@ -0,0 +1,54 @@
[
{
"name": "vat_id",
"l11n": {
"en": "VAT Id",
"de": "USt IdNr."
},
"value_type": 2,
"is_custom_allowed": true,
"validation_pattern": "",
"is_required": false,
"default_value": "",
"values": []
},
{
"name": "tax_id",
"l11n": {
"en": "Tax Id",
"de": "Steuernummer"
},
"value_type": 2,
"is_custom_allowed": true,
"validation_pattern": "",
"is_required": false,
"default_value": "",
"values": []
},
{
"name": "legal_form",
"l11n": {
"en": "Legal form",
"de": "Rechtsform"
},
"value_type": 2,
"is_custom_allowed": true,
"validation_pattern": "",
"is_required": false,
"default_value": "",
"values": []
},
{
"name": "registration_id",
"l11n": {
"en": "Registration Id",
"de": "Registrationsnummer"
},
"value_type": 2,
"is_custom_allowed": true,
"validation_pattern": "",
"is_required": false,
"default_value": "",
"values": []
}
]

View File

@ -18,8 +18,11 @@ use Modules\Organization\Models\Unit;
use Modules\Organization\Models\UnitMapper;
use phpOMS\Application\ApplicationAbstract;
use phpOMS\Config\SettingsInterface;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Module\InstallerAbstract;
use phpOMS\Module\ModuleInfo;
use phpOMS\Uri\HttpUri;
/**
* Installer class.
@ -47,6 +50,156 @@ final class Installer extends InstallerAbstract
parent::install($app, $info, $cfgHandler);
self::installDefaultUnit();
/* Attributes */
$fileContent = \file_get_contents(__DIR__ . '/Install/attributes.json');
if ($fileContent === false) {
return;
}
$attributes = \json_decode($fileContent, true);
$attrTypes = self::createUnitAttributeTypes($app, $attributes);
$attrValues = self::createUnitAttributeValues($app, $attrTypes, $attributes);
}
/**
* 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
*
* @return array<string, array>
*
* @since 1.0.0
*/
private static function createUnitAttributeTypes(ApplicationAbstract $app, array $attributes) : array
{
/** @var array<string, array> $unitAttrType */
$unitAttrType = [];
/** @var \Modules\Organization\Controller\ApiController $module */
$module = $app->moduleManager->getModuleInstance('Organization');
/** @var array $attribute */
foreach ($attributes as $attribute) {
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('name', $attribute['name'] ?? '');
$request->setData('title', \reset($attribute['l11n']));
$request->setData('language', \array_keys($attribute['l11n'])[0] ?? 'en');
$request->setData('is_required', $attribute['is_required'] ?? false);
$request->setData('is_custom_allowed', $attribute['is_custom_allowed'] ?? false);
$request->setData('validation_pattern', $attribute['validation_pattern'] ?? '');
$request->setData('datatype', (int) $attribute['value_type']);
$module->apiUnitAttributeTypeCreate($request, $response);
$responseData = $response->get('');
if (!\is_array($responseData)) {
continue;
}
$unitAttrType[$attribute['name']] = !\is_array($responseData['response'])
? $responseData['response']->toArray()
: $responseData['response'];
$isFirst = true;
foreach ($attribute['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', $unitAttrType[$attribute['name']]['id']);
$module->apiUnitAttributeTypeL11nCreate($request, $response);
}
}
return $unitAttrType;
}
/**
* Create default attribute values for types
*
* @param ApplicationAbstract $app Application
* @param array $unitAttrType 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>
*
* @since 1.0.0
*/
private static function createUnitAttributeValues(ApplicationAbstract $app, array $unitAttrType, array $attributes) : array
{
/** @var array<string, array> $unitAttrValue */
$unitAttrValue = [];
/** @var \Modules\Organization\Controller\ApiController $module */
$module = $app->moduleManager->getModuleInstance('Organization');
foreach ($attributes as $attribute) {
$unitAttrValue[$attribute['name']] = [];
/** @var array $value */
foreach ($attribute['values'] as $value) {
$response = new HttpResponse();
$request = new HttpRequest(new HttpUri(''));
$request->header->account = 1;
$request->setData('value', $value['value'] ?? '');
$request->setData('unit', $value['unit'] ?? '');
$request->setData('default', true); // always true since all defined values are possible default values
$request->setData('type', $unitAttrType[$attribute['name']]['id']);
if (isset($value['l11n']) && !empty($value['l11n'])) {
$request->setData('title', \reset($value['l11n']));
$request->setData('language', \array_keys($value['l11n'])[0] ?? 'en');
}
$module->apiUnitAttributeValueCreate($request, $response);
$responseData = $response->get('');
if (!\is_array($responseData)) {
continue;
}
$attrValue = !\is_array($responseData['response'])
? $responseData['response']->toArray()
: $responseData['response'];
$unitAttrValue[$attribute['name']][] = $attrValue;
$isFirst = true;
foreach (($value['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('value', $attrValue['id']);
$module->apiUnitAttributeValueL11nCreate($request, $response);
}
}
}
return $unitAttrValue;
}
/**

View File

@ -133,6 +133,18 @@ return [
],
],
'^.*/organization/unit/address/main(\?.*|$)' => [
[
'dest' => '\Modules\Organization\Controller\ApiController:apiUnitMainAddressSet',
'verb' => RouteVerb::SET,
'permission' => [
'module' => ApiController::NAME,
'type' => PermissionType::MODIFY,
'state' => PermissionCategory::UNIT,
],
],
],
'^.*/organization/unit/image(\?.*|$)' => [
[
'dest' => '\Modules\Organization\Controller\ApiController:apiUnitImageSet',

View File

@ -16,6 +16,9 @@ namespace Modules\Organization\Controller;
use Model\Setting;
use Model\SettingMapper;
use Modules\Admin\Models\Address;
use Modules\Admin\Models\AddressMapper;
use Modules\Admin\Models\NullAddress;
use Modules\Admin\Models\SettingsEnum as ModelsSettingsEnum;
use Modules\Media\Models\PathSettings;
use Modules\Organization\Models\Department;
@ -23,13 +26,26 @@ use Modules\Organization\Models\DepartmentMapper;
use Modules\Organization\Models\NullDepartment;
use Modules\Organization\Models\NullPosition;
use Modules\Organization\Models\NullUnit;
use Modules\Organization\Models\NullUnitAttributeType;
use Modules\Organization\Models\NullUnitAttributeValue;
use Modules\Organization\Models\Position;
use Modules\Organization\Models\PositionMapper;
use Modules\Organization\Models\SettingsEnum;
use Modules\Organization\Models\Status;
use Modules\Organization\Models\Unit;
use Modules\Organization\Models\UnitAttribute;
use Modules\Organization\Models\UnitAttributeMapper;
use Modules\Organization\Models\UnitAttributeType;
use Modules\Organization\Models\UnitAttributeTypeL11nMapper;
use Modules\Organization\Models\UnitAttributeTypeMapper;
use Modules\Organization\Models\UnitAttributeValue;
use Modules\Organization\Models\UnitAttributeValueL11nMapper;
use Modules\Organization\Models\UnitAttributeValueMapper;
use Modules\Organization\Models\UnitMapper;
use phpOMS\Account\GroupStatus;
use phpOMS\Localization\BaseStringL11n;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Localization\ISO639x1Enum;
use phpOMS\Message\Http\HttpRequest;
use phpOMS\Message\Http\HttpResponse;
use phpOMS\Message\Http\RequestStatusCode;
@ -215,12 +231,118 @@ final class ApiController extends Controller
module: 'Admin'
);
$this->createModel($request->header->account, $setting, SettingMapper::class, 'setting', $request->getOrigin());
}
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Unit', 'Unit successfully created.', $unit);
}
/**
* Api method to create a unit
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiUnitMainAddressSet(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateUnitMainAddressSet($request))) {
$response->set('unit_address_set', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
/** @var Unit $unit */
$unit = UnitMapper::get()->with('mainAddress')->where('id', $request->getData('unit'))->execute();
$oldUnit = clone $unit;
if ($unit->mainAddress->getId() !== 0) {
$oldAddr = clone $unit->mainAddress;
$addr = $this->updateUnitMainAddressFromRequest($request, $unit);
$this->updateModel($request->header->account, $oldAddr, $addr, AddressMapper::class, 'address', $request->getOrigin());
} else {
$addr = $this->createUnitMainAddressFromRequest($request);
$this->createModel($request->header->account, $addr, AddressMapper::class, 'address', $request->getOrigin());
$unit->mainAddress = new NullAddress($addr->getId());
$this->updateModel($request->header->account, $oldUnit, $unit, UnitMapper::class, 'unit', $request->getOrigin());
}
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Address', 'Address successfully set.', $unit);
}
/**
* Validate unit create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateUnitMainAddressSet(RequestAbstract $request) : array
{
$val = [];
if (($val['unit'] = empty($request->getData('unit')))
|| ($val['address'] = empty($request->getData('address')))
) {
return $val;
}
return [];
}
/**
* Method to create unit from request.
*
* @param RequestAbstract $request Request
*
* @return Address
*
* @since 1.0.0
*/
private function createUnitMainAddressFromRequest(RequestAbstract $request) : Address
{
$addr = new Address();
$addr->name = (string) ($request->getData('legal') ?? '');
$addr->address = (string) ($request->getData('address') ?? '');
$addr->postal = (string) ($request->getData('postal') ?? '');
$addr->city = (string) ($request->getData('city') ?? '');
$addr->setCountry($request->getData('country') ?? ISO3166TwoEnum::_XXX);
$addr->state = (string) ($request->getData('state') ?? '');
return $addr;
}
/**
* Method to create unit from request.
*
* @param RequestAbstract $request Request
*
* @return Address
*
* @since 1.0.0
*/
private function updateUnitMainAddressFromRequest(RequestAbstract $request, Unit $unit) : Address
{
$addr = $unit->mainAddress;
$addr->name = (string) ($request->getData('legal') ?? '');
$addr->address = (string) ($request->getData('address') ?? '');
$addr->postal = (string) ($request->getData('postal') ?? '');
$addr->city = (string) ($request->getData('city') ?? '');
$addr->setCountry($request->getData('country') ?? ISO3166TwoEnum::_XXX);
$addr->state = (string) ($request->getData('state') ?? '');
return $addr;
}
/**
* Method to create unit from request.
*
@ -240,6 +362,17 @@ final class ApiController extends Controller
$unit->parent = new NullUnit((int) $request->getData('parent'));
$unit->setStatus((int) $request->getData('status'));
if ($request->hasData('address')) {
$addr = new Address();
$addr->name = (string) ($request->getData('legal') ?? ($request->getData('name') ?? ''));
$addr->address = (string) ($request->getData('address') ?? '');
$addr->postal = (string) ($request->getData('postal') ?? '');
$addr->city = (string) ($request->getData('city') ?? '');
$addr->setCountry($request->getData('country') ?? ISO3166TwoEnum::_XXX);
$addr->state = (string) ($request->getData('state') ?? '');
$unit->mainAddress = $addr;
}
return $unit;
}
@ -712,4 +845,377 @@ final class ApiController extends Controller
)
);
}
/**
* Api method to create item attribute
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiUnitAttributeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateUnitAttributeCreate($request))) {
$response->set('attribute_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$attribute = $this->createUnitAttributeFromRequest($request);
$this->createModel($request->header->account, $attribute, UnitAttributeMapper::class, 'attribute', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully created', $attribute);
}
/**
* Method to create item attribute from request.
*
* @param RequestAbstract $request Request
*
* @return UnitAttribute
*
* @since 1.0.0
*/
private function createUnitAttributeFromRequest(RequestAbstract $request) : UnitAttribute
{
$attribute = new UnitAttribute();
$attribute->unit = (int) $request->getData('unit');
$attribute->type = new NullUnitAttributeType((int) $request->getData('type'));
if ($request->getData('value') !== null) {
$attribute->value = new NullUnitAttributeValue((int) $request->getData('value'));
} else {
$newRequest = clone $request;
$newRequest->setData('value', $request->getData('custom'), true);
$value = $this->createUnitAttributeValueFromRequest($newRequest);
$attribute->value = $value;
}
return $attribute;
}
/**
* Validate unit attribute create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateUnitAttributeCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['type'] = empty($request->getData('type')))
|| ($val['value'] = (empty($request->getData('value')) && empty($request->getData('custom'))))
|| ($val['unit'] = empty($request->getData('unit')))
) {
return $val;
}
return [];
}
/**
* Api method to create unit attribute l11n
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiUnitAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateUnitAttributeTypeL11nCreate($request))) {
$response->set('attr_type_l11n_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$attrL11n = $this->createUnitAttributeTypeL11nFromRequest($request);
$this->createModel($request->header->account, $attrL11n, UnitAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
}
/**
* Method to create unit attribute l11n from request.
*
* @param RequestAbstract $request Request
*
* @return BaseStringL11n
*
* @since 1.0.0
*/
private function createUnitAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
{
$attrL11n = new BaseStringL11n();
$attrL11n->ref = (int) ($request->getData('type') ?? 0);
$attrL11n->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage()
));
$attrL11n->content = (string) ($request->getData('title') ?? '');
return $attrL11n;
}
/**
* Validate unit attribute l11n create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateUnitAttributeTypeL11nCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['title'] = empty($request->getData('title')))
|| ($val['type'] = empty($request->getData('type')))
) {
return $val;
}
return [];
}
/**
* Api method to create unit attribute type
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiUnitAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateUnitAttributeTypeCreate($request))) {
$response->set('attr_type_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$attrType = $this->createUnitAttributeTypeFromRequest($request);
$this->createModel($request->header->account, $attrType, UnitAttributeTypeMapper::class, 'attr_type', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType);
}
/**
* Method to create unit attribute from request.
*
* @param RequestAbstract $request Request
*
* @return UnitAttributeType
*
* @since 1.0.0
*/
private function createUnitAttributeTypeFromRequest(RequestAbstract $request) : UnitAttributeType
{
$attrType = new UnitAttributeType($request->getData('name') ?? '');
$attrType->datatype = (int) ($request->getData('datatype') ?? 0);
$attrType->custom = (bool) ($request->getData('custom') ?? false);
$attrType->isRequired = (bool) ($request->getData('is_required') ?? false);
$attrType->validationPattern = (string) ($request->getData('validation_pattern') ?? '');
$attrType->setL11n((string) ($request->getData('title') ?? ''), $request->getData('language') ?? ISO639x1Enum::_EN);
$attrType->setFields((int) ($request->getData('fields') ?? 0));
return $attrType;
}
/**
* Validate unit attribute create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateUnitAttributeTypeCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['title'] = empty($request->getData('title')))
|| ($val['name'] = empty($request->getData('name')))
) {
return $val;
}
return [];
}
/**
* Api method to create unit attribute value
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiUnitAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateUnitAttributeValueCreate($request))) {
$response->set('attr_value_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$attrValue = $this->createUnitAttributeValueFromRequest($request);
$this->createModel($request->header->account, $attrValue, UnitAttributeValueMapper::class, 'attr_value', $request->getOrigin());
if ($attrValue->isDefault) {
$this->createModelRelation(
$request->header->account,
(int) $request->getData('type'),
$attrValue->getId(),
UnitAttributeTypeMapper::class, 'defaults', '', $request->getOrigin()
);
}
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute value', 'Attribute value successfully created', $attrValue);
}
/**
* Method to create unit attribute value from request.
*
* @param RequestAbstract $request Request
*
* @return UnitAttributeValue
*
* @since 1.0.0
*/
private function createUnitAttributeValueFromRequest(RequestAbstract $request) : UnitAttributeValue
{
/** @var UnitAttributeType $type */
$type = UnitAttributeTypeMapper::get()
->where('id', (int) ($request->getData('type') ?? 0))
->execute();
$attrValue = new UnitAttributeValue();
$attrValue->isDefault = (bool) ($request->getData('default') ?? false);
$attrValue->setValue($request->getData('value'), $type->datatype);
if ($request->getData('title') !== null) {
$attrValue->setL11n($request->getData('title'), $request->getData('language') ?? ISO639x1Enum::_EN);
}
return $attrValue;
}
/**
* Validate unit attribute value create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateUnitAttributeValueCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['type'] = empty($request->getData('type')))
|| ($val['value'] = empty($request->getData('value')))
) {
return $val;
}
return [];
}
/**
* Api method to create unit attribute l11n
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiUnitAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
{
if (!empty($val = $this->validateUnitAttributeValueL11nCreate($request))) {
$response->set('attr_value_l11n_create', new FormValidation($val));
$response->header->status = RequestStatusCode::R_400;
return;
}
$attrL11n = $this->createUnitAttributeValueL11nFromRequest($request);
$this->createModel($request->header->account, $attrL11n, UnitAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n);
}
/**
* Method to create unit attribute l11n from request.
*
* @param RequestAbstract $request Request
*
* @return BaseStringL11n
*
* @since 1.0.0
*/
private function createUnitAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n
{
$attrL11n = new BaseStringL11n();
$attrL11n->ref = (int) ($request->getData('value') ?? 0);
$attrL11n->setLanguage((string) (
$request->getData('language') ?? $request->getLanguage()
));
$attrL11n->content = (string) ($request->getData('title') ?? '');
return $attrL11n;
}
/**
* Validate unit attribute l11n create request
*
* @param RequestAbstract $request Request
*
* @return array<string, bool>
*
* @since 1.0.0
*/
private function validateUnitAttributeValueL11nCreate(RequestAbstract $request) : array
{
$val = [];
if (($val['title'] = empty($request->getData('title')))
|| ($val['value'] = empty($request->getData('value')))
) {
return $val;
}
return [];
}
}

View File

@ -96,6 +96,7 @@ final class BackendController extends Controller
$unit = UnitMapper::get()
->with('parent')
->with('mainAddress')
->with('image')
->where('id', (int) $request->getData('id'))
->execute();

40
Models/AttributeValueType.php Executable file
View File

@ -0,0 +1,40 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\Stdlib\Base\Enum;
/**
* Attribute value type enum.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
abstract class AttributeValueType extends Enum
{
public const _INT = 1;
public const _STRING = 2;
public const _FLOAT = 3;
public const _DATETIME = 4;
public const _BOOL = 5;
public const _FLOAT_INT = 6;
}

View File

@ -81,5 +81,5 @@ final class DepartmentMapper extends DataMapperFactory
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='organization_department_id';
public const PRIMARYFIELD = 'organization_department_id';
}

47
Models/NullUnitAttribute.php Executable file
View File

@ -0,0 +1,47 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
/**
* Null model
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullUnitAttribute extends UnitAttribute
{
/**
* Constructor
*
* @param int $id Model id
*
* @since 1.0.0
*/
public function __construct(int $id = 0)
{
parent::__construct();
$this->id = $id;
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return ['id' => $this->id];
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
/**
* Null model
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullUnitAttributeType extends UnitAttributeType
{
/**
* 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];
}
}

View File

@ -0,0 +1,46 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
/**
* Null model
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class NullUnitAttributeValue extends UnitAttributeValue
{
/**
* 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];
}
}

View File

@ -81,5 +81,5 @@ final class PositionMapper extends DataMapperFactory
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='organization_position_id';
public const PRIMARYFIELD = 'organization_position_id';
}

View File

@ -14,9 +14,10 @@ declare(strict_types=1);
namespace Modules\Organization\Models;
use Modules\Admin\Models\Address;
use Modules\Admin\Models\NullAddress;
use Modules\Media\Models\Media;
use Modules\Media\Models\NullMedia;
/**
* Organization unit class.
*
@ -83,6 +84,18 @@ class Unit implements \JsonSerializable
*/
protected int $status = Status::INACTIVE;
public Address $mainAddress;
private array $address = [];
/**
* Attributes.
*
* @var UnitAttribute[]
* @since 1.0.0
*/
private array $attributes = [];
/**
* Constructor.
*
@ -92,6 +105,7 @@ class Unit implements \JsonSerializable
{
$this->image = new NullMedia();
$this->parent = new NullUnit();
$this->mainAddress = new NullAddress();
}
/**
@ -106,6 +120,52 @@ class Unit implements \JsonSerializable
return $this->id;
}
/**
* Add attribute to client
*
* @param UnitAttribute $attribute Attribute
*
* @return void
*
* @since 1.0.0
*/
public function addAttribute(UnitAttribute $attribute) : void
{
$this->attributes[] = $attribute;
}
/**
* Get attributes
*
* @return UnitAttribute[]
*
* @since 1.0.0
*/
public function getAttributes() : array
{
return $this->attributes;
}
/**
* Get attribute
*
* @param string $attrName Attribute name
*
* @return null|UnitAttribute
*
* @since 1.0.0
*/
public function getAttribute(string $attrName) : ?UnitAttribute
{
foreach ($this->attributes as $attribute) {
if ($attribute->type->name === $attrName) {
return $attribute->value;
}
}
return null;
}
/**
* Get status
*
@ -132,6 +192,18 @@ class Unit implements \JsonSerializable
$this->status = $status;
}
/**
* Get addresses.
*
* @return array
*
* @since 1.0.0
*/
public function getAddresses() : array
{
return $this->address;
}
/**
* {@inheritdoc}
*/

102
Models/UnitAttribute.php Executable file
View File

@ -0,0 +1,102 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
/**
* Unit class.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class UnitAttribute implements \JsonSerializable
{
/**
* Id.
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Unit this attribute belongs to
*
* @var int
* @since 1.0.0
*/
public int $unit = 0;
/**
* Attribute type the attribute belongs to
*
* @var UnitAttributeType
* @since 1.0.0
*/
public UnitAttributeType $type;
/**
* Attribute value the attribute belongs to
*
* @var UnitAttributeValue
* @since 1.0.0
*/
public UnitAttributeValue $value;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct()
{
$this->type = new NullUnitAttributeType();
$this->value = new NullUnitAttributeValue();
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'unit' => $this->unit,
'type' => $this->type,
'value' => $this->value,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

74
Models/UnitAttributeMapper.php Executable file
View File

@ -0,0 +1,74 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Unit mapper class.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class UnitAttributeMapper 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 = [
'unit_attr_id' => ['name' => 'unit_attr_id', 'type' => 'int', 'internal' => 'id'],
'unit_attr_unit' => ['name' => 'unit_attr_unit', 'type' => 'int', 'internal' => 'unit'],
'unit_attr_type' => ['name' => 'unit_attr_type', 'type' => 'int', 'internal' => 'type'],
'unit_attr_value' => ['name' => 'unit_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' => UnitAttributeTypeMapper::class,
'external' => 'unit_attr_type',
],
'value' => [
'mapper' => UnitAttributeValueMapper::class,
'external' => 'unit_attr_value',
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'unit_attr';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD = 'unit_attr_id';
}

216
Models/UnitAttributeType.php Executable file
View File

@ -0,0 +1,216 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\Localization\BaseStringL11n;
use phpOMS\Localization\ISO639x1Enum;
/**
* Unit Attribute Type class.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class UnitAttributeType implements \JsonSerializable
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Name/string identifier by which it can be found/categorized
*
* @var string
* @since 1.0.0
*/
public string $name = '';
/**
* Which field data type is required (string, int, ...) in the value
*
* @var int
* @since 1.0.0
*/
protected int $fields = 0;
/**
* Is a custom value allowed (e.g. custom string)
*
* @var bool
* @since 1.0.0
*/
public bool $custom = false;
public string $validationPattern = '';
public bool $isRequired = false;
/**
* Datatype of the attribute
*
* @var int
* @since 1.0.0
*/
public int $datatype = AttributeValueType::_STRING;
/**
* Localization
*
* @var BaseStringL11n
*/
private string | BaseStringL11n $l11n = '';
/**
* Possible default attribute values
*
* @var array
*/
private array $defaults = [];
/**
* Default attribute value
*
* @var int
* @since 1.0.0
*/
public int $default = 0;
/**
* Constructor.
*
* @param string $name Name/identifier of the attribute type
*
* @since 1.0.0
*/
public function __construct(string $name = '')
{
$this->name = $name;
}
/**
* Get id
*
* @return int
*
* @since 1.0.0
*/
public function getId() : int
{
return $this->id;
}
public function getDefaultByValue(mixed $value) : UnitAttributeValue
{
foreach ($this->defaults as $default) {
if ($default->getValue() === $value) {
return $default;
}
}
return new NullUnitAttributeValue();
}
/**
* 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;
}
/**
* Set fields
*
* @param int $fields Fields
*
* @return void
*
* @since 1.0.0
*/
public function setFields(int $fields) : void
{
$this->fields = $fields;
}
/**
* Get default values
*
* @return array
*
* @sicne 1.0.0
*/
public function getDefaults() : array
{
return $this->defaults;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'name' => $this->name,
'validationPattern' => $this->validationPattern,
'custom' => $this->custom,
'isRequired' => $this->isRequired,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11n;
/**
* Unit mapper class.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class UnitAttributeTypeL11nMapper 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 = [
'unit_attr_type_l11n_id' => ['name' => 'unit_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
'unit_attr_type_l11n_title' => ['name' => 'unit_attr_type_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
'unit_attr_type_l11n_type' => ['name' => 'unit_attr_type_l11n_type', 'type' => 'int', 'internal' => 'ref'],
'unit_attr_type_l11n_lang' => ['name' => 'unit_attr_type_l11n_lang', 'type' => 'string', 'internal' => 'language'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'unit_attr_type_l11n';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD = 'unit_attr_type_l11n_id';
/**
* Model to use by the mapper.
*
* @var class-string
* @since 1.0.0
*/
public const MODEL = BaseStringL11n::class;
}

View File

@ -0,0 +1,82 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Unit mapper class.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class UnitAttributeTypeMapper 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 = [
'unit_attr_type_id' => ['name' => 'unit_attr_type_id', 'type' => 'int', 'internal' => 'id'],
'unit_attr_type_name' => ['name' => 'unit_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'unit_attr_type_datatype' => ['name' => 'unit_attr_type_datatype', 'type' => 'int', 'internal' => 'datatype'],
'unit_attr_type_fields' => ['name' => 'unit_attr_type_fields', 'type' => 'int', 'internal' => 'fields'],
'unit_attr_type_custom' => ['name' => 'unit_attr_type_custom', 'type' => 'bool', 'internal' => 'custom'],
'unit_attr_type_pattern' => ['name' => 'unit_attr_type_pattern', 'type' => 'string', 'internal' => 'validationPattern'],
'unit_attr_type_required' => ['name' => 'unit_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' => UnitAttributeTypeL11nMapper::class,
'table' => 'unit_attr_type_l11n',
'self' => 'unit_attr_type_l11n_type',
'column' => 'content',
'external' => null,
],
'defaults' => [
'mapper' => UnitAttributeValueMapper::class,
'table' => 'unit_attr_default',
'self' => 'unit_attr_default_type',
'external' => 'unit_attr_default_value',
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'unit_attr_type';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD = 'unit_attr_type_id';
}

230
Models/UnitAttributeValue.php Executable file
View File

@ -0,0 +1,230 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\Localization\BaseStringL11n;
use phpOMS\Localization\ISO639x1Enum;
/**
* Unit attribute value class.
*
* The relation with the type/bill is defined in the UnitAttribute class.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
class UnitAttributeValue implements \JsonSerializable
{
/**
* Id
*
* @var int
* @since 1.0.0
*/
protected int $id = 0;
/**
* Depending attribute type
*
* @var null|int
* @since 1.0.0
*/
public ?int $dependingAttributeType = null;
/**
* Depending attribute value
*
* @var null|int
* @since 1.0.0
*/
public ?int $dependingAttributeValue = null;
/**
* Int value
*
* @var null|int
* @since 1.0.0
*/
public ?int $valueInt = null;
/**
* String value
*
* @var null|string
* @since 1.0.0
*/
public ?string $valueStr = null;
/**
* Decimal value
*
* @var null|float
* @since 1.0.0
*/
public ?float $valueDec = null;
/**
* DateTime value
*
* @var null|\DateTimeInterface
* @since 1.0.0
*/
public ?\DateTimeInterface $valueDat = null;
/**
* Is a default value which can be selected
*
* @var bool
* @since 1.0.0
*/
public bool $isDefault = false;
/**
* Unit of the value
*
* @var string
* @since 1.0.0
*/
public string $unit = '';
/**
* Localization
*
* @var null|BaseStringL11n
*/
private ?BaseStringL11n $l11n = null;
/**
* 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;
$this->l11n->setLanguage($lang);
} else {
$this->l11n = new BaseStringL11n();
$this->l11n->content = $l11n;
$this->l11n->ref = $this->id;
$this->l11n->setLanguage($lang);
}
}
/**
* Get localization
*
* @return null|string
*
* @since 1.0.0
*/
public function getL11n() : ?string
{
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
}
/**
* Set value
*
* @param int|string|float $value Value
* @param int $datatype Datatype
*
* @return void
*
* @since 1.0.0
*/
public function setValue(mixed $value, int $datatype) : void
{
if ($datatype === AttributeValueType::_STRING) {
$this->valueStr = (string) $value;
} elseif ($datatype === AttributeValueType::_INT
|| $datatype === AttributeValueType::_FLOAT_INT
|| $datatype === AttributeValueType::_BOOL
) {
$this->valueInt = (int) $value;
} elseif ($datatype === AttributeValueType::_FLOAT) {
$this->valueDec = (float) $value;
} elseif ($datatype === AttributeValueType::_DATETIME) {
$this->valueDat = new \DateTime((string) $value);
}
}
/**
* Get value
*
* @return null|int|string|float|\DateTimeInterface
*
* @since 1.0.0
*/
public function getValue() : mixed
{
if (!empty($this->valueStr)) {
return $this->valueStr;
} elseif (!empty($this->valueInt)) {
return $this->valueInt;
} elseif (!empty($this->valueDec)) {
return $this->valueDec;
} elseif ($this->valueDat instanceof \DateTimeInterface) {
return $this->valueDat;
}
return null;
}
/**
* {@inheritdoc}
*/
public function toArray() : array
{
return [
'id' => $this->id,
'valueInt' => $this->valueInt,
'valueStr' => $this->valueStr,
'valueDec' => $this->valueDec,
'valueDat' => $this->valueDat,
'isDefault' => $this->isDefault,
];
}
/**
* {@inheritdoc}
*/
public function jsonSerialize() : mixed
{
return $this->toArray();
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\Localization\BaseStringL11n;
/**
* Unit mapper class.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class UnitAttributeValueL11nMapper 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 = [
'unit_attr_value_l11n_id' => ['name' => 'unit_attr_value_l11n_id', 'type' => 'int', 'internal' => 'id'],
'unit_attr_value_l11n_title' => ['name' => 'unit_attr_value_l11n_title', 'type' => 'string', 'internal' => 'content', 'autocomplete' => true],
'unit_attr_value_l11n_value' => ['name' => 'unit_attr_value_l11n_value', 'type' => 'int', 'internal' => 'ref'],
'unit_attr_value_l11n_lang' => ['name' => 'unit_attr_value_l11n_lang', 'type' => 'string', 'internal' => 'language'],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'unit_attr_value_l11n';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD = 'unit_attr_value_l11n_id';
/**
* Model to use by the mapper.
*
* @var class-string
* @since 1.0.0
*/
public const MODEL = BaseStringL11n::class;
}

View File

@ -0,0 +1,77 @@
<?php
/**
* Karaka
*
* PHP Version 8.1
*
* @package Modules\Organization\Models
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\Organization\Models;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/**
* Unit mapper class.
*
* @package Modules\Organization\Models
* @license OMS License 1.0
* @link https://jingga.app
* @since 1.0.0
*/
final class UnitAttributeValueMapper 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 = [
'unit_attr_value_id' => ['name' => 'unit_attr_value_id', 'type' => 'int', 'internal' => 'id'],
'unit_attr_value_default' => ['name' => 'unit_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
'unit_attr_value_valueStr' => ['name' => 'unit_attr_value_valueStr', 'type' => 'string', 'internal' => 'valueStr'],
'unit_attr_value_valueInt' => ['name' => 'unit_attr_value_valueInt', 'type' => 'int', 'internal' => 'valueInt'],
'unit_attr_value_valueDec' => ['name' => 'unit_attr_value_valueDec', 'type' => 'float', 'internal' => 'valueDec'],
'unit_attr_value_valueDat' => ['name' => 'unit_attr_value_valueDat', 'type' => 'DateTime', 'internal' => 'valueDat'],
'unit_attr_value_unit' => ['name' => 'unit_attr_value_unit', 'type' => 'string', 'internal' => 'unit'],
'unit_attr_value_deptype' => ['name' => 'unit_attr_value_deptype', 'type' => 'int', 'internal' => 'dependingAttributeType'],
'unit_attr_value_depvalue' => ['name' => 'unit_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' => UnitAttributeValueL11nMapper::class,
'table' => 'unit_attr_value_l11n',
'self' => 'unit_attr_value_l11n_value',
'external' => null,
],
];
/**
* Primary table.
*
* @var string
* @since 1.0.0
*/
public const TABLE = 'unit_attr_value';
/**
* Primary field name.
*
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD = 'unit_attr_value_id';
}

View File

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Modules\Organization\Models;
use Modules\Admin\Models\AddressMapper;
use Modules\Media\Models\MediaMapper;
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
@ -41,6 +42,29 @@ final class UnitMapper extends DataMapperFactory
'unit_descriptionraw' => ['name' => 'unit_descriptionraw', 'type' => 'string', 'internal' => 'descriptionRaw'],
'unit_parent' => ['name' => 'unit_parent', 'type' => 'int', 'internal' => 'parent'],
'unit_status' => ['name' => 'unit_status', 'type' => 'int', 'internal' => 'status'],
'unit_address' => ['name' => 'unit_address', 'type' => 'int', 'internal' => 'mainAddress'],
];
/**
* 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 = [
'address' => [
'mapper' => AddressMapper::class,
'table' => 'unit_address_rel',
'external' => 'unit_address_rel_address',
'self' => 'unit_address_rel_unit',
],
'attributes' => [
'mapper' => UnitAttributeMapper::class,
'table' => 'unit_attr',
'self' => 'unit_attr_unit',
'conditional' => true,
'external' => null,
],
];
/**
@ -50,6 +74,10 @@ final class UnitMapper extends DataMapperFactory
* @since 1.0.0
*/
public const OWNS_ONE = [
'mainAddress' => [
'mapper' => AddressMapper::class,
'external' => 'unit_address',
],
'image' => [
'mapper' => MediaMapper::class,
'external' => 'unit_image',
@ -91,5 +119,5 @@ final class UnitMapper extends DataMapperFactory
* @var string
* @since 1.0.0
*/
public const PRIMARYFIELD ='unit_id';
public const PRIMARYFIELD = 'unit_id';
}

View File

@ -28,5 +28,11 @@ return ['Organization' => [
'Unit' => 'Unit',
'UnitLogo' => 'Unit Logo',
'Units' => 'Units',
'LegalName' => 'Legal Name',
'Address' => 'Address',
'Postal' => 'Postal',
'City' => 'City',
'Country' => 'Country',
'MainAddress' => 'Main Address',
'IMG_alt_profile' => 'Unit image',
]];

View File

@ -13,34 +13,42 @@
declare(strict_types=1);
use Modules\Organization\Models\Status;
use phpOMS\Localization\ISO3166NameEnum;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Uri\UriFactory;
$countryCodes = ISO3166TwoEnum::getConstants();
$countries = ISO3166NameEnum::getConstants();
/** @var \phpOMS\Views\View $this */
echo $this->getData('nav')->render(); ?>
<form id="fUnitCreate" method="put" action="<?= UriFactory::build('{/api}organization/unit'); ?>">
<div class="row">
<div class="col-xs-12 col-md-6">
<div class="portlet">
<form id="fUnitCreate" method="put" action="<?= UriFactory::build('{/api}organization/unit'); ?>">
<div class="portlet-head"><?= $this->getHtml('Unit'); ?></div>
<div class="portlet-body">
<table class="layout wf-100" style="table-layout: fixed">
<tr><td><label for="iName"><?= $this->getHtml('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" placeholder="&#xf040; Karaka" required>
<tr><td><label for="iParent"><?= $this->getHtml('UnitLogo'); ?></label>
<tr><td><img id="preview-logo" alt="<?= $this->getHtml('Logo'); ?>"
itemprop="logo" loading="lazy" width="40x" class="preview" src="<?= UriFactory::build('Modules/Organization/Theme/Backend/img/org_default.png'); ?>" accept="image/*">
<tr><td><?= $this->getData('media-preview-upload')->render('fUnitCreate', 'logo', '/Modules/Organization'); ?>
<tr><td><label for="iParent"><?= $this->getHtml('Parent'); ?></label>
<tr><td><?= $this->getData('unit-selector')->render('iParent', 'parent', false); ?>
<tr><td><label for="iStatus"><?= $this->getHtml('Status'); ?></label>
<tr><td><select name="status" id="iStatus">
<option value="<?= Status::ACTIVE; ?>"><?= $this->getHtml('Active'); ?>
<option value="<?= Status::INACTIVE; ?>"><?= $this->getHtml('Inactive'); ?>
</select>
<tr><td><?= $this->getData('editor')->render('unit-editor'); ?>
<tr><td><?= $this->getData('editor')->getData('text')->render('unit-editor', 'description', 'fUnitCreate'); ?>
</table>
<div class="form-group">
<label for="iName"><?= $this->getHtml('Name'); ?></label>
<input type="text" name="name" id="iName" value="">
</div>
<div class="form-group">
<label for="iParent"><?= $this->getHtml('Parent'); ?></label>
<?= $this->getData('unit-selector')->render('iParent', 'parent', false); ?>
</div>
<div class="form-group">
<label for="iStatus"><?= $this->getHtml('Status'); ?></label>
<select name="status" id="iStatus">
<option value="<?= Status::ACTIVE; ?>"><?= $this->getHtml('Active'); ?>
<option value="<?= Status::INACTIVE; ?>"><?= $this->getHtml('Inactive'); ?>
</select>
</div>
<?= $this->getData('editor')->render('unit-editor'); ?>
<?= $this->getData('editor')->getData('text')->render('unit-editor', 'description', 'fUnitCreate'); ?>
</div>
<div class="portlet-foot">
<input id="iSubmit" name="submit" type="submit" value="<?= $this->getHtml('Create', '0', '0'); ?>">
@ -48,6 +56,48 @@ echo $this->getData('nav')->render(); ?>
</form>
</div>
</div>
</div>
<div class="col-xs-12 col-md-6">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('MainAddress'); ?></div>
<div class="portlet-body">
<div class="form-group">
<label for="iLegalName"><?= $this->getHtml('LegalName'); ?></label>
<input type="text" name="legal" id="iLegalName" value="">
</div>
<div class="form-group">
<label for="iAddress"><?= $this->getHtml('Address'); ?></label>
<input type="text" name="address" id="iAddress" value="">
</div>
<div class="form-group">
<label for="iPostal"><?= $this->getHtml('Postal'); ?></label>
<input type="text" name="postal" id="iPostal" value="">
</div>
<div class="form-group">
<label for="iCity"><?= $this->getHtml('City'); ?></label>
<input type="text" name="city" id="iCity" value="">
</div>
<div class="form-group">
<label for="iCountry"><?= $this->getHtml('Country'); ?></label>
<select id="iCountry" name="country">
<option disabled selected><?= $this->getHtml('PleaseSelect', '0', '0'); ?>
<?php
foreach ($countryCodes as $code3 => $code2) :
?>
<option value="<?= $this->printHtml($code2); ?>">
<?= $this->printHtml($countries[$code3]); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
</div>
</div>
</div>
</form>
<?= $this->getData('unit-selector')->getData('unit-selector-popup')->render(); ?>

View File

@ -14,6 +14,8 @@ declare(strict_types=1);
use Modules\Media\Models\NullMedia;
use Modules\Organization\Models\Status;
use phpOMS\Localization\ISO3166NameEnum;
use phpOMS\Localization\ISO3166TwoEnum;
use phpOMS\Uri\UriFactory;
/**
@ -22,6 +24,9 @@ use phpOMS\Uri\UriFactory;
*/
$unit = $this->getData('unit');
$countryCodes = ISO3166TwoEnum::getConstants();
$countries = ISO3166NameEnum::getConstants();
echo $this->getData('nav')->render(); ?>
<form id="iUnitUploadForm" action="<?= UriFactory::build('{/api}organization/unit/image?id={?id}'); ?>" method="post"><input class="preview" data-action='[{"listener": "change", "key": 1, "action": [{"key": 1, "type": "form.submit", "selector": "#iUnitUploadForm"}]}]' id="iUnitUpload" name="unitImage" type="file" accept="image/png,image/gif,image/jpeg" style="display: none;"></form>
@ -46,25 +51,83 @@ echo $this->getData('nav')->render(); ?>
<div><?= $this->getHtml('Unit'); ?></div>
</div>
<div class="portlet-body">
<table class="layout wf-100" style="table-layout: fixed">
<tr><td><label for="iName"><?= $this->getHtml('Name'); ?></label>
<tr><td><input type="text" name="name" id="iName" value="<?= $this->printHtml($unit->name); ?>">
<tr><td><label for="iParent"><?= $this->getHtml('Parent'); ?></label>
<tr><td><?= $this->getData('unit-selector')->render('iParent', 'parent', false); ?>
<tr><td><label for="iStatus"><?= $this->getHtml('Status'); ?></label>
<tr><td><select name="status" id="iStatus">
<option value="<?= Status::ACTIVE; ?>"<?= $unit->getStatus() === Status::ACTIVE ? ' selected' : ''; ?>><?= $this->getHtml('Active'); ?>
<option value="<?= Status::INACTIVE; ?>"<?= $unit->getStatus() === Status::INACTIVE ? ' selected' : ''; ?>><?= $this->getHtml('Inactive'); ?>
</select>
<tr><td><?= $this->getData('editor')->render('unit-editor'); ?>
<tr><td><?= $this->getData('editor')->getData('text')->render(
'unit-editor',
'description',
'iUnit',
$unit->descriptionRaw,
$unit->description
); ?>
</table>
<div class="form-group">
<label for="iName"><?= $this->getHtml('Name'); ?></label>
<input type="text" name="name" id="iName" value="<?= $this->printHtml($unit->name); ?>">
</div>
<div class="form-group">
<label for="iParent"><?= $this->getHtml('Parent'); ?></label>
<?= $this->getData('unit-selector')->render('iParent', 'parent', false); ?>
</div>
<div class="form-group">
<label for="iStatus"><?= $this->getHtml('Status'); ?></label>
<select name="status" id="iStatus">
<option value="<?= Status::ACTIVE; ?>"<?= $unit->getStatus() === Status::ACTIVE ? ' selected' : ''; ?>><?= $this->getHtml('Active'); ?>
<option value="<?= Status::INACTIVE; ?>"<?= $unit->getStatus() === Status::INACTIVE ? ' selected' : ''; ?>><?= $this->getHtml('Inactive'); ?>
</select>
</div>
<?= $this->getData('editor')->render('unit-editor'); ?>
<?= $this->getData('editor')->getData('text')->render(
'unit-editor',
'description',
'iUnit',
$unit->descriptionRaw,
$unit->description
); ?>
</div>
<div class="portlet-foot">
<input id="iUnitId" name="id" type="hidden" value="<?= (int) $unit->getId(); ?>">
<input id="iSubmit" name="submit" type="submit" value="<?= $this->getHtml('Save', '0', '0'); ?>">
</div>
</form>
</div>
</div>
<div class="col-xs-12 col-md-6">
<div class="portlet">
<div class="portlet-head"><?= $this->getHtml('MainAddress'); ?></div>
<form id="iUnitMainAdress" action="<?= UriFactory::build('{/api}organization/unit/address/main'); ?>" method="post">
<div class="portlet-body">
<div class="form-group">
<label for="iLegalName"><?= $this->getHtml('LegalName'); ?></label>
<input type="text" name="legal" id="iLegalName" value="<?= $this->printHtml($unit->mainAddress->name); ?>">
</div>
<div class="form-group">
<label for="iAddress"><?= $this->getHtml('Address'); ?></label>
<input type="text" name="address" id="iAddress" value="<?= $this->printHtml($unit->mainAddress->address); ?>">
</div>
<div class="form-group">
<label for="iPostal"><?= $this->getHtml('Postal'); ?></label>
<input type="text" name="postal" id="iPostal" value="<?= $this->printHtml($unit->mainAddress->postal); ?>">
</div>
<div class="form-group">
<label for="iCity"><?= $this->getHtml('City'); ?></label>
<input type="text" name="city" id="iCity" value="<?= $this->printHtml($unit->mainAddress->city); ?>">
</div>
<div class="form-group">
<label for="iCountry"><?= $this->getHtml('Country'); ?></label>
<select id="iCountry" name="country">
<?php
$selected = false;
foreach ($countryCodes as $code3 => $code2) :
if ($code2 === $unit->mainAddress->getCountry()) {
$selected = true;
}
?>
<option value="<?= $this->printHtml($code2); ?>"<?= $code2 === $unit->mainAddress->getCountry() ? ' selected' : ''; ?>>
<?= $this->printHtml($countries[$code3]); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="portlet-foot">
<input id="iUnitId" name="id" type="hidden" value="<?= (int) $unit->getId(); ?>">

View File

@ -1,6 +1,6 @@
{
"name": "karaka/module",
"description": "Module for Karaka.",
"description": "Module for Jingga.",
"authors": [
{
"name": "Dennis Eichhorn",

View File

@ -11,7 +11,7 @@
"phpOMS-db": "1.0.0"
},
"creator": {
"name": "Karaka",
"name": "Jingga",
"website": "jingga.app"
},
"description": "The business module.",