diff --git a/config/packages/mapping/ActorEntity.orm.xml b/config/packages/mapping/ActorEntity.orm.xml index bf0536c..108c2b4 100644 --- a/config/packages/mapping/ActorEntity.orm.xml +++ b/config/packages/mapping/ActorEntity.orm.xml @@ -5,6 +5,6 @@ - + \ No newline at end of file diff --git a/src/Controller/ActivityController.php b/src/Controller/ActivityController.php index 32d23de..b0453a5 100644 --- a/src/Controller/ActivityController.php +++ b/src/Controller/ActivityController.php @@ -34,7 +34,9 @@ // Activity add form /** @var ActivityAddForm $activityAddForm */ - $activityAddForm = $this->createNamedCustomForm('activityAdd', ActivityAddForm::class, ['actors' => $actorRepository->findAll()]); + $activityAddForm = $this->createNamedCustomForm('activityAdd', ActivityAddForm::class, [ + 'actors' => $actorRepository->findAll() + ]); $activityAddForm->handleRequest($request); if ($activityAddForm->isSubmitted() && $activityAddForm->isValid()) { $errors = $activityAddForm->validate(); @@ -113,7 +115,9 @@ // Activity edit form /** @var ActivityEditForm $activityEditForm */ - $activityEditForm = $this->createNamedCustomForm('edit', ActivityEditForm::class, ['actors' => $actorRepository->findAll()]); + $activityEditForm = $this->createNamedCustomForm('edit', ActivityEditForm::class, [ + 'actors' => $actorRepository->findAll() + ]); $activityEditForm->handleRequest($request); if ($activityEditForm->isSubmitted() && $activityEditForm->isValid()) { $errors = $activityEditForm->validate(); diff --git a/src/Entity/ActorEntity.php b/src/Entity/ActorEntity.php index ccb4c32..9a7784b 100644 --- a/src/Entity/ActorEntity.php +++ b/src/Entity/ActorEntity.php @@ -26,8 +26,8 @@ /** @var bool If the actor is still active, if set to false, he will not be proposed when setting and actor to a taks or activity */ protected $active = True; - /** @var Collection List of related activities */ - protected $activities = Null; + /** @var bool If the actor is followed, if set to true, it will apear on top of choices and on home page */ + protected $followed = False; /** * Init entity @@ -190,25 +190,24 @@ } /** - * * - * Get the list of activities + * If the actor is followed * - * @return Collection + * @return bool */ - public function getActivities(): Collection + public function getFollowed(): bool { - return $this->activities; + return $this->followed; } /** - * Set list of activities + * Set the followed status of the actor * - * @param Collection $activities + * @param bool $followed * @return self */ - public function setActivities(Collection $activities): self + public function setFollowed(bool $followed): self { - $this->activities = $activities; + $this->followed = $followed; return $this; } diff --git a/src/Form/Activity/ActivityAddForm.php b/src/Form/Activity/ActivityAddForm.php index 37922c3..711f018 100644 --- a/src/Form/Activity/ActivityAddForm.php +++ b/src/Form/Activity/ActivityAddForm.php @@ -65,7 +65,10 @@ ->add('actor', EntityType::class, [ 'class' => ActorEntity::class, 'choices' => $this->actors, - 'group_by' => function ($choice) { + 'group_by' => function (ActorEntity $choice) { + if ($choice->getFollowed()) { + return 'Suivi'; + } if ($choice->getActive()) { return 'Actif'; } diff --git a/src/Form/Activity/ActivityEditForm.php b/src/Form/Activity/ActivityEditForm.php index f65542e..494bfbc 100644 --- a/src/Form/Activity/ActivityEditForm.php +++ b/src/Form/Activity/ActivityEditForm.php @@ -82,15 +82,18 @@ protected function addFields($formBuilder, $options): void { $formBuilder->add('name', TextType::class) - ->add('actor', EntityType::class, [ + ->add('actor', EntityType::class, [ 'class' => ActorEntity::class, 'choices' => $this->actors, - 'group_by' => function ($choice) { - if ($choice->getActive()) { - return 'Actif'; - } - - return 'Inactif'; + 'group_by' => function (ActorEntity $choice) { + if ($choice->getFollowed()) { + return 'Suivi'; + } + if ($choice->getActive()) { + return 'Actif'; + } + + return 'Inactif'; }, 'choice_label' => 'displayName', 'required' => false, diff --git a/src/Form/Actors/ActorAddForm.php b/src/Form/Actors/ActorAddForm.php index 4998595..68cf65d 100644 --- a/src/Form/Actors/ActorAddForm.php +++ b/src/Form/Actors/ActorAddForm.php @@ -1,6 +1,7 @@ setFirstName($data['firstName']); $actor->setLastName($data['lastName']); $actor->setNickname($data['nickname'] ?? ""); + $actor->setFollowed($data['followed']); return $actor; } @@ -48,6 +50,9 @@ ->add('nickname', TextType::class, [ 'required' => false ]) + ->add('followed', CheckboxType::class, [ + 'required' => false + ]) ->add('submit', SubmitType::class); } } \ No newline at end of file diff --git a/src/Form/Actors/ActorEditForm.php b/src/Form/Actors/ActorEditForm.php index bba1396..061f36d 100644 --- a/src/Form/Actors/ActorEditForm.php +++ b/src/Form/Actors/ActorEditForm.php @@ -23,6 +23,7 @@ 'lastName' => $actor->getLastName(), 'nickname' => $actor->getNickname(), 'active' => $actor->getActive(), + 'followed' => $actor->getFollowed(), ]); return $this; @@ -41,6 +42,7 @@ $actor->setLastName($data['lastName']); $actor->setNickname($data['nickname'] ?? ""); $actor->setActive($data['active']); + $actor->setFollowed($data['followed']); return $this; } @@ -70,6 +72,9 @@ ->add('active', CheckboxType::class, [ 'required' => false ]) + ->add('followed', CheckboxType::class, [ + 'required' => false + ]) ->add('submit', SubmitType::class); } } \ No newline at end of file diff --git a/src/Repository/ActorRepository.php b/src/Repository/ActorRepository.php index 78a1a0f..8fea04b 100644 --- a/src/Repository/ActorRepository.php +++ b/src/Repository/ActorRepository.php @@ -12,6 +12,7 @@ /** @var array Default sorting */ public const DEFAULT_ORDER = [ + 'followed' => 'desc', 'active' => 'desc', 'firstName' => 'asc', 'lastName' => 'asc' diff --git a/templates/_includes/html/arrays/actor.html.twig b/templates/_includes/html/arrays/actor.html.twig index ba46627..a6483b6 100644 --- a/templates/_includes/html/arrays/actor.html.twig +++ b/templates/_includes/html/arrays/actor.html.twig @@ -4,6 +4,7 @@ Nom Prénom Surnom + Suivi Actif Actions @@ -14,13 +15,14 @@ {{ actor.firstName }} {{ actor.lastName }} {{ actor.nickname }} + {% if actor.followed %}Suivi {% endif %} {% if actor.active %}Actif {% endif %} Editer - {% if actorDeleteForm is defined %} - {% include '_includes/html/genericForm.html.twig' with {'form': actorDeleteForm, 'data': {actor: actor, variant: 'icon'}} only %} + {% if actorDeleteForm is defined %} {% include '_includes/html/genericForm.html.twig' with {'form': actorDeleteForm, 'data': {actor: actor, variant: 'icon'}} only %} {% endif %} {% endfor %} diff --git a/templates/_includes/html/form/actors/add.html.twig b/templates/_includes/html/form/actors/add.html.twig index 6a104dd..ac2ca6c 100644 --- a/templates/_includes/html/form/actors/add.html.twig +++ b/templates/_includes/html/form/actors/add.html.twig @@ -11,6 +11,10 @@ {{ form_label(form.nickname, 'Surnom', {label_attr: {class: 'input-text-label'}}) }} {{ form_widget(form.nickname, {attr: {class: 'w-100', title: 'Le nom tel qu\'il sera affiché.\nS\'il n\'est pas définit, il sera sous la form Prénom NOM.'}}) }} +
+ {{ form_widget(form.followed) }} + {{ form_label(form.followed, 'Suivi') }} +
{{ form_widget(form.submit, {attr: {class: 'w-100'}, label: 'Nouvel acteur'}) }}

diff --git a/templates/_includes/html/form/actors/edit.html.twig b/templates/_includes/html/form/actors/edit.html.twig index e0da1a7..e886c7f 100644 --- a/templates/_includes/html/form/actors/edit.html.twig +++ b/templates/_includes/html/form/actors/edit.html.twig @@ -15,6 +15,10 @@ {{ form_widget(form.active) }} {{ form_label(form.active, 'Actif') }} +
+ {{ form_widget(form.followed) }} + {{ form_label(form.followed, 'Suivi') }} +
{{ form_widget(form.submit, {attr: {class: 'w-100'}, label: 'Enregistrer'}) }}