MIOLO20
Carregando...
Procurando...
Nenhuma entrada encontrada
mcheckboxgroup.class
Ir para a documentação deste ficheiro.
1<?php
2
26{
41 public function __construct($name='', $label='', $options='', $hint='', $disposition='horizontal', $border='none', $showRequiredLabel=false)
42 {
43 $controls = array();
44
45 if ( !is_array($options) )
46 {
47 $options = array( $options );
48 }
49
50 $n = count($options);
51
52 for ( $i = 0; $i < $n; $i++ )
53 {
54 // we will accept an array of CheckBox ...
55 if ( $options[$i] instanceof MCheckBox )
56 {
57 $controls[] = clone $options[$i];
58 }
59 else
60 {
61 // we will accept an array of Options ...
62 if ( $options[$i] instanceof MOption )
63 {
64 $oName = $name . '_' . $options[$i]->name;
65 $oLabel = $options[$i]->label;
66 $oValue = $options[$i]->value;
67 $oChecked = $options[$i]->checked || ( $oValue == $_REQUEST[$oName] );
68 }
69 // or an array of label/value pairs ...
70 elseif ( is_array($options[$i]) )
71 {
72 $oName = $name . '_' . $i;
73 $oLabel = $options[$i][0];
74 $oValue = $options[$i][1];
75 $oChecked = $oValue == $_REQUEST[$oName];
76 }
77 // or a simple array of values
78 else
79 {
80 $oName = $name . '_' . $i;
81 $oLabel = $oValue = $options[$i];
82 $oChecked = $oValue == $_REQUEST[$oName];
83 }
84
85 $option = new MCheckBox($oName, $oValue, $oLabel, $oChecked, $oLabel);
86 $option->setFormMode(self::FORM_MODE_WHOLE_ROW);
87 if ( $options[$i] instanceof MOption )
88 {
89 $option->attrs = $options[$i]->attrs;
90 }
91 $controls[] = $option;
92 }
93 }
94
95 $fields[] = $container = new MContainer("{$name}_container", $controls, $disposition, self::FORM_MODE_SHOW_SIDE);
96 $container->setShowLabel(false);
97
98 parent::__construct($name, $fields, 'horizontal', self::FORM_MODE_SHOW_SIDE);
99 $this->showRequiredLabel = $showRequiredLabel;
100 $this->label = $label;
101 $this->setShowLabeL(false);
102 }
103
107 public function getValue()
108 {
109 $value = array( );
110 $controls = $this->GetControls();
111
112 foreach ( $controls as $control )
113 {
114 $value[$control->GetName()] = $control->checked ? $control->GetValue() : NULL;
115 }
116
117 return $value;
118 }
119}
120
121?>
__construct($name='', $label='', $options='', $hint='', $disposition='horizontal', $border='none', $showRequiredLabel=false)