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

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 $twigTranslatorInterface $translatorUserService $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.        
  26.         foreach ($this->collection as $item) {
  27.             if (in_array('getRoles'get_class_methods($item))) {
  28.                 if($item) {
  29.                     if (null == $item::getRoles()) {
  30.                         $searchCollection[] = $item;
  31.                     } else {
  32.                         foreach ($item::getRoles() as $requiredPermission) {
  33.                             if ($this->userService->isAccessAuthorized($requiredPermission)) {
  34.                                 $searchCollection[] = $item;
  35.         
  36.                                 break;
  37.                             }
  38.                         }
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.         return $this->twig->render('@UVDeskCoreFramework/Templates/search.html.twig', [
  44.             'collection' => $searchCollection
  45.         ]);
  46.     }
  47. }