Skip to content

Commit

Permalink
[Event] merge committee and default types
Browse files Browse the repository at this point in the history
  • Loading branch information
ottaviano committed Feb 4, 2025
1 parent ee51157 commit 4003648
Show file tree
Hide file tree
Showing 132 changed files with 875 additions and 1,694 deletions.
12 changes: 1 addition & 11 deletions config/services/admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,18 +196,8 @@
</service>

<service id="app.admin.event" class="App\Admin\EventAdmin">
<tag name="sonata.admin" manager-type="orm" label="Événements" group="Territoires" />
<tag name="sonata.admin" manager-type="orm" label="Événements" model_class="App\Entity\Event\Event" group="Territoires" />

<argument />
<argument>App\Entity\Event\BaseEvent</argument>
<argument />
<argument type="service" id="event_dispatcher"/>
<call method="setSubClasses">
<argument type="collection">
<argument>App\Entity\Event\DefaultEvent</argument>
<argument>App\Entity\Event\CommitteeEvent</argument>
</argument>
</call>
<call method="setTemplate">
<argument>show</argument>
<argument>admin/event/show.html.twig</argument>
Expand Down
5 changes: 0 additions & 5 deletions config/services/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

<!-- Doctrine Listeners -->
<service id="App\Entity\Listener\ContainingUserDocumentListener" public="true">
<tag name="doctrine.orm.entity_listener" entity="App\Entity\Event\CommitteeEvent" event="prePersist"/>
<tag name="doctrine.orm.entity_listener" entity="App\Entity\Event\CommitteeEvent" event="preUpdate"/>
<tag name="doctrine.orm.entity_listener" entity="App\Entity\Event\CommitteeEvent" event="postUpdate"/>
<tag name="doctrine.orm.entity_listener" entity="App\Entity\Event\CommitteeEvent" event="preRemove"/>
<tag name="doctrine.orm.entity_listener" entity="App\Entity\Event\CommitteeEvent" event="postRemove"/>
<tag name="doctrine.orm.entity_listener" entity="App\Entity\Jecoute\News" event="prePersist"/>
<tag name="doctrine.orm.entity_listener" entity="App\Entity\Jecoute\News" event="preUpdate"/>
<tag name="doctrine.orm.entity_listener" entity="App\Entity\Jecoute\News" event="postUpdate"/>
Expand Down
12 changes: 9 additions & 3 deletions features/api/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Feature:
"name": "Réunion de réflexion bellifontaine",
"description": null,
"time_zone": "Europe/Paris",
"committee": null,
"live_url": null,
"slug": "@string@",
"committee": null,
Expand Down Expand Up @@ -966,6 +967,7 @@ Feature:
"slug": "@string@-un-evenement-du-referent-annule",
"description": "Description de l'événement du référent annulé",
"time_zone": "Europe/Paris",
"committee": null,
"live_url": null,
"visibility": "public",
"created_at": "@string@.isDateTime()",
Expand Down Expand Up @@ -1017,6 +1019,7 @@ Feature:
"slug": "@string@-un-evenement-du-referent-annule",
"description": "Description de l'événement du référent annulé",
"time_zone": "Europe/Paris",
"committee": null,
"live_url": null,
"visibility": "public",
"created_at": "@string@.isDateTime()",
Expand Down Expand Up @@ -1249,6 +1252,7 @@ Feature:
"slug": "2023-01-29-nouveau-evenement",
"description": "Une description de l'événement",
"time_zone": "Europe/Paris",
"committee": null,
"live_url": null,
"visibility": "private",
"created_at": "@string@.isDateTime()",
Expand Down Expand Up @@ -1304,7 +1308,6 @@ Feature:
"""
{
"name": "Nouveau événement",
"type": "committee",
"category": "kiosque",
"description": "Une description de l'événement",
"begin_at": "2023-01-29 16:30:30",
Expand Down Expand Up @@ -1582,7 +1585,7 @@ Feature:
}
}
"""
And I should have 1 notification "CommitteeEventCreatedNotification" with data:
And I should have 1 notification "EventCreatedNotification" with data:
| key | value |
| data | {"link":"http://vox.code/evenements/2023-01-29-nouveau-evenement"} |
| scope | committee:17 |
Expand Down Expand Up @@ -1641,6 +1644,7 @@ Feature:
"slug": "@string@-nouvel-evenement-online",
"description": "Nouvelle description",
"time_zone": "Europe/Paris",
"committee": null,
"live_url": null,
"visibility": "public",
"created_at": "@string@.isDateTime()",
Expand Down Expand Up @@ -2007,6 +2011,7 @@ Feature:
"slug": "2023-01-29-nouveau-evenement",
"description": "Une description de l'événement",
"time_zone": "Europe/Paris",
"committee": null,
"live_url": null,
"visibility": "public",
"created_at": "@string@.isDateTime()",
Expand Down Expand Up @@ -2045,7 +2050,7 @@ Feature:
"edit_link": "@string@.isUrl()"
}
"""
And I should have 1 notification "DefaultEventCreatedNotification" with data:
And I should have 1 notification "EventCreatedNotification" with data:
| key | value |
| data | {"link":"http://vox.code/evenements/2023-01-29-nouveau-evenement"} |
| scope | zone:75 |
Expand Down Expand Up @@ -2087,6 +2092,7 @@ Feature:
"slug": "@string@-un-evenement-du-candidat-aux-legislatives",
"description": "Nouvelle description",
"time_zone": "Europe/Paris",
"committee": null,
"live_url": null,
"visibility": "public",
"created_at": "@string@.isDateTime()",
Expand Down
70 changes: 70 additions & 0 deletions migrations/2025/Version20250201142049.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20250201142049 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE event_user_documents DROP FOREIGN KEY FK_7D14491F6A24B1A2');
$this->addSql('ALTER TABLE event_user_documents DROP FOREIGN KEY FK_7D14491F71F7E88B');
$this->addSql('DROP TABLE event_user_documents');
$this->addSql('ALTER TABLE events DROP is_for_legislatives, DROP type, DROP renaissance_event');
$this->addSql('ALTER TABLE event_zone DROP FOREIGN KEY FK_BF208CAC3B1C4B73');
$this->addSql('DROP INDEX IDX_BF208CAC3B1C4B73 ON event_zone');
$this->addSql('DROP INDEX `primary` ON event_zone');
$this->addSql('ALTER TABLE event_zone CHANGE base_event_id event_id INT UNSIGNED NOT NULL');
$this->addSql('ALTER TABLE
event_zone
ADD
CONSTRAINT FK_BF208CAC71F7E88B FOREIGN KEY (event_id) REFERENCES `events` (id) ON DELETE CASCADE');
$this->addSql('CREATE INDEX IDX_BF208CAC71F7E88B ON event_zone (event_id)');
$this->addSql('ALTER TABLE event_zone ADD PRIMARY KEY (event_id, zone_id)');
}

public function down(Schema $schema): void
{
$this->addSql('CREATE TABLE event_user_documents (
event_id INT UNSIGNED NOT NULL,
user_document_id INT UNSIGNED NOT NULL,
INDEX IDX_7D14491F6A24B1A2 (user_document_id),
INDEX IDX_7D14491F71F7E88B (event_id),
PRIMARY KEY(event_id, user_document_id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = \'\'');
$this->addSql('ALTER TABLE
event_user_documents
ADD
CONSTRAINT FK_7D14491F6A24B1A2 FOREIGN KEY (user_document_id) REFERENCES user_documents (id) ON
UPDATE
NO ACTION ON DELETE CASCADE');
$this->addSql('ALTER TABLE
event_user_documents
ADD
CONSTRAINT FK_7D14491F71F7E88B FOREIGN KEY (event_id) REFERENCES events (id) ON
UPDATE
NO ACTION ON DELETE CASCADE');
$this->addSql('ALTER TABLE event_zone DROP FOREIGN KEY FK_BF208CAC71F7E88B');
$this->addSql('DROP INDEX IDX_BF208CAC71F7E88B ON event_zone');
$this->addSql('DROP INDEX `PRIMARY` ON event_zone');
$this->addSql('ALTER TABLE event_zone CHANGE event_id base_event_id INT UNSIGNED NOT NULL');
$this->addSql('ALTER TABLE
event_zone
ADD
CONSTRAINT FK_BF208CAC3B1C4B73 FOREIGN KEY (base_event_id) REFERENCES events (id) ON
UPDATE
NO ACTION ON DELETE CASCADE');
$this->addSql('CREATE INDEX IDX_BF208CAC3B1C4B73 ON event_zone (base_event_id)');
$this->addSql('ALTER TABLE event_zone ADD PRIMARY KEY (base_event_id, zone_id)');
$this->addSql('ALTER TABLE
`events`
ADD
is_for_legislatives TINYINT(1) DEFAULT 0,
ADD
type VARCHAR(255) NOT NULL,
ADD
renaissance_event TINYINT(1) DEFAULT 0 NOT NULL');
}
}
20 changes: 4 additions & 16 deletions src/Adherent/Unregistration/Handlers/UpdateEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
namespace App\Adherent\Unregistration\Handlers;

use App\Entity\Adherent;
use App\Event\EventTypeEnum;
use App\Repository\EventRepository;
use Doctrine\ORM\EntityManagerInterface;
use App\Repository\Event\EventRepository;

class UpdateEventHandler implements UnregistrationAdherentHandlerInterface
{
private EntityManagerInterface $entityManager;

public function __construct(EntityManagerInterface $entityManager)
public function __construct(private readonly EventRepository $repository)
{
$this->entityManager = $entityManager;
}

public function supports(Adherent $adherent): bool
Expand All @@ -23,14 +18,7 @@ public function supports(Adherent $adherent): bool

public function handle(Adherent $adherent): void
{
foreach (EventTypeEnum::CLASSES as $class) {
$this->updateEvents($this->entityManager->getRepository($class), $adherent);
}
}

private function updateEvents(EventRepository $repository, Adherent $adherent): void
{
$repository->removeOrganizerEvents($adherent, EventRepository::TYPE_PAST, true);
$repository->removeOrganizerEvents($adherent, EventRepository::TYPE_UPCOMING);
$this->repository->removeOrganizerEvents($adherent, EventRepository::TYPE_PAST, true);
$this->repository->removeOrganizerEvents($adherent, EventRepository::TYPE_UPCOMING);
}
}
70 changes: 22 additions & 48 deletions src/Admin/EventAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

use App\Admin\Filter\PostalCodeFilter;
use App\Admin\Filter\ZoneAutocompleteFilter;
use App\Entity\Event\BaseEvent;
use App\Entity\Event\CommitteeEvent;
use App\Entity\Event\DefaultEvent;
use App\Entity\Event\EventCategory;
use App\Event\CommitteeEventEvent;
use App\Entity\Event\Event;
use App\Event\EventEvent;
use App\Event\EventVisibilityEnum;
use App\Events;
use App\Form\EventCategoryType;
use App\Utils\PhpConfigurator;
use Doctrine\ORM\Query\Expr\Join;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Filter\Model\FilterData;
Expand All @@ -34,23 +29,13 @@
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\Service\Attribute\Required;

class EventAdmin extends AbstractAdmin
{
private $dispatcher;
private $beforeUpdate;

public function __construct(
$code,
$class,
$baseControllerName,
EventDispatcherInterface $dispatcher,
) {
parent::__construct($code, $class, $baseControllerName);

$this->dispatcher = $dispatcher;
}

protected function configureRoutes(RouteCollectionInterface $collection): void
{
$collection
Expand Down Expand Up @@ -134,7 +119,7 @@ protected function configureShowFields(ShowMapper $show): void
}

/**
* @param BaseEvent $object
* @param Event $object
*/
protected function alterObject(object $object): void
{
Expand All @@ -151,17 +136,11 @@ protected function preUpdate(object $object): void
}

/**
* @param BaseEvent $object
* @param Event $object
*/
protected function postUpdate(object $object): void
{
if ($object instanceof CommitteeEvent) {
$event = new CommitteeEventEvent($object->getOrganizer(), $object);
} else {
$event = new EventEvent($object->getOrganizer(), $object);
}

$this->dispatcher->dispatch($event, Events::EVENT_UPDATED);
$this->dispatcher->dispatch(new EventEvent($object->getOrganizer(), $object), Events::EVENT_UPDATED);
}

protected function configureFormFields(FormMapper $form): void
Expand All @@ -176,21 +155,15 @@ protected function configureFormFields(FormMapper $form): void
->add('category', EventCategoryType::class, [
'label' => 'Catégorie',
])
;

if (CommitteeEvent::class === $event::class) {
$form->add('committee', null, [
'label' => 'Comité organisateur',
]);
}

$form
->add('description', null, [
'label' => 'Description',
'attr' => [
'rows' => '3',
],
])
->add('committee', null, [
'label' => 'Comité organisateur',
])
->add('description', null, [
'label' => 'Description',
'attr' => [
'rows' => '3',
],
])
->add('beginAt', null, [
'label' => 'Date de début',
])
Expand All @@ -199,7 +172,7 @@ protected function configureFormFields(FormMapper $form): void
])
->add('status', ChoiceType::class, [
'label' => 'Statut',
'choices' => BaseEvent::STATUSES,
'choices' => Event::STATUSES,
'choice_translation_domain' => 'forms',
'choice_label' => function (?string $choice) {
return $choice;
Expand All @@ -212,9 +185,6 @@ protected function configureFormFields(FormMapper $form): void
'label' => 'Visibilité',
'class' => EventVisibilityEnum::class,
])
->add('renaissanceEvent', null, [
'label' => 'Événement renaissance',
])
->end()
->with('Adresse', ['class' => 'col-md-5'])
->add('postAddress.address', TextType::class, [
Expand Down Expand Up @@ -266,9 +236,7 @@ protected function configureDatagridFilters(DatagridMapper $filter): void
}

$qb
->leftJoin(CommitteeEvent::class, 'committeeEvent', Join::WITH, 'committeeEvent.id = '.$alias.'.id')
->leftJoin(DefaultEvent::class, 'defaultEvent', Join::WITH, 'defaultEvent.id = '.$alias.'.id')
->leftJoin(EventCategory::class, 'eventCategory', Join::WITH, 'eventCategory = committeeEvent.category OR eventCategory = defaultEvent.category')
->leftJoin('event.category', 'eventCategory')
->andWhere('eventCategory IN (:category)')
->setParameter('category', $value->getValue())
;
Expand Down Expand Up @@ -405,4 +373,10 @@ protected function configureExportFields(): array
'Date de modification' => 'updatedAt',
];
}

#[Required]
public function setDispatcher(EventDispatcherInterface $dispatcher): void
{
$this->dispatcher = $dispatcher;
}
}
Loading

0 comments on commit 4003648

Please sign in to comment.