2022-01-24 13:17:46 +00:00

109 lines
3.1 KiB
PHP

<?php
/**
* 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.
*/
declare(strict_types=1);
namespace Chill\MainBundle\Routing\MenuBuilder;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Notification\Counter\NotificationByUserCounter;
use Chill\MainBundle\Routing\LocalMenuBuilderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
class UserMenuBuilder implements LocalMenuBuilderInterface
{
private NotificationByUserCounter $notificationByUserCounter;
private Security $security;
private TranslatorInterface $translator;
public function __construct(
NotificationByUserCounter $notificationByUserCounter,
Security $security,
TranslatorInterface $translator
) {
$this->notificationByUserCounter = $notificationByUserCounter;
$this->security = $security;
$this->translator = $translator;
}
public function buildMenu($menuId, \Knp\Menu\MenuItem $menu, array $parameters)
{
$user = $this->security->getUser();
if ($user instanceof User) {
if (null !== $user->getCurrentLocation()) {
$locationTextMenu = $user->getCurrentLocation()->getName();
} else {
$locationTextMenu = 'Set a location';
}
$menu
->addChild(
$locationTextMenu,
['route' => 'chill_main_user_currentlocation_edit']
)
->setExtras([
'order' => -9999999,
'icon' => 'map-marker',
]);
$nbNotifications = $this->notificationByUserCounter->countUnreadByUser($user);
$menu
->addChild(
$this->translator->trans('notification.My notifications with counter', ['nb' => $nbNotifications]),
['route' => 'chill_main_notification_my']
)
->setExtras([
'order' => 600,
'icon' => 'envelope',
'counter' => $nbNotifications,
]);
$menu
->addChild(
$this->translator->trans('workflow.My workflows'),
['route' => 'chill_main_workflow_list_dest']
)
->setExtras([
'order' => 700,
]);
$menu
->addChild(
'Change password',
['route' => 'change_my_password']
)
->setExtras([
'order' => 99999999998,
]);
}
$menu
->addChild(
'Logout',
[
'route' => 'logout',
]
)
->setExtras([
'order' => 99999999999,
'icon' => 'power-off',
]);
}
public static function getMenuIds(): array
{
return ['user'];
}
}