/
Key.php
333 lines (285 loc) · 7.23 KB
/
Key.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<?php
namespace Concrete\Core\Entity\Attribute\Key;
use Concrete\Core\Attribute\AttributeKeyInterface;
use Concrete\Core\Attribute\View;
use Concrete\Core\Form\Context\ContextInterface;
use Concrete\Core\Attribute\Key\SearchIndexer\StandardSearchIndexer;
use Concrete\Core\Attribute\Type;
use Concrete\Core\Entity\Attribute\Category;
use Concrete\Core\Entity\Attribute\Set;
use Concrete\Core\Entity\PackageTrait;
use Concrete\Core\Export\ExportableInterface;
use Concrete\Core\Export\Item\AttributeKey;
use Concrete\Core\Form\Control\ControlInterface;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="akCategory", type="string")
* @ORM\EntityListeners({"\Concrete\Core\Attribute\Key\Listener"})
* @ORM\Table(
* name="AttributeKeys",
* indexes={
* @ORM\Index(name="pkgID", columns={"pkgID"})
* }
* )
*/
class Key implements AttributeKeyInterface, ExportableInterface, ControlInterface
{
use PackageTrait;
protected $settings;
/**
* @ORM\Id @ORM\Column(type="integer", options={"unsigned":true})
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $akID;
/**
* @ORM\Column(type="string")
*/
protected $akHandle;
/**
* @ORM\Column(type="string")
*/
protected $akName;
/**
* @ORM\Column(type="boolean")
*/
protected $akIsSearchable = true;
/**
* @ORM\Column(type="boolean")
*/
protected $akIsInternal = false;
/**
* @ORM\Column(type="boolean")
*/
protected $akIsSearchableIndexed = false;
/**
* @ORM\OneToMany(targetEntity="\Concrete\Core\Entity\Attribute\SetKey", mappedBy="attribute_key", cascade={"remove"}),
* @ORM\JoinColumn(name="akID", referencedColumnName="akID")
*/
protected $set_keys;
/**
* @var \Concrete\Core\Entity\Attribute\Type
* @ORM\ManyToOne(targetEntity="\Concrete\Core\Entity\Attribute\Type"),
* @ORM\JoinColumn(name="atID", referencedColumnName="atID")
*/
protected $type;
/**
* @ORM\ManyToOne(targetEntity="\Concrete\Core\Entity\Attribute\Category", inversedBy="keys")
* @ORM\JoinColumn(name="akCategoryID", referencedColumnName="akCategoryID")
**/
protected $category;
public function setAttributeKeyID($akID)
{
$this->akID = $akID;
}
/**
* @return mixed
*/
public function getAttributeKeyID()
{
return $this->akID;
}
/**
* @return mixed
*/
public function getAttributeKeyHandle()
{
return $this->akHandle;
}
/**
* @param mixed $handle
*/
public function setAttributeKeyHandle($akHandle)
{
$this->akHandle = $akHandle;
}
/**
* @return mixed
*/
public function isAttributeKeyInternal()
{
return $this->akIsInternal;
}
/**
* @param mixed $is_internal
*/
public function setIsAttributeKeyInternal($akIsInternal)
{
$this->akIsInternal = $akIsInternal;
}
/**
* @return mixed
*/
public function getAttributeKeyName()
{
return $this->akName;
}
/**
* @param mixed $name
*/
public function setAttributeKeyName($akName)
{
$this->akName = $akName;
}
/**
* @return mixed
*/
public function isAttributeKeySearchable()
{
return $this->akIsSearchable;
}
/**
* @param mixed $is_searchable
*/
public function setIsAttributeKeySearchable($akIsSearchable)
{
$this->akIsSearchable = $akIsSearchable;
}
/**
* @return mixed
*/
public function isAttributeKeyContentIndexed()
{
return $this->akIsSearchableIndexed;
}
/**
* @param mixed $is_indexed
*/
public function setIsAttributeKeyContentIndexed($akIsSearchableIndexed)
{
$this->akIsSearchableIndexed = $akIsSearchableIndexed;
}
/**
* @return mixed
*/
public function getAttributeKeySettings()
{
if (isset($this->settings)) {
return $this->settings;
}
return $this->getController()->getAttributeKeySettings();
}
/**
* @param mixed $type
*/
public function setAttributeKeySettings($settings)
{
$this->settings = $settings; // This allows us to pass it around more easily
}
/**
* @param \Concrete\Core\Entity\Attribute\Type $type
*/
public function setAttributeType($type)
{
$this->type = $type;
}
public function getAttributeType()
{
return $this->type;
}
public function getAttributeTypeHandle()
{
return $this->type->getAttributeTypeHandle();
}
public function getController()
{
$controller = $this->type->getController();
$controller->setAttributeKey($this);
return $controller;
}
public function getAttributeKeyCategoryHandle()
{
return false;
}
public function getAttributeCategoryEntity()
{
return $this->category;
}
public function getAttributeCategory()
{
$manager = \Core::make('manager/attribute/category');
$category = $manager->driver($this->getAttributeKeyCategoryHandle());
if (is_object($this->category)) {
$category->setCategoryEntity($this->category);
}
return $category;
}
/**
* @param mixed $category
*/
public function setAttributeCategoryEntity($category)
{
$this->category = $category;
}
public function getExporter()
{
return new AttributeKey();
}
public function getControlView(ContextInterface $context)
{
return $this->getController()->getControlView($context);
}
/**
* @deprecated
*/
public function render($view = 'view', $value = false, $return = false)
{
$resp = $this->getAttributeType()->render($view, $this, $value, $return);
if ($return) {
return $resp;
} else {
echo $resp;
}
}
public function getAttributeKeyDisplayName($format = 'html')
{
$value = tc('AttributeKeyName', $this->getAttributeKeyName());
switch ($format) {
case 'html':
return h($value);
case 'text':
default:
return $value;
}
}
public function getAttributeSets()
{
return \Concrete\Core\Attribute\Set::getByAttributeKey($this);
}
public function inAttributeSet(Set $set)
{
$sets = $this->getAttributeSets();
return in_array($set, $sets);
}
public function getSearchIndexer()
{
return \Core::make('Concrete\Core\Attribute\Key\SearchIndexer\StandardSearchIndexer');
}
/**
* Doctrine requires this for certain queries.
*
* @return mixed
*/
public function __toString()
{
return (string) $this->getAttributeKeyID();
}
/**
* @deprecated
*/
public function setAttributeSet($set)
{
if (!is_object($set)) {
$set = Set::getByHandle($set);
}
$set->addKey($this);
}
/**
* @deprecated
*/
public function getAttributeValueIDList()
{
return array();
}
}