-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathQuickActionButtonCollection.php
49 lines (41 loc) · 1.36 KB
/
QuickActionButtonCollection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
namespace Webkul\UVDesk\CoreFrameworkBundle\Tickets;
use Twig\Environment as TwigEnvironment;
use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
use Webkul\UVDesk\CoreFrameworkBundle\Dashboard\DashboardTemplate;
use Webkul\UVDesk\CoreFrameworkBundle\Framework\ExtendableComponentInterface;
class QuickActionButtonCollection implements ExtendableComponentInterface
{
private $collection = [];
public function __construct(TwigEnvironment $twig, DashboardTemplate $dashboard, UserService $userService)
{
$this->twig = $twig;
$this->dashboard = $dashboard;
$this->userService = $userService;
}
public function add(QuickActionButtonInterface $quickActionButton)
{
$this->collection[] = $quickActionButton;
}
public function injectTemplates()
{
return array_reduce($this->collection, function ($stream, $quickActionButton) {
return $stream .= $quickActionButton->renderTemplate($this->twig);
}, '');
}
public function prepareAssets()
{
foreach ($this->collection as $quickActionButton) {
if ($quickActionButton::getRoles() != null) {
foreach ($quickActionButton::getRoles() as $accessRole) {
if ($this->userService->isAccessAuthorized($accessRole)) {
$quickActionButton->prepareDashboard($this->dashboard);
break;
}
}
} else {
$quickActionButton->prepareDashboard($this->dashboard);
}
}
}
}