vendor/uvdesk/core-framework/Dashboard/AsideTemplate.php line 23

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Dashboard;
  3. use Twig\Environment as TwigEnvironment;
  4. use Symfony\Component\HttpFoundation\RequestStack;
  5. use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Framework\ExtendableComponentInterface;
  7. use Webkul\UVDesk\CoreFrameworkBundle\Dashboard\Segments\PanelSidebarInterface;
  8. use Webkul\UVDesk\CoreFrameworkBundle\Dashboard\Segments\PanelSidebarItemInterface;
  9. class AsideTemplate implements ExtendableComponentInterface
  10. {
  11.     CONST SECTION_TEMPLATE '<div class="uv-brick"><div class="uv-brick-head"><h6>[[ TITLE ]]</h6><p>[[ DESCRIPTION ]]</p></div><div class="uv-brick-section">[[ COLLECTION ]]</div></div>';
  12.     CONST SECTION_ITEM_TEMPLATE '<a href="[[ PATH ]]"><div class="uv-brick-container"><div class="uv-brick-icon">[[ SVG ]]</div><p>[[ TITLE ]]</p></div></a>';
  13.     private $panelSidebars = [];
  14.     private $panelSidebarItems = [];
  15.     private $isOrganized false;
  16.     public function __construct(RequestStack $requestStackTwigEnvironment $twigUserService $userService)
  17.     {
  18.         $this->twig $twig;
  19.         $this->userService $userService;
  20.         $this->requestStack $requestStack;
  21.     }
  22.     public function addPanelSidebar(PanelSidebarInterface $panelSidebar$tags = [])
  23.     {
  24.         $this->panelSidebars[get_class($panelSidebar)] = $panelSidebar;
  25.     }
  26.     public function addPanelSidebarItem(PanelSidebarItemInterface $panelSidebarItem$tags = [])
  27.     {
  28.         $this->panelSidebarItems[get_class($panelSidebarItem)] = $panelSidebarItem;
  29.     }
  30.     public function renderSidebar($sidebarReference)
  31.     {
  32.         $sidebar = [
  33.             'title' => null,
  34.             'collection' => [],
  35.         ];
  36.         
  37.         if (!empty($this->panelSidebars[$sidebarReference])) {
  38.             $sidebar['title'] = $sidebarReference::getTitle();
  39.             $route $this->requestStack->getCurrentRequest()->get('_route');
  40.             foreach ($this->panelSidebarItems as $itemReference => $item) {
  41.                 if ($item::getSidebarReferenceId() == $sidebarReference) {
  42.                     $supportedRoutes array_unique(array_merge((array) $item::getRouteName(), $item::getSupportedRoutes()));
  43.                     if (null == $item::getRoles()) {
  44.                         $sidebar['collection'][] = [
  45.                             'title' => $item::getTitle(),
  46.                             'routeName' => $item::getRouteName(),
  47.                             'isActive' => in_array($route$supportedRoutes),
  48.                         ];
  49.                     } else {
  50.                         foreach ($item::getRoles() as $requiredPermission) {
  51.                             if ($this->userService->isAccessAuthorized($requiredPermission)) {
  52.                                 $sidebar['collection'][] = [
  53.                                     'title' => $item::getTitle(),
  54.                                     'routeName' => $item::getRouteName(),
  55.                                     'isActive' => in_array($route$supportedRoutes),
  56.                                 ];
  57.     
  58.                                 break;
  59.                             }
  60.                         }
  61.                     }
  62.                 }
  63.             }
  64.         } else {
  65.             $sidebar['title'] = $sidebarReference::getTitle();
  66.             $route $this->requestStack->getCurrentRequest()->get('_route');
  67.             foreach ($this->panelSidebarItems as $itemReference => $item) {
  68.                 if ($item::getSidebarReferenceId() == $sidebarReference) {
  69.                     $supportedRoutes array_unique(array_merge((array) $item::getRouteName(), $item::getSupportedRoutes()));
  70.                     if (null == $item::getRoles()) {
  71.                         $sidebar['collection'][] = [
  72.                             'title' => $item::getTitle(),
  73.                             'routeName' => $item::getRouteName(),
  74.                             'isActive' => in_array($route$supportedRoutes),
  75.                         ];
  76.                     } else {
  77.                         foreach ($item::getRoles() as $requiredPermission) {
  78.                             if ($this->userService->isAccessAuthorized($requiredPermission)) {
  79.                                 $sidebar['collection'][] = [
  80.                                     'title' => $item::getTitle(),
  81.                                     'routeName' => $item::getRouteName(),
  82.                                     'isActive' => in_array($route$supportedRoutes),
  83.                                 ];
  84.     
  85.                                 break;
  86.                             }
  87.                         }
  88.                     }
  89.                 }
  90.             } 
  91.         }
  92.         // Sort sidebar items alphabatically
  93.         usort($sidebar['collection'], function ($item_1$item_2) {
  94.             return strcasecmp($item_1['title'], $item_2['title']);
  95.         });
  96.         return $this->twig->render('@UVDeskCoreFramework/Templates/aside.html.twig', [ 'sidebar' => $sidebar ]);
  97.     }
  98. }