|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Rik van der Kemp <[email protected]> |
|
4
|
|
|
* @copyright Zicht Online <http://zicht.nl> |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace Zicht\Bundle\UrlBundle\Entity; |
|
8
|
|
|
|
|
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* StaticReference |
|
14
|
|
|
* |
|
15
|
|
|
* @ORM\Table(name="static_reference") |
|
16
|
|
|
* @ORM\Entity(repositoryClass="Zicht\Bundle\UrlBundle\Entity\Repository\StaticReferenceRepository") |
|
17
|
|
|
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") |
|
18
|
|
|
*/ |
|
19
|
|
|
class StaticReference |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var integer |
|
23
|
|
|
* |
|
24
|
|
|
* @ORM\Column(name="id", type="integer") |
|
25
|
|
|
* @ORM\Id |
|
26
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
27
|
|
|
*/ |
|
28
|
|
|
private $id; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
* |
|
33
|
|
|
* @ORM\Column(name="machine_name", type="string", length=255) |
|
34
|
|
|
*/ |
|
35
|
|
|
private $machine_name; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var StaticReferenceTranslation[] |
|
39
|
|
|
* @ORM\OneToMany( |
|
40
|
|
|
* targetEntity="Zicht\Bundle\UrlBundle\Entity\StaticReferenceTranslation", |
|
41
|
|
|
* mappedBy="static_reference", |
|
42
|
|
|
* cascade={"persist", "remove"}, |
|
43
|
|
|
* orphanRemoval=true |
|
44
|
|
|
* ) |
|
45
|
|
|
*/ |
|
46
|
|
|
public $translations; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Default construction of entity |
|
50
|
|
|
* |
|
51
|
|
|
* @param string $machineName |
|
52
|
|
|
* @param array $translations |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function __construct($machineName = null, $translations = null) |
|
55
|
|
|
{ |
|
56
|
3 |
|
$this->translations = new ArrayCollection(); |
|
|
|
|
|
|
57
|
3 |
|
if (null !== $machineName) { |
|
58
|
1 |
|
$this->setMachineName($machineName); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
3 |
|
if (null !== $translations) { |
|
62
|
1 |
|
foreach ($translations as $language => $url) { |
|
63
|
1 |
|
$this->addTranslations(new StaticReferenceTranslation($language, $url)); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
3 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Get id |
|
70
|
|
|
* |
|
71
|
|
|
* @return integer |
|
72
|
|
|
*/ |
|
73
|
|
|
public function getId() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->id; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Set machine_name |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $machineName |
|
82
|
|
|
* |
|
83
|
|
|
* @return StaticReference |
|
84
|
|
|
*/ |
|
85
|
2 |
|
public function setMachineName($machineName) |
|
86
|
|
|
{ |
|
87
|
2 |
|
$this->machine_name = $machineName; |
|
88
|
|
|
|
|
89
|
2 |
|
return $this; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* Get machine_name |
|
94
|
|
|
* |
|
95
|
|
|
* @return string |
|
96
|
|
|
*/ |
|
97
|
2 |
|
public function getMachineName() |
|
98
|
|
|
{ |
|
99
|
2 |
|
return $this->machine_name; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param string $locale |
|
104
|
|
|
* |
|
105
|
|
|
* @return bool |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function getTranslation($locale) |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->hasTranslation($locale); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Setter for translations |
|
114
|
|
|
* |
|
115
|
|
|
* @param mixed $translations |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
|
|
public function setTranslations($translations) |
|
119
|
|
|
{ |
|
120
|
|
|
$this->translations = $translations; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return string |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function __toString() |
|
127
|
|
|
{ |
|
128
|
1 |
|
if (!empty($this->machine_name)) { |
|
129
|
1 |
|
return $this->machine_name; |
|
130
|
|
|
} else { |
|
131
|
1 |
|
return (string)$this->id; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Checks if a translation is set for the given locale |
|
137
|
|
|
* |
|
138
|
|
|
* @param string $locale |
|
139
|
|
|
* @return bool |
|
140
|
|
|
*/ |
|
141
|
1 |
|
public function hasTranslation($locale) |
|
142
|
|
|
{ |
|
143
|
1 |
|
foreach ($this->translations as $translation) { |
|
144
|
1 |
|
if ($locale == $translation->getLocale()) { |
|
145
|
1 |
|
return $translation; |
|
|
|
|
|
|
146
|
|
|
} |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
1 |
|
return false; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return mixed |
|
154
|
|
|
*/ |
|
155
|
2 |
|
public function getTranslations() |
|
156
|
|
|
{ |
|
157
|
2 |
|
return $this->translations; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Set translations that are not yet initialized |
|
162
|
|
|
* |
|
163
|
|
|
* @return void |
|
164
|
|
|
*/ |
|
165
|
|
|
public function addMissingTranslations() |
|
166
|
|
|
{ |
|
167
|
|
|
foreach ($this->translations as $translation) { |
|
168
|
|
|
$translation->setStaticReference($this); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Add a translation |
|
174
|
|
|
* |
|
175
|
|
|
* @param StaticReferenceTranslation $translation |
|
176
|
|
|
* @return void |
|
177
|
|
|
*/ |
|
178
|
2 |
|
public function addTranslations(StaticReferenceTranslation $translation) |
|
179
|
|
|
{ |
|
180
|
2 |
|
$translation->setStaticReference($this); |
|
181
|
|
|
|
|
182
|
2 |
|
$this->translations[] = $translation; |
|
183
|
2 |
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|
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..