Completed
Push — master ( 5a2949...79e283 )
by Pavel
02:44
created

ColumnLink::render()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 24
rs 8.6845
cc 4
eloc 11
nc 5
nop 1
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
	/**
42
	 * @param DataGrid $grid
43
	 * @param string $key
44
	 * @param string $column
45
	 * @param string $name
46
	 * @param string $href
47
	 * @param array  $params
48
	 */
49
	public function __construct(DataGrid $grid, $key, $column, $name, $href, $params)
50
	{
51
		parent::__construct($grid, $key, $column, $name);
52
53
		$this->href   = $href;
54
		$this->params = $params;
55
	}
56
57
58
	/**
59
	 * Render row item into template
60
	 * @param  Row   $row
61
	 * @return mixed
62
	 */
63
	public function render(Row $row)
64
	{
65
		/**
66
		 * Renderer function may be used
67
		 */
68
		try {
69
			return $this->useRenderer($row);
70
		} catch (DataGridColumnRendererException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
71
			/**
72
			 * Do not use renderer
73
			 */
74
		}
75
76
		$value = parent::render($row);
77
78
		$a = Html::el('a')
79
			->href($this->createLink($this->href, $this->getItemParams($row, $this->params)))
80
			->setText($value);
81
82
		if ($this->title) { $a->title($this->title); }
83
		if ($this->class) { $a->class($this->class); }
84
85
		return $a;
86
	}
87
88
89
	/**
90
	 * Set attribute title
91
	 * @param string $title
92
	 */
93
	public function setTitle($title)
94
	{
95
		$this->title = $title;
96
97
		return $this;
98
	}
99
100
101
	/**
102
	 * Get attribute title
103
	 */
104
	public function getTitle()
105
	{
106
		return $this->title;
107
	}
108
109
110
	/**
111
	 * Set attribute class
112
	 * @param string $class
113
	 */
114
	public function setClass($class)
115
	{
116
		$this->class = $class;
117
118
		return $this;
119
	}
120
121
122
	/**
123
	 * Get attribute class
124
	 */
125
	public function getClass()
126
	{
127
		return $this->class;
128
	}
129
130
}
131