Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
17 / 17 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| InventorySettingsWebController | |
100.00% |
16 / 16 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Inventory\Presentation\Web; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | use App\Core\Engine\Application\Service\InventoryApplicationService; |
| 12 | use App\Core\Engine\Domain\Repository\MetadataRepositoryInterface; |
| 13 | use App\Core\Instance\Application\Service\InstanceContextManagerInterface; |
| 14 | use Nyholm\Psr7\Factory\Psr17Factory; |
| 15 | use Psr\Http\Message\ResponseInterface; |
| 16 | use Psr\Http\Message\ServerRequestInterface; |
| 17 | use Twig\Environment as TwigEnvironment; |
| 18 | |
| 19 | /** |
| 20 | * Web controller for managing dynamic inventory fields in module settings. |
| 21 | */ |
| 22 | final readonly class InventorySettingsWebController |
| 23 | { |
| 24 | private const string HTML_CONTENT_TYPE = 'text/html; charset=utf-8'; |
| 25 | |
| 26 | public function __construct( |
| 27 | private InventoryApplicationService $inventoryService, |
| 28 | private MetadataRepositoryInterface $metadataRepository, |
| 29 | private TwigEnvironment $twig, |
| 30 | private Psr17Factory $psr17Factory, |
| 31 | private ?InstanceContextManagerInterface $instanceManager = null, |
| 32 | private string $appProfile = 'admin', |
| 33 | ) { |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Renders inventory fields management page for a given module (GET /settings/modules/{id:\d+}/inventory-fields). |
| 38 | */ |
| 39 | public function index(ServerRequestInterface $request, int $moduleId): ResponseInterface |
| 40 | { |
| 41 | $request->getMethod(); |
| 42 | $module = $this->metadataRepository->findModuleById($moduleId); |
| 43 | $fields = $this->inventoryService->getInventoryFields($moduleId); |
| 44 | $activeInstance = $this->instanceManager?->getActiveInstance(); |
| 45 | |
| 46 | $html = $this->twig->render('inventory/index.twig', [ |
| 47 | 'module' => $module, |
| 48 | 'fields' => $fields, |
| 49 | 'page_title' => 'Dynamic Inventory Fields - ' . $module->label, |
| 50 | 'active_instance' => $activeInstance, |
| 51 | 'app_profile' => $this->appProfile, |
| 52 | ]); |
| 53 | |
| 54 | $response = $this->psr17Factory->createResponse(200) |
| 55 | ->withHeader('Content-Type', self::HTML_CONTENT_TYPE); |
| 56 | $response->getBody()->write($html); |
| 57 | |
| 58 | return $response; |
| 59 | } |
| 60 | } |