1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.newicon.net/neon |
4
|
|
|
* @copyright Copyright (c) 2016 Newicon Ltd |
5
|
|
|
* @license http://www.newicon.net/neon/license |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace neon\core\form\fields; |
9
|
|
|
|
10
|
|
|
use neon\core\grid\query\IQuery; |
11
|
|
|
use neon\core\helpers\Arr; |
12
|
|
|
use \neon\core\helpers\Html; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Multichoice |
16
|
|
|
* Allow a user to select multiple options from a fixed choice list |
17
|
|
|
* |
18
|
|
|
* @package neon\core\form |
19
|
|
|
*/ |
20
|
|
|
class ChoiceMultiple extends Choice |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @inheritdoc |
24
|
|
|
*/ |
25
|
|
|
public $ddsDataType = 'choice_multiple'; |
26
|
|
|
|
27
|
|
|
protected $_value = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @inheritDoc |
31
|
|
|
*/ |
32
|
|
|
public function getValueDisplay($context='') |
33
|
|
|
{ |
34
|
|
|
$items = $this->getSelectedItems(); |
35
|
|
|
return implode(',', $items); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @inheritdoc |
40
|
|
|
*/ |
41
|
|
|
public function setValueFromDb($value) |
42
|
|
|
{ |
43
|
|
|
$items = []; |
44
|
|
|
foreach ($value as $item) |
45
|
|
|
$items[] = $item['key']; |
46
|
|
|
return parent::setValueFromDb($items); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Get the items that have been selected (as opposed to the total set of |
51
|
|
|
* available items) |
52
|
|
|
* |
53
|
|
|
* @return array [ 'key' => 'value' ] |
54
|
|
|
*/ |
55
|
|
|
public function getSelectedItems() |
56
|
|
|
{ |
57
|
|
|
$values = $this->getValue(); |
58
|
|
|
if (!is_array($values)) |
59
|
|
|
$values = [$values]; |
60
|
|
|
if ($this->create === false) |
61
|
|
|
return Arr::only($this->getItems(), $values); |
62
|
|
|
return $values; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @inheritdoc |
67
|
|
|
*/ |
68
|
|
|
public function getFilterField() |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
'class' => 'neon\core\form\fields\SelectMultiple', |
72
|
|
|
'multiple' => true, |
73
|
|
|
'items' => $this->getItems() |
74
|
|
|
]; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritdoc |
79
|
|
|
*/ |
80
|
|
|
public function processAsFilter(IQuery $query, $searchData=null) |
81
|
|
|
{ |
82
|
|
|
if (isset($searchData[0])) { |
83
|
|
|
$keys = explode(',', $searchData[0]); |
84
|
|
|
foreach($keys as $key) { |
85
|
|
|
if (!empty($key) && $key !== 'null') { |
86
|
|
|
$query->where($this->getDataKey(), 'like', $key); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @inheritdoc |
94
|
|
|
*/ |
95
|
|
|
public function getComponentDetails() |
96
|
|
|
{ |
97
|
|
|
return [ |
98
|
|
|
'label' => 'Multichoice (Abstract)', 'group' => 'Do Not Use', 'icon' => 'fa fa-list', 'order' => 1500, |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|