diff --git a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php index 3446fa6dd..14ede1335 100644 --- a/src/Bundle/ChillActivityBundle/Entity/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Entity/ActivityType.php @@ -248,6 +248,16 @@ class ActivityType */ private string $socialActionsLabel = ''; + /** + * @ORM\Column(type="smallint", nullable=false, options={"default"=1}) + */ + private int $locationVisible = self::FIELD_INVISIBLE; + + /** + * @ORM\Column(type="string", nullable=false, options={"default"=""}) + */ + private string $locationLabel = ''; + /** * @ORM\Column(type="float", options={"default"="0.0"}) */ @@ -820,4 +830,29 @@ class ActivityType return $this; } + + public function getLocationVisible(): ?int + { + return $this->locationVisible; + } + + public function setLocationVisible(int $locationVisible): self + { + $this->locationVisible = $locationVisible; + + return $this; + } + + public function getLocationLabel(): ?string + { + return $this->locationLabel; + } + + public function setLocationLabel(string $locationLabel): self + { + $this->locationLabel = $locationLabel; + + return $this; + } + } diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index 94c639d17..24b3c7ab6 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -302,18 +302,9 @@ class ActivityType extends AbstractType ; } - /* if ($activityType->isVisible('location')) { - $builder - ->add('location', HiddenType::class) - ->get('location') - ->addModelTransformer(new CallbackTransformer( - function () {}, - function () {} - )) - ; + $builder->add('location', HiddenType::class); } - */ if ($activityType->isVisible('emergency')) { $builder->add('emergency', CheckboxType::class, [ diff --git a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue index e25923850..6ee4ba669 100644 --- a/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue +++ b/src/Bundle/ChillActivityBundle/Resources/public/vuejs/Activity/components/Location.vue @@ -65,7 +65,7 @@ export default { })) }, customLabel(value) { - return `${value.type.title.fr} ${value.name}`; + return `${value.locationType.title.fr} ${value.name}`; } } } diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig index 6e5caeda3..07e5d7a59 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/edit.html.twig @@ -54,7 +54,10 @@ {{ form_row(edit_form.date) }} {% endif %} -
+{%- if edit_form.location is defined -%} + {{ form_row(edit_form.location) }} +
+{% endif %} {%- if edit_form.durationTime is defined -%} {{ form_row(edit_form.durationTime) }} diff --git a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig index 8a73ec074..10afd77a2 100644 --- a/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig +++ b/src/Bundle/ChillActivityBundle/Resources/views/Activity/new.html.twig @@ -55,7 +55,10 @@ {{ form_row(form.date) }} {% endif %} -
+{%- if form.location is defined -%} + {{ form_row(form.location) }} +
+{% endif %} {%- if form.durationTime is defined -%} {{ form_row(form.durationTime) }} diff --git a/src/Bundle/ChillMainBundle/Entity/Location.php b/src/Bundle/ChillMainBundle/Entity/Location.php index 976867d6a..7a8e37750 100644 --- a/src/Bundle/ChillMainBundle/Entity/Location.php +++ b/src/Bundle/ChillMainBundle/Entity/Location.php @@ -29,7 +29,7 @@ class Location implements TrackCreationInterface, TrackUpdateInterface * @ORM\JoinColumn(nullable=false) * @Serializer\Groups({"read"}) */ - private ?LocationType $type = null; + private ?LocationType $locationType = null; /** * @ORM\OneToOne(targetEntity=Address::class, cascade={"persist", "remove"}) @@ -104,14 +104,14 @@ class Location implements TrackCreationInterface, TrackUpdateInterface return $this->id; } - public function getType(): ?LocationType + public function getLocationType(): ?LocationType { - return $this->type; + return $this->locationType; } - public function setType(?LocationType $type): self + public function setLocationType(?LocationType $locationType): self { - $this->type = $type; + $this->locationType = $locationType; return $this; } diff --git a/src/Bundle/ChillMainBundle/Entity/LocationType.php b/src/Bundle/ChillMainBundle/Entity/LocationType.php index 374d1db10..12646aaf3 100644 --- a/src/Bundle/ChillMainBundle/Entity/LocationType.php +++ b/src/Bundle/ChillMainBundle/Entity/LocationType.php @@ -12,9 +12,9 @@ use Symfony\Component\Serializer\Annotation as Serializer; */ class LocationType { - const STATUS_OPTIONAL = 'facultatif'; - const STATUS_REQUIRED = 'obligatoire'; - const STATUS_NEVER = 'jamais'; + const STATUS_OPTIONAL = 'optional'; + const STATUS_REQUIRED = 'required'; + const STATUS_NEVER = 'never'; /** * @ORM\Id @@ -37,16 +37,16 @@ class LocationType private bool $availableForUsers = true; /** - * @ORM\Column(type="string", length=32) + * @ORM\Column(type="string", length=32, options={"default"="optional"}) * @Serializer\Groups({"read"}) */ - private ?string $addressRequired = null; + private string $addressRequired = self::STATUS_OPTIONAL; /** - * @ORM\Column(type="string", length=32) + * @ORM\Column(type="string", length=32, options={"default"="optional"}) * @Serializer\Groups({"read"}) */ - private ?string $contactData = null; + private string $contactData = self::STATUS_OPTIONAL; public function getId(): ?int diff --git a/src/Bundle/ChillMainBundle/migrations/Version20211012141336.php b/src/Bundle/ChillMainBundle/migrations/Version20211012141336.php index 89f2d6221..4ed8da1dc 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20211012141336.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20211012141336.php @@ -21,15 +21,18 @@ final class Version20211012141336 extends AbstractMigration { $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 TABLE chill_main_location (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, locationType_id INT NOT NULL, createdBy_id INT DEFAULT NULL, updatedBy_id INT DEFAULT NULL, PRIMARY KEY(id))'); + + $this->addSql('CREATE INDEX IDX_90E4736AB8B0DA8E ON chill_main_location (locationType_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('CREATE TABLE chill_main_location_type (id INT NOT NULL, title JSON NOT NULL, availableForUsers BOOLEAN NOT NULL, addressRequired VARCHAR(32) DEFAULT \'optional\' NOT NULL, contactData VARCHAR(32) DEFAULT \'optional\' NOT NULL, PRIMARY KEY(id))'); + + $this->addSql('ALTER TABLE chill_main_location ADD CONSTRAINT FK_90E4736AB8B0DA8E FOREIGN KEY (locationType_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'); @@ -45,13 +48,14 @@ final class Version20211012141336 extends AbstractMigration 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('ALTER TABLE chill_main_location DROP CONSTRAINT FK_90E4736AB8B0DA8E'); $this->addSql('DROP SEQUENCE chill_main_location_id_seq CASCADE'); $this->addSql('DROP SEQUENCE chill_main_location_type_id_seq CASCADE'); diff --git a/src/Bundle/ChillMainBundle/migrations/Version20211013124455.php b/src/Bundle/ChillMainBundle/migrations/Version20211013124455.php new file mode 100644 index 000000000..0d30cece5 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20211013124455.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE activitytype ADD locationVisible SMALLINT DEFAULT 1 NOT NULL'); + $this->addSql('ALTER TABLE activitytype ADD locationLabel VARCHAR(255) DEFAULT \'\' NOT NULL'); + + // fix old migration !? + $this->addSql('ALTER TABLE activitytype ALTER category_id DROP DEFAULT'); + + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE activitytype DROP locationVisible'); + $this->addSql('ALTER TABLE activitytype DROP locationLabel'); + + // fix old migration !? + $this->addSql('ALTER TABLE activitytype ALTER category_id SET DEFAULT 1'); + + } +}