<?php
namespace PaperKite\Admin\Controller;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Config\UserMenu;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use PaperKite\Common\Entity\Company;
use PaperKite\Common\Entity\Department;
use PaperKite\Common\Entity\DocumentType;
use PaperKite\Common\Entity\DossierType;
use PaperKite\Common\Entity\HealthInsurance;
use PaperKite\Common\Entity\HealthMutual;
use PaperKite\Common\Entity\SportFederation;
use PaperKite\Common\Entity\SubscriptionPlan;
use PaperKite\Common\Entity\Support\MessageDocumentGeneratorInfo;
use PaperKite\Common\Entity\Support\Placeholder;
use PaperKite\Common\Entity\Support\PredefinedMessage;
use PaperKite\Common\Entity\Support\PredefinedTemplate;
use PaperKite\Common\Entity\Tariff;
use PaperKite\CompanyApi\Entity\CompanyUser;
use PaperKite\EmployeeApi\Entity\Employee;
use PaperKite\EmployeeApi\Entity\EmployeeInterface;
use PaperKite\HealthMutualApi\Entity\HealthMutualUser;
use PaperKite\Log\Entity\AuditLog;
use PaperKite\MyCmcmApi\Entity\FaqEntry;
use PaperKite\MyCmcmApi\Entity\InquiryCategory;
use PaperKite\MyCmcmApi\Entity\MyCmcmUser;
use PaperKite\MyCmcmApi\Entity\Page;
use PaperKite\MyCmcmApi\Entity\SliderItem;
use PaperKite\MyCmcmApi\Entity\TicketTopic;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\User\UserInterface;
class DashboardController extends AbstractDashboardController
{
public function __construct(
private string $appUrl,
) {
}
#[Route(path: '/', name: 'admin_dashboard')]
public function index(): Response
{
return $this->render('admin/dashboard.html.twig');
}
public function configureDashboard(): Dashboard
{
return Dashboard::new()
->setTitle(
<<<EOT
<img src="/cmcm-logo.svg">
<span style="display: block; padding: 10px 0; text-align: center; color: #0033A0;">Admin Tool</span>
EOT
)
->setTranslationDomain('admin')
->setFaviconPath('/favicon.ico')
->renderContentMaximized(true);
}
public function configureMenuItems(): iterable
{
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
yield MenuItem::linkToUrl('Paperkite app', 'fa fa-mobile-alt', $this->appUrl)
->setLinkTarget('_blank');
if ($this->isGranted('ROLE_CMCM_ADMIN')) {
yield MenuItem::section('Configuration');
if ($this->isGranted('ROLE_ADMIN_EMPLOYEE_CRUD')) {
yield MenuItem::linkToCrud('employees', 'fa fa-users', Employee::class);
}
if ($this->isGranted('ROLE_ADMIN_DEPARTMENT_CRUD')) {
yield MenuItem::linkToCrud('departments', 'fa fa-building', Department::class);
}
if ($this->isGranted('ROLE_ADMIN_DOSSIER_TYPE_CRUD')) {
yield MenuItem::linkToCrud('dossier_types', 'fa fa-folder', DossierType::class);
}
if ($this->isGranted('ROLE_ADMIN_DOCUMENT_TYPE_CRUD')) {
yield MenuItem::linkToCrud('document_type.title', 'fa fa-folder', DocumentType::class);
}
if ($this->isGranted('ROLE_ADMIN_TARIFF_CRUD')) {
yield MenuItem::linkToCrud('Tariffs', 'fa fa-coins', Tariff::class);
}
yield MenuItem::linkToCrud('subscription_plans', 'fa fa-euro-sign', SubscriptionPlan::class);
yield MenuItem::linkToCrud('health_mutuals', 'fa fa-hospital', HealthMutual::class);
yield MenuItem::linkToCrud('health_mutual_users', 'fa fa-hospital-user', HealthMutualUser::class);
yield MenuItem::linkToCrud('federations', 'fa fa-futbol-o', SportFederation::class);
yield MenuItem::linkToCrud('health_insurances', 'fa fa-notes-medical', HealthInsurance::class);
yield MenuItem::linkToCrud('companies', 'fa fa-building', Company::class);
yield MenuItem::linkToCrud('company_users', 'fa fa-building-user', CompanyUser::class);
yield MenuItem::linkToCrud('mycmcm_users', 'fa fa-user', MyCmcmUser::class);
}
if ($this->isGranted('ROLE_ADMIN_SUPPORT')) {
yield MenuItem::section('Support');
if ($this->isGranted('ROLE_ADMIN_PREDEFINED_TEMPLATE_CRUD')) {
yield MenuItem::linkToCrud('predefined_templates', 'fa fa-file', PredefinedTemplate::class);
}
if ($this->isGranted('ROLE_ADMIN_PREDEFINED_MESSAGE_CRUD')) {
yield MenuItem::linkToCrud('predefined_messages', 'fa fa-file', PredefinedMessage::class);
}
if ($this->isGranted('ROLE_ADMIN_PLACEHOLDER_CRUD')) {
yield MenuItem::linkToCrud('placeholders', 'fa fa-file', Placeholder::class);
}
yield MenuItem::linkToCrud('ticket_topics', 'fa fa-clipboard-list', TicketTopic::class);
}
if ($this->isGranted('ROLE_ADMIN_MARKETING')) {
yield MenuItem::section('MyCMCM content');
if ($this->isGranted('ROLE_ADMIN_SLIDER_CRUD')) {
yield MenuItem::linkToCrud('slider', 'fa fa-image', SliderItem::class);
}
}
if ($this->isGranted('ROLE_CMCM_ADMIN')) {
yield MenuItem::linkToCrud('inquiry_categories', 'fa fa-tag', InquiryCategory::class);
yield MenuItem::linkToCrud('pages', 'fa fa-file-lines', Page::class);
yield MenuItem::linkToCrud('faq', 'fa fa-question', FaqEntry::class);
}
if ($this->isGranted('ROLE_CMCM_ADMIN')) {
yield MenuItem::section('IT');
yield MenuItem::linkToCrud('Audit logs', 'fa fa-road-barrier', AuditLog::class);
yield MenuItem::linkToCrud('Message Document generator info', 'fa fa-road-barrier', MessageDocumentGeneratorInfo::class);
yield MenuItem::linkToRoute('Messenger queue', 'fa fa-road-barrier', 'admin_messenger_messages');
}
if ($this->isGranted('ROLE_SUPER_ADMIN')) {
yield MenuItem::linkToRoute('Api doc', 'fa fa-book', 'employee_show_apidoc')
->setLinkTarget('_blank');
yield MenuItem::linkToUrl('Openapi doc', 'fa fa-book-atlas', '/openapi/index.html')
->setLinkTarget('_blank');
yield MenuItem::linkToRoute('Add inquiry', ' fa fa-ban', 'admin_inquiry_new');
}
}
public function configureUserMenu(UserInterface $user): UserMenu
{
$userMenu = parent::configureUserMenu($user);
if ($user instanceof EmployeeInterface) {
$userMenu->setName($user->getFirstName() ?? $user->getUserIdentifier())
->displayUserName(true)
->setAvatarUrl($user->getAvatarImageUrl() ?? '')
;
}
return $userMenu;
}
}