Completed
Push — master ( 546114...e895bf )
by Pavel
03:26
created

TButton::setClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
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\Traits;
10
11
use Ublaboo\DataGrid\DataGrid;
12
use Nette\Utils\Html;
13
use Ublaboo\DataGrid\Row;
14
15
trait TButton
16
{
17
18
	/**
19
	 * @var string
20
	 */
21
	protected $title = '';
22
23
	/**
24
	 * @var string
25
	 */
26
	protected $class = 'btn btn-xs btn-default';
27
28
	/**
29
	 * @var string
30
	 */
31
	protected $icon;
32
33
	/**
34
	 * @var string
35
	 */
36
	protected $text = '';
37
38
39
	/**
40
	 * Should the element has an icon?
41
	 * @param  Html            $el
42
	 * @param  string|null     $icon
43
	 * @param  string          $name
44
	 * @return void
45
	 */
46
	public function tryAddIcon($el, $icon, $name)
47
	{
48
		if ($icon) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $icon of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
49
			$el->add(Html::el('span')->class(DataGrid::$icon_prefix.$icon));
50
51
			if (strlen($name)) {
52
				$el->add('&nbsp;');
53
			}
54
		}
55
	}
56
57
58
	/**
59
	 * Set attribute title
60
	 * @param string $title
61
	 */
62
	public function setTitle($title)
63
	{
64
		$this->title = $title;
65
66
		return $this;
67
	}
68
69
70
	/**
71
	 * Get attribute title
72
	 * @return string
73
	 */
74
	public function getTitle()
75
	{
76
		return $this->title;
77
	}
78
79
80
	/**
81
	 * Set attribute class
82
	 * @param string $class
83
	 */
84
	public function setClass($class)
85
	{
86
		$this->class = $class;
87
88
		return $this;
89
	}
90
91
92
	/**
93
	 * Get attribute class
94
	 * @return string
95
	 */
96
	public function getClass()
97
	{
98
		return $this->class;
99
	}
100
101
102
	/**
103
	 * Set icon
104
	 * @param string $icon
105
	 */
106
	public function setIcon($icon)
107
	{
108
		$this->icon = $icon;
109
110
		return $this;
111
	}
112
113
114
	/**
115
	 * Get icon
116
	 * @return string
117
	 */
118
	public function getIcon()
119
	{
120
		return $this->icon;
121
	}
122
123
124
	/**
125
	 * Set text
126
	 * @param string $text
127
	 */
128
	public function setText($text)
129
	{
130
		$this->text = $text;
131
132
		return $this;
133
	}
134
135
136
	/**
137
	 * Get text
138
	 * @return string
139
	 */
140
	public function getText()
141
	{
142
		return $this->text;
143
	}
144
145
}
146