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
|
<?php
namespace Icinga\Module\Director\Web\Table;
use Error;
use Exception;
use Icinga\Module\Director\Hook\ImportSourceHook;
use Icinga\Module\Director\Objects\ImportSource;
use gipfl\IcingaWeb2\Link;
use gipfl\IcingaWeb2\Table\Extension\ZfSortablePriority;
use gipfl\IcingaWeb2\Table\ZfQueryBasedTable;
use gipfl\IcingaWeb2\Url;
class PropertymodifierTable extends ZfQueryBasedTable
{
use ZfSortablePriority;
protected $searchColumns = [
'property_name',
'target_property',
];
/** @var ImportSource */
protected $source;
/** @var Url */
protected $url;
protected $keyColumn = 'id';
protected $priorityColumn = 'priority';
protected $readOnly = false;
public static function load(ImportSource $source, Url $url)
{
$table = new static($source->getConnection());
$table->source = $source;
$table->url = $url;
return $table;
}
public function setReadOnly($readOnly = true)
{
$this->readOnly = $readOnly;
return $this;
}
public function render()
{
if ($this->readOnly) {
return parent::render();
}
return $this->renderWithSortableForm();
}
protected function assemble()
{
$this->getAttributes()->set('data-base-target', '_self');
}
public function getColumns()
{
return array(
'id' => 'm.id',
'source_id' => 'm.source_id',
'property_name' => 'm.property_name',
'target_property' => 'm.target_property',
'description' => 'm.description',
'provider_class' => 'm.provider_class',
'priority' => 'm.priority',
);
}
public function renderRow($row)
{
$caption = $row->property_name;
if ($row->target_property !== null) {
$caption .= ' -> ' . $row->target_property;
}
if ($row->description === null) {
$class = $row->provider_class;
try {
/** @var ImportSourceHook $hook */
$hook = new $class;
$caption .= ': ' . $hook->getName();
} catch (Exception $e) {
$caption = $this->createErrorCaption($caption, $e);
} catch (Error $e) {
$caption = $this->createErrorCaption($caption, $e);
}
} else {
$caption .= ': ' . $row->description;
}
$renderedRow = $this::row([
Link::create($caption, 'director/importsource/editmodifier', [
'id' => $row->id,
'source_id' => $row->source_id,
]),
]);
if ($this->readOnly) {
return $renderedRow;
}
return $this->addSortPriorityButtons(
$renderedRow,
$row
);
}
/**
* @param $caption
* @param Exception|Error $e
* @return array
*/
protected function createErrorCaption($caption, $e)
{
return [
$caption,
': ',
$this::tag('span', ['class' => 'error'], $e->getMessage())
];
}
public function getColumnsToBeRendered()
{
if ($this->readOnly) {
return [$this->translate('Property')];
}
return [
$this->translate('Property'),
$this->getSortPriorityTitle()
];
}
public function prepareQuery()
{
return $this->db()->select()->from(
['m' => 'import_row_modifier'],
$this->getColumns()
)->where('m.source_id = ?', $this->source->get('id'))
->order('priority');
}
}
|