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

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 $requestStack, TwigEnvironment $twig, UserService $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. if (!empty($this->panelSidebars[$sidebarReference])) {
  37. $sidebar['title'] = $sidebarReference::getTitle();
  38. $route = $this->requestStack->getCurrentRequest()->get('_route');
  39. foreach ($this->panelSidebarItems as $itemReference => $item) {
  40. if ($item::getSidebarReferenceId() == $sidebarReference) {
  41. $supportedRoutes = array_unique(array_merge((array) $item::getRouteName(), $item::getSupportedRoutes()));
  42. if (null == $item::getRoles()) {
  43. $sidebar['collection'][] = [
  44. 'title' => $item::getTitle(),
  45. 'routeName' => $item::getRouteName(),
  46. 'isActive' => in_array($route, $supportedRoutes),
  47. ];
  48. } else {
  49. foreach ($item::getRoles() as $requiredPermission) {
  50. if ($this->userService->isAccessAuthorized($requiredPermission)) {
  51. $sidebar['collection'][] = [
  52. 'title' => $item::getTitle(),
  53. 'routeName' => $item::getRouteName(),
  54. 'isActive' => in_array($route, $supportedRoutes),
  55. ];
  56. break;
  57. }
  58. }
  59. }
  60. }
  61. }
  62. } else {
  63. $sidebar['title'] = $sidebarReference::getTitle();
  64. $route = $this->requestStack->getCurrentRequest()->get('_route');
  65. foreach ($this->panelSidebarItems as $itemReference => $item) {
  66. if ($item::getSidebarReferenceId() == $sidebarReference) {
  67. $supportedRoutes = array_unique(array_merge((array) $item::getRouteName(), $item::getSupportedRoutes()));
  68. if (null == $item::getRoles()) {
  69. $sidebar['collection'][] = [
  70. 'title' => $item::getTitle(),
  71. 'routeName' => $item::getRouteName(),
  72. 'isActive' => in_array($route, $supportedRoutes),
  73. ];
  74. } else {
  75. foreach ($item::getRoles() as $requiredPermission) {
  76. if ($this->userService->isAccessAuthorized($requiredPermission)) {
  77. $sidebar['collection'][] = [
  78. 'title' => $item::getTitle(),
  79. 'routeName' => $item::getRouteName(),
  80. 'isActive' => in_array($route, $supportedRoutes),
  81. ];
  82. break;
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89. // Sort sidebar items alphabatically
  90. usort($sidebar['collection'], function ($item_1, $item_2) {
  91. return strcasecmp($item_1['title'], $item_2['title']);
  92. });
  93. return $this->twig->render('@UVDeskCoreFramework/Templates/aside.html.twig', [ 'sidebar' => $sidebar ]);
  94. }
  95. }