1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2015 Giant.cz <[email protected]> |
5
|
|
|
* @author Pavel Janda <[email protected]> |
6
|
|
|
* @package Giant |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Ublaboo\DataGrid\Column; |
10
|
|
|
|
11
|
|
|
use Nette\Utils\Html; |
12
|
|
|
use Ublaboo\DataGrid\DataGrid; |
13
|
|
|
use Ublaboo\DataGrid\Row; |
14
|
|
|
use Ublaboo\DataGrid\Exception\DataGridHasToBeAttachedToPresenterComponentException; |
15
|
|
|
use Ublaboo\DataGrid\Exception\DataGridColumnRendererException; |
16
|
|
|
|
17
|
|
|
class ColumnLink extends Column |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $title; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $class; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $params; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $href; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $icon; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected $data_attributes = []; |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param DataGrid $grid |
53
|
|
|
* @param string $key |
54
|
|
|
* @param string $column |
55
|
|
|
* @param string $name |
56
|
|
|
* @param string $href |
57
|
|
|
* @param array $params |
58
|
|
|
*/ |
59
|
|
|
public function __construct(DataGrid $grid, $key, $column, $name, $href, $params) |
60
|
|
|
{ |
61
|
|
|
parent::__construct($grid, $key, $column, $name); |
62
|
|
|
|
63
|
|
|
$this->href = $href; |
64
|
|
|
$this->params = $params; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Render row item into template |
70
|
|
|
* @param Row $row |
71
|
|
|
* @return mixed |
72
|
|
|
*/ |
73
|
|
|
public function render(Row $row) |
74
|
|
|
{ |
75
|
|
|
/** |
76
|
|
|
* Renderer function may be used |
77
|
|
|
*/ |
78
|
|
|
try { |
79
|
|
|
return $this->useRenderer($row); |
80
|
|
|
} catch (DataGridColumnRendererException $e) { |
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Do not use renderer |
83
|
|
|
*/ |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$value = parent::render($row); |
87
|
|
|
|
88
|
|
|
$a = Html::el('a') |
89
|
|
|
->href($this->createLink($this->href, $this->getItemParams($row, $this->params))) |
90
|
|
|
->setText($value); |
91
|
|
|
|
92
|
|
|
if ($this->title) { $a->title($this->title); } |
93
|
|
|
if ($this->class) { $a->class($this->class); } |
94
|
|
|
$element = $a; |
|
|
|
|
95
|
|
|
|
96
|
|
|
if($this->icon != NULL) { |
97
|
|
|
$emptyEl = Html::el('span'); |
98
|
|
|
|
99
|
|
|
$span = Html::el('span')->addAttributes(array("class" => $this->icon)); |
100
|
|
|
$span->setHtml(" "); |
101
|
|
|
|
102
|
|
|
$emptyEl->add($span); |
103
|
|
|
$emptyEl->add($a); |
104
|
|
|
|
105
|
|
|
$element = $emptyEl; |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return $a; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Set icon before simple link |
114
|
|
|
* @param string $class |
115
|
|
|
* @return ColumnLink |
116
|
|
|
*/ |
117
|
|
|
public function setIcon($class = NULL) |
118
|
|
|
{ |
119
|
|
|
$this->icon = $class; |
120
|
|
|
|
121
|
|
|
return $this; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Setting data attributes |
127
|
|
|
* @param string $key |
128
|
|
|
* @param mixed $value |
129
|
|
|
* @return static |
130
|
|
|
*/ |
131
|
|
|
public function setDataAttribute($key, $value) |
132
|
|
|
{ |
133
|
|
|
$this->data_attributes[$key] = $value; |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Set attribute title |
141
|
|
|
* @param string $title |
142
|
|
|
*/ |
143
|
|
|
public function setTitle($title) |
144
|
|
|
{ |
145
|
|
|
$this->title = $title; |
146
|
|
|
|
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Get attribute title |
153
|
|
|
*/ |
154
|
|
|
public function getTitle() |
155
|
|
|
{ |
156
|
|
|
return $this->title; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Set attribute class |
162
|
|
|
* @param string $class |
163
|
|
|
*/ |
164
|
|
|
public function setClass($class) |
165
|
|
|
{ |
166
|
|
|
$this->class = $class; |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Get attribute class |
174
|
|
|
*/ |
175
|
|
|
public function getClass() |
176
|
|
|
{ |
177
|
|
|
return $this->class; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
} |
181
|
|
|
|