diff --git a/composer.lock b/composer.lock index 34a9b86dc..b2c8731be 100644 --- a/composer.lock +++ b/composer.lock @@ -3987,12 +3987,12 @@ "source": { "type": "git", "url": "https://github.com/dvsa/olcs-common.git", - "reference": "f1403681db7501e3429540951938e43b20069e37" + "reference": "22d7aa1de4f3a1c9fbdd6215d2bb9c37356c79d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dvsa/olcs-common/zipball/f1403681db7501e3429540951938e43b20069e37", - "reference": "f1403681db7501e3429540951938e43b20069e37", + "url": "https://api.github.com/repos/dvsa/olcs-common/zipball/22d7aa1de4f3a1c9fbdd6215d2bb9c37356c79d0", + "reference": "22d7aa1de4f3a1c9fbdd6215d2bb9c37356c79d0", "shasum": "" }, "require": { @@ -4052,7 +4052,7 @@ "support": { "source": "https://github.com/dvsa/olcs-common/tree/project/messaging" }, - "time": "2024-01-30T15:47:21+00:00" + "time": "2024-02-08T09:45:26+00:00" }, { "name": "olcs/olcs-logging", @@ -4112,12 +4112,12 @@ "source": { "type": "git", "url": "https://github.com/dvsa/olcs-transfer.git", - "reference": "fe1dd3a6903c8db9705a8f2d200c2db5c812dbff" + "reference": "e2727d8e365a41f2b6093282a96800794cbcc8c3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dvsa/olcs-transfer/zipball/fe1dd3a6903c8db9705a8f2d200c2db5c812dbff", - "reference": "fe1dd3a6903c8db9705a8f2d200c2db5c812dbff", + "url": "https://api.github.com/repos/dvsa/olcs-transfer/zipball/e2727d8e365a41f2b6093282a96800794cbcc8c3", + "reference": "e2727d8e365a41f2b6093282a96800794cbcc8c3", "shasum": "" }, "require": { @@ -4159,7 +4159,7 @@ "support": { "source": "https://github.com/dvsa/olcs-transfer/tree/project/messaging" }, - "time": "2024-01-29T14:40:36+00:00" + "time": "2024-02-06T15:11:55+00:00" }, { "name": "olcs/olcs-utils", @@ -8027,5 +8027,5 @@ "platform-overrides": { "ext-redis": "4.3" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/module/Olcs/config/module.config.php b/module/Olcs/config/module.config.php index 8f3d37e92..eb30f7230 100644 --- a/module/Olcs/config/module.config.php +++ b/module/Olcs/config/module.config.php @@ -18,6 +18,7 @@ use Olcs\Controller\Factory\IndexControllerFactory; use Olcs\Controller\Factory\MyDetailsControllerFactory; use Olcs\Controller\IndexController; +use Common\Service\Data as CommonDataService; use Olcs\Controller\Licence\Vehicle\ListVehicleController; use Olcs\Controller\Lva\Adapters\ApplicationPeopleAdapter; use Olcs\Controller\Lva\Adapters\LicencePeopleAdapter; @@ -45,6 +46,7 @@ use Olcs\Logging\Log\Processor\CorrelationId; use Olcs\Logging\Log\Processor\CorrelationIdFactory; use Olcs\Service\Cookie as CookieService; +use Olcs\Service\Data as DataService; use Olcs\Service\Processing as ProcessingService; use Olcs\Service\Qa as QaService; use Olcs\Session\LicenceVehicleManagement; @@ -1462,7 +1464,7 @@ VariationTransportManagerAdapter::class => VariationTransportManagerAdapterFactory::class, VariationPeopleAdapter::class => VariationPeopleAdapterFactory::class, \Olcs\Logging\Log\Processor\CorrelationId::class => \Olcs\Logging\Log\Processor\CorrelationIdFactory::class, - ] + ], ), 'log_processors' => [ 'factories' => [ @@ -1504,6 +1506,11 @@ 'simple_date_format' => array( 'default' => 'd-m-Y' ), + 'data_services' => [ + 'factories' => [ + DataService\MessagingAppOrLicNo::class => CommonDataService\AbstractListDataServiceFactory::class, + ], + ], 'view_helpers' => array( 'factories' => [ \Olcs\View\Helper\SessionTimeoutWarning\SessionTimeoutWarning::class => \Olcs\View\Helper\SessionTimeoutWarning\SessionTimeoutWarningFactory::class, diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php index f027cf303..026c9d3fa 100644 --- a/module/Olcs/src/Controller/ConversationsController.php +++ b/module/Olcs/src/Controller/ConversationsController.php @@ -11,6 +11,7 @@ use Common\Service\Helper\FlashMessengerHelperService; use Common\Service\Helper\FormHelperService; use Common\Service\Table\TableFactory; +use Dvsa\Olcs\Transfer\Command\Messaging\Conversation\Create; use Dvsa\Olcs\Transfer\Command\Messaging\Message\Create as CreateMessageCommand; use Dvsa\Olcs\Transfer\Query\Messaging\Messages\ByConversation as ByConversationQuery; use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByOrganisation as ByOrganisationQuery; @@ -19,6 +20,8 @@ use Laminas\View\Model\ViewModel; use LmcRbacMvc\Service\AuthorizationService; use Olcs\Form\Model\Form\Message\Reply as ReplyForm; +use Olcs\Form\Model\Form\Message\Create as CreateForm; +use Olcs\Service\Data\MessagingAppOrLicNo; class ConversationsController extends AbstractController implements ToggleAwareInterface { @@ -75,14 +78,75 @@ public function indexAction(): ViewModel return $view; } + /** + * @throws \Exception + */ public function addAction(): ViewModel { - $view = new ViewModel([]); + $form = $this->formHelperService->createForm(CreateForm::class, true, false); + if ($this->getRequest()->isPost()) { + $form->setData($this->getRequest()->getPost()); + if ($form->isValid()) { + return $this->submitConversation($form); + } + } + + $view = new ViewModel(); + $view->setVariable('form', $form); $view->setTemplate('messages-new'); return $view; } + /** + * @return Response|ViewModel + * @throws \Exception + */ + private function submitConversation(\Laminas\Form\Form $form) + { + $response = $this->handleCommand($this->mapFormDataToCommand($form)); + if (!$response->isOk()) { + $this->flashMessengerHelper->addErrorMessage('There was an server error when submitting your conversation; please try later'); + return $this->addAction(); + } + + $conversationId = $response->getResult()['id']['conversation'] ?? null; + if (empty($conversationId)) { + $this->flashMessengerHelper->addErrorMessage('There was an server error when submitting your conversation; please try later'); + return $this->addAction(); + } + + $this->flashMessengerHelper->addSuccessMessage('Conversation was created successfully'); + return $this->redirect()->toRoute('conversations/view', ['conversationId' => $conversationId]); + } + + /** + * @throws \Exception + */ + private function mapFormDataToCommand(\Laminas\Form\Form $form): Create + { + $data = $form->getData(); + $processedData = [ + 'messageSubject' => $data['form-actions']['messageSubject'], + 'messageContent' => $data['form-actions']['messageContent'], + ]; + + $appOrLicNoPrefix = substr($data['form-actions']['appOrLicNo'], 0, 1); + $appOrLicNoSuffix = substr($data['form-actions']['appOrLicNo'], 1); + switch($appOrLicNoPrefix) { + case MessagingAppOrLicNo::PREFIX_LICENCE: + $processedData['licence'] = $appOrLicNoSuffix; + break; + case MessagingAppOrLicNo::PREFIX_APPLICATION: + $processedData['application'] = $appOrLicNoSuffix; + break; + default: + throw new \Exception('Invalid prefix on appOrLicNo'); + } + + return Create::create($processedData); + } + /** @return ViewModel|Response */ public function viewAction() { diff --git a/module/Olcs/src/Form/Model/Fieldset/Message/Create.php b/module/Olcs/src/Form/Model/Fieldset/Message/Create.php new file mode 100644 index 000000000..2c2c84b7f --- /dev/null +++ b/module/Olcs/src/Form/Model/Fieldset/Message/Create.php @@ -0,0 +1,84 @@ +getData('licapp'); + + if (count($data) !== 0) { + return $data; + } + + $response = $this->handleQuery( + TransferQry\Messaging\ApplicationLicenceList\ByOrganisation::create([]) + ); + + if (!$response->isOk()) { + throw new DataServiceException('Unknown Error - ' . json_encode($response)); + } + + $result = $response->getResult(); + + $this->setData('licapp', ($result['results'] ?? null)); + + return $this->getData('licapp'); + } + + public function formatDataForGroups(array $data): array + { + $optionData = [ + [ + 'label' => 'Licence', + 'options' => [] + ], + [ + 'label' => 'Application', + 'options' => [] + ] + ]; + + $optionData[0]['options'] = $data['licences']; + $optionData[1]['options'] = $data['applications']; + + $this->prefixArrayKey($optionData[0]['options'], static::PREFIX_LICENCE); + $this->prefixArrayKey($optionData[1]['options'], static::PREFIX_APPLICATION); + + return $optionData; + } + + private function prefixArrayKey(array &$array, string $prefix): void + { + foreach ($array as $k => $v) + { + $array[$prefix . $k] = $v; + unset($array[$k]); + } + } +} diff --git a/module/Olcs/view/messages-new.phtml b/module/Olcs/view/messages-new.phtml index 95b188978..ae6ad7105 100644 --- a/module/Olcs/view/messages-new.phtml +++ b/module/Olcs/view/messages-new.phtml @@ -19,6 +19,14 @@ echo $this->partial( ->setMaxDepth(0) ->setPartial('partials/tabs-nav'); ?> + +