blob: c3b44f36f0503f6a037778bff3928bb7bed399b9 (
plain)
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
|
<?php
namespace Icinga\Module\Director\Web\Table;
use Icinga\Module\Director\PlainObjectRenderer;
use Icinga\Module\Director\Web\Form\QuickForm;
use Zend_Form_Element as ZfElement;
use Zend_Form_DisplayGroup as ZfDisplayGroup;
class ReadOnlyFormAvpTable
{
protected $form;
public function __construct(QuickForm $form)
{
$this->form = $form;
}
protected function renderDisplayGroups(QuickForm $form)
{
$html = '';
foreach ($form->getDisplayGroups() as $group) {
$elements = $this->filterGroupElements($group);
if (empty($elements)) {
continue;
}
$html .= '<tr><th colspan="2" style="text-align: right">' . $group->getLegend() . '</th></tr>';
$html .= $this->renderElements($elements);
}
return $html;
}
/**
* @param ZfDisplayGroup $group
* @return ZfElement[]
*/
protected function filterGroupElements(ZfDisplayGroup $group)
{
$blacklist = array('disabled', 'assign_filter');
$elements = array();
/** @var ZfElement $element */
foreach ($group->getElements() as $element) {
if ($element->getValue() === null) {
continue;
}
if ($element->getType() === 'Zend_Form_Element_Hidden') {
continue;
}
if (in_array($element->getName(), $blacklist)) {
continue;
}
$elements[] = $element;
}
return $elements;
}
protected function renderElements($elements)
{
$html = '';
foreach ($elements as $element) {
$html .= $this->renderElement($element);
}
return $html;
}
/**
* @param ZfElement $element
*
* @return string
*/
protected function renderElement(ZfElement $element)
{
$value = $element->getValue();
return '<tr><th>'
. $this->escape($element->getLabel())
. '</th><td>'
. $this->renderValue($value)
. '</td></tr>';
}
protected function renderValue($value)
{
if (is_string($value)) {
return $this->escape($value);
} elseif (is_array($value)) {
return $this->escape(implode(', ', $value));
}
return $this->escape(PlainObjectRenderer::render($value));
}
protected function escape($string)
{
return htmlspecialchars($string);
}
public function render()
{
$this->form->initializeForObject();
return '<table class="name-value-table">' . "\n"
. $this->renderDisplayGroups($this->form)
. '</table>';
}
}
|