oms-LoanManagement/Admin/Installer.php
Dennis Eichhorn dc981a4f5d
Some checks failed
Image optimization / general_image_workflow (push) Has been cancelled
CI / general_module_workflow_php (push) Has been cancelled
CI / general_module_workflow_js (push) Has been cancelled
fix version and bugs
2024-05-21 00:09:13 +02:00

122 lines
3.4 KiB
PHP
Executable File

<?php
/**
* Jingga
*
* PHP Version 8.2
*
* @package Modules\LoanManagement\Admin
* @copyright Dennis Eichhorn
* @license OMS License 2.2
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace Modules\LoanManagement\Admin;
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;
/**
* Installer class.
*
* @package Modules\LoanManagement\Admin
* @license OMS License 2.2
* @link https://jingga.app
* @since 1.0.0
*/
final class Installer extends InstallerAbstract
{
/**
* Path of the file
*
* @var string
* @since 1.0.0
*/
public const PATH = __DIR__;
/**
* {@inheritdoc}
*/
public static function install(ApplicationAbstract $app, ModuleInfo $info, SettingsInterface $cfgHandler) : void
{
parent::install($app, $info, $cfgHandler);
/* Material types */
$fileContent = \file_get_contents(__DIR__ . '/Install/costtypes.json');
if ($fileContent === false) {
return;
}
/** @var array $types */
$types = \json_decode($fileContent, true);
$materialTypeArray = self::createCostTypes($app, $types);
}
/**
* Install default material types
*
* @param ApplicationAbstract $app Application
* @param array $types Material type definitions
*
* @return array
*
* @since 1.0.0
*/
private static function createCostTypes(ApplicationAbstract $app, array $types) : array
{
/** @var array<string, array> $costType */
$costType = [];
/** @var \Modules\LoanManagement\Controller\ApiController $module */
$module = $app->moduleManager->get('LoanManagement', 'Api');
/** @var array $type */
foreach ($types as $type) {
$response = new HttpResponse();
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('name', $type['name'] ?? '');
$request->setData('title', \reset($type['l11n']));
$request->setData('sign', $type['sign'] ?? -1);
$request->setData('is_loan', $type['isLoan'] ?? false);
$module->apiLoanCostTypeCreate($request, $response);
$responseData = $response->getData('');
if (!\is_array($responseData)) {
continue;
}
$costType[$type['name']] = \is_array($responseData['response'])
? $responseData['response']
: $responseData['response']->toArray();
$isFirst = true;
foreach ($type['l11n'] as $language => $l11n) {
if ($isFirst) {
$isFirst = false;
continue;
}
$response = new HttpResponse();
$request = new HttpRequest();
$request->header->account = 1;
$request->setData('title', $l11n);
$request->setData('language', $language);
$request->setData('type', $costType[$type['name']]['id']);
$module->apiLoanCostTypeL11nCreate($request, $response);
}
}
return $costType;
}
}