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

ColumnLink   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 110
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 7
Bugs 1 Features 1
Metric Value
wmc 9
c 7
b 1
f 1
lcom 1
cbo 2
dl 0
loc 110
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A render() 0 20 4
A setTitle() 0 6 1
A getTitle() 0 4 1
A setClass() 0 6 1
A getClass() 0 4 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 $column
44
	 * @param string $name
45
	 * @param string $href
46
	 * @param array $params
47
	 */
48
	public function __construct(DataGrid $grid, $column, $name, $href, $params)
49
	{
50
		parent::__construct($column, $name);
51
52
		$this->href   = $href;
53
		$this->grid   = $grid;
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
		$value = parent::render($row);
73
74
		$a = Html::el('a')
75
			->href($this->createLink($this->href, $this->getItemParams($row, $this->params)))
76
			->setText($value);
77
78
		if ($this->title) { $a->title($this->title); }
79
		if ($this->class) { $a->class($this->class); }
80
81
		return $a;
82
	}
83
84
85
	/**
86
	 * Set attribute title
87
	 * @param string $title
88
	 */
89
	public function setTitle($title)
90
	{
91
		$this->title = $title;
92
93
		return $this;
94
	}
95
96
97
	/**
98
	 * Get attribute title
99
	 */
100
	public function getTitle()
101
	{
102
		return $this->title;
103
	}
104
105
106
	/**
107
	 * Set attribute class
108
	 * @param string $class
109
	 */
110
	public function setClass($class)
111
	{
112
		$this->class = $class;
113
114
		return $this;
115
	}
116
117
118
	/**
119
	 * Get attribute class
120
	 */
121
	public function getClass()
122
	{
123
		return $this->class;
124
	}
125
126
}
127