adding Entities Location and LocationType (for activity/calendar) + doctrine migration

This commit is contained in:
Mathieu Jaumotte 2021-10-12 16:34:19 +02:00
parent 82ae300bd9
commit e570f5c28e
7 changed files with 502 additions and 3 deletions

View File

@ -23,6 +23,7 @@ namespace Chill\ActivityBundle\Entity;
use Chill\DocStoreBundle\Entity\Document;
use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\Location;
use Chill\PersonBundle\AccompanyingPeriod\SocialIssueConsistency\AccompanyingPeriodLinkedWithSocialIssuesEntityInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\SocialWork\SocialAction;
@ -177,6 +178,13 @@ class Activity implements HasCenterInterface, HasScopeInterface, AccompanyingPer
*/
private string $sentReceived = '';
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Location")
* @groups({"read"})
*/
private ?Location $location = null;
public function __construct()
{
$this->reasons = new ArrayCollection();
@ -555,4 +563,22 @@ class Activity implements HasCenterInterface, HasScopeInterface, AccompanyingPer
return $this;
}
/**
* @return Location|null
*/
public function getLocation(): ?Location
{
return $this->location;
}
/**
* @param Location|null $location
* @return Activity
*/
public function setLocation(?Location $location): Activity
{
$this->location = $location;
return $this;
}
}

View File

@ -2,6 +2,7 @@
namespace Chill\CalendarBundle\Entity;
use Chill\MainBundle\Entity\Location;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection;
@ -136,6 +137,13 @@ class Calendar
*/
private ?bool $sendSMS;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Location")
* @groups({"read"})
*/
private ?Location $location = null;
public function __construct()
{
$this->comment = new CommentEmbeddable();
@ -354,7 +362,7 @@ class Calendar
return $this;
}
public function getPersonsAssociated(): array
public function getPersonsAssociated(): array
{
if (null !== $this->accompanyingPeriod) {
$personsAssociated = [];
@ -363,11 +371,11 @@ class Calendar
$personsAssociated[] = $participation->getPerson();
}
}
return $personsAssociated;
return $personsAssociated;
}
return [];
}
public function getPersonsNotAssociated(): array
{
if (null !== $this->accompanyingPeriod) {
@ -407,4 +415,22 @@ class Calendar
]));
}
/**
* @return Location|null
*/
public function getLocation(): ?Location
{
return $this->location;
}
/**
* @param Location|null $location
* @return Calendar
*/
public function setLocation(?Location $location): Calendar
{
$this->location = $location;
return $this;
}
}

View File

@ -0,0 +1,238 @@
<?php
namespace Chill\MainBundle\Entity;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Repository\LocationRepository;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Table(name="chill_main_location")
* @ORM\Entity(repositoryClass=LocationRepository::class)
*/
class Location implements TrackCreationInterface, TrackUpdateInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
*/
private ?int $id = null;
/**
* @ORM\ManyToOne(targetEntity=LocationType::class)
* @ORM\JoinColumn(nullable=false)
* @Serializer\Groups({"read"})
*/
private ?LocationType $type = null;
/**
* @ORM\OneToOne(targetEntity=Address::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
* @Serializer\Groups({"read"})
*/
private ?Address $address = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Serializer\Groups({"read"})
*/
private ?string $name = null;
/**
* @ORM\Column(type="string", length=64, nullable=true)
* @Serializer\Groups({"read"})
* @Assert\Regex(pattern="/^([\+{1}])([0-9\s*]{4,20})$/")
* @PhonenumberConstraint(type="any")
*/
private ?string $phonenumber1 = null;
/**
* @ORM\Column(type="string", length=64, nullable=true)
* @Serializer\Groups({"read"})
* @Assert\Regex(pattern="/^([\+{1}])([0-9\s*]{4,20})$/")
* @PhonenumberConstraint(type="any")
*/
private ?string $phonenumber2 = null;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Serializer\Groups({"read"})
*/
private ?string $email = null;
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({"read"})
*/
private bool $availableForUsers = false;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @Serializer\Groups({"read"})
*/
private ?User $createdBy = null;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
* @Serializer\Groups({"read"})
*/
private ?\DateTimeImmutable $createdAt = null;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @Serializer\Groups({"read"})
*/
private ?User $updatedBy = null;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
* @Serializer\Groups({"read"})
*/
private ?\DateTimeImmutable $updatedAt = null;
public function getId(): ?int
{
return $this->id;
}
public function getType(): ?LocationType
{
return $this->type;
}
public function setType(?LocationType $type): self
{
$this->type = $type;
return $this;
}
public function getAddress(): ?Address
{
return $this->address;
}
public function setAddress(Address $address): self
{
$this->address = $address;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getPhonenumber1(): ?string
{
return $this->phonenumber1;
}
public function setPhonenumber1(?string $phonenumber1): self
{
$this->phonenumber1 = $phonenumber1;
return $this;
}
public function getPhonenumber2(): ?string
{
return $this->phonenumber2;
}
public function setPhonenumber2(?string $phonenumber2): self
{
$this->phonenumber2 = $phonenumber2;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): self
{
$this->email = $email;
return $this;
}
public function getAvailableForUsers(): ?bool
{
return $this->availableForUsers;
}
public function setAvailableForUsers(bool $availableForUsers): self
{
$this->availableForUsers = $availableForUsers;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->createdBy;
}
public function setCreatedBy(?User $createdBy): self
{
$this->createdBy = $createdBy;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedBy(): ?User
{
return $this->updatedBy;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
}

View File

@ -0,0 +1,104 @@
<?php
namespace Chill\MainBundle\Entity;
use Chill\MainBundle\Repository\LocationTypeRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_main_location_type")
* @ORM\Entity(repositoryClass=LocationTypeRepository::class)
*/
class LocationType
{
const STATUS_OPTIONAL = 'facultatif';
const STATUS_REQUIRED = 'obligatoire';
const STATUS_NEVER = 'jamais';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
* @Serializer\Groups({"read"})
*/
private array $title = [];
/**
* @ORM\Column(type="boolean")
* @Serializer\Groups({"read"})
*/
private bool $availableForUsers = true;
/**
* @ORM\Column(type="string", length=32)
* @Serializer\Groups({"read"})
*/
private ?string $addressRequired = null;
/**
* @ORM\Column(type="string", length=32)
* @Serializer\Groups({"read"})
*/
private ?string $contactData = null;
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?array
{
return $this->title;
}
public function setTitle(array $title): self
{
$this->title = $title;
return $this;
}
public function getAvailableForUsers(): ?bool
{
return $this->availableForUsers;
}
public function setAvailableForUsers(bool $availableForUsers): self
{
$this->availableForUsers = $availableForUsers;
return $this;
}
public function getAddressRequired(): ?string
{
return $this->addressRequired;
}
public function setAddressRequired(string $addressRequired): self
{
$this->addressRequired = $addressRequired;
return $this;
}
public function getContactData(): ?string
{
return $this->contactData;
}
public function setContactData(string $contactData): self
{
$this->contactData = $contactData;
return $this;
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\Location;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method Location|null find($id, $lockMode = null, $lockVersion = null)
* @method Location|null findOneBy(array $criteria, array $orderBy = null)
* @method Location[] findAll()
* @method Location[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class LocationRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Location::class);
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Chill\MainBundle\Repository;
use Chill\MainBundle\Entity\LocationType;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method LocationType|null find($id, $lockMode = null, $lockVersion = null)
* @method LocationType|null findOneBy(array $criteria, array $orderBy = null)
* @method LocationType[] findAll()
* @method LocationType[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class LocationTypeRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, LocationType::class);
}
}

View File

@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* @Author Mathieu Jaumotte mathieu.jaumotte@champs-libres.coop
*/
final class Version20211012141336 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add Location and LocationType Entities (for activity and calendar)';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE SEQUENCE chill_main_location_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE SEQUENCE chill_main_location_type_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE chill_main_location (id INT NOT NULL, type_id INT NOT NULL, address_id INT DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, phonenumber1 VARCHAR(64) DEFAULT NULL, phonenumber2 VARCHAR(64) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, availableForUsers BOOLEAN NOT NULL, createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, updatedAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, createdBy_id INT DEFAULT NULL, updatedBy_id INT DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_90E4736AC54C8C93 ON chill_main_location (type_id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_90E4736AF5B7AF75 ON chill_main_location (address_id)');
$this->addSql('CREATE INDEX IDX_90E4736A3174800F ON chill_main_location (createdBy_id)');
$this->addSql('CREATE INDEX IDX_90E4736A65FF1AEC ON chill_main_location (updatedBy_id)');
$this->addSql('COMMENT ON COLUMN chill_main_location.createdAt IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_main_location.updatedAt IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('CREATE TABLE chill_main_location_type (id INT NOT NULL, title JSON NOT NULL, availableForUsers BOOLEAN NOT NULL, addressRequired VARCHAR(32) NOT NULL, contactData VARCHAR(32) NOT NULL, PRIMARY KEY(id))');
$this->addSql('ALTER TABLE chill_main_location ADD CONSTRAINT FK_90E4736AC54C8C93 FOREIGN KEY (type_id) REFERENCES chill_main_location_type (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_main_location ADD CONSTRAINT FK_90E4736AF5B7AF75 FOREIGN KEY (address_id) REFERENCES chill_main_address (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_main_location ADD CONSTRAINT FK_90E4736A3174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_main_location ADD CONSTRAINT FK_90E4736A65FF1AEC FOREIGN KEY (updatedBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE activity ADD location_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE activity ADD CONSTRAINT FK_AC74095A64D218E FOREIGN KEY (location_id) REFERENCES chill_main_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_AC74095A64D218E ON activity (location_id)');
$this->addSql('ALTER TABLE chill_calendar.calendar ADD location_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE chill_calendar.calendar ADD CONSTRAINT FK_712315AC64D218E FOREIGN KEY (location_id) REFERENCES chill_main_location (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_712315AC64D218E ON chill_calendar.calendar (location_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE activity DROP CONSTRAINT FK_AC74095A64D218E');
$this->addSql('ALTER TABLE activity DROP location_id');
$this->addSql('ALTER TABLE chill_calendar.calendar DROP CONSTRAINT FK_712315AC64D218E');
$this->addSql('ALTER TABLE chill_calendar.calendar DROP location_id');
$this->addSql('ALTER TABLE chill_main_location DROP CONSTRAINT FK_90E4736AC54C8C93');
$this->addSql('DROP SEQUENCE chill_main_location_id_seq CASCADE');
$this->addSql('DROP SEQUENCE chill_main_location_type_id_seq CASCADE');
$this->addSql('DROP TABLE chill_main_location');
$this->addSql('DROP TABLE chill_main_location_type');
}
}