|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Setono\SyliusStockMovementPlugin\Menu; |
|
6
|
|
|
|
|
7
|
|
|
use Knp\Menu\FactoryInterface; |
|
8
|
|
|
use Knp\Menu\ItemInterface; |
|
9
|
|
|
use Setono\SyliusStockMovementPlugin\Event\ReportShowMenuBuilderEvent; |
|
10
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
11
|
|
|
|
|
12
|
|
|
final class ReportShowMenuBuilder |
|
13
|
|
|
{ |
|
14
|
|
|
public const EVENT_NAME = 'setono_sylius_stock_movement.menu.admin.report.show'; |
|
15
|
|
|
|
|
16
|
|
|
/** @var FactoryInterface */ |
|
17
|
|
|
private $factory; |
|
18
|
|
|
|
|
19
|
|
|
/** @var EventDispatcherInterface */ |
|
20
|
|
|
private $eventDispatcher; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct(FactoryInterface $factory, EventDispatcherInterface $eventDispatcher) |
|
23
|
|
|
{ |
|
24
|
|
|
$this->factory = $factory; |
|
25
|
|
|
$this->eventDispatcher = $eventDispatcher; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function createMenu(array $options): ItemInterface |
|
29
|
|
|
{ |
|
30
|
|
|
$menu = $this->factory->createItem('root'); |
|
31
|
|
|
|
|
32
|
|
|
if (!isset($options['report'])) { |
|
33
|
|
|
return $menu; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$report = $options['report']; |
|
37
|
|
|
|
|
38
|
|
|
$menu |
|
39
|
|
|
->addChild('send_report', [ |
|
40
|
|
|
'route' => 'setono_sylius_stock_movement_admin_report_send', |
|
41
|
|
|
'routeParameters' => ['id' => $report->getId()], |
|
42
|
|
|
]) |
|
43
|
|
|
->setAttribute('type', 'link') |
|
44
|
|
|
->setLabel('setono_sylius_stock_movement.ui.send_report') |
|
45
|
|
|
->setLabelAttribute('icon', 'paper plane') |
|
46
|
|
|
; |
|
47
|
|
|
|
|
48
|
|
|
$menu |
|
49
|
|
|
->addChild('download_report', [ |
|
50
|
|
|
'route' => 'setono_sylius_stock_movement_admin_report_download', |
|
51
|
|
|
'routeParameters' => ['id' => $report->getId()], |
|
52
|
|
|
]) |
|
53
|
|
|
->setAttribute('type', 'link') |
|
54
|
|
|
->setLabel('setono_sylius_stock_movement.ui.download_report') |
|
55
|
|
|
->setLabelAttribute('icon', 'cloud download') |
|
56
|
|
|
->setLabelAttribute('color', 'yellow') |
|
57
|
|
|
; |
|
58
|
|
|
|
|
59
|
|
|
$this->eventDispatcher->dispatch(new ReportShowMenuBuilderEvent($this->factory, $menu, $report)); |
|
60
|
|
|
|
|
61
|
|
|
return $menu; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|