src/Menu/AccountLeftMenuBuilder.php line 44

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-05-21
  5.  * Time: 18:54
  6.  */
  7. namespace App\Menu;
  8. use App\Entity\Account\Advertiser;
  9. use App\Entity\Account\Customer;
  10. use App\Entity\User;
  11. use App\Repository\ProfileCommentRepository;
  12. use App\Repository\ProfileRepository;
  13. use App\Repository\SaloonCommentRepository;
  14. use App\Repository\SaloonRepository;
  15. use App\Repository\SupportMessagesRepository;
  16. use App\Service\Features;
  17. use App\Specification\Saloon\SaloonIsActive;
  18. use App\Specification\Saloon\SaloonIsNotHidden;
  19. use App\Specification\Saloon\SaloonOwner;
  20. use Happyr\DoctrineSpecification\Spec;
  21. use Knp\Menu\FactoryInterface;
  22. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  23. use Symfony\Contracts\Translation\TranslatorInterface;
  24. class AccountLeftMenuBuilder
  25. {
  26.     const NAME 'account_left';
  27.     const TRANSLATION_DOMAIN 'account_left_menu';
  28.     public function __construct(
  29.         private FactoryInterface $factory,
  30.         private Features $features,
  31.         private TokenStorageInterface $tokenStorage,
  32.         private TranslatorInterface $translator,
  33.         private ProfileRepository $profileRepository,
  34.         private SaloonRepository $saloonRepository,
  35.         private SupportMessagesRepository $supportMessagesRepository,
  36.         private ProfileCommentRepository $profileCommentRepository,
  37.         private SaloonCommentRepository $saloonCommentRepository,
  38.     ) {}
  39.     public function build(array $options)
  40.     {
  41.         $menu $this->factory->createItem(self::NAME);
  42.         if (null !== $authenticatedUser $this->getAuthenticatedUser()) {
  43.             if($authenticatedUser instanceof Advertiser) {
  44.                 $menu->addChild('PaidServices', [
  45.                     'label' => $this->translator->trans('Стоимость рекламы', [], self::TRANSLATION_DOMAIN),
  46.                     'route' => 'account.paid_services.info_page',
  47.                 ]);
  48.                 $menu->addChild('Edit', [
  49.                     'label' => $this->translator->trans('Мои данные', [], self::TRANSLATION_DOMAIN),
  50.                     'route' => 'account.settings',
  51.                 ]);
  52.                 $menu->addChild('Pay', [
  53.                     'label' => $this->translator->trans('Пополнить баланс', [], self::TRANSLATION_DOMAIN),
  54.                     'route' => 'account.finances.pay',
  55.                 ]);
  56.                 $menu->addChild('Help', [
  57.                     'label' => $this->translator->trans('Помощь', [], self::TRANSLATION_DOMAIN),
  58.                     'uri' => '#',
  59.                 ]);
  60.                 $menu->addChild('Forum', [
  61.                     'label' => $this->translator->trans('Рекламный форум', [], self::TRANSLATION_DOMAIN),
  62.                     'uri' => '#',
  63.                 ]);
  64.             
  65.                 $profilesLabel $this->translator->trans('Ваши анкеты %active%/%all%', [
  66.                     '%active%' => $this->profileRepository->countActiveOfOwner($authenticatedUser,$this->features->non_masseur_on_account_profile_list() ? false null),
  67.                     '%all%' => $this->profileRepository->countAllOfOwnerNotDeleted($authenticatedUser$this->features->non_masseur_on_account_profile_list() ? false null),
  68.                 ], self::TRANSLATION_DOMAIN);
  69.                 $menu->addChild('ProfileList', [
  70.                     'label' => $profilesLabel,
  71.                     'route' => 'account.profile_management.list',
  72.                 ]);
  73.                 $menu->addChild('AddProfile', [
  74.                     'label' => $this->translator->trans('Добавить анкету', [], self::TRANSLATION_DOMAIN),
  75.                     'route' => 'account.profile_editing.create',
  76.                 ]);
  77.                 if ($this->features->has_masseurs()/* && false == $this->features->non_masseur_on_account_profile_list()*/) {
  78.                     $masseursLabel $this->translator->trans('Массажистки %active%/%all%', [
  79.                         '%active%' => $this->profileRepository->countActiveOfOwner($authenticatedUsertrue),
  80.                         '%all%' => $this->profileRepository->countAllOfOwnerNotDeleted($authenticatedUsertrue),
  81.                     ], self::TRANSLATION_DOMAIN);
  82.                     $menu->addChild('MasseurList', [
  83.                         'label' => $masseursLabel,
  84.                         'route' => 'account.profile_management.list_masseur',
  85.                     ]);
  86.                     $menu->addChild('AddMasseur', [
  87.                         'label' => $this->translator->trans('Добавить массаж-ку', [], self::TRANSLATION_DOMAIN),
  88.                         'route' => 'account.profile_editing.create_masseur',
  89.                     ]);
  90.                 }
  91.                 if ($this->features->has_saloons()) {
  92.                     $criteria Spec::andX(
  93.                         $this->features->free_profiles() ? new SaloonIsNotHidden() : new SaloonIsActive(),
  94.                         new SaloonOwner($authenticatedUser),
  95.                     );
  96.                     $saloonsLabel $this->translator->trans('Ваши салоны %active%/%all%', [
  97.                         '%active%' => $this->saloonRepository->countMatchingSpec($criteria),
  98.                         '%all%' => $this->saloonRepository->countAllOfOwner($authenticatedUser),
  99.                     ], self::TRANSLATION_DOMAIN);
  100.                     $menu->addChild('SaloonList', [
  101.                         'label' => $saloonsLabel,
  102.                         'route' => 'account_saloons',
  103.                     ]);
  104.                     $menu->addChild('AddSaloon', [
  105.                         'label' => $this->translator->trans('Добавить салон', [], self::TRANSLATION_DOMAIN),
  106.                         'route' => 'account.saloon_editing.create',
  107.                     ]);
  108.                 }
  109.                 $bannersLabel $this->translator->trans('Ваши баннеры %active%/%all%', [
  110.                     '%active%' => 0,
  111.                     '%all%' => 0,
  112.                 ], self::TRANSLATION_DOMAIN);
  113.                 $menu->addChild('BannerList', [
  114.                     'label' => $bannersLabel,
  115.                     'uri' => '#',
  116.                 ]);
  117.                 $menu->addChild('AddBanner', [
  118.                     'label' => $this->translator->trans('Добавить баннер', [], self::TRANSLATION_DOMAIN),
  119.                     'uri' => '#',
  120.                 ]);
  121.                 $menu->addChild('PaidLineList', [
  122.                     'label' => $this->translator->trans('Платные строчки', [], self::TRANSLATION_DOMAIN),
  123.                     'uri' => '#',
  124.                 ]);
  125.                 $menu->addChild('Blacklist', [
  126.                     'label' => $this->translator->trans('Черный список', [], self::TRANSLATION_DOMAIN),
  127.                     'route' => 'account.phone_review',
  128.                 ]);
  129.                 $menu->addChild('PaymentHistory', [
  130.                     'label' => $this->translator->trans('История платежей', [], self::TRANSLATION_DOMAIN),
  131.                     'route' => 'account.finances.transactions',
  132.                 ]);
  133.                 $menu->addChild('TopPlacementPlace', [
  134.                     'label' => $this->translator->trans('Разместить в топ', [], self::TRANSLATION_DOMAIN),
  135.                     'route' => 'account.profile.top_placement',
  136.                 ]);
  137.                 $menu->addChild('SupportMessages', [
  138.                     'label' => $this->translator->trans('Сообщения %unread_count%', [
  139.                         '%unread_count%' => $this->supportMessagesRepository->countUnreadOfOwner($authenticatedUser),
  140.                     ], self::TRANSLATION_DOMAIN),
  141.                     'route' => 'account.support_messages.list',
  142.                 ]);
  143.                 $menu->addChild('SupportMessageWrite', [
  144.                     'label' => $this->translator->trans('Написать сообщение', [], self::TRANSLATION_DOMAIN),
  145.                     'route' => 'account.support_messages.write',
  146.                 ]);
  147.                 if($this->features->profile_comments()) {
  148.                     $countCommentsWithoutReply $this->profileCommentRepository->countOfAdvertiserNotAnswered($authenticatedUser);
  149.                     $menu->addChild('ReviewsForProfiles', [
  150.                         'label' => $this->translator->trans('Отзывы на анкеты (%new%)', [
  151.                             '%new%' => $countCommentsWithoutReply,
  152.                         ], self::TRANSLATION_DOMAIN),
  153.                         'route' => 'account.profile_management.commented_profiles',
  154.                     ]);
  155.                     if($this->features->has_saloons()) {
  156.                         $countCommentsWithoutReply $this->saloonCommentRepository->countOfAdvertiserNotAnswered($authenticatedUser);
  157.                         $menu->addChild('ReviewsForSaloons', [
  158.                             'label' => $this->translator->trans('Отзывы на салоны (%new%)', [
  159.                                 '%new%' => $countCommentsWithoutReply,
  160.                             ], self::TRANSLATION_DOMAIN),
  161.                             'route' => 'account.saloon_management.commented_saloons',
  162.                         ]);
  163.                     }
  164.                 }
  165.                 $menu->addChild('TopPlacementPlace', [
  166.                     'label' => $this->translator->trans('Разместить в топ', [], self::TRANSLATION_DOMAIN),
  167.                     'route' => 'account.profile.top_placement',
  168.                 ]);
  169.                 $menu->addChild('ClientReviews', [
  170.                     'label' => $this->translator->trans('Отзывы о клиентах', [], self::TRANSLATION_DOMAIN),
  171.                     'route' => 'account.phone_reviews.list',
  172.                 ]);
  173.                 $menu->addChild('SupportMessages', [
  174.                     'label' => $this->translator->trans('Сообщения %unread_count%', [
  175.                         '%unread_count%' => $this->supportMessagesRepository->countUnreadOfOwner($authenticatedUser),
  176.                     ], self::TRANSLATION_DOMAIN),
  177.                     'route' => 'account.support_messages.list',
  178.                 ]);
  179.                 $menu->addChild('SupportMessageWrite', [
  180.                     'label' => $this->translator->trans('Написать сообщение', [], self::TRANSLATION_DOMAIN),
  181.                     'route' => 'account.support_messages.write',
  182.                 ]);
  183.             } else if($authenticatedUser instanceof Customer) {
  184.                 $menu->addChild('ForYou', [
  185.                     'label' => $this->translator->trans('Для Вас', [], self::TRANSLATION_DOMAIN),
  186.                     'route' => 'account.preferred_profiles.list',
  187.                 ]);
  188.                 $menu->addChild('InYourCity', [
  189.                     'label' => $this->translator->trans('В Вашем городе', [], self::TRANSLATION_DOMAIN),
  190.                     'route' => 'account.city_profiles',
  191.                 ]);
  192.                 $menu->addChild('FavouriteProfiles', [
  193.                     'label' => $this->translator->trans('Избранное', [], self::TRANSLATION_DOMAIN),
  194.                     'route' => 'account.favourites.profiles',
  195.                 ]);
  196.                 $menu->addChild('Preferences', [
  197.                     'label' => $this->translator->trans('Предпочтения', [], self::TRANSLATION_DOMAIN),
  198.                     'route' => 'account.profile_preferences',
  199.                 ]);
  200.                 if($this->features->profile_comments()) {
  201.                     $menu->addChild('ReviewsOfProfiles', [
  202.                         'label' => $this->translator->trans('Отзывы к анкетам', [], self::TRANSLATION_DOMAIN),
  203.                         'route' => 'account.reviews.profile',
  204.                     ]);
  205.                     if ($this->features->has_saloons()) {
  206.                         $menu->addChild('ReviewsOfSaloons', [
  207.                             'label' => $this->translator->trans('Отзывы к салонам', [], self::TRANSLATION_DOMAIN),
  208.                             'route' => 'account.reviews.saloon',
  209.                         ]);
  210.                     }
  211.                 }
  212.                 $menu->addChild('Settings', [
  213.                     'label' => $this->translator->trans('Настройки', [], self::TRANSLATION_DOMAIN),
  214.                     'route' => 'account.settings',
  215.                 ]);
  216.             }
  217.             $menu->addChild('Logout', [
  218.                 'label' => $this->translator->trans('Выход', [], self::TRANSLATION_DOMAIN),
  219.                 'route' => 'logout',
  220.             ]);
  221.         }
  222.         return $menu;
  223.     }
  224.     /**
  225.      * @return User|null
  226.      */
  227.     protected function getAuthenticatedUser(): ?User
  228.     {
  229.         $token $this->tokenStorage->getToken();
  230.         if (null === $token) {
  231.             return null;
  232.         }
  233.         $authenticatedUser $token->getUser();
  234.         return ($authenticatedUser instanceof User) ? $authenticatedUser null;
  235.     }
  236. }