<?php
namespace App\Component\AdminMenu\EventSubscriber;
use App\Component\AdminMenu\Event\AbstractBuildMenuEvent;
use App\Component\AdminMenu\Event\BuildATSMenuEvent;
use App\Dto\MenuItem;
use App\EventListener\FeatureFlagListener;
use Knp\Menu\ItemInterface;
class ATSHeaderMenuSubscriber extends AbstractMenuBuildEventSubscriber
{
protected static string $eventClass = BuildATSMenuEvent::class;
public function buildMenu(AbstractBuildMenuEvent $event)
{
if (!$event instanceof BuildATSMenuEvent) {
return;
}
$atsFeatures = array_filter(array_column($event->getATSList(), 'feature'));
$atsFeatures[] = FeatureFlagListener::FEATURE_ATS;
$atsFeatures = array_unique($atsFeatures);
$hasAtsEnabled = $this->checkFeatures($atsFeatures);
if (
!$hasAtsEnabled && (!$this->hasAccess(['ROLE_ADMIN_USER']) || $this->hasAccess(['ROLE_ADMIN_HIRING_MANAGER']))
) {
$event->stopPropagation();
return;
}
$menuBuilder = $this->getMenuBuilder($event->getMenu())
->addSection('ATS', 'skin-lemon');
/** @var ItemInterface $currentItem */
$currentItem = $menuBuilder->getCurrentContext();
$atsDto = new MenuItem($currentItem);
if (
(
$this->hasAccess(['ROLE_ADMIN_HIRING_MANAGER'])
|| $this->hasAccess(['ROLE_ADMIN_USER'])
)
&& $this->checkFeatures([FeatureFlagListener::FEATURE_ATS])
) {
$menuBuilder->addMainItem('Applicants', 'fal fa-users', 'admin_applicants', [
'view' => $this->featureManager->isActive(FeatureFlagListener::FEATURE_ATS) ? 'funnel' : 'grid',
])->end();
$menuBuilder->addMainItem('Open applicants', 'fal fa-id-badge', 'admin_applicants_open')->end();
$menuBuilder->addMainItem('Applicant form', 'fal fa-file-alt', 'applicant_forms')->end();
}
if ($this->checkFeatures([FeatureFlagListener::FEATURE_ATS]) && $this->hasAccess(['ROLE_ADMIN_USER'])) {
$menuBuilder->addMainItem('Recipients', 'fal fa-at', 'ats_recipients')
->end()
->addMainItem('Hire/Reject reasons', 'fal fa-tasks', 'ats_reject_reason')
->end()
->addMainItem('Applicant status', 'fal fa-thermometer-half', 'ats_status')
->end()
;
}
if (!$this->hasAccess(['ROLE_ADMIN_USER'])) {
$atsDto->close();
return;
}
foreach ($event->getATSList() as $title => $details) {
if (!$this->checkFeatures([$details['feature']])) {
continue;
}
$menuBuilder->addMainItem(
$title,
$details['icon'] ?? 'fal fa-network-wired',
$details['route']
)->end();
}
if ($this->checkFeatures([FeatureFlagListener::FEATURE_EXTERNAL_INTEGRATION_LOG])) {
$menuBuilder->addMainItem('Integration log', 'fal fa-info-square', 'admin_external_integration_log');
}
$atsDto->close();
}
}