diff --git a/module/Olcs/src/Controller/ConversationsController.php b/module/Olcs/src/Controller/ConversationsController.php
index 92185cc4b..f027cf303 100644
--- a/module/Olcs/src/Controller/ConversationsController.php
+++ b/module/Olcs/src/Controller/ConversationsController.php
@@ -7,14 +7,18 @@
use Common\Controller\Interfaces\ToggleAwareInterface;
use Common\Controller\Lva\AbstractController;
use Common\FeatureToggle;
+use Common\Form\Form;
use Common\Service\Helper\FlashMessengerHelperService;
+use Common\Service\Helper\FormHelperService;
use Common\Service\Table\TableFactory;
+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;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
+use Laminas\Http\Response;
use Laminas\View\Model\ViewModel;
-use Laminas\View\View;
use LmcRbacMvc\Service\AuthorizationService;
+use Olcs\Form\Model\Form\Message\Reply as ReplyForm;
class ConversationsController extends AbstractController implements ToggleAwareInterface
{
@@ -25,17 +29,19 @@ class ConversationsController extends AbstractController implements ToggleAwareI
];
protected FlashMessengerHelperService $flashMessengerHelper;
- protected TableFactory $tableFactory;
+ protected TableFactory $tableFactory;
+ protected FormHelperService $formHelperService;
public function __construct(
- NiTextTranslation $niTextTranslationUtil,
- AuthorizationService $authService,
+ NiTextTranslation $niTextTranslationUtil,
+ AuthorizationService $authService,
FlashMessengerHelperService $flashMessengerHelper,
- TableFactory $tableFactory
- )
- {
+ TableFactory $tableFactory,
+ FormHelperService $formHelperService
+ ) {
$this->flashMessengerHelper = $flashMessengerHelper;
$this->tableFactory = $tableFactory;
+ $this->formHelperService = $formHelperService;
parent::__construct($niTextTranslationUtil, $authService);
}
@@ -77,7 +83,8 @@ public function addAction(): ViewModel
return $view;
}
- public function viewAction(): ViewModel
+ /** @return ViewModel|Response */
+ public function viewAction()
{
$params = [
'page' => $this->params()->fromQuery('page', 1),
@@ -95,12 +102,53 @@ public function viewAction(): ViewModel
$messages = [];
}
+ $form = $this->formHelperService->createForm(ReplyForm::class, true, false);
+ $this->formHelperService->setFormActionFromRequest($form, $this->getRequest());
+
$table = $this->tableFactory
->buildTable('messages-view', $messages, $params);
- $view = new ViewModel(['table' => $table]);
+ $view = new ViewModel(
+ [
+ 'table' => $table,
+ 'form' => $form,
+ ],
+ );
$view->setTemplate('messages-view');
+ if ($this->getRequest()->isPost() && $this->params()->fromPost('action') === 'reply') {
+ return $this->parseReply($view, $form);
+ }
+
return $view;
}
+
+ /** @return Response|ViewModel */
+ protected function parseReply(ViewModel $view, Form $form)
+ {
+ $form->setData((array)$this->params()->fromPost());
+ $form->get('id')->setValue($this->params()->fromRoute('conversation'));
+
+ if (!$form->isValid()) {
+ return $view;
+ }
+
+ $response = $this->handleCommand(
+ CreateMessageCommand::create(
+ [
+ 'conversation' => $this->params()->fromRoute('conversationId'),
+ 'messageContent' => $form->get('form-actions')->get('reply')->getValue(),
+ ],
+ ),
+ );
+
+ if ($response->isOk()) {
+ $this->flashMessengerHelper->addSuccessMessage('Reply submitted successfully');
+ return $this->redirect()->toRoute('conversations/view', $this->params()->fromRoute());
+ }
+
+ $this->handleErrors($response->getResult());
+
+ return parent::indexAction();
+ }
}
diff --git a/module/Olcs/src/Controller/Factory/ConversationsControllerFactory.php b/module/Olcs/src/Controller/Factory/ConversationsControllerFactory.php
index ec05a471f..96e6cb6ad 100644
--- a/module/Olcs/src/Controller/Factory/ConversationsControllerFactory.php
+++ b/module/Olcs/src/Controller/Factory/ConversationsControllerFactory.php
@@ -5,6 +5,7 @@
namespace Olcs\Controller\Factory;
use Common\Service\Helper\FlashMessengerHelperService;
+use Common\Service\Helper\FormHelperService;
use Common\Service\Table\TableFactory;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Interop\Container\ContainerInterface;
@@ -15,18 +16,23 @@
class ConversationsControllerFactory implements FactoryInterface
{
- public function __invoke(ContainerInterface $container, $requestedName, array $options = null): ConversationsController
- {
+ public function __invoke(
+ ContainerInterface $container,
+ $requestedName,
+ array $options = null
+ ): ConversationsController {
$niTextTranslationUtil = $container->get(NiTextTranslation::class);
$authService = $container->get(AuthorizationService::class);
$flashMessengerHelper = $container->get(FlashMessengerHelperService::class);
$tableFactory = $container->get(TableFactory::class);
+ $formHelperService = $container->get(FormHelperService::class);
return new ConversationsController(
$niTextTranslationUtil,
$authService,
$flashMessengerHelper,
$tableFactory,
+ $formHelperService,
);
}
}
diff --git a/module/Olcs/src/Form/Model/Fieldset/Message/Reply.php b/module/Olcs/src/Form/Model/Fieldset/Message/Reply.php
new file mode 100644
index 000000000..debb24e15
--- /dev/null
+++ b/module/Olcs/src/Form/Model/Fieldset/Message/Reply.php
@@ -0,0 +1,43 @@
+partial(
echo $menu->setMinDepth(0)
->setMaxDepth(0)
->setPartial('partials/tabs-nav');
-
+ ?>
+
+
+ Send a reply
+
+
+