vendor/bluue/planning-bundle/src/EventSubscriber/ProjectsBundle/TaskViewSubscriber.php line 105

Open in your IDE?
  1. <?php
  2. /**
  3.  * @author Thomas HERISSON (contact@scaledev.fr)
  4.  * @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
  5.  * @license commercial
  6.  */
  7. declare(strict_types=1);
  8. namespace Bluue\PlanningBundle\EventSubscriber\ProjectsBundle;
  9. use ReflectionClass;
  10. use App\Services\CheckBundleInstall;
  11. use Bluue\ProjectsBundle\Entity\Task;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. use Bluue\PlanningBundle\Repository\SlotRepository;
  14. use Symfony\Contracts\Translation\TranslatorInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class TaskViewSubscriber implements EventSubscriberInterface
  17. {
  18.     /**
  19.      * @var RequestStack
  20.      */
  21.     protected RequestStack $requestStack;
  22.     /**
  23.      * @var TranslatorInterface
  24.      */
  25.     private TranslatorInterface $tr;
  26.     /**
  27.      * @var SlotRepository
  28.      */
  29.     private SlotRepository $slotRepo;
  30.     /**
  31.      * @param RequestStack $requestStack
  32.      * @param TranslatorInterface $tr
  33.      * @param SlotRepository $slotRepo
  34.      */
  35.     public function __construct(
  36.         RequestStack $requestStack,
  37.         TranslatorInterface $tr,
  38.         SlotRepository $slotRepo
  39.     ) {
  40.         $this->requestStack $requestStack;
  41.         $this->tr $tr;
  42.         $this->slotRepo $slotRepo;
  43.     }
  44.     /**
  45.      * @return string[]
  46.      */
  47.     public static function getSubscribedEvents(): array
  48.     {
  49.         if (CheckBundleInstall::exist('projects-bundle')) {
  50.             $reflectionClass = new ReflectionClass('Bluue\ProjectsBundle\Event\TaskViewEvent');
  51.             return [
  52.                 $reflectionClass->getConstant('TABS') => 'tabs',
  53.                 $reflectionClass->getConstant('TABS_PARAMS') => 'tabsParams',
  54.                 $reflectionClass->getConstant('PATHS') => 'paths'
  55.             ];
  56.         }
  57.         return [];
  58.     }
  59.     /**
  60.      * @param object $event
  61.      * @return void
  62.      */
  63.     public function tabs(object $event): void
  64.     {
  65.         $tabs $event->getTabs();
  66.         $newTabs = [
  67.             [
  68.                 'template' => '@Planning/ProjectsBundle/planning.html.twig',
  69.                 'name' => $this->tr->trans('Planning', [], 'PlanningBundle'),
  70.                 'icon' => 'fas fa-calendar-alt',
  71.                 'key' => 'planning'
  72.             ]
  73.         ];
  74.         $event->setTabs(array_merge($tabs$newTabs));
  75.     }
  76.     /**
  77.      * @param object $event
  78.      * @return void
  79.      */
  80.     public function tabsParams(object $event): void
  81.     {
  82.         $params $event->getTabsParams();
  83.         $task $params['task'];
  84.         $event->setTabsParams(array_merge($params, [
  85.             'slots' => $this->slotRepo->findBy(['task' => $task])
  86.         ]));
  87.     }
  88.     /**
  89.      * @param object $event
  90.      * @return void
  91.      */
  92.     public function paths(object $event): void
  93.     {
  94.         /** @var Task $task */
  95.         $task $event->getTabsParams()['task'];
  96.         $event->addPath([
  97.             'url' => 'planning_bundle__task_view_next_slot',
  98.             'id' => $task->getId()
  99.         ]);
  100.     }
  101. }