mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 07:33:50 +00:00
full generation for accompanying period
This commit is contained in:
@@ -11,8 +11,14 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Context;
|
||||
|
||||
use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException;
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
|
||||
class ContextManager
|
||||
{
|
||||
/**
|
||||
* @var DocGeneratorContextInterface[]|iterable
|
||||
*/
|
||||
private iterable $contexts;
|
||||
|
||||
public function __construct(iterable $contexts)
|
||||
@@ -20,7 +26,21 @@ class ContextManager
|
||||
$this->contexts = $contexts;
|
||||
}
|
||||
|
||||
public function getContext(): array
|
||||
/**
|
||||
* @throw ContextNotFoundException when the context is not found
|
||||
*/
|
||||
public function getContextByDocGeneratorTemplate(DocGeneratorTemplate $docGeneratorTemplate): DocGeneratorContextInterface
|
||||
{
|
||||
foreach ($this->contexts as $key => $context) {
|
||||
if ($docGeneratorTemplate->getContext() === $key) {
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ContextNotFoundException($docGeneratorTemplate->getContext());
|
||||
}
|
||||
|
||||
public function getContexts(): array
|
||||
{
|
||||
return iterator_to_array($this->contexts);
|
||||
}
|
||||
|
@@ -11,6 +11,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Context;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
|
||||
/**
|
||||
* Interface for context for for document generation.
|
||||
*/
|
||||
@@ -39,6 +42,8 @@ interface DocGeneratorContextInterface
|
||||
*/
|
||||
public function hasForm(): bool;
|
||||
|
||||
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity): void;
|
||||
|
||||
/**
|
||||
* True of false which entity supports.
|
||||
*/
|
||||
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Context\Exception;
|
||||
|
||||
use RuntimeException;
|
||||
|
||||
class ContextNotFoundException extends RuntimeException
|
||||
{
|
||||
public function __construct($contextName)
|
||||
{
|
||||
parent::__construct(sprintf('the context with name %s is not found', $contextName));
|
||||
}
|
||||
}
|
@@ -11,9 +11,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\DocGeneratorBundle\Context;
|
||||
|
||||
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Exception;
|
||||
use function count;
|
||||
use function get_class;
|
||||
@@ -23,6 +27,13 @@ use function get_class;
|
||||
*/
|
||||
class HouseholdMemberSelectionContext implements DocGeneratorContextInterface
|
||||
{
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data that will be injected to the generated document.
|
||||
*
|
||||
@@ -107,6 +118,19 @@ class HouseholdMemberSelectionContext implements DocGeneratorContextInterface
|
||||
return true;
|
||||
}
|
||||
|
||||
public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity): void
|
||||
{
|
||||
// Only for evaluation
|
||||
if ($entity instanceof AccompanyingPeriodWorkEvaluation) {
|
||||
$doc = new AccompanyingPeriodWorkEvaluationDocument();
|
||||
$doc
|
||||
->setStoredObject($storedObject)
|
||||
->setTemplate($template);
|
||||
$entity->addDocument($doc);
|
||||
$this->em->persist($doc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* True of false which entity supports.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user