MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/help.cafsindia.com/vendor/uvdesk/core-framework/Dashboard/SearchTemplate.php
<?php

namespace Webkul\UVDesk\CoreFrameworkBundle\Dashboard;

use Twig\Environment as TwigEnvironment;
use Webkul\UVDesk\CoreFrameworkBundle\Dashboard\Segments\SearchItemInterface;
use Webkul\UVDesk\CoreFrameworkBundle\Framework\ExtendableComponentInterface;
use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
use Symfony\Contracts\Translation\TranslatorInterface;


class SearchTemplate implements ExtendableComponentInterface
{
    private $collection = [];

    public function __construct(TwigEnvironment $twig, TranslatorInterface $translator, UserService $userService)
    {
        $this->twig = $twig;
        $this->translator = $translator;
        $this->userService = $userService;
    }

    public function appendSearchItem(SearchItemInterface $segment, $tags = [])
    {
        $this->collection[] = $segment; 
    }

    public function render()
    {
        // Compile accessible segments by end-user
		$searchCollection = [];
       
		foreach ($this->collection as $item) {
            if (in_array('getRoles', get_class_methods($item))) {
                if($item) {
                    if (null == $item::getRoles()) {
                        $searchCollection[] = $item;
                    } else {
                        foreach ($item::getRoles() as $requiredPermission) {
                            if ($this->userService->isAccessAuthorized($requiredPermission)) {
                                $searchCollection[] = $item;
        
                                break;
                            }
                        }
                    }
                }
            }
		}

        return $this->twig->render('@UVDeskCoreFramework/Templates/search.html.twig', [
            'collection' => $searchCollection
        ]);
    }
}