add initial comment to accompanying period

This commit is contained in:
Julien Fastré 2021-05-18 19:04:09 +02:00
parent d327dae9fa
commit 2610730219
4 changed files with 110 additions and 6 deletions

View File

@ -122,10 +122,17 @@ class AccompanyingPeriod
* cascade={"persist", "remove"},
* orphanRemoval=true
* )
* @Groups({"read"})
*/
private $comments;
/**
* @ORM\ManyToOne(
* targetEntity=Comment::class
* )
* @Groups({"read"})
*/
private ?Comment $initialComment = null;
/**
* @var Collection
*
@ -210,21 +217,21 @@ class AccompanyingPeriod
/**
* @var bool
* @ORM\Column(type="boolean")
* @ORM\Column(type="boolean", options={"default": false} )
* @Groups({"read", "write"})
*/
private $requestorAnonymous = false;
/**
* @var bool
* @ORM\Column(type="boolean")
* @ORM\Column(type="boolean", options={"default": false} )
* @Groups({"read", "write"})
*/
private $emergency = false;
/**
* @var bool
* @ORM\Column(type="boolean")
* @ORM\Column(type="boolean", options={"default": false} )
* @Groups({"read", "write"})
*/
private $confidential = false;
@ -264,6 +271,7 @@ class AccompanyingPeriod
$this->participations = new ArrayCollection();
$this->scopes = new ArrayCollection();
$this->socialIssues = new ArrayCollection();
$this->comments = new ArrayCollection();
}
/**
@ -357,9 +365,14 @@ class AccompanyingPeriod
return $this->remark;
}
/**
* @Groups({"read"})
*/
public function getComments(): Collection
{
return $this->comments;
return $this->comments->filter(function (Comment $c) {
return $c !== $this->initialComment;
});
}
public function addComment(Comment $comment): self
@ -376,6 +389,30 @@ class AccompanyingPeriod
$this->comments->removeElement($comment);
}
/**
* @Groups({"write"})
*/
public function setInitialComment(?Comment $comment = null): self
{
if (NULL === $comment && NULL !== $this->initialComment) {
$this->removeComment($this->initialComment);
} elseif ($comment instanceof Comment) {
$this->addComment($comment);
}
$this->initialComment = $comment;
return $this;
}
/**
* @Groups({"read"})
*/
public function getInitialComment(): ?Comment
{
return $this->initialComment;
}
/**
* Get Participations Collection
*/

View File

@ -25,6 +25,7 @@ namespace Chill\PersonBundle\Tests\Entity;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
{
@ -131,4 +132,23 @@ class AccompanyingPeriodTest extends \PHPUnit\Framework\TestCase
$this->assertNull($period->getRequestorPerson());
$this->assertNull($period->getRequestor());
}
public function testInitialComment()
{
$period = new AccompanyingPeriod(new \DateTime());
$comment = new Comment();
$period->setInitialComment(NULL);
$this->assertNull($period->getInitialComment());
$period->setInitialComment($comment);
$this->assertSame($period->getInitialComment(), $comment);
$this->assertSame($period, $comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments");
$period->setInitialComment(NULL);
$this->assertNull($period->getInitialComment());
$this->assertNull($comment->getAccompanyingPeriod());
$this->assertEquals(0, count($period->getComments()), "The initial comment should not appears in the list of comments");
}
}

View File

@ -202,7 +202,7 @@ paths:
patch:
tags:
- person
summary: "Return the description for an accompanying course (accompanying period)"
summary: "Alter an accompanying course (accompanying period)"
parameters:
- name: id
in: path
@ -219,6 +219,22 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/AccompanyingPeriod'
examples:
Set the requestor as anonymous:
value:
type: accompanying_period
id: 12345
requestorAnonymous: true
Adding an initial comment:
value:
type: accompanying_period
id: 2668,
initialComment:
type: accompanying_period_comment
content: >
This is my an initial comment.
Say hello to the new "parcours"!
responses:
401:
description: "Unauthorized"

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Person;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Add a column "initial comment" in accompanying period
*/
final class Version20210518162439 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a column "initial comment" in accompanying period';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD initialComment_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_person_accompanying_period ADD CONSTRAINT FK_E260A8683111D50B FOREIGN KEY (initialComment_id) REFERENCES chill_person_accompanying_period_comment (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_E260A8683111D50B ON chill_person_accompanying_period (initialComment_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_person_accompanying_period DROP initialComment_id');
}
}