<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 2019-05-21
* Time: 18:54
*/
namespace App\Menu;
use App\Entity\Account\Advertiser;
use App\Entity\Account\Customer;
use App\Entity\User;
use App\Repository\ProfileCommentRepository;
use App\Repository\ProfileRepository;
use App\Repository\SaloonCommentRepository;
use App\Repository\SaloonRepository;
use App\Repository\SupportMessagesRepository;
use App\Service\Features;
use App\Specification\Saloon\SaloonIsActive;
use App\Specification\Saloon\SaloonIsNotHidden;
use App\Specification\Saloon\SaloonOwner;
use Happyr\DoctrineSpecification\Spec;
use Knp\Menu\FactoryInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class AccountLeftMenuBuilder
{
const NAME = 'account_left';
const TRANSLATION_DOMAIN = 'account_left_menu';
public function __construct(
private FactoryInterface $factory,
private Features $features,
private TokenStorageInterface $tokenStorage,
private TranslatorInterface $translator,
private ProfileRepository $profileRepository,
private SaloonRepository $saloonRepository,
private SupportMessagesRepository $supportMessagesRepository,
private ProfileCommentRepository $profileCommentRepository,
private SaloonCommentRepository $saloonCommentRepository,
) {}
public function build(array $options)
{
$menu = $this->factory->createItem(self::NAME);
if (null !== $authenticatedUser = $this->getAuthenticatedUser()) {
if($authenticatedUser instanceof Advertiser) {
$menu->addChild('PaidServices', [
'label' => $this->translator->trans('Стоимость рекламы', [], self::TRANSLATION_DOMAIN),
'route' => 'account.paid_services.info_page',
]);
$menu->addChild('Edit', [
'label' => $this->translator->trans('Мои данные', [], self::TRANSLATION_DOMAIN),
'route' => 'account.settings',
]);
$menu->addChild('Pay', [
'label' => $this->translator->trans('Пополнить баланс', [], self::TRANSLATION_DOMAIN),
'route' => 'account.finances.pay',
]);
$menu->addChild('Help', [
'label' => $this->translator->trans('Помощь', [], self::TRANSLATION_DOMAIN),
'uri' => '#',
]);
$menu->addChild('Forum', [
'label' => $this->translator->trans('Рекламный форум', [], self::TRANSLATION_DOMAIN),
'uri' => '#',
]);
$profilesLabel = $this->translator->trans('Ваши анкеты %active%/%all%', [
'%active%' => $this->profileRepository->countActiveOfOwner($authenticatedUser,$this->features->non_masseur_on_account_profile_list() ? false : null),
'%all%' => $this->profileRepository->countAllOfOwnerNotDeleted($authenticatedUser, $this->features->non_masseur_on_account_profile_list() ? false : null),
], self::TRANSLATION_DOMAIN);
$menu->addChild('ProfileList', [
'label' => $profilesLabel,
'route' => 'account.profile_management.list',
]);
$menu->addChild('AddProfile', [
'label' => $this->translator->trans('Добавить анкету', [], self::TRANSLATION_DOMAIN),
'route' => 'account.profile_editing.create',
]);
if ($this->features->has_masseurs()/* && false == $this->features->non_masseur_on_account_profile_list()*/) {
$masseursLabel = $this->translator->trans('Массажистки %active%/%all%', [
'%active%' => $this->profileRepository->countActiveOfOwner($authenticatedUser, true),
'%all%' => $this->profileRepository->countAllOfOwnerNotDeleted($authenticatedUser, true),
], self::TRANSLATION_DOMAIN);
$menu->addChild('MasseurList', [
'label' => $masseursLabel,
'route' => 'account.profile_management.list_masseur',
]);
$menu->addChild('AddMasseur', [
'label' => $this->translator->trans('Добавить массаж-ку', [], self::TRANSLATION_DOMAIN),
'route' => 'account.profile_editing.create_masseur',
]);
}
if ($this->features->has_saloons()) {
$criteria = Spec::andX(
$this->features->free_profiles() ? new SaloonIsNotHidden() : new SaloonIsActive(),
new SaloonOwner($authenticatedUser),
);
$saloonsLabel = $this->translator->trans('Ваши салоны %active%/%all%', [
'%active%' => $this->saloonRepository->countMatchingSpec($criteria),
'%all%' => $this->saloonRepository->countAllOfOwner($authenticatedUser),
], self::TRANSLATION_DOMAIN);
$menu->addChild('SaloonList', [
'label' => $saloonsLabel,
'route' => 'account_saloons',
]);
$menu->addChild('AddSaloon', [
'label' => $this->translator->trans('Добавить салон', [], self::TRANSLATION_DOMAIN),
'route' => 'account.saloon_editing.create',
]);
}
$bannersLabel = $this->translator->trans('Ваши баннеры %active%/%all%', [
'%active%' => 0,
'%all%' => 0,
], self::TRANSLATION_DOMAIN);
$menu->addChild('BannerList', [
'label' => $bannersLabel,
'uri' => '#',
]);
$menu->addChild('AddBanner', [
'label' => $this->translator->trans('Добавить баннер', [], self::TRANSLATION_DOMAIN),
'uri' => '#',
]);
$menu->addChild('PaidLineList', [
'label' => $this->translator->trans('Платные строчки', [], self::TRANSLATION_DOMAIN),
'uri' => '#',
]);
$menu->addChild('Blacklist', [
'label' => $this->translator->trans('Черный список', [], self::TRANSLATION_DOMAIN),
'route' => 'account.phone_review',
]);
$menu->addChild('PaymentHistory', [
'label' => $this->translator->trans('История платежей', [], self::TRANSLATION_DOMAIN),
'route' => 'account.finances.transactions',
]);
$menu->addChild('TopPlacementPlace', [
'label' => $this->translator->trans('Разместить в топ', [], self::TRANSLATION_DOMAIN),
'route' => 'account.profile.top_placement',
]);
$menu->addChild('SupportMessages', [
'label' => $this->translator->trans('Сообщения %unread_count%', [
'%unread_count%' => $this->supportMessagesRepository->countUnreadOfOwner($authenticatedUser),
], self::TRANSLATION_DOMAIN),
'route' => 'account.support_messages.list',
]);
$menu->addChild('SupportMessageWrite', [
'label' => $this->translator->trans('Написать сообщение', [], self::TRANSLATION_DOMAIN),
'route' => 'account.support_messages.write',
]);
if($this->features->profile_comments()) {
$countCommentsWithoutReply = $this->profileCommentRepository->countOfAdvertiserNotAnswered($authenticatedUser);
$menu->addChild('ReviewsForProfiles', [
'label' => $this->translator->trans('Отзывы на анкеты (%new%)', [
'%new%' => $countCommentsWithoutReply,
], self::TRANSLATION_DOMAIN),
'route' => 'account.profile_management.commented_profiles',
]);
if($this->features->has_saloons()) {
$countCommentsWithoutReply = $this->saloonCommentRepository->countOfAdvertiserNotAnswered($authenticatedUser);
$menu->addChild('ReviewsForSaloons', [
'label' => $this->translator->trans('Отзывы на салоны (%new%)', [
'%new%' => $countCommentsWithoutReply,
], self::TRANSLATION_DOMAIN),
'route' => 'account.saloon_management.commented_saloons',
]);
}
}
$menu->addChild('TopPlacementPlace', [
'label' => $this->translator->trans('Разместить в топ', [], self::TRANSLATION_DOMAIN),
'route' => 'account.profile.top_placement',
]);
$menu->addChild('ClientReviews', [
'label' => $this->translator->trans('Отзывы о клиентах', [], self::TRANSLATION_DOMAIN),
'route' => 'account.phone_reviews.list',
]);
$menu->addChild('SupportMessages', [
'label' => $this->translator->trans('Сообщения %unread_count%', [
'%unread_count%' => $this->supportMessagesRepository->countUnreadOfOwner($authenticatedUser),
], self::TRANSLATION_DOMAIN),
'route' => 'account.support_messages.list',
]);
$menu->addChild('SupportMessageWrite', [
'label' => $this->translator->trans('Написать сообщение', [], self::TRANSLATION_DOMAIN),
'route' => 'account.support_messages.write',
]);
} else if($authenticatedUser instanceof Customer) {
$menu->addChild('ForYou', [
'label' => $this->translator->trans('Для Вас', [], self::TRANSLATION_DOMAIN),
'route' => 'account.preferred_profiles.list',
]);
$menu->addChild('InYourCity', [
'label' => $this->translator->trans('В Вашем городе', [], self::TRANSLATION_DOMAIN),
'route' => 'account.city_profiles',
]);
$menu->addChild('FavouriteProfiles', [
'label' => $this->translator->trans('Избранное', [], self::TRANSLATION_DOMAIN),
'route' => 'account.favourites.profiles',
]);
$menu->addChild('Preferences', [
'label' => $this->translator->trans('Предпочтения', [], self::TRANSLATION_DOMAIN),
'route' => 'account.profile_preferences',
]);
if($this->features->profile_comments()) {
$menu->addChild('ReviewsOfProfiles', [
'label' => $this->translator->trans('Отзывы к анкетам', [], self::TRANSLATION_DOMAIN),
'route' => 'account.reviews.profile',
]);
if ($this->features->has_saloons()) {
$menu->addChild('ReviewsOfSaloons', [
'label' => $this->translator->trans('Отзывы к салонам', [], self::TRANSLATION_DOMAIN),
'route' => 'account.reviews.saloon',
]);
}
}
$menu->addChild('Settings', [
'label' => $this->translator->trans('Настройки', [], self::TRANSLATION_DOMAIN),
'route' => 'account.settings',
]);
}
$menu->addChild('Logout', [
'label' => $this->translator->trans('Выход', [], self::TRANSLATION_DOMAIN),
'route' => 'logout',
]);
}
return $menu;
}
/**
* @return User|null
*/
protected function getAuthenticatedUser(): ?User
{
$token = $this->tokenStorage->getToken();
if (null === $token) {
return null;
}
$authenticatedUser = $token->getUser();
return ($authenticatedUser instanceof User) ? $authenticatedUser : null;
}
}