/
key_selector.php
84 lines (71 loc) · 2.05 KB
/
key_selector.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
<?php
namespace Concrete\Controller\Element\Attribute\Component;
use Concrete\Core\Attribute\Category\CategoryInterface;
use Concrete\Core\Attribute\Key\Component\KeySelector\ObjectSerializer;
use Concrete\Core\Attribute\Key\Component\KeySelector\ObjectsSerializer;
use Concrete\Core\Attribute\Key\Component\KeySelector\SetSerializer;
use Concrete\Core\Attribute\ObjectInterface;
use Concrete\Core\Controller\ElementController;
class KeySelector extends ElementController
{
/**
* @var string
*/
protected $selectAttributeUrl;
/**
* @var CategoryInterface
*/
protected $category;
/**
* @var ObjectInterface[]
*/
protected $objects = [];
public function __construct(CategoryInterface $category)
{
$this->category = $category;
}
public function getElement()
{
return 'attribute/component/key_selector';
}
/**
* @return mixed
*/
public function getSelectAttributeUrl()
{
return $this->selectAttributeUrl;
}
/**
* @param mixed $selectAttributeUrl
*/
public function setSelectAttributeUrl($selectAttributeUrl): void
{
$this->selectAttributeUrl = $selectAttributeUrl;
}
/**
* @return ObjectInterface[]
*/
public function getObjects(): array
{
return $this->objects;
}
/**
* @param ObjectInterface[] $objects
*/
public function setObjects(array $objects): void
{
$this->objects = $objects;
}
public function view()
{
$serializer = new SetSerializer($this->category->getSetManager());
$this->set('selectAttributeUrl', $this->selectAttributeUrl);
$this->set('attributes', json_encode($serializer));
$this->set('isBulkMode', json_encode(count($this->objects) > 1));
$this->set('selectedAttributes', json_encode(
count($this->objects) === 1
? new ObjectSerializer($this->category, head($this->objects))
: new ObjectsSerializer($this->category, $this->objects)
));
}
}