src/JanusHercules/Shared/Presentation/Component/Header/HeaderTwigLiveComponent.php line 23

Open in your IDE?
  1. <?php
  2. namespace JanusHercules\Shared\Presentation\Component\Header;
  3. use App\Entity\Profile\JoboffererProfile;
  4. use App\Entity\Profile\JobseekerProfile;
  5. use App\Entity\User;
  6. use Exception;
  7. use JanusHercules\Shared\Presentation\Entity\GroupNavigationItem;
  8. use JanusHercules\Shared\Presentation\Entity\NavigationItem;
  9. use JanusHercules\Shared\Presentation\Service\HeaderPresentationService;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
  13. use Symfony\UX\LiveComponent\Attribute\LiveAction;
  14. use Symfony\UX\LiveComponent\ComponentToolsTrait;
  15. use Symfony\UX\LiveComponent\DefaultActionTrait;
  16. #[AsLiveComponent(
  17. 'Header',
  18. '@janus_hercules.shared.presentation/header/header_twig_component.html.twig'
  19. )]
  20. class HeaderTwigLiveComponent extends AbstractController
  21. {
  22. use DefaultActionTrait;
  23. use ComponentToolsTrait;
  24. public function __construct(
  25. private readonly HeaderPresentationService $headerService,
  26. private readonly RequestStack $request,
  27. ) {
  28. }
  29. #[LiveAction]
  30. public function getShowJoboffererHeader(): bool
  31. {
  32. /** @var ?User $user */
  33. $user = $this->getUser();
  34. /** @var ?string $fromDigitalEstate */
  35. $fromDigitalEstate = $this->request->getCurrentRequest()?->query?->get('fromDigitalEstate');
  36. /** @var ?string $isJoboffererLogin */
  37. $isJoboffererLogin = $this->request->getCurrentRequest()?->query?->get('isJoboffererLogin');
  38. /** @var ?string $createWithRole */
  39. $createWithRole = $this->request->getCurrentRequest()?->query?->get('createWithRole');
  40. /** @var ?string $pathInfo */
  41. $pathInfo = $this->request->getCurrentRequest()?->getPathInfo();
  42. return $this->headerService->showJoboffererHeader($user, $fromDigitalEstate, $createWithRole, $pathInfo, $isJoboffererLogin);
  43. }
  44. #[LiveAction]
  45. public function getDigitalEstateUrlPro(): string
  46. {
  47. return $this->headerService->getDigitalEstateUrlPro();
  48. }
  49. /**
  50. * @throws Exception
  51. */
  52. #[LiveAction]
  53. public function getProfileLabel(): string
  54. {
  55. /** @var ?User $user */
  56. $user = $this->getUser();
  57. /** @var ?JobseekerProfile $jobseekerProfile */
  58. $jobseekerProfile = $user?->getDefaultJobseekerProfile();
  59. /** @var ?JoboffererProfile $joboffererProfile */
  60. $joboffererProfile = $user?->getDefaultJoboffererProfile();
  61. $displayName = null;
  62. if ($jobseekerProfile !== null && $jobseekerProfile->getFullDisplayName()) {
  63. $displayName = $jobseekerProfile->getFullDisplayName();
  64. } elseif ($joboffererProfile !== null && $joboffererProfile->getFullDisplayName()) {
  65. $displayName = $joboffererProfile->getFullDisplayName();
  66. } else {
  67. $displayName = $user?->getUsername();
  68. }
  69. return $displayName ?? 'Profil';
  70. }
  71. /**
  72. * @throws Exception
  73. */
  74. #[LiveAction]
  75. public function getUserCanSeeWebsiteNavigationItems(): bool
  76. {
  77. /** @var ?User $user */
  78. $user = $this->getUser();
  79. if ($user) {
  80. return $this->headerService->userCanSeeWebsiteNavigationItems($user);
  81. }
  82. return false;
  83. }
  84. #[LiveAction]
  85. public function getIsLoginFromAdmin(): bool
  86. {
  87. return $this->request->getCurrentRequest() && $this->request->getCurrentRequest()->cookies->has($this->headerService::COOKIE_NAME_LOGIN_WAS_FROM_ADMIN)
  88. && ($this->request->getCurrentRequest()->cookies->get($this->headerService::COOKIE_NAME_LOGIN_WAS_FROM_ADMIN) == '1');
  89. }
  90. /**
  91. * @return GroupNavigationItem[]
  92. */
  93. #[LiveAction]
  94. public function getJoboffererNavbarItems(): array
  95. {
  96. return [
  97. new GroupNavigationItem('JOBOO!®', [
  98. new NavigationItem('', 'Darum JOBOO!®', '', $this->getDigitalEstateUrlPro()),
  99. new NavigationItem('', 'Preise', '', $this->getDigitalEstateUrlPro() . '/preise'),
  100. new NavigationItem('', 'Arbeitskräfte finden', '', $this->generateUrl('wanted_jobs_search.form')),
  101. ]),
  102. new GroupNavigationItem('Lösungen', [
  103. new NavigationItem('', 'Einsatzzeit Matching', '', $this->getDigitalEstateUrlPro() . '/stellenanzeigen#KIMatching'),
  104. new NavigationItem('', 'Stellenanzeigen', '', $this->getDigitalEstateUrlPro() . '/stellenanzeigen'),
  105. new NavigationItem('', 'Bewerberdatenbank', '', $this->getDigitalEstateUrlPro() . '/active-sourcing'),
  106. ]),
  107. new GroupNavigationItem('Profil', [
  108. new NavigationItem('', 'Login', '', $this->generateUrl('fos_user_security_login', ['isJoboffererLogin' => true])),
  109. new NavigationItem('', 'Registrieren', '', $this->generateUrl('fos_user_registration_register', ['createWithRole' => User::ROLE_NAME_JOBOFFERER])),
  110. ]), new GroupNavigationItem('', [
  111. new NavigationItem('', 'Für Jobsuchende', '', '/de/'),
  112. ])
  113. ];
  114. }
  115. /**
  116. * @return GroupNavigationItem[]
  117. */
  118. #[LiveAction]
  119. public function getSolutionsLinks(): array
  120. {
  121. return [
  122. new GroupNavigationItem('', [
  123. new NavigationItem('', 'Einsatzzeit Matching', '', $this->getDigitalEstateUrlPro() . '/stellenanzeigen#KIMatching'),
  124. new NavigationItem('', 'Stellenanzeigen', '', $this->getDigitalEstateUrlPro() . '/stellenanzeigen'),
  125. new NavigationItem('', 'Bewerberdatenbank', '', $this->getDigitalEstateUrlPro() . '/active-sourcing'),
  126. ]),
  127. ];
  128. }
  129. }