Add animators property to event

This commit is contained in:
Julie Lenaerts 2025-05-07 10:26:39 +02:00
parent d5599ac6cc
commit 36a484c708
7 changed files with 116 additions and 49 deletions

View File

@ -23,6 +23,7 @@ use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\Location;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
@ -48,20 +49,28 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
#[ORM\ManyToOne(targetEntity: Scope::class)]
private ?Scope $circle = null;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE)]
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTime $date = null;
#[ORM\Id]
#[ORM\Column(name: 'id', type: \Doctrine\DBAL\Types\Types::INTEGER)]
#[ORM\Column(name: 'id', type: Types::INTEGER)]
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $moderator = null;
/**
* @var Collection<int, ThirdParty>
*/
#[ORM\ManyToMany(targetEntity: ThirdParty::class)]
#[Serializer\Groups(['read'])]
#[ORM\JoinTable('chill_event_thirdparty')]
private Collection $animators;
#[Assert\NotBlank]
#[Serializer\Groups(['read'])]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 150)]
#[ORM\Column(type: Types::STRING, length: 150)]
private ?string $name = null;
/**
@ -99,9 +108,6 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
#[ORM\JoinTable('chill_event_event_documents')]
private Collection $documents;
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 4, nullable: true, options: ['default' => '0.0'])]
private string $organizationCost = '0.0';
/**
* @var Collection<int, EventBudgetElement>
*/
@ -119,6 +125,7 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
$this->comment = new CommentEmbeddable();
$this->themes = new ArrayCollection();
$this->budgetElements = new ArrayCollection();
$this->animators = new ArrayCollection();
}
public function addBudgetElement(EventBudgetElement $budgetElement)
@ -176,17 +183,28 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
$this->themes->removeElement($theme);
}
/**
* @return Center
*/
public function getAnimators(): Collection
{
return $this->animators;
}
public function addAnimator(ThirdParty $tp): self
{
$this->animators->add($tp);
return $this;
}
public function removeAnimator(ThirdParty $tp): void
{
$this->animators->removeElement($tp);
}
public function getCenter(): ?Center
{
return $this->center;
}
/**
* @return Scope
*/
public function getCircle(): ?Scope
{
return $this->circle;
@ -194,8 +212,6 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
/**
* Get date.
*
* @return \DateTime
*/
public function getDate(): ?\DateTime
{
@ -204,8 +220,6 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
/**
* Get id.
*
* @return int
*/
public function getId(): ?int
{
@ -219,8 +233,6 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
/**
* Get label.
*
* @return string
*/
public function getName(): ?string
{
@ -257,17 +269,12 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
/**
* @deprecated
*
* @return Scope
*/
public function getScope(): ?Scope
{
return $this->getCircle();
}
/**
* @return EventType
*/
public function getType(): ?EventType
{
return $this->type;
@ -376,14 +383,4 @@ class Event implements HasCenterInterface, HasScopeInterface, TrackCreationInter
{
$this->documents = $documents;
}
public function getOrganizationCost(): string
{
return $this->organizationCost;
}
public function setOrganizationCost(string $organizationCost): void
{
$this->organizationCost = $organizationCost;
}
}

View File

@ -15,7 +15,6 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Form\StoredObjectType;
use Chill\EventBundle\Entity\BudgetTypeEnum;
use Chill\EventBundle\Entity\Event;
use Chill\EventBundle\Form\Type\PickEventBudgetKindType;
use Chill\EventBundle\Form\Type\PickEventThemeType;
use Chill\EventBundle\Form\Type\PickEventTypeType;
use Chill\EventBundle\Repository\EventBudgetKindRepository;
@ -26,10 +25,9 @@ use Chill\MainBundle\Form\Type\ChillDateTimeType;
use Chill\MainBundle\Form\Type\CommentType;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\ThirdPartyBundle\Form\Type\PickThirdpartyDynamicType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -39,10 +37,9 @@ class EventType extends AbstractType
public function __construct(
private readonly IdToLocationDataTransformer $idToLocationDataTransformer,
private readonly EventBudgetKindRepository $eventBudgetKindRepository,
private readonly TranslatableStringHelperInterface $translatableStringHelper,
) {}
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$chargeKinds = $this->eventBudgetKindRepository->findByType(BudgetTypeEnum::CHARGE->value);
$resourceKinds = $this->eventBudgetKindRepository->findByType(BudgetTypeEnum::RESOURCE->value);
@ -70,6 +67,9 @@ class EventType extends AbstractType
->add('moderator', PickUserDynamicType::class, [
'label' => 'Pick a moderator',
])
->add('animators', PickThirdpartyDynamicType::class, [
'multiple' => true,
])
->add('budgetElements', ChillCollectionType::class, [
'entry_type' => AddEventBudgetElementType::class,
'entry_options' => ['label' => false],
@ -91,10 +91,6 @@ class EventType extends AbstractType
'delete_empty' => fn (StoredObject $storedObject): bool => '' === $storedObject->getFilename(),
'button_remove_label' => 'event.form.remove_document',
'button_add_label' => 'event.form.add_document',
])
->add('organizationCost', MoneyType::class, [
'label' => 'event.fields.organizationCost',
'help' => 'event.form.organisationCost_help',
]);
$builder->add('location', HiddenType::class)
@ -116,7 +112,7 @@ class EventType extends AbstractType
/**
* @return string
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
// as the js shares some hardcoded items from the activity bundle, we have to rewrite block prefix
return 'chill_activitybundle_activity';

View File

@ -19,10 +19,9 @@
{{ form_row(edit_form.type, { label: "Event type" }) }}
{{ form_row(edit_form.themes) }}
{{ form_row(edit_form.moderator) }}
{{ form_row(edit_form.animators) }}
{{ form_row(edit_form.location) }}
{{ form_row(edit_form.budgetElements) }}
{{ form_row(edit_form.organizationCost) }}
{{ form_row(edit_form.comment) }}
{{ form_row(edit_form.documents) }}

View File

@ -20,9 +20,9 @@
{{ form_row(form.type, { label: "Event type" }) }}
{{ form_row(form.themes) }}
{{ form_row(form.moderator) }}
{{ form_row(form.animators) }}
{{ form_row(form.location) }}
<div id="location"></div>
{{ form_row(form.organizationCost) }}
{{ form_row(form.budgetElements) }}
{{ form_row(form.comment) }}
{{ form_row(form.documents) }}

View File

@ -16,6 +16,16 @@
{{ encore_entry_link_tags('mod_document_action_buttons_group') }}
{% endblock %}
{% macro insert_onthefly(type, entity, parent = null) %}
{% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
action: 'show', displayBadge: true,
targetEntity: { name: type, id: entity.id },
buttonText: entity|chill_entity_render_string,
isDead: entity.deathdate is defined and entity.deathdate is not null,
parent: parent
} %}
{% endmacro %}
{% block event_content -%}
<div class="col-10">
<h1>{{ 'Details of an event'|trans }}</h1>
@ -48,7 +58,15 @@
</tr>
<tr>
<th>{{ 'Moderator'|trans }}</th>
<td>{{ event.moderator|trans|default('-') }}</td>
<td>{{ event.moderator|chill_entity_render_string }}</td>
</tr>
<tr>
<th>{{ 'Animators'|trans }}</th>
<td>
{% for a in event.animators %}
{{ _self.insert_onthefly('thirdparty', a) }}
{% endfor %}
</td>
</tr>
<tr>
<th>{{ 'event.fields.location'|trans }}</th>

View File

@ -0,0 +1,57 @@
<?php
declare(strict_types=1);
namespace Chill\Migrations\Event;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250507073301 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add animators field to an event';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
CREATE TABLE chill_event_thirdparty (event_id INT NOT NULL, thirdparty_id INT NOT NULL, PRIMARY KEY(event_id, thirdparty_id))
SQL);
$this->addSql(<<<'SQL'
CREATE INDEX IDX_9946573E71F7E88B ON chill_event_thirdparty (event_id)
SQL);
$this->addSql(<<<'SQL'
CREATE INDEX IDX_9946573EC7D3A8E6 ON chill_event_thirdparty (thirdparty_id)
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_event_thirdparty ADD CONSTRAINT FK_9946573E71F7E88B FOREIGN KEY (event_id) REFERENCES chill_event_event (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_event_thirdparty ADD CONSTRAINT FK_9946573EC7D3A8E6 FOREIGN KEY (thirdparty_id) REFERENCES chill_3party.third_party (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_event_event DROP organizationcost
SQL);
}
public function down(Schema $schema): void
{
$this->addSql(<<<'SQL'
ALTER TABLE chill_event_thirdparty DROP CONSTRAINT FK_9946573E71F7E88B
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_event_thirdparty DROP CONSTRAINT FK_9946573EC7D3A8E6
SQL);
$this->addSql(<<<'SQL'
DROP TABLE chill_event_thirdparty
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_event_event ADD organizationcost NUMERIC(10, 4) DEFAULT '0.0'
SQL);
}
}

View File

@ -7,7 +7,7 @@ Participation: Participation
Participations: Participations
Status: Statut
Last update: Dernière mise à jour
Moderator: Animateur
Moderator: Responsable
#CRUD event
Details of an event: Détails d'un événement
@ -74,7 +74,7 @@ Show the event: Voir l'événement
Subscribe an event: Ajouter un événement
Pick an event: Choisir un événement
Pick a type of event: Choisir un type d'événement
Pick a moderator: Choisir un animateur
Pick a moderator: Choisir un responsable
# exports
Select a format: Choisir un format