From a710da7d2a3e336783695c6171d3488f98eb637f Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 29 Oct 2021 14:49:55 +0200 Subject: [PATCH] bug and media fixes --- Controller/ApiController.php | 18 ++++++++---------- Controller/BackendController.php | 9 ++------- Models/Contract.php | 20 ++++++++++---------- Models/ContractMapper.php | 22 +++++++++++----------- Models/ContractType.php | 2 +- Models/ContractTypeL11n.php | 6 +++--- Models/ContractTypeMapper.php | 2 +- Theme/Backend/Lang/Navigation.en.lang.php | 6 +++--- Theme/Backend/Lang/en.lang.php | 4 ++-- Theme/Backend/contract-list.tpl.php | 3 +-- Theme/Backend/contract-single.tpl.php | 5 +---- tests/Controller/ApiControllerTest.php | 14 +++++--------- tests/Models/ContractTest.php | 22 +++++++++++----------- tests/Models/ContractTypeL11nTest.php | 8 ++++---- tests/Models/ContractTypeTest.php | 3 +-- 15 files changed, 64 insertions(+), 80 deletions(-) diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 7d98bf4..6fe1c12 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -15,23 +15,20 @@ declare(strict_types=1); namespace Modules\ContractManagement\Controller; use Modules\Admin\Models\NullAccount; +use Modules\ContractManagement\Models\Contract; +use Modules\ContractManagement\Models\ContractMapper; use Modules\ContractManagement\Models\ContractType; -use Modules\ContractManagement\Models\ContractTypeMapper; use Modules\ContractManagement\Models\ContractTypeL11n; use Modules\ContractManagement\Models\ContractTypeL11nMapper; -use phpOMS\Message\Http\HttpResponse; +use Modules\ContractManagement\Models\ContractTypeMapper; +use Modules\ContractManagement\Models\NullContractType; +use Modules\Media\Models\PathSettings; +use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Model\Message\FormValidation; -use phpOMS\Utils\Parser\Markdown\Markdown; -use phpOMS\Message\Http\HttpRequest; -use Modules\Media\Models\PathSettings; -use Modules\ContractManagement\Models\Contract; -use Modules\ContractManagement\Models\NullContractType; -use Modules\ContractManagement\Models\ContractMapper; -use phpOMS\Localization\ISO639x1Enum; /** * Api controller for the contracts module. @@ -143,7 +140,8 @@ final class ApiController extends Controller } $uploaded = $this->app->moduleManager->get('Media')->uploadFiles( - [$request->getData('name') ?? ''], + $request->getDataList('names') ?? [], + $request->getDataList('filenames') ?? [], $uploadedFiles, $request->header->account, __DIR__ . '/../../../Modules/Media/Files/Modules/ContractManagement/Contracts/' . ($request->getData('contract_title') ?? '0'), diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 29812ba..6eec690 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -14,17 +14,12 @@ declare(strict_types=1); namespace Modules\ContractManagement\Controller; -use Modules\ContractManagement\Models\PermissionState; -use phpOMS\Account\PermissionType; -use phpOMS\Asset\AssetType; +use Modules\ContractManagement\Models\ContractMapper; +use Modules\ContractManagement\Models\ContractTypeL11n; use phpOMS\Contract\RenderableInterface; -use phpOMS\Message\Http\RequestStatusCode; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Views\View; -use Modules\ContractManagement\Models\ContractMapper; -use Modules\ContractManagement\Models\ContractType; -use Modules\ContractManagement\Models\ContractTypeL11n; /** * Backend controller for the contracts module. diff --git a/Models/Contract.php b/Models/Contract.php index d9c88cb..615542b 100755 --- a/Models/Contract.php +++ b/Models/Contract.php @@ -14,9 +14,9 @@ declare(strict_types=1); namespace Modules\ContractManagement\Models; -use Modules\Media\Models\Media; use Modules\Admin\Models\Account; use Modules\Admin\Models\NullAccount; +use Modules\Media\Models\Media; use phpOMS\Localization\Money; /** @@ -129,17 +129,17 @@ class Contract public function toArray() : array { return [ - 'id' => $this->id, - 'title' => $this->title, + 'id' => $this->id, + 'title' => $this->title, 'description' => $this->description, - 'start' => $this->start, - 'end' => $this->end, - 'duration' => $this->duration, - 'warning' => $this->warning, + 'start' => $this->start, + 'end' => $this->end, + 'duration' => $this->duration, + 'warning' => $this->warning, 'responsible' => $this->responsible, - 'createdAt' => $this->createdAt, - 'costs' => $this->costs, - 'type' => $this->type, + 'createdAt' => $this->createdAt, + 'costs' => $this->costs, + 'type' => $this->type, ]; } diff --git a/Models/ContractMapper.php b/Models/ContractMapper.php index 058bb2e..345379e 100755 --- a/Models/ContractMapper.php +++ b/Models/ContractMapper.php @@ -14,8 +14,8 @@ declare(strict_types=1); namespace Modules\ContractManagement\Models; -use Modules\Media\Models\MediaMapper; use Modules\Admin\Models\AccountMapper; +use Modules\Media\Models\MediaMapper; use phpOMS\DataStorage\Database\DataMapperAbstract; /** @@ -35,18 +35,18 @@ final class ContractMapper extends DataMapperAbstract * @since 1.0.0 */ protected static array $columns = [ - 'contractmgmt_contract_id' => ['name' => 'contractmgmt_contract_id', 'type' => 'int', 'internal' => 'id'], - 'contractmgmt_contract_title' => ['name' => 'contractmgmt_contract_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], + 'contractmgmt_contract_id' => ['name' => 'contractmgmt_contract_id', 'type' => 'int', 'internal' => 'id'], + 'contractmgmt_contract_title' => ['name' => 'contractmgmt_contract_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], 'contractmgmt_contract_description' => ['name' => 'contractmgmt_contract_description', 'type' => 'string', 'internal' => 'description'], - 'contractmgmt_contract_account' => ['name' => 'contractmgmt_contract_account', 'type' => 'int', 'internal' => 'account'], - 'contractmgmt_contract_costs' => ['name' => 'contractmgmt_contract_costs', 'type' => 'Serializable', 'internal' => 'costs'], - 'contractmgmt_contract_duration' => ['name' => 'contractmgmt_contract_duration', 'type' => 'int', 'internal' => 'duration'], - 'contractmgmt_contract_warning' => ['name' => 'contractmgmt_contract_warning', 'type' => 'int', 'internal' => 'warning'], - 'contractmgmt_contract_start' => ['name' => 'contractmgmt_contract_start', 'type' => 'DateTime', 'internal' => 'start'], - 'contractmgmt_contract_end' => ['name' => 'contractmgmt_contract_end', 'type' => 'DateTime', 'internal' => 'end'], + 'contractmgmt_contract_account' => ['name' => 'contractmgmt_contract_account', 'type' => 'int', 'internal' => 'account'], + 'contractmgmt_contract_costs' => ['name' => 'contractmgmt_contract_costs', 'type' => 'Serializable', 'internal' => 'costs'], + 'contractmgmt_contract_duration' => ['name' => 'contractmgmt_contract_duration', 'type' => 'int', 'internal' => 'duration'], + 'contractmgmt_contract_warning' => ['name' => 'contractmgmt_contract_warning', 'type' => 'int', 'internal' => 'warning'], + 'contractmgmt_contract_start' => ['name' => 'contractmgmt_contract_start', 'type' => 'DateTime', 'internal' => 'start'], + 'contractmgmt_contract_end' => ['name' => 'contractmgmt_contract_end', 'type' => 'DateTime', 'internal' => 'end'], 'contractmgmt_contract_responsible' => ['name' => 'contractmgmt_contract_responsible', 'type' => 'int', 'internal' => 'responsible'], - 'contractmgmt_contract_type' => ['name' => 'contractmgmt_contract_type', 'type' => 'int', 'internal' => 'type'], - 'contractmgmt_contract_created_at' => ['name' => 'contractmgmt_contract_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt'], + 'contractmgmt_contract_type' => ['name' => 'contractmgmt_contract_type', 'type' => 'int', 'internal' => 'type'], + 'contractmgmt_contract_created_at' => ['name' => 'contractmgmt_contract_created_at', 'type' => 'DateTimeImmutable', 'internal' => 'createdAt'], ]; /** diff --git a/Models/ContractType.php b/Models/ContractType.php index 27eb374..86095df 100755 --- a/Models/ContractType.php +++ b/Models/ContractType.php @@ -105,7 +105,7 @@ class ContractType implements \JsonSerializable, ArrayableInterface public function toArray() : array { return [ - 'id' => $this->id, + 'id' => $this->id, 'l11n' => $this->l11n, ]; } diff --git a/Models/ContractTypeL11n.php b/Models/ContractTypeL11n.php index e9994ca..9244c4c 100755 --- a/Models/ContractTypeL11n.php +++ b/Models/ContractTypeL11n.php @@ -119,9 +119,9 @@ class ContractTypeL11n implements \JsonSerializable, ArrayableInterface public function toArray() : array { return [ - 'id' => $this->id, - 'title' => $this->title, - 'type' => $this->type, + 'id' => $this->id, + 'title' => $this->title, + 'type' => $this->type, 'language' => $this->language, ]; } diff --git a/Models/ContractTypeMapper.php b/Models/ContractTypeMapper.php index e8efc6c..886e666 100755 --- a/Models/ContractTypeMapper.php +++ b/Models/ContractTypeMapper.php @@ -50,7 +50,7 @@ final class ContractTypeMapper extends DataMapperAbstract 'column' => 'title', 'conditional' => true, 'external' => null, - ] + ], ]; /** diff --git a/Theme/Backend/Lang/Navigation.en.lang.php b/Theme/Backend/Lang/Navigation.en.lang.php index cc9f997..9555eb4 100755 --- a/Theme/Backend/Lang/Navigation.en.lang.php +++ b/Theme/Backend/Lang/Navigation.en.lang.php @@ -13,8 +13,8 @@ declare(strict_types=1); return ['Navigation' => [ - 'Create' => 'Create', - 'Contract' => 'Contract', + 'Create' => 'Create', + 'Contract' => 'Contract', 'Contracts' => 'Contracts', - 'List' => 'List', + 'List' => 'List', ]]; diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index d7a021d..be48f1b 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -13,7 +13,7 @@ declare(strict_types=1); return ['ContractManagement' => [ - 'Contract' => 'Contract', + 'Contract' => 'Contract', 'Contracts' => 'Contracts', - 'Title' => 'Title', + 'Title' => 'Title', ]]; diff --git a/Theme/Backend/contract-list.tpl.php b/Theme/Backend/contract-list.tpl.php index 6b0f5b0..c8284ce 100755 --- a/Theme/Backend/contract-list.tpl.php +++ b/Theme/Backend/contract-list.tpl.php @@ -12,11 +12,10 @@ */ declare(strict_types=1); -use Modules\Media\Models\NullMedia; use phpOMS\Uri\UriFactory; /** - * @var \phpOMS\Views\View $this + * @var \phpOMS\Views\View $this * @var \Modules\ContractManagement\Models\Contract[] $contracts */ $contracts = $this->getData('contracts') ?? []; diff --git a/Theme/Backend/contract-single.tpl.php b/Theme/Backend/contract-single.tpl.php index 8863029..5a96bfe 100755 --- a/Theme/Backend/contract-single.tpl.php +++ b/Theme/Backend/contract-single.tpl.php @@ -12,11 +12,8 @@ */ declare(strict_types=1); -use Modules\Media\Models\NullMedia; -use phpOMS\Uri\UriFactory; - /** - * @var \phpOMS\Views\View $this + * @var \phpOMS\Views\View $this * @var \Modules\ContractManagement\Models\Contract $contract */ $contract = $this->getData('contract'); diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 7320305..4bd3e3e 100644 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -16,26 +16,22 @@ namespace Modules\ContractManagement\tests\Controller; use Model\CoreSettings; use Modules\Admin\Models\AccountPermission; -use phpOMS\DataStorage\Session\HttpSession; use phpOMS\Account\Account; use phpOMS\Account\AccountManager; use phpOMS\Account\PermissionType; use phpOMS\Application\ApplicationAbstract; +use phpOMS\DataStorage\Session\HttpSession; use phpOMS\Dispatcher\Dispatcher; use phpOMS\Event\EventManager; -use phpOMS\Module\ModuleAbstract; -use phpOMS\Module\ModuleManager; -use phpOMS\Router\WebRouter; -use phpOMS\Utils\TestUtils; use phpOMS\Localization\ISO639x1Enum; -use Modules\Media\Models\MediaMapper; -use Modules\Media\Models\PathSettings; -use Modules\Media\Models\UploadStatus; use phpOMS\Message\Http\HttpRequest; use phpOMS\Message\Http\HttpResponse; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\System\File\Local\Directory; +use phpOMS\Module\ModuleAbstract; +use phpOMS\Module\ModuleManager; +use phpOMS\Router\WebRouter; use phpOMS\Uri\HttpUri; +use phpOMS\Utils\TestUtils; /** * @testdox Modules\ContractManagement\tests\Controller\ApiControllerTest: ContractManagement api controller diff --git a/tests/Models/ContractTest.php b/tests/Models/ContractTest.php index 45b6e47..37e6329 100644 --- a/tests/Models/ContractTest.php +++ b/tests/Models/ContractTest.php @@ -59,26 +59,26 @@ final class ContractTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->contract->title = 'Title'; + $this->contract->title = 'Title'; $this->contract->description = 'Description'; - $this->contract->duration = 123; - $this->contract->warning = 2; + $this->contract->duration = 123; + $this->contract->warning = 2; $serialized = $this->contract->jsonSerialize(); unset($serialized['createdAt']); self::assertEquals( [ - 'id' => 0, - 'title' => 'Title', + 'id' => 0, + 'title' => 'Title', 'description' => 'Description', - 'start' => null, - 'end' => null, - 'duration' => 123, - 'warning' => 2, + 'start' => null, + 'end' => null, + 'duration' => 123, + 'warning' => 2, 'responsible' => null, - 'costs' => null, - 'type' => new ContractType(), + 'costs' => null, + 'type' => new ContractType(), ], $serialized ); diff --git a/tests/Models/ContractTypeL11nTest.php b/tests/Models/ContractTypeL11nTest.php index efa9e53..ca3967c 100644 --- a/tests/Models/ContractTypeL11nTest.php +++ b/tests/Models/ContractTypeL11nTest.php @@ -70,16 +70,16 @@ final class ContractTypeL11nTest extends \PHPUnit\Framework\TestCase */ public function testSerialize() : void { - $this->l11n->title = 'Title'; + $this->l11n->title = 'Title'; $this->l11n->type = 2; $this->l11n->setLanguage(ISO639x1Enum::_DE); self::assertEquals( [ - 'id' => 0, - 'title' => 'Title', + 'id' => 0, + 'title' => 'Title', 'type' => 2, - 'language' => ISO639x1Enum::_DE, + 'language' => ISO639x1Enum::_DE, ], $this->l11n->jsonSerialize() ); diff --git a/tests/Models/ContractTypeTest.php b/tests/Models/ContractTypeTest.php index 19a6917..85854e0 100644 --- a/tests/Models/ContractTypeTest.php +++ b/tests/Models/ContractTypeTest.php @@ -16,7 +16,6 @@ namespace Modules\ContractManagement\tests\Models; use Modules\ContractManagement\Models\ContractType; use Modules\ContractManagement\Models\ContractTypeL11n; -use phpOMS\Localization\ISO639x1Enum; /** * @internal @@ -67,7 +66,7 @@ final class ContractTypeTest extends \PHPUnit\Framework\TestCase self::assertEquals( [ 'id' => 0, - 'l11n' => new ContractTypeL11n(), + 'l11n' => new ContractTypeL11n(), ], $this->type->jsonSerialize() );