vendor/uvdesk/core-framework/Dashboard/SearchTemplate.php line 18

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Dashboard;
  3. use Twig\Environment as TwigEnvironment;
  4. use Webkul\UVDesk\CoreFrameworkBundle\Dashboard\Segments\SearchItemInterface;
  5. use Webkul\UVDesk\CoreFrameworkBundle\Framework\ExtendableComponentInterface;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. class SearchTemplate implements ExtendableComponentInterface
  9. {
  10. private $collection = [];
  11. public function __construct(TwigEnvironment $twig, TranslatorInterface $translator, UserService $userService)
  12. {
  13. $this->twig = $twig;
  14. $this->translator = $translator;
  15. $this->userService = $userService;
  16. }
  17. public function appendSearchItem(SearchItemInterface $segment, $tags = [])
  18. {
  19. $this->collection[] = $segment;
  20. }
  21. public function render()
  22. {
  23. // Compile accessible segments by end-user
  24. $searchCollection = [];
  25. foreach ($this->collection as $item) {
  26. if (in_array('getRoles', get_class_methods($item))) {
  27. if($item) {
  28. if (null == $item::getRoles()) {
  29. $searchCollection[] = $item;
  30. } else {
  31. foreach ($item::getRoles() as $requiredPermission) {
  32. if ($this->userService->isAccessAuthorized($requiredPermission)) {
  33. $searchCollection[] = $item;
  34. break;
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. return $this->twig->render('@UVDeskCoreFramework/Templates/search.html.twig', [
  42. 'collection' => $searchCollection
  43. ]);
  44. }
  45. }