My favorites | Sign in
Project Logo
lux
Lux
                
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
174
175
176
177
<?php
/**
*
* Helper to build a list of action links.
*
* @category Lux
*
* @package Lux_View
*
* @author Rodrigo Moraes <rodrigo.moraes@gmail.com>
*
* @license http://opensource.org/licenses/bsd-license.php BSD
*
* @version $Id$
*
*/
class Lux_View_Helper_ActionList extends Solar_View_Helper
{
/**
*
* User-defined configuration values.
*
* Keys are...
*
* `list_type`
* : (string) The type of list to use; default is 'ul'. Only 'ul' and 'ol'
* are honored.
*
* `list_id`
* : (string) The ID attribute for the list.
*
* `list_class`
* :(string) The class attribute for the list.
*
* `first_class`
* : (string) The CSS class for the first item in the list.
*
* `curr_class`
* : (string) The CSS class for the currently active item in the list.
*
* `last_class`
* : (string) The CSS class for the last item in the list.
*
* @var array
*
*/
protected $_Lux_View_Helper_ActionList = array(
'list_type' => 'ul',
'list_id' => null,
'list_class' => null,
'first_class' => 'first',
'curr_class' => 'curr',
'last_class' => 'last',
);

/**
*
* Returns a list of action links.
*
* @param array $items List of items using. See examples for the format:

* {{code: php
*
* $items = array();
*
* // Simple item: create action using the provided locale code. The key
* // is used to check if this is the active item.
* $items['/path/to/action'] = 'ACTION_LOCALE_CODE';
*
* // Named item: same as above, but using a array for the definition.
* // The key doesn't need to be the action, allowing "named" items.
* // Optionally, a CSS class name can be passed as a third value.
* $items['item-name'] = array(
* '/path/to/action',
* 'ACTION_LOCALE_CODE',
* 'css-class-for-this-item'
* );
*
* // No-action item: just escape and add the content to the list
* $items[] = 'some text to add to the list';
*
* }}
*
* @param string $current The currently "active" item in the list, if any.
*
* @param array $config Additional config options to build the list.
*
* @return string A HTML list.
*
*/
public function actionList($items, $current = null, $config = null)
{
if ($config) {
$config = array_merge($this->_config, (array) $config);
} else {
$config = $this->_config;
}

$attribs = $this->_view->attribs(array(
'id' => $config['list_id'],
'class' => $config['list_class'],
));

// make sure we have ol or ul
$list_type = strtolower($config['list_type']);
if ($list_type != 'ol') {
$list_type = 'ul';
}

// start the list
$html = "<$list_type$attribs>\n";

$iter = 1;
$total = count($items);
foreach ($items as $key => $spec) {
// reset class and attributes for this item
$class = array();
$attribs = '';

// add 'first' class?
if (($iter == 1) && $config['first_class']) {
$class[] = $config['first_class'];
}

// add 'last' class?
if (($iter == $total) && $config['last_class']) {
$class[] = $config['last_class'];
}

// add 'current' class?
if (($key === $current) && $config['curr_class']) {
$class[] = $config['curr_class'];
}

// is this an action item?
if (is_string($key) || is_array($spec)) {
// using array for the item info?
if (is_array($spec)) {
// make sure we have always three values in the array
$spec = array_pad(array_values($spec), 3, null);

// add a special class for this item?
if ($spec[2]) {
$class[] = $spec[2];
}

// extract href and text
$key = $spec[0];
$spec = $spec[1];
}

// build the action
$href = $this->_view->escape($key);
$text = $this->_view->escape($spec);
$content = "<a href=\"$href\">$text</a>";
} else {
// no action: just escape the content
$content = $this->_view->escape($spec);
}

// add any CSS class?
if (! empty($class)) {
$attribs = $this->_view->attribs(array(
'class' => $class,
));
}

// set the item
$html .= " <li$attribs>$content</li>\n";
$iter++;
}

// done.
$html .= "</$list_type>";
return $html;
}
}
Show details Hide details

Change log

r137 by rodrigo.moraes on Sep 29, 2008   Diff
Re-added list helpers, much simpler and
flexible enough.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 5308 bytes, 177 lines

File properties

svn:keywords
Id
Hosted by Google Code