vendor/uvdesk/core-framework/Tickets/QuickActionButtonCollection.php line 18

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Tickets;
  3. use Twig\Environment as TwigEnvironment;
  4. use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
  5. use Webkul\UVDesk\CoreFrameworkBundle\Dashboard\DashboardTemplate;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Framework\ExtendableComponentInterface;
  7. class QuickActionButtonCollection implements ExtendableComponentInterface
  8. {
  9. private $collection = [];
  10. public function __construct(TwigEnvironment $twig, DashboardTemplate $dashboard, UserService $userService)
  11. {
  12. $this->twig = $twig;
  13. $this->dashboard = $dashboard;
  14. $this->userService = $userService;
  15. }
  16. public function add(QuickActionButtonInterface $quickActionButton)
  17. {
  18. $this->collection[] = $quickActionButton;
  19. }
  20. public function injectTemplates()
  21. {
  22. return array_reduce($this->collection, function ($stream, $quickActionButton) {
  23. return $stream .= $quickActionButton->renderTemplate($this->twig);
  24. }, '');
  25. }
  26. public function prepareAssets()
  27. {
  28. foreach ($this->collection as $quickActionButton) {
  29. if ($quickActionButton::getRoles() != null) {
  30. foreach ($quickActionButton::getRoles() as $accessRole) {
  31. if ($this->userService->isAccessAuthorized($accessRole)) {
  32. $quickActionButton->prepareDashboard($this->dashboard);
  33. break;
  34. }
  35. }
  36. } else {
  37. $quickActionButton->prepareDashboard($this->dashboard);
  38. }
  39. }
  40. }
  41. }