mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Add capability to store closing motive when closing accompanying period
The commit introduces new functionality in the bundle that allows storing the closing motive when a course is closed. This is achieved by modifying the model and database schema to include a new `closingMotive` field in AccompanyingPeriodStepHistory entity.
This commit is contained in:
parent
0c9010f065
commit
f8840d89bf
@ -62,7 +62,7 @@ class AccompanyingCourseController extends \Symfony\Bundle\FrameworkBundle\Contr
|
|||||||
$workflow = $this->registry->get($accompanyingCourse);
|
$workflow = $this->registry->get($accompanyingCourse);
|
||||||
|
|
||||||
if ($workflow->can($accompanyingCourse, 'close')) {
|
if ($workflow->can($accompanyingCourse, 'close')) {
|
||||||
$workflow->apply($accompanyingCourse, 'close');
|
$workflow->apply($accompanyingCourse, 'close', ['closing_motive' => $form['closingMotive']->getData()]);
|
||||||
|
|
||||||
$em->flush();
|
$em->flush();
|
||||||
|
|
||||||
|
@ -1449,7 +1449,7 @@ class AccompanyingPeriod implements
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setStep(string $step): self
|
public function setStep(string $step, array $context = []): self
|
||||||
{
|
{
|
||||||
$previous = $this->step;
|
$previous = $this->step;
|
||||||
|
|
||||||
@ -1464,7 +1464,7 @@ class AccompanyingPeriod implements
|
|||||||
$history = new AccompanyingPeriodStepHistory();
|
$history = new AccompanyingPeriodStepHistory();
|
||||||
$history->setStep($this->step)->setStartDate(new \DateTimeImmutable('now'));
|
$history->setStep($this->step)->setStartDate(new \DateTimeImmutable('now'));
|
||||||
|
|
||||||
$this->addStepHistory($history);
|
$this->addStepHistory($history, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -1507,11 +1507,14 @@ class AccompanyingPeriod implements
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function addStepHistory(AccompanyingPeriodStepHistory $stepHistory): self
|
private function addStepHistory(AccompanyingPeriodStepHistory $stepHistory, array $context = []): self
|
||||||
{
|
{
|
||||||
if (!$this->stepHistories->contains($stepHistory)) {
|
if (!$this->stepHistories->contains($stepHistory)) {
|
||||||
$this->stepHistories[] = $stepHistory;
|
$this->stepHistories[] = $stepHistory;
|
||||||
$stepHistory->setPeriod($this);
|
$stepHistory->setPeriod($this);
|
||||||
|
if (($context['closing_motive'] ?? null) instanceof ClosingMotive) {
|
||||||
|
$stepHistory->setClosingMotive($context['closing_motive']);
|
||||||
|
}
|
||||||
$this->ensureStepContinuity();
|
$this->ensureStepContinuity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,13 @@ class AccompanyingPeriodStepHistory implements TrackCreationInterface, TrackUpda
|
|||||||
*/
|
*/
|
||||||
private string $step;
|
private string $step;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ORM\ManyToOne(targetEntity=ClosingMotive::class)
|
||||||
|
*
|
||||||
|
* @ORM\JoinColumn(nullable=true)
|
||||||
|
*/
|
||||||
|
private ?AccompanyingPeriod\ClosingMotive $closingMotive = null;
|
||||||
|
|
||||||
public function getEndDate(): ?\DateTimeImmutable
|
public function getEndDate(): ?\DateTimeImmutable
|
||||||
{
|
{
|
||||||
return $this->endDate;
|
return $this->endDate;
|
||||||
@ -114,4 +121,16 @@ class AccompanyingPeriodStepHistory implements TrackCreationInterface, TrackUpda
|
|||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getClosingMotive(): ?AccompanyingPeriod\ClosingMotive
|
||||||
|
{
|
||||||
|
return $this->closingMotive;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setClosingMotive(?AccompanyingPeriod\ClosingMotive $closingMotive): self
|
||||||
|
{
|
||||||
|
$this->closingMotive = $closingMotive;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,4 +312,34 @@ final class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
|
|||||||
$this->assertNull($period->getRequestorPerson());
|
$this->assertNull($period->getRequestorPerson());
|
||||||
$this->assertNull($period->getRequestor());
|
$this->assertNull($period->getRequestor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetStep(): void
|
||||||
|
{
|
||||||
|
$period = new AccompanyingPeriod();
|
||||||
|
|
||||||
|
$period->setStep(AccompanyingPeriod::STEP_CONFIRMED);
|
||||||
|
|
||||||
|
self::assertEquals(AccompanyingPeriod::STEP_CONFIRMED, $period->getStep());
|
||||||
|
self::assertCount(1, $period->getStepHistories());
|
||||||
|
|
||||||
|
$period->setStep(AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT);
|
||||||
|
|
||||||
|
self::assertEquals(AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT, $period->getStep());
|
||||||
|
self::assertCount(2, $period->getStepHistories());
|
||||||
|
|
||||||
|
$periodInactiveSteps = $period->getStepHistories()->filter(fn (AccompanyingPeriod\AccompanyingPeriodStepHistory $h) => AccompanyingPeriod::STEP_CONFIRMED_INACTIVE_SHORT === $h->getStep());
|
||||||
|
self::assertCount(1, $periodInactiveSteps);
|
||||||
|
|
||||||
|
$period->setStep(AccompanyingPeriod::STEP_CLOSED, ['closing_motive' => $closingMotive = new AccompanyingPeriod\ClosingMotive()]);
|
||||||
|
|
||||||
|
self::assertEquals(AccompanyingPeriod::STEP_CLOSED, $period->getStep());
|
||||||
|
self::assertCount(3, $period->getStepHistories());
|
||||||
|
|
||||||
|
$periodClosedSteps = $period->getStepHistories()->filter(fn (AccompanyingPeriod\AccompanyingPeriodStepHistory $h) => AccompanyingPeriod::STEP_CLOSED === $h->getStep());
|
||||||
|
self::assertCount(1, $periodClosedSteps);
|
||||||
|
|
||||||
|
$periodClosedStep = $periodClosedSteps->first();
|
||||||
|
|
||||||
|
self::assertSame($closingMotive, $periodClosedStep->getClosingMotive());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
<?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\Migrations\Person;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
final class Version20240123161457 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return 'Store closing motive when closing a course';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_person_accompanying_period_step_history ADD closingMotive_id INT DEFAULT NULL');
|
||||||
|
$this->addSql('ALTER TABLE chill_person_accompanying_period_step_history ADD CONSTRAINT FK_84D514AC504CB38D FOREIGN KEY (closingMotive_id) REFERENCES chill_person_accompanying_period_closingmotive (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql('ALTER TABLE chill_person_accompanying_period_step_history ADD CONSTRAINT FK_84D514AC65FF1AEC FOREIGN KEY (updatedBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
|
||||||
|
$this->addSql(<<<'EOF'
|
||||||
|
WITH last_step AS (
|
||||||
|
SELECT * FROM (
|
||||||
|
SELECT *, rank() OVER (partition by period_id ORDER BY startdate DESC, id DESC) AS r FROM chill_person_accompanying_period_step_history cpapsh
|
||||||
|
) as sq
|
||||||
|
WHERE r = 1
|
||||||
|
)
|
||||||
|
UPDATE chill_person_accompanying_period_step_history
|
||||||
|
SET closingMotive_id = chill_person_accompanying_period.closingmotive_id
|
||||||
|
FROM last_step, chill_person_accompanying_period
|
||||||
|
WHERE last_step.period_id = chill_person_accompanying_period_step_history.period_id AND chill_person_accompanying_period.id = chill_person_accompanying_period_step_history.period_id
|
||||||
|
AND last_step.step = 'CLOSED';
|
||||||
|
EOF);
|
||||||
|
$this->addSql('CREATE INDEX IDX_84D514AC504CB38D ON chill_person_accompanying_period_step_history (closingMotive_id)');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
$this->addSql('ALTER TABLE chill_person_accompanying_period_step_history DROP CONSTRAINT FK_84D514AC504CB38D');
|
||||||
|
$this->addSql('ALTER TABLE chill_person_accompanying_period_step_history DROP CONSTRAINT FK_84D514AC65FF1AEC');
|
||||||
|
$this->addSql('DROP INDEX IDX_84D514AC504CB38D');
|
||||||
|
$this->addSql('ALTER TABLE chill_person_accompanying_period_step_history DROP closingMotive_id');
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user