Elgg  Version 1.9
checkboxes.php
Go to the documentation of this file.
1 <?php
31 $defaults = array(
32  'align' => 'vertical',
33  'value' => array(),
34  'default' => 0,
35  'disabled' => false,
36  'options' => array(),
37  'name' => '',
38 );
39 
40 $vars = array_merge($defaults, $vars);
41 
42 $class = "elgg-input-checkboxes elgg-{$vars['align']}";
43 if (isset($vars['class'])) {
44  $class .= " {$vars['class']}";
45  unset($vars['class']);
46 }
47 
48 $id = '';
49 if (isset($vars['id'])) {
50  $id = "id=\"{$vars['id']}\"";
51  unset($vars['id']);
52 }
53 
54 if (is_array($vars['value'])) {
55  $values = array_map('elgg_strtolower', $vars['value']);
56 } else {
57  $values = array(elgg_strtolower($vars['value']));
58 }
59 
61 $input_vars['default'] = false;
62 if ($vars['name']) {
63  $input_vars['name'] = "{$vars['name']}[]";
64 }
65 unset($input_vars['align']);
66 unset($input_vars['options']);
67 
68 if (count($vars['options']) > 0) {
69  // include a default value so if nothing is checked 0 will be passed.
70  if ($vars['name'] && $vars['default'] !== false) {
71  echo "<input type=\"hidden\" name=\"{$vars['name']}\" value=\"{$vars['default']}\" />";
72  }
73 
74  echo "<ul class=\"$class\" $id>";
75  foreach ($vars['options'] as $label => $value) {
76  // @deprecated 1.8 Remove in 1.9
77  if (is_integer($label)) {
78  elgg_deprecated_notice('$vars[\'options\'] must be an associative array in input/checkboxes', 1.8);
79  $label = $value;
80  }
81 
82  $input_vars['checked'] = in_array(elgg_strtolower($value), $values);
83  $input_vars['value'] = $value;
84  $input_vars['label'] = $label;
85 
86  $input = elgg_view('input/checkbox', $input_vars);
87 
88  echo "<li>$input</li>";
89  }
90  echo '</ul>';
91 }
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $input
Definition: edit.php:19
$value
Definition: longtext.php:29
elgg_strtolower()
Wrapper function for mb_strtolower().
Definition: mb_wrapper.php:178
$vars
Definition: checkboxes.php:40
$class
Definition: checkboxes.php:42
elgg echo
Translates a string.
Definition: languages.js:43
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
$input_vars
Definition: checkboxes.php:60
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
$label
Elgg profile plugin edit default profile action.
Definition: add.php:7
if(isset($vars['class'])) $id
Definition: checkboxes.php:48
$defaults
Definition: checkboxes.php:31