diff --git a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php index 97097c079..55c2c141b 100644 --- a/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php +++ b/src/Bundle/ChillMainBundle/Form/UserCurrentLocationType.php @@ -3,6 +3,7 @@ namespace Chill\MainBundle\Form; use Chill\MainBundle\Entity\Location; +use Chill\MainBundle\Repository\LocationRepository; use Chill\MainBundle\Templating\TranslatableStringHelper; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; @@ -11,15 +12,16 @@ use Symfony\Component\Form\FormBuilderInterface; class UserCurrentLocationType extends AbstractType { - + private LocationRepository $locationRepository; private TranslatableStringHelper $translatableStringHelper; /** * @param TranslatableStringHelper $translatableStringHelper */ - public function __construct(TranslatableStringHelper $translatableStringHelper) + public function __construct(TranslatableStringHelper $translatableStringHelper, LocationRepository $locationRepository) { $this->translatableStringHelper = $translatableStringHelper; + $this->locationRepository = $locationRepository; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -27,11 +29,14 @@ class UserCurrentLocationType extends AbstractType $builder ->add('currentLocation', EntityType::class, [ 'class' => Location::class, + 'choices' => $this->locationRepository->findByPublicLocations(), 'choice_label' => function (Location $entity) { return $entity->getName() ? - $this->translatableStringHelper->localize($entity->getLocationType()->getTitle()) . ' ' . $entity->getName() : + $entity->getName().' ('.$this->translatableStringHelper->localize($entity->getLocationType()->getTitle()).')' : $this->translatableStringHelper->localize($entity->getLocationType()->getTitle()); }, + 'placeholder' => 'Pick a location', + 'required' => false, ]); } } diff --git a/src/Bundle/ChillMainBundle/Repository/LocationRepository.php b/src/Bundle/ChillMainBundle/Repository/LocationRepository.php index 8e67fecea..fcc4ff7e3 100644 --- a/src/Bundle/ChillMainBundle/Repository/LocationRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/LocationRepository.php @@ -18,4 +18,14 @@ class LocationRepository extends ServiceEntityRepository { parent::__construct($registry, Location::class); } + + /** + * fetch locations which are selectable for users + * + * @return Location[] + */ + public function findByPublicLocations() + { + return $this->findBy(['active' => true, 'availableForUsers' => true]); + } } diff --git a/src/Bundle/ChillMainBundle/Resources/views/User/edit_current_location.html.twig b/src/Bundle/ChillMainBundle/Resources/views/User/edit_current_location.html.twig index 206c96642..b1990833c 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/User/edit_current_location.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/User/edit_current_location.html.twig @@ -3,21 +3,19 @@ {% block title %}{{ 'Edit my current location'|trans }}{% endblock %} {% block content -%} -

{{ 'Edit my current location'|trans }}

+
+

{{ 'Edit my current location'|trans }}

- {{ form_start(edit_form) }} - {{ form_row(edit_form.currentLocation) }} + {{ form_start(edit_form) }} + {{ form_row(edit_form.currentLocation) }} - + - {{ form_end(edit_form) }} + {{ form_end(edit_form) }} + +
{% endblock %} diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php index bbe160371..4945c2f0d 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/UserMenuBuilder.php @@ -20,35 +20,37 @@ namespace Chill\MainBundle\Routing\MenuBuilder; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Chill\MainBundle\Entity\User; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Symfony\Component\Security\Core\Security; -/** - * - * - * @author Julien Fastré - */ class UserMenuBuilder implements LocalMenuBuilderInterface { - /** - * - * @var TokenStorageInterface - */ - protected $tokenStorage; - - public function __construct(TokenStorageInterface $tokenStorage) + private Security $security; + + public function __construct(Security $security) { - $this->tokenStorage = $tokenStorage; + $this->security = $security; } public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters) { - if ($this->tokenStorage->getToken()->getUser() instanceof User) { + $user = $this->security->getUser(); + + if ($user instanceof User) { + + if (null !== $user->getCurrentLocation()) { + $locationTextMenu = $user->getCurrentLocation()->getName(); + } else { + $locationTextMenu = 'Set a location'; + } + $menu ->addChild( - 'Change location', + $locationTextMenu, ['route' => 'chill_main_user_currentlocation_edit'] ) ->setExtras([ - 'order' => 99999999997 + 'order' => -9999999, + 'icon' => 'map-marker' ]); $menu ->addChild( diff --git a/src/Bundle/ChillMainBundle/config/services/menu.yaml b/src/Bundle/ChillMainBundle/config/services/menu.yaml index a41e90345..97a1d5e89 100644 --- a/src/Bundle/ChillMainBundle/config/services/menu.yaml +++ b/src/Bundle/ChillMainBundle/config/services/menu.yaml @@ -7,8 +7,8 @@ services: resource: '../../Routing/MenuBuilder' Chill\MainBundle\Routing\MenuBuilder\UserMenuBuilder: - arguments: - $tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface' + autowire: true + autoconfigure: true tags: - { name: 'chill.menu_builder' } diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index fcd31ce72..210227fbe 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -184,8 +184,9 @@ User jobs: Métiers Current location: Localisation actuelle Edit my current location: Éditer ma localisation actuelle Change current location: Changer ma localisation actuelle -Change location: Changer ma localisation +Set a location: Indiquer une localisation Current location successfully updated: Localisation actuelle mise à jour +Pick a location: Choisir un lieu #admin section for circles (old: scopes) List circles: Cercles