Completed
Push — master ( 91ef18...a6f36a )
by Pavel
03:04
created

ItemDetail::renderButton()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
f 1
dl 0
loc 16
rs 9.4285
cc 3
eloc 10
nc 4
nop 1
1
<?php
2
3
/**
4
 * @copyright   Copyright (c) 2015 ublaboo <[email protected]>
5
 * @author      Pavel Janda <[email protected]>
6
 * @package     Ublaboo
7
 */
8
9
namespace Ublaboo\DataGrid\Column;
10
11
use Nette\Utils\Html;
12
use Ublaboo\DataGrid\DataGrid;
13
use Ublaboo;
14
use Ublaboo\DataGrid\Traits;
15
16
class ItemDetail extends Ublaboo\DataGrid\Object
17
{
18
19
	use Traits\ButtonIconTrait;
20
21
	/**
22
	 * (renderer | template | block)
23
	 * @var string
24
	 */
25
	protected $type;
26
27
	/**
28
	 * @var string
29
	 */
30
	protected $template;
31
32
	/**
33
	 * @var callable
34
	 */
35
	protected $renderer;
36
37
	/**
38
	 * @var string
39
	 */
40
	protected $title;
41
42
	/**
43
	 * @var string
44
	 */
45
	protected $class = 'btn btn-xs btn-default ajax';
46
47
	/**
48
	 * @var string
49
	 */
50
	protected $icon = 'eye';
51
52
	/**
53
	 * @var string
54
	 */
55
	protected $text = '';
56
57
	/**
58
	 * @var DataGrid
59
	 */
60
	protected $grid;
61
62
	/**
63
	 * @var string
64
	 */
65
	protected $primary_where_column;
66
67
68
	/**
69
	 * @param DataGrid $grid
70
	 * @param string   $primary_where_column
71
	 */
72
	public function __construct(DataGrid $grid, $primary_where_column)
73
	{
74
		$this->grid = $grid;
75
		$this->primary_where_column = $primary_where_column;
76
	}
77
78
79
	/**
80
	 * Render row item detail button
81
	 * @param  Row $row
82
	 * @return Html
83
	 */
84
	public function renderButton($row)
85
	{
86
		$a = Html::el('a')
87
			->href($this->grid->link('getItemDetail!', ['id' => $row->getId()]))
88
			->data('toggle-detail', $row->getId())
89
			->data('toggle-detail-grid', $this->grid->getName());
90
91
		$this->tryAddIcon($a, $this->getIcon(), $this->getText());
92
93
		$a->add($this->text);
94
95
		if ($this->title) { $a->title($this->title); }
96
		if ($this->class) { $a->class($this->class); }
97
98
		return $a;
99
	}
100
101
102
	/**
103
	 * Render item detail
104
	 * @param  mixed $item
105
	 * @return mixed
106
	 */
107
	public function render($item)
108
	{
109
		return call_user_func($this->getRenderer(), $item);
110
	}
111
112
113
	/**
114
	 * Get primary column for where clause
115
	 * @return string
116
	 */
117
	public function getPrimaryWhereColumn()
118
	{
119
		return $this->primary_where_column;
120
	}
121
122
123
	/**
124
	 * Set attribute title
125
	 * @param string $title
126
	 */
127
	public function setTitle($title)
128
	{
129
		$this->title = $title;
130
131
		return $this;
132
	}
133
134
135
	/**
136
	 * Get attribute title
137
	 * @return string
138
	 */
139
	public function getTitle()
140
	{
141
		return $this->title;
142
	}
143
144
145
	/**
146
	 * Set attribute class
147
	 * @param string $class
148
	 */
149
	public function setClass($class)
150
	{
151
		$this->class = $class;
152
153
		return $this;
154
	}
155
156
157
	/**
158
	 * Get attribute class
159
	 * @return string
160
	 */
161
	public function getClass()
162
	{
163
		return $this->class;
164
	}
165
166
167
	/**
168
	 * Set icon
169
	 * @param string $icon
170
	 */
171
	public function setIcon($icon)
172
	{
173
		$this->icon = $icon;
174
175
		return $this;
176
	}
177
178
179
	/**
180
	 * Get icon
181
	 * @return string
182
	 */
183
	public function getIcon()
184
	{
185
		return $this->icon;
186
	}
187
188
189
	/**
190
	 * Set text
191
	 * @param string $text
192
	 */
193
	public function setText($text)
194
	{
195
		$this->text = $text;
196
197
		return $this;
198
	}
199
200
201
	/**
202
	 * Get text
203
	 * @return string
204
	 */
205
	public function getText()
206
	{
207
		return $this->text;
208
	}
209
210
211
	/**
212
	 * Set item detail type
213
	 * @param string $type
214
	 */
215
	public function setType($type)
216
	{
217
		$this->type = (string) $type;
218
219
		return $this;
220
	}
221
222
223
	/**
224
	 * Get item detail type
225
	 * @return string
226
	 */
227
	public function getType()
228
	{
229
		return $this->type;
230
	}
231
232
233
	/**
234
	 * Set item detail template
235
	 * @param string $template
236
	 */
237
	public function setTemplate($template)
238
	{
239
		$this->template = (string) $template;
240
241
		return $this;
242
	}
243
244
245
	/**
246
	 * Get item detail template
247
	 * @return string
248
	 */
249
	public function getTemplate()
250
	{
251
		return $this->template;
252
	}
253
254
255
	/**
256
	 * Set item detail renderer
257
	 * @param callable $renderer
258
	 */
259
	public function setRenderer($renderer)
260
	{
261
		$this->renderer = $renderer;
262
263
		return $this;
264
	}
265
266
267
	/**
268
	 * Get item detail renderer
269
	 * @return callable
270
	 */
271
	public function getRenderer()
272
	{
273
		return $this->renderer;
274
	}
275
276
}
277