mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-18 14:56:13 +00:00
Add field in event for themes
This commit is contained in:
parent
4895b31b2c
commit
2ac59ad763
@ -11,6 +11,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Chill\EventBundle\Entity;
|
namespace Chill\EventBundle\Entity;
|
||||||
|
|
||||||
|
use Chill\EventBundle\Repository\EventThemeRepository;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\DBAL\Types\Types;
|
use Doctrine\DBAL\Types\Types;
|
||||||
@ -19,8 +20,8 @@ use Doctrine\ORM\Mapping as ORM;
|
|||||||
/**
|
/**
|
||||||
* Class EventTheme.
|
* Class EventTheme.
|
||||||
*/
|
*/
|
||||||
#[ORM\Entity]
|
|
||||||
#[ORM\HasLifecycleCallbacks]
|
#[ORM\HasLifecycleCallbacks]
|
||||||
|
#[ORM\Entity(repositoryClass: EventThemeRepository::class)]
|
||||||
#[ORM\Table(name: 'chill_event_event_theme')]
|
#[ORM\Table(name: 'chill_event_event_theme')]
|
||||||
class EventTheme
|
class EventTheme
|
||||||
{
|
{
|
||||||
@ -82,7 +83,6 @@ class EventTheme
|
|||||||
/**
|
/**
|
||||||
* Set active.
|
* Set active.
|
||||||
*
|
*
|
||||||
* @param bool $active
|
|
||||||
* @return EventTheme
|
* @return EventTheme
|
||||||
*/
|
*/
|
||||||
public function setIsActive(bool $active): static
|
public function setIsActive(bool $active): static
|
||||||
@ -95,7 +95,6 @@ class EventTheme
|
|||||||
/**
|
/**
|
||||||
* Set label.
|
* Set label.
|
||||||
*
|
*
|
||||||
* @param array $label
|
|
||||||
* @return EventTheme
|
* @return EventTheme
|
||||||
*/
|
*/
|
||||||
public function setName(array $label): static
|
public function setName(array $label): static
|
||||||
|
@ -14,7 +14,10 @@ namespace Chill\EventBundle\Form;
|
|||||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||||
use Chill\DocStoreBundle\Form\StoredObjectType;
|
use Chill\DocStoreBundle\Form\StoredObjectType;
|
||||||
use Chill\EventBundle\Entity\Event;
|
use Chill\EventBundle\Entity\Event;
|
||||||
|
use Chill\EventBundle\Entity\EventTheme;
|
||||||
|
use Chill\EventBundle\Form\Type\PickEventThemeType;
|
||||||
use Chill\EventBundle\Form\Type\PickEventTypeType;
|
use Chill\EventBundle\Form\Type\PickEventTypeType;
|
||||||
|
use Chill\EventBundle\Repository\EventThemeRepository;
|
||||||
use Chill\MainBundle\Entity\Center;
|
use Chill\MainBundle\Entity\Center;
|
||||||
use Chill\MainBundle\Form\Type\ChillCollectionType;
|
use Chill\MainBundle\Form\Type\ChillCollectionType;
|
||||||
use Chill\MainBundle\Form\Type\ChillDateTimeType;
|
use Chill\MainBundle\Form\Type\ChillDateTimeType;
|
||||||
@ -22,14 +25,19 @@ use Chill\MainBundle\Form\Type\CommentType;
|
|||||||
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
use Chill\MainBundle\Form\Type\PickUserDynamicType;
|
||||||
use Chill\MainBundle\Form\Type\PickUserLocationType;
|
use Chill\MainBundle\Form\Type\PickUserLocationType;
|
||||||
use Chill\MainBundle\Form\Type\ScopePickerType;
|
use Chill\MainBundle\Form\Type\ScopePickerType;
|
||||||
|
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
use Symfony\Component\Form\AbstractType;
|
use Symfony\Component\Form\AbstractType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
use Symfony\Component\Form\Extension\Core\Type\MoneyType;
|
||||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class EventType extends AbstractType
|
class EventType extends AbstractType
|
||||||
{
|
{
|
||||||
|
public function __construct(private readonly EventThemeRepository $eventThemeRepository, private readonly TranslatorInterface $translator, private readonly TranslatableStringHelperInterface $translatableStringHelper) {}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||||
{
|
{
|
||||||
$builder
|
$builder
|
||||||
@ -49,6 +57,9 @@ class EventType extends AbstractType
|
|||||||
'class' => '',
|
'class' => '',
|
||||||
],
|
],
|
||||||
])
|
])
|
||||||
|
->add('themes', PickEventThemeType::class, [
|
||||||
|
'multiple' => true,
|
||||||
|
])
|
||||||
->add('moderator', PickUserDynamicType::class, [
|
->add('moderator', PickUserDynamicType::class, [
|
||||||
'label' => 'Pick a moderator',
|
'label' => 'Pick a moderator',
|
||||||
])
|
])
|
||||||
|
45
src/Bundle/ChillEventBundle/Form/Type/PickEventThemeType.php
Normal file
45
src/Bundle/ChillEventBundle/Form/Type/PickEventThemeType.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\EventBundle\Form\Type;
|
||||||
|
|
||||||
|
use Chill\EventBundle\Entity\EventTheme;
|
||||||
|
use Chill\EventBundle\Repository\EventThemeRepository;
|
||||||
|
use Chill\EventBundle\Templating\Entity\EventThemeRender;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\AbstractType;
|
||||||
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
|
|
||||||
|
class PickEventThemeType extends AbstractType
|
||||||
|
{
|
||||||
|
public function __construct(private readonly EventThemeRender $eventThemeRender, private readonly EventThemeRepository $eventThemeRepository) {}
|
||||||
|
|
||||||
|
public function configureOptions(OptionsResolver $resolver)
|
||||||
|
{
|
||||||
|
$resolver
|
||||||
|
->setDefaults([
|
||||||
|
'class' => EventTheme::class,
|
||||||
|
'choices' => $this->eventThemeRepository->findByActiveOrdered(),
|
||||||
|
'choice_label' => fn (EventTheme $et) => $this->eventThemeRender->renderString($et, []),
|
||||||
|
'placeholder' => 'event.form.Select one or more themes',
|
||||||
|
'required' => true,
|
||||||
|
'attr' => ['class' => 'select2'],
|
||||||
|
'label' => 'event.theme.label',
|
||||||
|
'multiple' => false,
|
||||||
|
])
|
||||||
|
->setAllowedTypes('multiple', ['bool']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getParent(): string
|
||||||
|
{
|
||||||
|
return EntityType::class;
|
||||||
|
}
|
||||||
|
}
|
@ -23,10 +23,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
|
|||||||
*/
|
*/
|
||||||
class PickEventTypeType extends AbstractType
|
class PickEventTypeType extends AbstractType
|
||||||
{
|
{
|
||||||
/**
|
protected TranslatableStringHelper $translatableStringHelper;
|
||||||
* @var TranslatableStringHelper
|
|
||||||
*/
|
|
||||||
protected $translatableStringHelper;
|
|
||||||
|
|
||||||
public function __construct(TranslatableStringHelper $helper)
|
public function __construct(TranslatableStringHelper $helper)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chill is a software for social workers
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view
|
||||||
|
* the LICENSE file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Chill\EventBundle\Repository;
|
||||||
|
|
||||||
|
use Chill\EventBundle\Entity\EventTheme;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<EventTheme>
|
||||||
|
*/
|
||||||
|
class EventThemeRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, EventTheme::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function findByActiveOrdered(): array
|
||||||
|
{
|
||||||
|
return $this->createQueryBuilder('t')
|
||||||
|
->select('t')
|
||||||
|
->where('t.isActive = True')
|
||||||
|
->orderBy('t.ordering', 'ASC')
|
||||||
|
->getQuery()
|
||||||
|
->getResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -47,18 +47,18 @@ class EventThemeRender implements ChillEntityRenderInterface
|
|||||||
* @throws SyntaxError
|
* @throws SyntaxError
|
||||||
* @throws LoaderError
|
* @throws LoaderError
|
||||||
*/
|
*/
|
||||||
public function renderBox($eventTheme, array $options): string
|
public function renderBox($entity, array $options): string
|
||||||
{
|
{
|
||||||
$options = array_merge(self::DEFAULT_ARGS, $options);
|
$options = array_merge(self::DEFAULT_ARGS, $options);
|
||||||
// give some help to twig: an array of parents
|
// give some help to twig: an array of parents
|
||||||
$parents = $this->buildParents($eventTheme);
|
$parents = $this->buildParents($entity);
|
||||||
|
|
||||||
return $this
|
return $this
|
||||||
->engine
|
->engine
|
||||||
->render(
|
->render(
|
||||||
'@ChillEvent/Entity/event_theme.html.twig',
|
'@ChillEvent/Entity/event_theme.html.twig',
|
||||||
[
|
[
|
||||||
'eventTheme' => $eventTheme,
|
'eventTheme' => $entity,
|
||||||
'parents' => $parents,
|
'parents' => $parents,
|
||||||
'options' => $options,
|
'options' => $options,
|
||||||
]
|
]
|
||||||
@ -76,7 +76,7 @@ class EventThemeRender implements ChillEntityRenderInterface
|
|||||||
while ($entity->hasParent()) {
|
while ($entity->hasParent()) {
|
||||||
$entity = $entity->getParent();
|
$entity = $entity->getParent();
|
||||||
$titles[] = $this->translatableStringHelper->localize(
|
$titles[] = $this->translatableStringHelper->localize(
|
||||||
$entity->getTitle()
|
$entity->getName()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,12 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: form.type }
|
- { name: form.type }
|
||||||
|
|
||||||
Chill\EventBundle\Form\EventThemeType:
|
Chill\EventBundle\Form\Type\PickEventThemeType:
|
||||||
tags:
|
tags:
|
||||||
- { name: form.type }
|
- { name: form.type }
|
||||||
|
|
||||||
|
Chill\EventBundle\Form\EventType:
|
||||||
|
tags:
|
||||||
|
- { name: form.type }
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user