Implement the controller action to view the EntityworkflowSend

This commit is contained in:
2024-10-07 15:35:36 +02:00
parent a0b5c208eb
commit 5c0f3cb317
9 changed files with 381 additions and 5 deletions

View File

@@ -13,9 +13,16 @@ namespace Chill\MainBundle\Workflow;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSend;
use Chill\MainBundle\Workflow\Exception\HandlerNotFoundException;
use Chill\MainBundle\Workflow\Exception\HandlerWithPublicViewNotFoundException;
use Symfony\Component\Workflow\Registry;
/**
* Manage the handler and performs some operation on handlers.
*
* Each handler must implement @{EntityWorkflowHandlerInterface::class}.
*/
class EntityWorkflowManager
{
/**
@@ -63,4 +70,26 @@ class EntityWorkflowManager
return [];
}
/**
* Renders the public view for the given entity workflow send.
*
* @param EntityWorkflowSend $entityWorkflowSend the entity workflow send object
*
* @return string the rendered public view
*
* @throws HandlerWithPublicViewNotFoundException if no handler with public view is found
*/
public function renderPublicView(EntityWorkflowSend $entityWorkflowSend): string
{
$entityWorkflow = $entityWorkflowSend->getEntityWorkflowStep()->getEntityWorkflow();
foreach ($this->handlers as $handler) {
if ($handler instanceof EntityWorkflowWithPublicViewInterface && $handler->supports($entityWorkflow)) {
return $handler->renderPublicView($entityWorkflowSend);
}
}
throw new HandlerWithPublicViewNotFoundException();
}
}

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Workflow;
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSend;
interface EntityWorkflowWithPublicViewInterface
{
/**
* Render the public view for EntityWorkflowSend.
*
* The public view must be a safe html string
*/
public function renderPublicView(EntityWorkflowSend $entityWorkflowSend): string;
}

View File

@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Workflow\Exception;
class HandlerWithPublicViewNotFoundException extends \RuntimeException {}