mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-02 21:13:57 +00:00
Create a duplicator service for accompanying course document
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?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\DocStoreBundle\Workflow;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\AccompanyingCourseDocument;
|
||||
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectDuplicate;
|
||||
use Symfony\Component\Clock\ClockInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
* Stores the logic to duplicate an AccompanyingCourseDocument associated to a workflow.
|
||||
*/
|
||||
class AccompanyingCourseDocumentDuplicator
|
||||
{
|
||||
public function __construct(
|
||||
private readonly StoredObjectDuplicate $storedObjectDuplicate,
|
||||
private readonly TranslatorInterface $translator,
|
||||
private readonly ClockInterface $clock,
|
||||
) {}
|
||||
|
||||
public function duplicate(AccompanyingCourseDocument $document): AccompanyingCourseDocument
|
||||
{
|
||||
$newDoc = new AccompanyingCourseDocument();
|
||||
$newDoc
|
||||
->setCourse($document->getCourse())
|
||||
->setTitle($document->getTitle().' ('.$this->translator->trans('acc_course_document.duplicated_at', ['at' => $this->clock->now()]).')')
|
||||
->setDate($document->getDate())
|
||||
->setDescription($document->getDescription())
|
||||
->setCategory($document->getCategory())
|
||||
->setUser($document->getUser())
|
||||
->setObject($this->storedObjectDuplicate->duplicate($document->getObject()))
|
||||
;
|
||||
|
||||
return $newDoc;
|
||||
}
|
||||
}
|
@@ -17,6 +17,7 @@ use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowWithDuplicableRelatedEntityInterface;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowWithStoredObjectHandlerInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
@@ -27,8 +28,8 @@ use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
readonly class AccompanyingCourseDocumentWorkflowHandler implements EntityWorkflowWithStoredObjectHandlerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private TranslatorInterface $translator,
|
||||
private EntityWorkflowRepository $workflowRepository,
|
||||
private TranslatorInterface $translator,
|
||||
private EntityWorkflowRepository $workflowRepository,
|
||||
private AccompanyingCourseDocumentRepository $repository,
|
||||
) {}
|
||||
|
||||
|
Reference in New Issue
Block a user