-
Notifications
You must be signed in to change notification settings - Fork 36
/
InfinitasHelper.php
executable file
·173 lines (153 loc) · 4.49 KB
/
InfinitasHelper.php
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/**
* Infinitas Helper.
*
* Does a lot of stuff like generating ordering buttons, load modules and
* other things needed all over infinitas.
*
* Copyright (c) 2010 Carl Sutton ( dogmatic69 )
*
* @filesource
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package libs
* @subpackage libs.views.helpers.infinitas
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since 0.6a
*
* @author Carl Sutton ( dogmatic69 )
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*/
App::uses('CakeTime', 'Utility');
App::uses('AppHelper', 'View/Helper');
class InfinitasHelper extends AppHelper {
/**
* @brief other helpers being used
*
* @var array
*/
public $helpers = array(
'Html',
'Form',
'Libs.Design',
'Libs.Image',
'Libs.Wysiwyg'
);
/**
* JSON errors.
*
* Set up some errors for json.
* @access public
*/
public $jsonErrors = array(
JSON_ERROR_NONE => 'No error',
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
);
protected $_menuData = '';
protected $_menuLevel = 0;
public $View = null;
private $__massActionCheckBoxCounter = 0;
/**
* Set to true when the menu has a current marker to avoid duplicates.
* @var unknown_type
*/
protected $_currentCssDone = false;
/**
* Create a status icon.
*
* Takes a int 0 || 1 and returns a icon with title tags etc to be used
* in places like admin to show iff something is on/off etc.
*
* @param int $status the status tinyint(1) from a db find.
*
* @return string some html for the generated image.
*/
public function status($status, $options = array()) {
$params = array('class' => 'icon-status');
$options = array_merge(
array(
'title_yes' => __d('infinitas', 'Status :: This record is active'),
'title_no' => __d('infinitas', 'Status :: This record is disabled'),
),
(array)$options
);
if(in_array((string)strtolower($status), array('1', 'yes', 'on'))) {
$params['title'] = $options['title_yes'];
$params['alt'] = __d('infinitas', 'On');
return $this->Image->image('status', 'active', $params);
}
$params['title'] = $options['title_no'];
$params['alt'] = __d('infinitas', 'Off');
return $this->Image->image('status', 'inactive', $params);
}
/**
* @brief generate a checkbox for rows that use mass_action stuff
*
* it will keep track of the $i for the checkbox number so there are no duplicates.
* MassActionComponent::filter() will remove these fields from the searches so there
* are no sql errors.
*
* @param array $data the row from find either find('first') or find('all')[x]
* @param array $options set the fk or model manually
*
* @return a checkbox
*/
public function massActionCheckBox(array $data, $options = array()) {
$alias = current(array_keys($this->request->params['models']));
$modelClass = implode('.', $this->request->params['models'][$alias]);
$options = array_merge(
array('alias' => $alias, 'hidden' => false, 'checked' => false, 'primaryKey' => false),
$options
);
if(empty($options['primaryKey'])) {
$options['primaryKey'] = ClassRegistry::init($modelClass)->primaryKey;
}
if(empty($data[$options['alias']]) || empty($data[$options['alias']][$options['primaryKey']])) {
return false;
}
$checkbox = $this->Form->checkbox(
$options['alias'] . '.' . $this->__massActionCheckBoxCounter++ . '.' . 'massCheckBox',
array(
'value' => $data[$options['alias']][$options['primaryKey']],
'hidden' => $options['hidden'],
'checked' => $options['checked']
)
);
return $checkbox;
}
/**
* @brief generate a date display box
*
* @param string|array $date a date string or record with created / modified date
* @param string $method the CakeTime method to use
*
* @return string
*/
public function date($date, $method = 'niceShort') {
if(!method_exists('CakeTime', $method)) {
return false;
}
if(is_array($date)) {
if(!empty($date['modified'])) {
$date = $date['modified'];
} elseif(!empty($date['created'])) {
$date = $date['created'];
} else {
$date = null;
}
}
if(empty($date)) {
return false;
}
return $this->Html->tag(
'div',
$this->Html->tag('span', call_user_func('CakeTime::' . $method), array('class' => $method)) .
$this->Html->tag('span', $date, array('class' => 'full')),
array('class' => 'date')
);
}
}