1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Victoire\Bundle\TemplateBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
8
|
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface; |
9
|
|
|
use Victoire\Bundle\CoreBundle\Entity\View; |
10
|
|
|
use Victoire\Bundle\PageBundle\Entity\BasePage; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Template. |
14
|
|
|
* |
15
|
|
|
* @ORM\Entity(repositoryClass="Victoire\Bundle\TemplateBundle\Repository\TemplateRepository") |
16
|
|
|
*/ |
17
|
|
|
class Template extends View |
18
|
|
|
{ |
19
|
|
|
const TYPE = 'template'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string |
23
|
|
|
* |
24
|
|
|
* @ORM\OneToMany(targetEntity="\Victoire\Bundle\CoreBundle\Entity\View", mappedBy="template") |
25
|
|
|
*/ |
26
|
|
|
protected $inheritors; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var string |
30
|
|
|
* |
31
|
|
|
* @ORM\Column(name="layout", type="string", length=255) |
32
|
|
|
*/ |
33
|
|
|
protected $layout; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Construct. |
37
|
|
|
**/ |
38
|
|
|
public function __construct() |
39
|
|
|
{ |
40
|
|
|
parent::__construct(); |
41
|
|
|
$this->widgets = new ArrayCollection(); |
|
|
|
|
42
|
|
|
$this->inheritors = new ArrayCollection(); |
|
|
|
|
43
|
|
|
$this->pages = new ArrayCollection(); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* to string. |
48
|
|
|
* |
49
|
|
|
* @return string |
50
|
|
|
**/ |
51
|
|
|
public function __toString() |
52
|
|
|
{ |
53
|
|
|
return 'Modèle > '.$this->getName(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* add page. |
58
|
|
|
* |
59
|
|
|
* @param BasePage $page |
60
|
|
|
* |
61
|
|
|
* @return Template |
62
|
|
|
**/ |
63
|
|
|
public function addPage(BasePage $page) |
64
|
|
|
{ |
65
|
|
|
$page->setTemplate($this); |
66
|
|
|
$this->pages[] = $page; |
67
|
|
|
|
68
|
|
|
return $this; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* set page. |
73
|
|
|
* |
74
|
|
|
* @param array $pages |
75
|
|
|
* |
76
|
|
|
* @return Template |
77
|
|
|
**/ |
78
|
|
|
public function setPages(array $pages) |
79
|
|
|
{ |
80
|
|
|
foreach ($pages as $page) { |
81
|
|
|
$this->addPage($page); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* remove page. |
89
|
|
|
* |
90
|
|
|
* @param BasePage $page |
91
|
|
|
* |
92
|
|
|
* @return Template |
93
|
|
|
**/ |
94
|
|
|
public function removePage($page) |
95
|
|
|
{ |
96
|
|
|
$this->pages->removeElement($page); |
97
|
|
|
|
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get pages (all Pages having this object as Template). |
103
|
|
|
* |
104
|
|
|
* @return ArrayCollection |
105
|
|
|
*/ |
106
|
|
|
public function getPages() |
107
|
|
|
{ |
108
|
|
|
return $this->pages; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Set layout. |
113
|
|
|
* |
114
|
|
|
* @param string $layout |
115
|
|
|
* |
116
|
|
|
* @return Template |
117
|
|
|
*/ |
118
|
|
|
public function setLayout($layout) |
119
|
|
|
{ |
120
|
|
|
$this->layout = $layout; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get layout. |
127
|
|
|
* |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function getLayout() |
131
|
|
|
{ |
132
|
|
|
return $this->layout; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Set inheritors. |
137
|
|
|
* |
138
|
|
|
* @param string $inheritors |
139
|
|
|
* |
140
|
|
|
* @return Template |
141
|
|
|
*/ |
142
|
|
|
public function setInheritors($inheritors) |
143
|
|
|
{ |
144
|
|
|
$this->inheritors = $inheritors; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Get inheritors (all Views having this object as Template). |
151
|
|
|
* |
152
|
|
|
* @return [View] |
|
|
|
|
153
|
|
|
*/ |
154
|
|
|
public function getInheritors() |
155
|
|
|
{ |
156
|
|
|
return $this->inheritors; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Get inheritors (all Templates having this object as Template). |
161
|
|
|
* |
162
|
|
|
* @return [Template] |
|
|
|
|
163
|
|
|
*/ |
164
|
|
View Code Duplication |
public function getTemplateInheritors() |
|
|
|
|
165
|
|
|
{ |
166
|
|
|
$templateInheritors = []; |
167
|
|
|
foreach ($this->inheritors as $inheritor) { |
|
|
|
|
168
|
|
|
if ($inheritor instanceof self) { |
169
|
|
|
$templateInheritors[] = $inheritor; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
return $templateInheritors; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @Assert\Callback(groups={"victoire"}) |
178
|
|
|
* |
179
|
|
|
* @param ExecutionContextInterface $context |
180
|
|
|
*/ |
181
|
|
|
public function validate(ExecutionContextInterface $context) |
182
|
|
|
{ |
183
|
|
|
$template = $this; |
184
|
|
|
while ($template != null) { |
185
|
|
|
if ($template->getLayout() != null) { |
186
|
|
|
return; |
187
|
|
|
} |
188
|
|
|
$template = $template->getTemplate(); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
if ($this->getLayout() == null) { |
192
|
|
|
$context->buildViolation('data.template.templateform.view.type.template.layout.validator_message')->addViolation(); |
193
|
|
|
} |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..