mirror of
https://github.com/Karaka-Management/oms-SupplierManagement.git
synced 2026-01-11 17:28:41 +00:00
phpstan, phpcs, phpunit fixes
This commit is contained in:
parent
620ca0ec5b
commit
781f96a5e8
|
|
@ -64,6 +64,66 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"suppliermgmt_supplier_l11n_type": {
|
||||
"name": "suppliermgmt_supplier_l11n_type",
|
||||
"fields": {
|
||||
"suppliermgmt_supplier_l11n_type_id": {
|
||||
"name": "suppliermgmt_supplier_l11n_type_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"suppliermgmt_supplier_l11n_type_title": {
|
||||
"name": "suppliermgmt_supplier_l11n_type_title",
|
||||
"type": "VARCHAR(50)",
|
||||
"null": false
|
||||
},
|
||||
"suppliermgmt_supplier_l11n_type_required": {
|
||||
"name": "suppliermgmt_supplier_l11n_type_required",
|
||||
"type": "TINYINT(1)",
|
||||
"null": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"suppliermgmt_supplier_l11n": {
|
||||
"name": "suppliermgmt_supplier_l11n",
|
||||
"fields": {
|
||||
"suppliermgmt_supplier_l11n_id": {
|
||||
"name": "suppliermgmt_supplier_l11n_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"suppliermgmt_supplier_l11n_description": {
|
||||
"name": "suppliermgmt_supplier_l11n_description",
|
||||
"type": "TEXT",
|
||||
"null": false
|
||||
},
|
||||
"suppliermgmt_supplier_l11n_supplier": {
|
||||
"name": "suppliermgmt_supplier_l11n_supplier",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "suppliermgmt_supplier",
|
||||
"foreignKey": "suppliermgmt_supplier_id"
|
||||
},
|
||||
"suppliermgmt_supplier_l11n_typeref": {
|
||||
"name": "suppliermgmt_supplier_l11n_typeref",
|
||||
"type": "INT(11)",
|
||||
"null": false,
|
||||
"foreignTable": "suppliermgmt_supplier_l11n_type",
|
||||
"foreignKey": "suppliermgmt_supplier_l11n_type_id"
|
||||
},
|
||||
"suppliermgmt_supplier_l11n_lang": {
|
||||
"name": "suppliermgmt_supplier_l11n_lang",
|
||||
"type": "VARCHAR(2)",
|
||||
"null": false,
|
||||
"foreignTable": "language",
|
||||
"foreignKey": "language_639_1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"suppliermgmt_supplier_contactelement": {
|
||||
"name": "suppliermgmt_supplier_contactelement",
|
||||
"fields": {
|
||||
|
|
|
|||
|
|
@ -176,9 +176,9 @@ final class Installer extends InstallerAbstract
|
|||
/**
|
||||
* Create default attribute values for types
|
||||
*
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param ApplicationAbstract $app Application
|
||||
* @param array $supplierAttrType 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
|
||||
* @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>
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,11 +16,13 @@ namespace Modules\SupplierManagement\Controller;
|
|||
|
||||
use Modules\Admin\Models\Account;
|
||||
use Modules\Admin\Models\Address;
|
||||
use Modules\Media\Models\MediaMapper;
|
||||
use Modules\Media\Models\PathSettings;
|
||||
use Modules\Profile\Models\ContactElementMapper;
|
||||
use Modules\Profile\Models\Profile;
|
||||
use Modules\SupplierManagement\Models\NullSupplierAttributeType;
|
||||
use Modules\SupplierManagement\Models\NullSupplierAttributeValue;
|
||||
use Modules\SupplierManagement\Models\NullSupplierL11nType;
|
||||
use Modules\SupplierManagement\Models\Supplier;
|
||||
use Modules\SupplierManagement\Models\SupplierAttribute;
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeMapper;
|
||||
|
|
@ -28,7 +30,12 @@ use Modules\SupplierManagement\Models\SupplierAttributeType;
|
|||
use Modules\SupplierManagement\Models\SupplierAttributeTypeL11nMapper;
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeTypeMapper;
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeValue;
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeValueL11nMapper;
|
||||
use Modules\SupplierManagement\Models\SupplierAttributeValueMapper;
|
||||
use Modules\SupplierManagement\Models\SupplierL11n;
|
||||
use Modules\SupplierManagement\Models\SupplierL11nMapper;
|
||||
use Modules\SupplierManagement\Models\SupplierL11nType;
|
||||
use Modules\SupplierManagement\Models\SupplierL11nTypeMapper;
|
||||
use Modules\SupplierManagement\Models\SupplierMapper;
|
||||
use phpOMS\Localization\BaseStringL11n;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
|
@ -131,7 +138,7 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Routing end-point for application behaviour.
|
||||
* Api method to create supplier l11n
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
|
|
@ -143,27 +150,126 @@ final class ApiController extends Controller
|
|||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiContactElementCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
public function apiSupplierL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
/** @var \Modules\Profile\Controller\ApiController $profileModule */
|
||||
$profileModule = $this->app->moduleManager->get('Profile');
|
||||
|
||||
if (!empty($val = $profileModule->validateContactElementCreate($request))) {
|
||||
$response->set('contact_element_create', new FormValidation($val));
|
||||
if (!empty($val = $this->validateSupplierL11nCreate($request))) {
|
||||
$response->set('supplier_l11n_create', new FormValidation($val));
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$contactElement = $profileModule->createContactElementFromRequest($request);
|
||||
$supplierL11n = $this->createSupplierL11nFromRequest($request);
|
||||
$this->createModel($request->header->account, $supplierL11n, SupplierL11nMapper::class, 'supplier_l11n', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Supplier localization', 'Supplier localization successfully created', $supplierL11n);
|
||||
}
|
||||
|
||||
$this->createModel($request->header->account, $contactElement, ContactElementMapper::class, 'supplier-contactElement', $request->getOrigin());
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
(int) $request->getData('account'),
|
||||
$contactElement->getId(),
|
||||
SupplierMapper::class, 'contactElements', '', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Contact Element', 'Contact element successfully created', $contactElement);
|
||||
/**
|
||||
* Method to create supplier l11n from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return SupplierL11n
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createSupplierL11nFromRequest(RequestAbstract $request) : SupplierL11n
|
||||
{
|
||||
$supplierL11n = new SupplierL11n();
|
||||
$supplierL11n->supplier = (int) ($request->getData('supplier') ?? 0);
|
||||
$supplierL11n->type = new NullSupplierL11nType((int) ($request->getData('type') ?? 0));
|
||||
$supplierL11n->setLanguage((string) (
|
||||
$request->getData('language') ?? $request->getLanguage()
|
||||
));
|
||||
$supplierL11n->description = (string) ($request->getData('description') ?? '');
|
||||
|
||||
return $supplierL11n;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate supplier l11n create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateSupplierL11nCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['supplier'] = empty($request->getData('supplier')))
|
||||
|| ($val['type'] = empty($request->getData('type')))
|
||||
|| ($val['description'] = empty($request->getData('description')))
|
||||
) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to create supplier l11n type
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
* @param ResponseAbstract $response Response
|
||||
* @param mixed $data Generic data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function apiSupplierL11nTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void
|
||||
{
|
||||
if (!empty($val = $this->validateSupplierL11nTypeCreate($request))) {
|
||||
$response->set('supplier_l11n_type_create', new FormValidation($val));
|
||||
$response->header->status = RequestStatusCode::R_400;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$supplierL11nType = $this->createSupplierL11nTypeFromRequest($request);
|
||||
$this->createModel($request->header->account, $supplierL11nType, SupplierL11nTypeMapper::class, 'supplier_l11n_type', $request->getOrigin());
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Supplier localization type', 'Supplier localization type successfully created', $supplierL11nType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create supplier l11n type from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return SupplierL11nType
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createSupplierL11nTypeFromRequest(RequestAbstract $request) : SupplierL11nType
|
||||
{
|
||||
$supplierL11nType = new SupplierL11nType();
|
||||
$supplierL11nType->title = (string) ($request->getData('title') ?? '');
|
||||
$supplierL11nType->isRequired = (bool) ($request->getData('is_required') ?? false);
|
||||
|
||||
return $supplierL11nType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate supplier l11n type create request
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return array<string, bool>
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function validateSupplierL11nTypeCreate(RequestAbstract $request) : array
|
||||
{
|
||||
$val = [];
|
||||
if (($val['title'] = empty($request->getData('title')))) {
|
||||
return $val;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -272,8 +378,8 @@ final class ApiController extends Controller
|
|||
*/
|
||||
private function createSupplierAttributeTypeL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = (int) ($request->getData('type') ?? 0);
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = (int) ($request->getData('type') ?? 0);
|
||||
$attrL11n->setLanguage((string) (
|
||||
$request->getData('language') ?? $request->getLanguage()
|
||||
));
|
||||
|
|
@ -342,13 +448,13 @@ final class ApiController extends Controller
|
|||
*/
|
||||
private function createSupplierAttributeTypeFromRequest(RequestAbstract $request) : SupplierAttributeType
|
||||
{
|
||||
$attrType = new SupplierAttributeType($request->getData('name') ?? '');
|
||||
$attrType->setL11n((string) ($request->getData('title') ?? ''), $request->getData('language') ?? ISO639x1Enum::_EN);
|
||||
$attrType->datatype = (int) ($request->getData('datatype') ?? 0);
|
||||
$attrType->setFields((int) ($request->getData('fields') ?? 0));
|
||||
$attrType = new SupplierAttributeType($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;
|
||||
}
|
||||
|
|
@ -422,6 +528,7 @@ final class ApiController extends Controller
|
|||
*/
|
||||
private function createSupplierAttributeValueFromRequest(RequestAbstract $request) : SupplierAttributeValue
|
||||
{
|
||||
/** @var SupplierAttributeType $type */
|
||||
$type = SupplierAttributeTypeMapper::get()
|
||||
->where('id', (int) ($request->getData('type') ?? 0))
|
||||
->execute();
|
||||
|
|
@ -496,8 +603,8 @@ final class ApiController extends Controller
|
|||
*/
|
||||
private function createSupplierAttributeValueL11nFromRequest(RequestAbstract $request) : BaseStringL11n
|
||||
{
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = (int) ($request->getData('value') ?? 0);
|
||||
$attrL11n = new BaseStringL11n();
|
||||
$attrL11n->ref = (int) ($request->getData('value') ?? 0);
|
||||
$attrL11n->setLanguage((string) (
|
||||
$request->getData('language') ?? $request->getLanguage()
|
||||
));
|
||||
|
|
@ -552,16 +659,29 @@ final class ApiController extends Controller
|
|||
}
|
||||
|
||||
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
|
||||
$request->getDataList('names'),
|
||||
$request->getDataList('filenames'),
|
||||
$uploadedFiles,
|
||||
$request->header->account,
|
||||
__DIR__ . '/../../../Modules/Media/Files/Modules/SupplierManagement/' . ($request->getData('supplier') ?? '0'),
|
||||
'/Modules/SupplierManagement/' . ($request->getData('supplier') ?? '0'),
|
||||
$request->getData('type', 'int'),
|
||||
names: $request->getDataList('names'),
|
||||
fileNames: $request->getDataList('filenames'),
|
||||
files: $uploadedFiles,
|
||||
account: $request->header->account,
|
||||
basePath: __DIR__ . '/../../../Modules/Media/Files/Modules/SupplierManagement/' . ($request->getData('supplier') ?? '0'),
|
||||
virtualPath: '/Modules/SupplierManagement/' . ($request->getData('supplier') ?? '0'),
|
||||
pathSettings: PathSettings::FILE_PATH
|
||||
);
|
||||
|
||||
if ($request->hasData('type')) {
|
||||
foreach ($uploaded as $file) {
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
$file->getId(),
|
||||
$request->getData('type', 'int'),
|
||||
MediaMapper::class,
|
||||
'types',
|
||||
'',
|
||||
$request->getOrigin()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->createModelRelation(
|
||||
$request->header->account,
|
||||
(int) $request->getData('supplier'),
|
||||
|
|
|
|||
47
Models/NullSupplierL11n.php
Executable file
47
Models/NullSupplierL11n.php
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\SupplierManagement\Models;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullSupplierL11n extends SupplierL11n
|
||||
{
|
||||
/**
|
||||
* 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];
|
||||
}
|
||||
}
|
||||
46
Models/NullSupplierL11nType.php
Executable file
46
Models/NullSupplierL11nType.php
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\SupplierManagement\Models;
|
||||
|
||||
/**
|
||||
* Null model
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class NullSupplierL11nType extends SupplierL11nType
|
||||
{
|
||||
/**
|
||||
* 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];
|
||||
}
|
||||
}
|
||||
|
|
@ -72,6 +72,12 @@ class Supplier
|
|||
*/
|
||||
private array $notes = [];
|
||||
|
||||
/**
|
||||
* Files.
|
||||
*
|
||||
* @var Media[]
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private array $files = [];
|
||||
|
||||
private array $contactElements = [];
|
||||
|
|
@ -192,18 +198,6 @@ class Supplier
|
|||
return $this->notes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get media.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getFiles() : array
|
||||
{
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add media.
|
||||
*
|
||||
|
|
@ -346,28 +340,19 @@ class Supplier
|
|||
}
|
||||
|
||||
/**
|
||||
* Get all media files by type
|
||||
*
|
||||
* @param null|int $type Media type
|
||||
* Get files
|
||||
*
|
||||
* @return Media[]
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getFilesByType(int $type = null) : array
|
||||
public function getFiles() : array
|
||||
{
|
||||
$files = [];
|
||||
foreach ($this->files as $file) {
|
||||
if ($file->type === $type) {
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
return $this->files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all media files by type
|
||||
* Get media file by type
|
||||
*
|
||||
* @param int $type Media type
|
||||
*
|
||||
|
|
@ -378,7 +363,7 @@ class Supplier
|
|||
public function getFileByType(int $type) : Media
|
||||
{
|
||||
foreach ($this->files as $file) {
|
||||
if ($file->type === $type) {
|
||||
if ($file->hasMediaTypeId($type)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
|
@ -398,7 +383,7 @@ class Supplier
|
|||
public function getFileByTypeName(string $type) : Media
|
||||
{
|
||||
foreach ($this->files as $file) {
|
||||
if ($file->type->name === $type) {
|
||||
if ($file->hasMediaTypeName($type)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ final class SupplierAttributeMapper extends DataMapperFactory
|
|||
/**
|
||||
* Has one relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const OWNS_ONE = [
|
||||
|
|
|
|||
|
|
@ -124,7 +124,8 @@ class SupplierAttributeType implements \JsonSerializable
|
|||
if ($l11n instanceof BaseStringL11n) {
|
||||
$this->l11n = $l11n;
|
||||
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
|
||||
$this->l11n->content = $l11n;
|
||||
$this->l11n->content = $l11n;
|
||||
$this->l11n->setLanguage($lang);
|
||||
} else {
|
||||
$this->l11n = new BaseStringL11n();
|
||||
$this->l11n->content = $l11n;
|
||||
|
|
@ -139,6 +140,10 @@ class SupplierAttributeType implements \JsonSerializable
|
|||
*/
|
||||
public function getL11n() : string
|
||||
{
|
||||
if (!isset($this->l11n)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ final class SupplierAttributeTypeL11nMapper extends DataMapperFactory
|
|||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var string
|
||||
* @var class-string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = BaseStringL11n::class;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ final class SupplierAttributeTypeMapper extends DataMapperFactory
|
|||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const HAS_MANY = [
|
||||
|
|
|
|||
|
|
@ -136,7 +136,8 @@ class SupplierAttributeValue implements \JsonSerializable
|
|||
if ($l11n instanceof BaseStringL11n) {
|
||||
$this->l11n = $l11n;
|
||||
} elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) {
|
||||
$this->l11n->content = $l11n;
|
||||
$this->l11n->content = $l11n;
|
||||
$this->l11n->setLanguage($lang);
|
||||
} else {
|
||||
$this->l11n = new BaseStringL11n();
|
||||
$this->l11n->content = $l11n;
|
||||
|
|
@ -160,8 +161,8 @@ class SupplierAttributeValue implements \JsonSerializable
|
|||
/**
|
||||
* Set value
|
||||
*
|
||||
* @param int|string|float|\DateTimeInterface $value Value
|
||||
* @param int $type Datatype
|
||||
* @param int|string|float $value Value
|
||||
* @param int $datatype Datatype
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
|
|
@ -179,7 +180,7 @@ class SupplierAttributeValue implements \JsonSerializable
|
|||
} elseif ($datatype === AttributeValueType::_FLOAT) {
|
||||
$this->valueDec = (float) $value;
|
||||
} elseif ($datatype === AttributeValueType::_DATETIME) {
|
||||
$this->valueDat = new \DateTime($value);
|
||||
$this->valueDat = new \DateTime((string) $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ final class SupplierAttributeValueL11nMapper extends DataMapperFactory
|
|||
/**
|
||||
* Model to use by the mapper.
|
||||
*
|
||||
* @var string
|
||||
* @var class-string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const MODEL = BaseStringL11n::class;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ final class SupplierAttributeValueMapper extends DataMapperFactory
|
|||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const HAS_MANY = [
|
||||
|
|
|
|||
143
Models/SupplierL11n.php
Executable file
143
Models/SupplierL11n.php
Executable file
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\SupplierManagement\Models;
|
||||
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* Localization of the supplier class.
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SupplierL11n implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Article ID.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Supplier ID.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public int $supplier = 0;
|
||||
|
||||
/**
|
||||
* Supplier ID.
|
||||
*
|
||||
* @var SupplierL11nType
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public SupplierL11nType $type;
|
||||
|
||||
/**
|
||||
* Language.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected string $language = ISO639x1Enum::_EN;
|
||||
|
||||
/**
|
||||
* Title.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $description = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param SupplierL11nType $type Supplier localization type
|
||||
* @param string $description Description/content
|
||||
* @param string $language Language
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(SupplierL11nType $type = null, string $description = '', string $language = ISO639x1Enum::_EN)
|
||||
{
|
||||
$this->type = $type ?? new SupplierL11nType();
|
||||
$this->description = $description;
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getId() : int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getLanguage() : string
|
||||
{
|
||||
return $this->language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set language
|
||||
*
|
||||
* @param string $language Language
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setLanguage(string $language) : void
|
||||
{
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'description' => $this->description,
|
||||
'supplier' => $this->supplier,
|
||||
'language' => $this->language,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
71
Models/SupplierL11nMapper.php
Executable file
71
Models/SupplierL11nMapper.php
Executable file
|
|
@ -0,0 +1,71 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\SupplierManagement\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Supplier mapper class.
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class SupplierL11nMapper 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 = [
|
||||
'suppliermgmt_supplier_l11n_id' => ['name' => 'suppliermgmt_supplier_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'suppliermgmt_supplier_l11n_description' => ['name' => 'suppliermgmt_supplier_l11n_description', 'type' => 'string', 'internal' => 'description', 'autocomplete' => true],
|
||||
'suppliermgmt_supplier_l11n_supplier' => ['name' => 'suppliermgmt_supplier_l11n_supplier', 'type' => 'int', 'internal' => 'supplier'],
|
||||
'suppliermgmt_supplier_l11n_lang' => ['name' => 'suppliermgmt_supplier_l11n_lang', 'type' => 'string', 'internal' => 'language'],
|
||||
'suppliermgmt_supplier_l11n_typeref' => ['name' => 'suppliermgmt_supplier_l11n_typeref', 'type' => 'int', 'internal' => 'type'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has one relation.
|
||||
*
|
||||
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const OWNS_ONE = [
|
||||
'type' => [
|
||||
'mapper' => SupplierL11nTypeMapper::class,
|
||||
'external' => 'suppliermgmt_supplier_l11n_typeref',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'suppliermgmt_supplier_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD ='suppliermgmt_supplier_l11n_id';
|
||||
}
|
||||
93
Models/SupplierL11nType.php
Executable file
93
Models/SupplierL11nType.php
Executable file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\SupplierManagement\Models;
|
||||
|
||||
/**
|
||||
* Supplier class.
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class SupplierL11nType implements \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Article ID.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Identifier for the l11n type.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public string $title = '';
|
||||
|
||||
/**
|
||||
* Is the l11n type required for an item?
|
||||
*
|
||||
* @var bool
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public bool $isRequired = false;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $title Title
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function __construct(string $title = '')
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getId() : int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize() : mixed
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
56
Models/SupplierL11nTypeMapper.php
Executable file
56
Models/SupplierL11nTypeMapper.php
Executable file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
/**
|
||||
* Karaka
|
||||
*
|
||||
* PHP Version 8.1
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://jingga.app
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\SupplierManagement\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
|
||||
/**
|
||||
* Supplier mapper class.
|
||||
*
|
||||
* @package Modules\SupplierManagement\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://jingga.app
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class SupplierL11nTypeMapper 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 = [
|
||||
'suppliermgmt_supplier_l11n_type_id' => ['name' => 'suppliermgmt_supplier_l11n_type_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'suppliermgmt_supplier_l11n_type_title' => ['name' => 'suppliermgmt_supplier_l11n_type_title', 'type' => 'string', 'internal' => 'title'],
|
||||
'suppliermgmt_supplier_l11n_type_required' => ['name' => 'suppliermgmt_supplier_l11n_type_required', 'type' => 'bool', 'internal' => 'isRequired'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const TABLE = 'suppliermgmt_supplier_l11n_type';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const PRIMARYFIELD ='suppliermgmt_supplier_l11n_type_id';
|
||||
}
|
||||
|
|
@ -77,7 +77,7 @@ final class SupplierMapper extends DataMapperFactory
|
|||
/**
|
||||
* Has one relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @var array<string, array{mapper:class-string, external:string, by?:string, column?:string, conditional?:bool}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const OWNS_ONE = [
|
||||
|
|
@ -94,7 +94,7 @@ final class SupplierMapper extends DataMapperFactory
|
|||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @var array<string, array{mapper:class-string, table:string, self?:?string, external?:?string, column?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public const HAS_MANY = [
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ trait ApiControllerAttributeTrait
|
|||
|
||||
$request->header->account = 1;
|
||||
$request->setData('title', 'EN:1');
|
||||
$request->setData('name', 'test_name');
|
||||
$request->setData('language', ISO639x1Enum::_EN);
|
||||
|
||||
$this->module->apiSupplierAttributeTypeCreate($request, $response);
|
||||
|
|
@ -69,7 +70,7 @@ trait ApiControllerAttributeTrait
|
|||
|
||||
$request->header->account = 1;
|
||||
$request->setData('default', '1');
|
||||
$request->setData('attributetype', '1');
|
||||
$request->setData('type', '1');
|
||||
$request->setData('value', '1');
|
||||
$request->setData('language', ISO639x1Enum::_DE);
|
||||
$request->setData('country', ISO3166TwoEnum::_DEU);
|
||||
|
|
@ -89,7 +90,7 @@ trait ApiControllerAttributeTrait
|
|||
|
||||
$request->header->account = 1;
|
||||
$request->setData('value', '1');
|
||||
$request->setData('attributetype', '1');
|
||||
$request->setData('type', '1');
|
||||
$request->setData('language', ISO639x1Enum::_DE);
|
||||
$request->setData('country', ISO3166TwoEnum::_DEU);
|
||||
|
||||
|
|
@ -108,7 +109,7 @@ trait ApiControllerAttributeTrait
|
|||
|
||||
$request->header->account = 1;
|
||||
$request->setData('value', '1.1');
|
||||
$request->setData('attributetype', '1');
|
||||
$request->setData('type', '1');
|
||||
$request->setData('language', ISO639x1Enum::_DE);
|
||||
$request->setData('country', ISO3166TwoEnum::_DEU);
|
||||
|
||||
|
|
@ -127,7 +128,7 @@ trait ApiControllerAttributeTrait
|
|||
|
||||
$request->header->account = 1;
|
||||
$request->setData('value', '2020-08-02');
|
||||
$request->setData('attributetype', '1');
|
||||
$request->setData('type', '1');
|
||||
$request->setData('language', ISO639x1Enum::_DE);
|
||||
$request->setData('country', ISO3166TwoEnum::_DEU);
|
||||
|
||||
|
|
|
|||
|
|
@ -59,41 +59,6 @@ trait ApiControllerSupplierTrait
|
|||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiSupplierContactElementCreate() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('account', '1'); // supplier id in this case
|
||||
$request->setData('type', ContactType::EMAIL);
|
||||
$request->setData('content', 'email@email.com');
|
||||
|
||||
$this->module->apiContactElementCreate($request, $response);
|
||||
|
||||
self::assertGreaterThan(0, $response->get('')['response']->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Controller\ApiController
|
||||
* @group module
|
||||
*/
|
||||
public function testApiSupplierContactElementCreateInvalidData() : void
|
||||
{
|
||||
$response = new HttpResponse();
|
||||
$request = new HttpRequest(new HttpUri(''));
|
||||
|
||||
$request->header->account = 1;
|
||||
$request->setData('invalid', '1');
|
||||
|
||||
$this->module->apiContactElementCreate($request, $response);
|
||||
self::assertEquals(RequestStatusCode::R_400, $response->header->status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Modules\SupplierManagement\Controller\ApiController
|
||||
* @group module
|
||||
|
|
@ -124,7 +89,7 @@ trait ApiControllerSupplierTrait
|
|||
$request->header->account = 1;
|
||||
$request->setData('name', '123456 backend');
|
||||
$request->setData('supplier', 1);
|
||||
$request->setData('type', 'backend_image');
|
||||
$request->setData('type', '1');
|
||||
|
||||
TestUtils::setMember($request, 'files', [
|
||||
'file1' => [
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ final class SupplierTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals([], $this->supplier->getFiles());
|
||||
self::assertEquals([], $this->supplier->getAddresses());
|
||||
self::assertEquals([], $this->supplier->getContactElements());
|
||||
self::assertEquals([], $this->supplier->getFilesByType(0));
|
||||
self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->supplier->createdAt->format('Y-m-d'));
|
||||
self::assertInstanceOf('\Modules\Profile\Models\Profile', $this->supplier->profile);
|
||||
self::assertInstanceOf('\Modules\Admin\Models\Address', $this->supplier->mainAddress);
|
||||
|
|
@ -86,7 +85,6 @@ final class SupplierTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$this->supplier->addFile($temp = new Media());
|
||||
self::assertCount(1, $this->supplier->getFiles());
|
||||
self::assertEquals([$temp], $this->supplier->getFilesByType());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user