1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace mQueue\Form; |
4
|
|
|
|
5
|
|
|
use mQueue\Model\Status; |
6
|
|
|
use mQueue\Model\UserMapper; |
7
|
|
|
use Zend_Form_SubForm; |
8
|
|
|
|
9
|
|
|
class Filter extends Zend_Form_SubForm |
10
|
|
|
{ |
11
|
1 |
|
public function init(): void |
12
|
|
|
{ |
13
|
|
|
// Set the method for the display form to GET |
14
|
1 |
|
$this->setMethod('get'); |
15
|
|
|
|
16
|
1 |
|
$users = []; |
17
|
1 |
|
if (\mQueue\Model\User::getCurrent()) { |
18
|
|
|
$users = [0 => _tr('<< me >>')]; |
19
|
|
|
} |
20
|
|
|
|
21
|
1 |
|
foreach (UserMapper::fetchAll() as $user) { |
22
|
1 |
|
$users[$user->id] = $user->nickname; |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
1 |
|
$this->addElement('select', 'user', [ |
26
|
1 |
|
'multiOptions' => $users, |
27
|
|
|
'required' => true, |
28
|
1 |
|
'class' => 'filterUser', |
29
|
|
|
'validators' => [ |
30
|
1 |
|
['validator' => new Validate\User()], |
31
|
|
|
], |
32
|
|
|
'filters' => [ |
33
|
|
|
['int'], |
34
|
|
|
], |
35
|
|
|
]); |
36
|
|
|
|
37
|
1 |
|
$this->addElement('select', 'condition', [ |
38
|
1 |
|
'multiOptions' => ['is' => _tr('rating is'), 'isnot' => _tr('rating is not')], |
39
|
|
|
'required' => true, |
40
|
|
|
]); |
41
|
|
|
|
42
|
1 |
|
$statuses = []; |
43
|
1 |
|
foreach (Status::$ratings as $rating => $label) { |
44
|
1 |
|
$statuses[$rating] = $this->getView()->rating($rating); |
45
|
|
|
} |
46
|
1 |
|
$statuses = $statuses + [0 => _tr('nothing')]; |
47
|
|
|
|
48
|
1 |
|
$this->addElement('multiCheckbox', 'status', [ |
49
|
1 |
|
'escape' => false, |
50
|
1 |
|
'multiOptions' => $statuses, |
51
|
|
|
'required' => true, |
52
|
1 |
|
'separator' => ' ', |
53
|
|
|
'filters' => [ |
54
|
|
|
['int'], |
55
|
|
|
], |
56
|
|
|
]); |
57
|
1 |
|
$this->status->getDecorator('HtmlTag')->setOption('class', 'filterStatus'); |
|
|
|
|
58
|
|
|
|
59
|
|
|
// Add the title element |
60
|
1 |
|
$this->addElement('text', 'title', [ |
61
|
1 |
|
'placeholder' => _tr('title'), |
62
|
|
|
'autofocus' => true, |
63
|
|
|
'filters' => [ |
64
|
|
|
['stringTrim'], |
65
|
|
|
], |
66
|
|
|
]); |
67
|
|
|
|
68
|
|
|
// Add the filter element |
69
|
1 |
|
$this->addElement('checkbox', 'withSource', [ |
70
|
1 |
|
'label' => _tr('With source'), |
71
|
|
|
]); |
72
|
1 |
|
$this->withSource->getDecorator('Label')->setOptions(['placement' => 'append']); |
|
|
|
|
73
|
|
|
|
74
|
1 |
|
$this->setDecorators([ |
75
|
1 |
|
'FormElements', |
76
|
|
|
[['row' => 'HtmlTag'], ['tag' => 'dl', 'class' => 'filter']], |
77
|
|
|
]); |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Disable extra field elements |
82
|
|
|
*/ |
83
|
|
|
public function disableExtraFields(): void |
84
|
|
|
{ |
85
|
|
|
$this->removeElement('title'); |
86
|
|
|
$this->removeElement('withSource'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Override getValues() to replace special '0' value with current user |
91
|
|
|
* |
92
|
|
|
* @param bool $suppressArrayNotation |
93
|
|
|
* |
94
|
|
|
* @return array values |
95
|
|
|
*/ |
96
|
1 |
|
public function getValues($suppressArrayNotation = false) |
97
|
|
|
{ |
98
|
1 |
|
$values = parent::getValues($suppressArrayNotation); |
99
|
|
|
|
100
|
1 |
|
if ($values['user'] == '0') { |
101
|
|
|
$values['user'] = \mQueue\Model\User::getCurrent()->id; |
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
1 |
|
return $values; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Returns values as readable text for end-user |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
1 |
|
public function getValuesText() |
113
|
|
|
{ |
114
|
1 |
|
$text = ''; |
115
|
1 |
|
$values = $this->getValues(true); |
116
|
|
|
|
117
|
1 |
|
if (@$values['title']) { |
118
|
|
|
$text = _tr('title') . ':"' . $values['title'] . '" + '; |
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
$users = $this->getElement('user')->getMultiOptions(); |
122
|
1 |
|
$statuses = $this->getElement('status')->getMultiOptions(); |
123
|
|
|
|
124
|
1 |
|
$statusLabels = []; |
125
|
1 |
|
foreach ($values['status'] as $status) { |
126
|
1 |
|
$statusLabels[] = Status::$ratings[$status] ?? $statuses[$status]; |
127
|
|
|
} |
128
|
1 |
|
$text .= $users[$values['user']] . ':' . implode('+', $statusLabels); |
129
|
|
|
|
130
|
1 |
|
return $text; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|