<?php
namespace App\Component\AdminMenu\EventSubscriber;
use App\Component\AdminMenu\Event\AbstractBuildMenuEvent;
use App\Component\AdminMenu\Event\BuildVacancyMenuEvent;
use App\Component\Configuration\Util\Config;
use App\Component\UserRole\Permission\UserRolePermission;
use App\Dto\MenuItem;
use App\Entity\Applicant;
use App\Entity\ApplicantForm;
use App\Entity\ApplicationProcessItemCollection;
use App\Entity\Feed;
use App\Entity\InternFormEntry;
use App\Entity\JobProfile;
use App\Entity\KnockoutQuestion;
use App\Entity\NoticeCategory;
use App\Entity\PayrollQuestion;
use App\Entity\SearchAnalytics;
use App\Entity\SiteUserData;
use App\Entity\VacancyAttribute;
use App\Entity\VacancyDomain;
use App\Entity\VacancyMoreInfo;
use App\Entity\VacancyTemplate;
use App\Entity\VacancyUsp;
use App\Entity\XmlFeed;
use App\EventListener\FeatureFlagListener;
use Flagception\Manager\FeatureManagerInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Security;
class VacancyMenuSubscriber extends AbstractMenuBuildEventSubscriber
{
protected static string $eventClass = BuildVacancyMenuEvent::class;
public function __construct(
AuthorizationCheckerInterface $authorizationChecker,
FeatureManagerInterface $featureManager,
private readonly Config $config,
private readonly Security $security,
) {
parent::__construct($authorizationChecker, $featureManager);
}
public function buildMenu(AbstractBuildMenuEvent $event)
{
$menuBuilder = $this->getMenuBuilder($event->getMenu(), 'Vacancies');
$menuBuilder
->addMainItem('Vacancies', 'fal fa-suitcase')
->addOverlay()
->addSection('Vacancies')
->addColumn('General', 'fal fa-suitcase')
->addItem('View vacancies', 'admin_vacancies');
if (!(true === $this->config->get('job_owner_hide_vacancy_create_without_template')
&& $this->security->isGranted('ROLE_ADMIN_JOB_OWNER')
&& !$this->security->isGranted('ROLE_ADMIN_HIRING_MANAGER'))
) {
$menuBuilder->addItem('Create vacancy', 'admin_vacancy_create');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, ApplicationProcessItemCollection::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_APPLICATION_PROCESS])
) {
$menuBuilder->addItem('Application Process', 'admin_application_process');
}
if (
(
$this->hasAccess(['ROLE_ADMIN_HIRING_MANAGER', [UserRolePermission::MASK_VIEW, VacancyMoreInfo::class]])
|| $this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, VacancyMoreInfo::class]])
)
&& $this->checkFeatures([FeatureFlagListener::FEATURE_VACANCY_MORE_INFO_BUTTON])
) {
$menuBuilder->addItem('More info requests', 'admin_vacancy_more_info_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, VacancyUsp::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_VACANCY_USPS])
) {
$menuBuilder->addItem("Vacancy USP's", 'admin_vacancyusps');
}
if (
(
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, VacancyDomain::class]])
|| $this->hasAccess(['ROLE_ADMIN_JOB_OWNER', [UserRolePermission::MASK_VIEW, VacancyDomain::class]])
)
&& $this->checkFeatures([FeatureFlagListener::FEATURE_VACANCY_DOMAIN])
) {
$menuBuilder->addItem('Vacancy domains', 'admin_vacancy_domain');
}
if ($this->hasAccess([[UserRolePermission::MASK_VIEW, VacancyTemplate::class]])) {
$menuBuilder->addItem('Vacancy templates', 'admin_vacancy_template');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, InternFormEntry::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_INTERNSHIP_FORM])
) {
$menuBuilder->addItem('Internship forms', 'admin_intern_form_index');
}
if ($this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, SearchAnalytics::class]])) {
$menuBuilder->addItem('Search statistics', 'admin_vacancy_analytics_index');
}
if ($this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, VacancyAttribute::class]])) {
$menuBuilder->addItem('Vacancy attributes', 'admin_vacancy_attribute_index');
}
$menuBuilder->end();
$menuBuilder->addColumn('Applicants', 'fal fa-users');
/** @var ItemInterface $currentItem */
$currentItem = $menuBuilder->getCurrentContext();
$applicantsDto = new MenuItem($currentItem);
if (
$this->hasAccess(['ROLE_ADMIN_JOB_OWNER'])
|| $this->hasAccess(['ROLE_ADMIN_USER'])
) {
if ($this->authorizationChecker->isGranted(UserRolePermission::MASK_VIEW, Applicant::class)) {
$menuBuilder->addItem('Applicants', 'admin_applicants', [
'view' => $this->featureManager->isActive(FeatureFlagListener::FEATURE_ATS) ? 'funnel' : 'grid',
])
->additem('Open applicants', 'admin_applicants_open');
}
if ($this->authorizationChecker->isGranted(UserRolePermission::MASK_VIEW, ApplicantForm::class)) {
$menuBuilder->additem('Applicant form', 'applicant_forms');
}
}
if (
$this->hasAccess([[UserRolePermission::MASK_VIEW, SiteUserData::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_RESUME_DATABASE])
) {
$menuBuilder->addItem('Resumes', 'admin_resume_database_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_MOBILITY_USER', [UserRolePermission::MASK_VIEW, JobProfile::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_MOBILITY_PLATFORM])
) {
$menuBuilder->addItem('Job Profiles', 'admin_job_profiles');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, KnockoutQuestion::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_VACANCY_KNOCKOUT_QUESTIONS])
) {
$menuBuilder
->addItem('Knockout Questions', 'admin_knockout_questions');
}
$menuBuilder->end();
$applicantsDto->close();
if (!$this->checkFeatures([
FeatureFlagListener::FEATURE_PAYROLL,
FeatureFlagListener::FEATURE_COMPANY_DASHBOARD,
FeatureFlagListener::FEATURE_FEEDS,
FeatureFlagListener::FEATURE_XML_VACANCY_FEEDS,
])) {
return;
}
$menuBuilder->addColumn('Other', 'fal fa-globe');
/** @var ItemInterface $currentItem */
$currentItem = $menuBuilder->getCurrentContext();
$otherDto = new MenuItem($currentItem);
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, Feed::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_FEEDS])
) {
$menuBuilder->addItem('Feeds', 'admin_feeds');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, XmlFeed::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_XML_VACANCY_FEEDS])
) {
$menuBuilder->addItem('XML feeds', 'admin_xml_feed_index');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, NoticeCategory::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_COMPANY_DASHBOARD])
) {
$menuBuilder->addItem('Notice Categories', 'admin_notice_category');
}
if (
$this->hasAccess(['ROLE_ADMIN_USER', [UserRolePermission::MASK_VIEW, PayrollQuestion::class]])
&& $this->checkFeatures([FeatureFlagListener::FEATURE_PAYROLL])
) {
$menuBuilder->addItem('Payroll', 'admin_payroll');
}
$otherDto->close();
}
}