1 | <?php |
||
2 | |||
3 | /* |
||
4 | * @copyright 2014 Mautic Contributors. All rights reserved |
||
5 | * @author Mautic |
||
6 | * |
||
7 | * @link http://mautic.org |
||
8 | * |
||
9 | * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
||
10 | */ |
||
11 | |||
12 | namespace Mautic\CoreBundle\Event; |
||
13 | |||
14 | use Symfony\Bundle\FrameworkBundle\Templating\PhpEngine; |
||
15 | use Symfony\Component\EventDispatcher\Event; |
||
16 | |||
17 | class SidebarCanvasEvent extends Event |
||
18 | { |
||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | private $sections = ['header', 'footer', 'content']; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $left = []; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $right = []; |
||
33 | |||
34 | /** |
||
35 | * @var PhpEngine |
||
36 | */ |
||
37 | private $templating; |
||
38 | |||
39 | /** |
||
40 | * @var array |
||
41 | */ |
||
42 | private $main = []; |
||
43 | |||
44 | public function __construct(PhpEngine $templating) |
||
45 | { |
||
46 | $this->templating = $templating; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Insert content into left canvas. |
||
51 | */ |
||
52 | public function pushToLeftCanvas(array $sections) |
||
53 | { |
||
54 | $this->setCanvasSection('left', $sections); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * Insert content into right canvas. |
||
59 | */ |
||
60 | public function pushToRightCanvas(array $sections) |
||
61 | { |
||
62 | $this->setCanvasSection('right', $sections); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Insert content into main canvas. |
||
67 | * |
||
68 | * Note that header is not allowed for main |
||
69 | */ |
||
70 | public function pushToMainCanvas(array $sections) |
||
71 | { |
||
72 | $this->setCanvasSection('main', $sections); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param $canvas |
||
77 | * @param $sections |
||
78 | */ |
||
79 | private function setCanvasSection($canvas, $sections) |
||
80 | { |
||
81 | $canvasSections = []; |
||
82 | foreach ($this->sections as $section) { |
||
83 | $canvasSections[$section] = (isset($sections[$section])) ? $sections[$section] : ''; |
||
84 | } |
||
85 | |||
86 | $this->{$canvas} = $canvasSections; |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get the canvas sections. |
||
91 | * |
||
92 | * @param null $canvas |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | public function getCanvasContent($canvas = null) |
||
97 | { |
||
98 | if ($canvas) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
99 | return $this->$canvas; |
||
100 | } else { |
||
101 | return [ |
||
102 | 'left' => $this->left, |
||
103 | 'right' => $this->right, |
||
104 | 'main' => $this->main, |
||
105 | ]; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @return mixed |
||
111 | */ |
||
112 | public function getTemplating() |
||
113 | { |
||
114 | return $this->templating; |
||
115 | } |
||
116 | } |
||
117 |