Repository navigation
Expand file tree
/
Copy pathBooleanHelper.php
More file actions
60 lines (52 loc) · 1.5 KB
/
Copy pathBooleanHelper.php
File metadata and controls
60 lines (52 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
/**
* Helper for the output of boolean values as ticks and crosses
*
* @author David Yell
*/
class BooleanHelper extends AppHelper {
/**
* Include the helpers that we need to create output
* @var array
*/
public $helpers = array('Html');
/**
* A set of default options for the helper. These can be overridden when you are instantiating the helper
* @var array
*/
public $settings = array(
1 => array(
'class' => 'badge badge-success',
'display' => '✔'
),
0 => array(
'class' => 'badge badge-important',
'display' => '✘'
)
);
/**
* Build the helper and overwrites the default options with any user passed options into the helper
* @param View $view
* @param array $settings
*/
public function __construct(View $view, $settings = array()) {
parent::__construct($view, $settings);
if (!empty($settings)) {
$this->settings = $settings;
}
}
/**
* Output the tag
*
* @param boolean $value The boolean value of the item
* @return html Returns a formatted HTML tag
*/
public function display($value) {
if ($value === true || $value == 1) {
$return = $this->Html->tag('span', $this->settings[1]['display'], array('class' => $this->settings[1]['class']));
} else {
$return = $this->Html->tag('span', $this->settings[0]['display'], array('class' => $this->settings[0]['class']));
}
return $return;
}
}