From fb51e44e45a8bf5395e58b49419416dee3308665 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 11 Jan 2023 17:16:37 +0100 Subject: [PATCH 01/43] FEATURE [absence][in_progress] add absence property to user, create form, controller, template, migration and menu entry --- .../Controller/AbsenceController.php | 42 +++++++++++++++++++ src/Bundle/ChillMainBundle/Entity/User.php | 23 +++++++++- .../ChillMainBundle/Form/AbsenceType.php | 36 ++++++++++++++++ .../Resources/views/Menu/absence.html.twig | 10 +++++ .../Routing/MenuBuilder/UserMenuBuilder.php | 9 ++++ src/Bundle/ChillMainBundle/config/routes.yaml | 4 ++ .../migrations/Version20230111160610.php | 36 ++++++++++++++++ 7 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillMainBundle/Controller/AbsenceController.php create mode 100644 src/Bundle/ChillMainBundle/Form/AbsenceType.php create mode 100644 src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20230111160610.php diff --git a/src/Bundle/ChillMainBundle/Controller/AbsenceController.php b/src/Bundle/ChillMainBundle/Controller/AbsenceController.php new file mode 100644 index 000000000..97ca2979c --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/AbsenceController.php @@ -0,0 +1,42 @@ +getUser(); + $form = $this->createForm(AbsenceType::class, $user); + $form->add('submit', SubmitType::class, ['label' => 'Create']); + + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $em = $this->getDoctrine()->getManager(); + $em->persist($user); + $em->flush(); + + return $this->redirect($this->generateUrl('chill_main_homepage')); + } + + return $this->render('@ChillMain/Menu/absence.html.twig', [ + 'user' => $user, + 'form' => $form->createView(), + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 80a0b5b2a..10620dc0f 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -11,14 +11,15 @@ declare(strict_types=1); namespace Chill\MainBundle\Entity; +use DateTimeImmutable; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use RuntimeException; use Symfony\Component\Security\Core\User\AdvancedUserInterface; use Symfony\Component\Serializer\Annotation as Serializer; -use Symfony\Component\Validator\Context\ExecutionContextInterface; +use Symfony\Component\Validator\Context\ExecutionContextInterface; use function in_array; /** @@ -40,6 +41,11 @@ class User implements AdvancedUserInterface */ protected ?int $id = null; + /** + * @ORM\Column(type="datetime", nullable=true) + */ + private ?DateTimeImmutable $absenceStart = null; + /** * Array where SAML attributes's data are stored. * @@ -175,6 +181,11 @@ class User implements AdvancedUserInterface { } + public function getAbsenceStart(): ?DateTimeImmutable + { + return $this->absenceStart; + } + /** * Get attributes. * @@ -295,6 +306,11 @@ class User implements AdvancedUserInterface return $this->usernameCanonical; } + public function isAbsent(): bool + { + return null !== $this->getAbsenceStart() ? true : false; + } + /** * @return bool */ @@ -359,6 +375,11 @@ class User implements AdvancedUserInterface } } + public function setAbsenceStart(?DateTimeImmutable $absenceStart): void + { + $this->absenceStart = $absenceStart; + } + public function setAttributeByDomain(string $domain, string $key, $value): self { $this->attributes[$domain][$key] = $value; diff --git a/src/Bundle/ChillMainBundle/Form/AbsenceType.php b/src/Bundle/ChillMainBundle/Form/AbsenceType.php new file mode 100644 index 000000000..1f43093e5 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Form/AbsenceType.php @@ -0,0 +1,36 @@ +add('absenceStart', ChillDateTimeType::class, [ + 'required' => true, + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => User::class, + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig new file mode 100644 index 000000000..37b4bdd2f --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig @@ -0,0 +1,10 @@ +{% if user.absenceStart is not null %} + +

Votre absence est indiqué à partier de {{ user.absenceStart|format_datetime() }}

+ +{% endif %} + +{{ form_start(form) }} +{{ form_row(form.absenceStart) }} +{{ form_row(form.submit, { 'attr' : { 'class' : 'btn btn-chill-green' } } ) }} +{{ form_end(form) }} diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php index e0e8a782f..e91aa040b 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php @@ -78,6 +78,15 @@ class UserMenuBuilder implements LocalMenuBuilderInterface $nbNotifications = $this->notificationByUserCounter->countUnreadByUser($user); + //TODO add an icon? How exactly? For example a clock icon... + $menu + ->addChild($this->translator->trans('absence.Set absence date'), [ + 'route' => 'chill_absence_user', + ]) + ->setExtras([ + 'order' => -8888888, + ]); + $menu ->addChild( $this->translator->trans('notification.My notifications with counter', ['nb' => $nbNotifications]), diff --git a/src/Bundle/ChillMainBundle/config/routes.yaml b/src/Bundle/ChillMainBundle/config/routes.yaml index d25f2aaff..d1fde6f5c 100644 --- a/src/Bundle/ChillMainBundle/config/routes.yaml +++ b/src/Bundle/ChillMainBundle/config/routes.yaml @@ -94,3 +94,7 @@ login_check: logout: path: /logout + +chill_absence_user: + path: /{_locale}/absence + controller: Chill\MainBundle\Controller\AbsenceController::setAbsence diff --git a/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php b/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php new file mode 100644 index 000000000..1c5f74897 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE users DROP absenceStart'); + } + + public function getDescription(): string + { + return 'Add absence property to user'; + } + + public function up(Schema $schema): void + { + $this->addSql('ALTER TABLE users ADD absenceStart TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL'); + } +} From b2924ede704863778e7d79543999c666b7c6114c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Jan 2023 11:10:41 +0100 Subject: [PATCH 02/43] FEAUTURE [routing][absence] use routing annotation instead of config file --- .../ChillMainBundle/Controller/AbsenceController.php | 10 ++++++++-- src/Bundle/ChillMainBundle/config/routes.yaml | 4 ---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/AbsenceController.php b/src/Bundle/ChillMainBundle/Controller/AbsenceController.php index 97ca2979c..7241e15be 100644 --- a/src/Bundle/ChillMainBundle/Controller/AbsenceController.php +++ b/src/Bundle/ChillMainBundle/Controller/AbsenceController.php @@ -13,16 +13,22 @@ namespace Chill\MainBundle\Controller; use Chill\MainBundle\Form\AbsenceType; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Annotation\Route; class AbsenceController extends AbstractController { + /** + * @Route( + * "/{_locale}/absence", + * name="chill_absence_user", + * methods={"GET", "POST"} + * ) + */ public function setAbsence(Request $request) { $user = $this->getUser(); $form = $this->createForm(AbsenceType::class, $user); - $form->add('submit', SubmitType::class, ['label' => 'Create']); $form->handleRequest($request); diff --git a/src/Bundle/ChillMainBundle/config/routes.yaml b/src/Bundle/ChillMainBundle/config/routes.yaml index d1fde6f5c..d25f2aaff 100644 --- a/src/Bundle/ChillMainBundle/config/routes.yaml +++ b/src/Bundle/ChillMainBundle/config/routes.yaml @@ -94,7 +94,3 @@ login_check: logout: path: /logout - -chill_absence_user: - path: /{_locale}/absence - controller: Chill\MainBundle\Controller\AbsenceController::setAbsence From b93b78615bd4866439a33a9bce7e79931eee9ee9 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Jan 2023 11:11:43 +0100 Subject: [PATCH 03/43] FIX [migration][absence] fix the typing in db for absence datetime immuatable --- src/Bundle/ChillMainBundle/Entity/User.php | 2 +- src/Bundle/ChillMainBundle/Form/AbsenceType.php | 1 + src/Bundle/ChillMainBundle/migrations/Version20230111160610.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 10620dc0f..c38dd97c6 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -42,7 +42,7 @@ class User implements AdvancedUserInterface protected ?int $id = null; /** - * @ORM\Column(type="datetime", nullable=true) + * @ORM\Column(type="datetime_immutable", nullable=true) */ private ?DateTimeImmutable $absenceStart = null; diff --git a/src/Bundle/ChillMainBundle/Form/AbsenceType.php b/src/Bundle/ChillMainBundle/Form/AbsenceType.php index 1f43093e5..8600fd019 100644 --- a/src/Bundle/ChillMainBundle/Form/AbsenceType.php +++ b/src/Bundle/ChillMainBundle/Form/AbsenceType.php @@ -24,6 +24,7 @@ class AbsenceType extends AbstractType $builder ->add('absenceStart', ChillDateTimeType::class, [ 'required' => true, + 'input' => 'datetime_immutable', ]); } diff --git a/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php b/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php index 1c5f74897..3bdffa6ea 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php @@ -22,6 +22,7 @@ final class Version20230111160610 extends AbstractMigration public function down(Schema $schema): void { $this->addSql('ALTER TABLE users DROP absenceStart'); + $this->addSql('COMMENT ON COLUMN users.absenceStart IS \'(DC2Type:datetime_immutable)\''); } public function getDescription(): string From 68998c9156ec6764681b56d8e679c12d539ca07f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Jan 2023 11:50:06 +0100 Subject: [PATCH 04/43] FEATURE [translations][absence] add translations --- src/Bundle/ChillMainBundle/Form/AbsenceType.php | 9 +++++++++ src/Bundle/ChillMainBundle/config/services/form.yaml | 4 ++++ src/Bundle/ChillMainBundle/translations/messages.fr.yml | 7 +++++++ 3 files changed, 20 insertions(+) diff --git a/src/Bundle/ChillMainBundle/Form/AbsenceType.php b/src/Bundle/ChillMainBundle/Form/AbsenceType.php index 8600fd019..e5e92398e 100644 --- a/src/Bundle/ChillMainBundle/Form/AbsenceType.php +++ b/src/Bundle/ChillMainBundle/Form/AbsenceType.php @@ -16,15 +16,24 @@ use Chill\MainBundle\Form\Type\ChillDateTimeType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Contracts\Translation\TranslatorInterface; class AbsenceType extends AbstractType { + private TranslatorInterface $translator; + + public function __construct(TranslatorInterface $translator) + { + $this->translator = $translator; + } + public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('absenceStart', ChillDateTimeType::class, [ 'required' => true, 'input' => 'datetime_immutable', + 'label' => $this->translator->trans('absence.Absence start'), ]); } diff --git a/src/Bundle/ChillMainBundle/config/services/form.yaml b/src/Bundle/ChillMainBundle/config/services/form.yaml index 58f01883f..c8a46132f 100644 --- a/src/Bundle/ChillMainBundle/config/services/form.yaml +++ b/src/Bundle/ChillMainBundle/config/services/form.yaml @@ -138,6 +138,10 @@ services: autowire: true autoconfigure: true + Chill\MainBundle\Form\AbsenceType: + autowire: true + autoconfigure: true + Chill\MainBundle\Form\DataTransformer\IdToLocationDataTransformer: ~ Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer: ~ Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer: ~ diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index b19a7a52f..b80171c8c 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -573,3 +573,10 @@ saved_export: Export is deleted: L'export est supprimé Saved export is saved!: L'export est enregistré Created on %date%: Créé le %date% + + +absence: + My absence: Mon absence + Unset absence: Supprimer la date d'absence + Set absence date: Indiquer date d'absence + Absence start: Absence à partir de From 44ef21f940b03e43d1b3d030d474d97d25511546 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Jan 2023 11:51:42 +0100 Subject: [PATCH 05/43] FEATURE [delete][absence] add functionality to unset absence --- .../Controller/AbsenceController.php | 25 +++++++++- .../Resources/views/Menu/absence.html.twig | 50 ++++++++++++++++--- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/AbsenceController.php b/src/Bundle/ChillMainBundle/Controller/AbsenceController.php index 7241e15be..9c3dc679d 100644 --- a/src/Bundle/ChillMainBundle/Controller/AbsenceController.php +++ b/src/Bundle/ChillMainBundle/Controller/AbsenceController.php @@ -37,7 +37,7 @@ class AbsenceController extends AbstractController $em->persist($user); $em->flush(); - return $this->redirect($this->generateUrl('chill_main_homepage')); + return $this->redirect($this->generateUrl('chill_absence_user')); } return $this->render('@ChillMain/Menu/absence.html.twig', [ @@ -45,4 +45,27 @@ class AbsenceController extends AbstractController 'form' => $form->createView(), ]); } + + /** + * @Route( + * "/{_locale}/absence/unset", + * name="chill_unset_absence_user", + * methods={"GET", "POST", "DELETE"} + * ) + */ + public function unsetAbsence(Request $request) + { + $user = $this->getUser(); + $form = $this->createForm(AbsenceType::class, $user); + + $user->setAbsenceStart(null); + $em = $this->getDoctrine()->getManager(); + $em->persist($user); + $em->flush(); + + return $this->render('@ChillMain/Menu/absence.html.twig', [ + 'user' => $user, + 'form' => $form->createView(), + ]); + } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig index 37b4bdd2f..8b27773e4 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig @@ -1,10 +1,46 @@ -{% if user.absenceStart is not null %} +{% extends '@ChillMain/Admin/layout.html.twig' %} -

Votre absence est indiqué à partier de {{ user.absenceStart|format_datetime() }}

+{% block title %} + {{ 'My absence'|trans }} +{% endblock title %} -{% endif %} +{% block content %} -{{ form_start(form) }} -{{ form_row(form.absenceStart) }} -{{ form_row(form.submit, { 'attr' : { 'class' : 'btn btn-chill-green' } } ) }} -{{ form_end(form) }} +
+

{{ 'absence.My absence'|trans }}

+ + {% if user.absenceStart is not null %} +
+

Votre absence est indiqué à partier de {{ user.absenceStart|format_datetime() }}.

+ +
+ {% else %} +
+

Aucune absence indiquer.

+
+ {% endif %} + +
+ {{ form_start(form) }} + {{ form_row(form.absenceStart) }} + +
    +
  • + +
  • +
+ + {{ form_end(form) }} +
+
+ + + +{% endblock %} From 2c5c815f68e7691b2903399768e4d4def74ee51b Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Jan 2023 12:02:52 +0100 Subject: [PATCH 06/43] FEATURE [admin][absence] add possibility for admin to set absence of a user --- src/Bundle/ChillMainBundle/Form/UserType.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Form/UserType.php b/src/Bundle/ChillMainBundle/Form/UserType.php index b738cc8c7..532bc7b5b 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\UserJob; +use Chill\MainBundle\Form\Type\ChillDateTimeType; use Chill\MainBundle\Form\Type\PickCivilityType; use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\EntityRepository; @@ -31,6 +32,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints\Length; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\Regex; +use Symfony\Contracts\Translation\TranslatorInterface; class UserType extends AbstractType { @@ -38,12 +40,16 @@ class UserType extends AbstractType private TranslatableStringHelper $translatableStringHelper; + private TranslatorInterface $translator; + public function __construct( TranslatableStringHelper $translatableStringHelper, - ParameterBagInterface $parameterBag + ParameterBagInterface $parameterBag, + TranslatorInterface $translator ) { $this->translatableStringHelper = $translatableStringHelper; $this->parameterBag = $parameterBag; + $this->translator = $translator; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -110,6 +116,11 @@ class UserType extends AbstractType return $qb; }, + ]) + ->add('absenceStart', ChillDateTimeType::class, [ + 'required' => false, + 'input' => 'datetime_immutable', + 'label' => $this->translator->trans('absence.Absence start'), ]); // @phpstan-ignore-next-line From 5bbe5af12488944d587790273e6b8d09ecb5058a Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Jan 2023 13:30:28 +0100 Subject: [PATCH 07/43] FEATURE [absence][render] add absence tag to renderbox and renderstring --- .../Resources/views/Entity/user.html.twig | 5 +++++ .../Templating/Entity/UserRender.php | 16 ++++++++++++++-- .../ChillMainBundle/translations/messages.fr.yml | 1 + 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig index 77dc959a2..12a1a618c 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig @@ -6,4 +6,9 @@ {%- if opts['main_scope'] and user.mainScope is not null %} ({{ user.mainScope.name|localize_translatable_string }}) {%- endif -%} + {%- if opts['absence'] and user.absenceStart is not null %} + {%- if date(user.absenceStart) < date() %} + ({{ 'absence.Absent'|trans }}) + {%- endif %} + {%- endif -%} diff --git a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php index 141de2649..2cef950d5 100644 --- a/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php +++ b/src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php @@ -13,8 +13,10 @@ namespace Chill\MainBundle\Templating\Entity; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Templating\TranslatableStringHelper; -use Symfony\Component\Templating\EngineInterface; +use DateTimeImmutable; +use Symfony\Component\Templating\EngineInterface; +use Symfony\Contracts\Translation\TranslatorInterface; use function array_merge; class UserRender implements ChillEntityRenderInterface @@ -22,16 +24,20 @@ class UserRender implements ChillEntityRenderInterface public const DEFAULT_OPTIONS = [ 'main_scope' => true, 'user_job' => true, + 'absence' => true, ]; private EngineInterface $engine; private TranslatableStringHelper $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine) + private TranslatorInterface $translator; + + public function __construct(TranslatableStringHelper $translatableStringHelper, EngineInterface $engine, TranslatorInterface $translator) { $this->translatableStringHelper = $translatableStringHelper; $this->engine = $engine; + $this->translator = $translator; } public function renderBox($entity, array $options): string @@ -63,6 +69,12 @@ class UserRender implements ChillEntityRenderInterface ->localize($entity->getMainScope()->getName()) . ')'; } + $current_date = new DateTimeImmutable(); + + if (null !== $entity->getAbsenceStart() && $entity->getAbsenceStart() < $current_date && $opts['main_scope']) { + $str .= ' (' . $this->translator->trans('absence.Absent') . ')'; + } + return $str; } diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index b80171c8c..c7d376c48 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -580,3 +580,4 @@ absence: Unset absence: Supprimer la date d'absence Set absence date: Indiquer date d'absence Absence start: Absence à partir de + Absent: Absent From 6c1108b8aa020c7464a767ead127260788f22f4f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Jan 2023 13:50:29 +0100 Subject: [PATCH 08/43] FEATURE: [homepage][absence] display message to let user know they are still marked as absent --- .../Resources/views/Homepage/index.html.twig | 11 ++++++++--- .../ChillMainBundle/translations/messages.fr.yml | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig index aec38f3c3..5dc88faf3 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig @@ -1,15 +1,20 @@
- + {# vue component #} + {% if app.user.absenceStart is not null and date(app.user.absenceStart) < date() %} +

{{'absence.You are marked as being absent'|trans }}

+ {% endif %} +
- + {% include '@ChillMain/Homepage/fast_actions.html.twig' %}
+ {% block css %} {{ encore_entry_link_tags('page_homepage_widget') }} {% endblock %} {% block js %} {{ encore_entry_script_tags('page_homepage_widget') }} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index c7d376c48..cffb0d6f9 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -581,3 +581,4 @@ absence: Set absence date: Indiquer date d'absence Absence start: Absence à partir de Absent: Absent + You are marked as being absent: Vous êtes marquer comme absent. From de9d53936f805501c57ec8e6380f4aee946306a3 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 12 Jan 2023 19:51:43 +0100 Subject: [PATCH 09/43] FEATURE [styling][absence] give styling --- .../Resources/public/chill/scss/render_box.scss | 2 +- .../ChillMainBundle/Resources/views/Entity/user.html.twig | 6 +++++- .../Resources/views/Homepage/index.html.twig | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss index 4d0bfcf8e..92becc089 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/scss/render_box.scss @@ -106,7 +106,7 @@ section.chill-entity { // used for comment-embeddable &.entity-comment-embeddable { width: 100%; - + /* already defined !! div.metadata { font-size: smaller; diff --git a/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig index 12a1a618c..779be6740 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig @@ -8,7 +8,11 @@ {%- endif -%} {%- if opts['absence'] and user.absenceStart is not null %} {%- if date(user.absenceStart) < date() %} - ({{ 'absence.Absent'|trans }}) + + + A + + {%- endif %} {%- endif -%} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig index 5dc88faf3..60f6c88ff 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig @@ -2,7 +2,7 @@ {# vue component #} {% if app.user.absenceStart is not null and date(app.user.absenceStart) < date() %} -

{{'absence.You are marked as being absent'|trans }}

+ {% endif %}
From 7f9e045d5db27f0b627f1d8bef1433c073d63a28 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Thu, 26 Jan 2023 11:28:13 +0100 Subject: [PATCH 10/43] FEATURE [regroupment][exports] first commit to implement regroupment entity in exports --- .../ChillMainBundle/Controller/ExportController.php | 2 ++ .../Form/Type/Export/PickRegroupmentType.php | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php diff --git a/src/Bundle/ChillMainBundle/Controller/ExportController.php b/src/Bundle/ChillMainBundle/Controller/ExportController.php index 84bf80c6b..caeec8327 100644 --- a/src/Bundle/ChillMainBundle/Controller/ExportController.php +++ b/src/Bundle/ChillMainBundle/Controller/ExportController.php @@ -298,6 +298,8 @@ class ExportController extends AbstractController 'csrf_protection' => $isGenerate ? false : true, ]); + // TODO: add a condition to be able to select a regroupment of centers? + if ('centers' === $step || 'generate_centers' === $step) { $builder->add('centers', PickCenterType::class, [ 'export_alias' => $alias, diff --git a/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php b/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php new file mode 100644 index 000000000..e60388fd3 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Form/Type/Export/PickRegroupmentType.php @@ -0,0 +1,10 @@ + Date: Thu, 26 Jan 2023 17:11:50 +0100 Subject: [PATCH 11/43] Fixed: [migration] fix the required comment for doctrine on new column --- src/Bundle/ChillMainBundle/migrations/Version20230111160610.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php b/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php index 3bdffa6ea..c00a3f521 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20230111160610.php @@ -22,7 +22,6 @@ final class Version20230111160610 extends AbstractMigration public function down(Schema $schema): void { $this->addSql('ALTER TABLE users DROP absenceStart'); - $this->addSql('COMMENT ON COLUMN users.absenceStart IS \'(DC2Type:datetime_immutable)\''); } public function getDescription(): string @@ -33,5 +32,6 @@ final class Version20230111160610 extends AbstractMigration public function up(Schema $schema): void { $this->addSql('ALTER TABLE users ADD absenceStart TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL'); + $this->addSql('COMMENT ON COLUMN users.absenceStart IS \'(DC2Type:datetime_immutable)\''); } } From 86b5f4dfac0a5bc6ac530dac68e00db2c0d58c7f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 27 Jan 2023 10:44:25 +0100 Subject: [PATCH 12/43] FIX [template][translations] fixes to template and translations --- .../Resources/views/Menu/absence.html.twig | 8 ++++---- src/Bundle/ChillMainBundle/translations/messages.fr.yml | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig index 8b27773e4..d8508d8fd 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig @@ -1,7 +1,7 @@ {% extends '@ChillMain/Admin/layout.html.twig' %} {% block title %} - {{ 'My absence'|trans }} + {{ 'absence.My absence'|trans }} {% endblock title %} {% block content %} @@ -11,7 +11,7 @@ {% if user.absenceStart is not null %}
-

Votre absence est indiqué à partier de {{ user.absenceStart|format_datetime() }}.

+

{{ 'absence.You are listed as absent, as of'|trans }} {{ user.absenceStart|format_date('long') }}

  • {% else %}
    -

    Aucune absence indiquer.

    +

    {{ 'absence.No absence listed'|trans }}

    {% endif %} @@ -32,7 +32,7 @@
    diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 8218bf827..94041b78d 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -589,6 +589,8 @@ absence: My absence: Mon absence Unset absence: Supprimer la date d'absence Set absence date: Indiquer date d'absence - Absence start: Absence à partir de + Absence start: Absence à partir du Absent: Absent - You are marked as being absent: Vous êtes marquer comme absent. + You are marked as being absent: Vous êtes indiqué absent. + You are listed as absent, as of: Votre absence est indiqué à partir du + No absence listed: Aucune absence indiquée. From f76c031ff311eea32ec79942640cb3ec35333b37 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 27 Jan 2023 10:51:59 +0100 Subject: [PATCH 13/43] FIX [translations][types] remove redundant translator and change datetime field to date field --- src/Bundle/ChillMainBundle/Form/AbsenceType.php | 12 +++--------- src/Bundle/ChillMainBundle/Form/UserType.php | 11 ++++------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Form/AbsenceType.php b/src/Bundle/ChillMainBundle/Form/AbsenceType.php index e5e92398e..e23e350c9 100644 --- a/src/Bundle/ChillMainBundle/Form/AbsenceType.php +++ b/src/Bundle/ChillMainBundle/Form/AbsenceType.php @@ -13,6 +13,7 @@ namespace Chill\MainBundle\Form; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Form\Type\ChillDateTimeType; +use Chill\MainBundle\Form\Type\ChillDateType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; @@ -20,20 +21,13 @@ use Symfony\Contracts\Translation\TranslatorInterface; class AbsenceType extends AbstractType { - private TranslatorInterface $translator; - - public function __construct(TranslatorInterface $translator) - { - $this->translator = $translator; - } - public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('absenceStart', ChillDateTimeType::class, [ + ->add('absenceStart', ChillDateType::class, [ 'required' => true, 'input' => 'datetime_immutable', - 'label' => $this->translator->trans('absence.Absence start'), + 'label' => 'absence.Absence start', ]); } diff --git a/src/Bundle/ChillMainBundle/Form/UserType.php b/src/Bundle/ChillMainBundle/Form/UserType.php index 532bc7b5b..f37c48a92 100644 --- a/src/Bundle/ChillMainBundle/Form/UserType.php +++ b/src/Bundle/ChillMainBundle/Form/UserType.php @@ -16,6 +16,7 @@ use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Form\Type\ChillDateTimeType; +use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\PickCivilityType; use Chill\MainBundle\Templating\TranslatableStringHelper; use Doctrine\ORM\EntityRepository; @@ -40,16 +41,12 @@ class UserType extends AbstractType private TranslatableStringHelper $translatableStringHelper; - private TranslatorInterface $translator; - public function __construct( TranslatableStringHelper $translatableStringHelper, - ParameterBagInterface $parameterBag, - TranslatorInterface $translator + ParameterBagInterface $parameterBag ) { $this->translatableStringHelper = $translatableStringHelper; $this->parameterBag = $parameterBag; - $this->translator = $translator; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -117,10 +114,10 @@ class UserType extends AbstractType return $qb; }, ]) - ->add('absenceStart', ChillDateTimeType::class, [ + ->add('absenceStart', ChillDateType::class, [ 'required' => false, 'input' => 'datetime_immutable', - 'label' => $this->translator->trans('absence.Absence start'), + 'label' => 'absence.Absence start', ]); // @phpstan-ignore-next-line From bb7d072cc8af6b83574c10de87f6dfe3a7b7e80f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 27 Jan 2023 11:10:17 +0100 Subject: [PATCH 14/43] FIX [render] use isAbsent method to render user as absent or not + place homepage msg above searchbar --- src/Bundle/ChillMainBundle/Entity/User.php | 2 +- .../ChillMainBundle/Resources/views/Entity/user.html.twig | 2 +- .../ChillMainBundle/Resources/views/Homepage/index.html.twig | 5 ----- src/Bundle/ChillMainBundle/Resources/views/layout.html.twig | 5 +++++ src/Bundle/ChillMainBundle/Templating/Entity/UserRender.php | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 43a63c52d..24e88e7ba 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -304,7 +304,7 @@ class User implements UserInterface public function isAbsent(): bool { - return null !== $this->getAbsenceStart() ? true : false; + return (null !== $this->getAbsenceStart() && $this->getAbsenceStart() <= new DateTimeImmutable('now')) ? true : false; } /** diff --git a/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig index 779be6740..6d6e095d5 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Entity/user.html.twig @@ -6,7 +6,7 @@ {%- if opts['main_scope'] and user.mainScope is not null %} ({{ user.mainScope.name|localize_translatable_string }}) {%- endif -%} - {%- if opts['absence'] and user.absenceStart is not null %} + {%- if opts['absence'] and user.isAbsent %} {%- if date(user.absenceStart) < date() %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig index 60f6c88ff..98af21171 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Homepage/index.html.twig @@ -1,10 +1,5 @@
    - {# vue component #} - {% if app.user.absenceStart is not null and date(app.user.absenceStart) < date() %} - - {% endif %} -
    {% include '@ChillMain/Homepage/fast_actions.html.twig' %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig index 319adad81..9b4007266 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/layout.html.twig @@ -69,6 +69,11 @@ {% block content %}