rdv: adapt calendar entities: drop useless field and change field type

This commit is contained in:
nobohan 2021-07-23 09:59:20 +02:00
parent de6df983a0
commit c54290a265
5 changed files with 53 additions and 43 deletions

View File

@ -25,18 +25,18 @@ class LoadCancelReason extends Fixture implements FixtureGroupInterface
public function load(ObjectManager $manager): void
{
$arr = array(
array('name' => array('fr' => 'Annulé par l\'utilisateur')),
array('name' => array('fr' => 'Annulé par l\'usager')),
array('name' => array('fr' => 'Ne pas comptabiliser')),
array('name' => CancelReason::CANCELEDBY_USER),
array('name' => CancelReason::CANCELEDBY_PERSON),
array('name' => CancelReason::CANCELEDBY_DONOTCOUNT),
);
foreach ($arr as $a) {
print "Creating calendar cancel reason : " . $a['name']['fr'] . "\n";
print "Creating calendar cancel reason : " . $a['name'] . "\n";
$cancelReason= (new CancelReason())
->setCanceledBy($a['name'])
->setActive(true);
$manager->persist($cancelReason);
$reference = 'CancelReason_'.$a['name']['fr'];
$reference = 'CancelReason_'.$a['name'];
$this->addReference($reference, $cancelReason);
static::$references[] = $reference;
}

View File

@ -65,15 +65,6 @@ class Calendar
*/
private ?Collection $persons = null;
/**
*
* @ORM\ManyToMany(
* targetEntity="Chill\PersonBundle\Entity\Person",
* cascade={"persist", "remove", "merge", "detach"})
* @ORM\JoinTable(name="chill_calendar.calendar_to_non_professionals")
*/
private ?Collection $nonProfessionals = null;
/**
*
* @ORM\ManyToMany(
@ -140,7 +131,6 @@ class Calendar
{
$this->comment = new CommentEmbeddable();
$this->persons = new ArrayCollection();
$this->nonProfessionals = new ArrayCollection();
$this->professionals = new ArrayCollection();
$this->invites = new ArrayCollection();
}
@ -271,30 +261,6 @@ class Calendar
return $this;
}
/**
* @return Collection|Person[]
*/
public function getNonProfessionals(): Collection
{
return $this->nonProfessionals;
}
public function addNonProfessional(Person $nonProfessional): self
{
if (!$this->nonProfessionals->contains($nonProfessional)) {
$this->nonProfessionals[] = $nonProfessional;
}
return $this;
}
public function removeNonProfessional(Person $nonProfessional): self
{
$this->nonProfessionals->removeElement($nonProfessional);
return $this;
}
/**
* @return Collection|ThirdParty[]
*/

View File

@ -11,6 +11,11 @@ use Doctrine\ORM\Mapping as ORM;
*/
class CancelReason
{
const CANCELEDBY_USER = 'CANCELEDBY_USER';
const CANCELEDBY_PERSON = 'CANCELEDBY_PERSON';
const CANCELEDBY_DONOTCOUNT = 'CANCELEDBY_DONOTCOUNT';
/**
* @ORM\Id
* @ORM\GeneratedValue
@ -24,7 +29,7 @@ class CancelReason
private $active;
/**
* @ORM\Column(type="json_array")
* @ORM\Column(type="string", length=255)
*/
private $canceledBy;
@ -50,12 +55,12 @@ class CancelReason
return $this;
}
public function getCanceledBy(): ?array
public function getCanceledBy(): ?string
{
return $this->canceledBy;
}
public function setCanceledBy(array $canceledBy): self
public function setCanceledBy(string $canceledBy): self
{
$this->canceledBy = $canceledBy;

View File

@ -69,7 +69,7 @@ class CalendarType extends AbstractType
'required' => false,
'class' => CancelReason::class,
'choice_label' => function (CancelReason $entity) {
return $this->translatableStringHelper->localize($entity->getCanceledBy());
return $entity->getCanceledBy();
},
))
->add('sendSMS', ChoiceType::class, array(

View File

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Calendar;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Adapt calendar entities
*/
final class Version20210723074557 extends AbstractMigration
{
public function getDescription(): string
{
return 'Adapt calendar entities';
}
public function up(Schema $schema): void
{
$this->addSql('DROP TABLE chill_calendar.calendar_to_non_professionals');
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledby TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledby DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN chill_calendar.cancel_reason.canceledBy IS NULL');
}
public function down(Schema $schema): void
{
$this->addSql('CREATE TABLE chill_calendar.calendar_to_non_professionals (calendar_id INT NOT NULL, person_id INT NOT NULL, PRIMARY KEY(calendar_id, person_id))');
$this->addSql('CREATE INDEX idx_fadf2c77217bbb47 ON chill_calendar.calendar_to_non_professionals (person_id)');
$this->addSql('CREATE INDEX idx_fadf2c77a40a2c8 ON chill_calendar.calendar_to_non_professionals (calendar_id)');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals ADD CONSTRAINT fk_fadf2c77a40a2c8 FOREIGN KEY (calendar_id) REFERENCES chill_calendar.calendar (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_calendar.calendar_to_non_professionals ADD CONSTRAINT fk_fadf2c77217bbb47 FOREIGN KEY (person_id) REFERENCES chill_person_person (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledBy TYPE JSON');
$this->addSql('ALTER TABLE chill_calendar.cancel_reason ALTER canceledBy DROP DEFAULT');
$this->addSql('COMMENT ON COLUMN chill_calendar.cancel_reason.canceledby IS \'(DC2Type:json_array)\'');
}
}