Overview

Packages

  • Auth
  • Config
  • Controller
  • Date
  • Db
  • Feed
    • Abstract
    • Writers
  • File
    • Decorator
  • Form
    • Element
  • Image
  • Log
    • Writer
  • Net
    • Exception
  • None
  • PHP
  • PHPMailer
  • Session
  • Util
  • Validate
    • Validator
  • Zend
    • Registry

Classes

  • Form_Element_AutoCompleter
  • Form_Element_Checkbox
  • Form_Element_Colorpicker
  • Form_Element_Date
  • Form_Element_DatePicker
  • Form_Element_Email
  • Form_Element_File
  • Form_Element_Hidden
  • Form_Element_Html
  • Form_Element_Ip
  • Form_Element_Mac
  • Form_Element_Multi
  • Form_Element_NumericStepper
  • Form_Element_Password
  • Form_Element_Radio
  • Form_Element_Select
  • Form_Element_Slider
  • Form_Element_Submit
  • Form_Element_Text
  • Form_Element_Textarea
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Pry Framework
  4:  *
  5:  * LICENSE
  6:  *
  7:  * This source file is subject to the new BSD license that is bundled
  8:  * with this package in the file LICENSE.txt.
  9:  * 
 10:  * @version $Revision: 276 $
 11:  */
 12: 
 13: /**
 14:  * Element Select. 
 15:  * @category Pry
 16:  * @package Form
 17:  * @subpackage Form_Element
 18:  * @version 1.1.0 
 19:  * @author Olivier ROGER <oroger.fr>
 20:  */
 21: class Form_Element_Select extends Form_Element_Multi
 22: {
 23:     /**
 24:      * Stockage du nom en cas de select multiple
 25:      *
 26:      * @var string
 27:      * @access private
 28:      */
 29:     private $name;
 30:     
 31:     /**
 32:      * Etat de l'activation du plugin jQuery
 33:      * @var boolean
 34:      */
 35:     private $jQuerymultiple;
 36:     
 37:     /**
 38:      * Tableau contenant les traductions du plugin
 39:      * @var array
 40:      */
 41:     private $jQueryTexts;
 42:     
 43:     /**
 44:      * Nombre de résultats sélectionnés à afficher par le plugin
 45:      * @var int
 46:      */
 47:     private $jQuerySelectedList;
 48:     
 49:     /**
 50:      * Constructeur
 51:      *
 52:      * @param string $nom
 53:      * @param Form_Form $form
 54:      */
 55:     public function __construct($nom,$form)
 56:     {
 57:         parent::__construct($nom,$form);
 58:         $this->name = $nom;
 59:         $this->jQuerymultiple   = false;
 60:         $this->jQueryTexts      = array('checkAll'  => 'Tout sélectionner',
 61:                                         'unCheckAll'=> 'Tout déselectionner',
 62:                                         'selected'  => '# sélectionnée(s)',
 63:                                         'noneSelected'  => 'Choisir...');
 64:         $this->jQuerySelectedList = 0;
 65:     }
 66:     
 67:     /**
 68:      * Défini si il sagit d'un select multiple ou non
 69:      *
 70:      * @param boolean $bool
 71:      * @param int $size Taille du select
 72:      * @access public
 73:      * @return Form_Element_Select
 74:      */
 75:     public function multiple($bool = true,$size = 5)
 76:     {
 77:         if($bool)
 78:         {
 79:             $this->attrs['multiple'] = 'multiple';
 80:             $this->attrs['name'] = $this->attrs['name'].'[]';
 81:             $this->attrs['size'] = $size;
 82:         }
 83:         else
 84:         {
 85:             unset($this->attrs['multiple']);
 86:             unset($this->attrs['size']);
 87:         }
 88:         
 89:         return $this;
 90:     }
 91:     
 92:     /**
 93:      * Active ou non le plugin jQuery pour les listes multiple
 94:      * @param boolean $bool
 95:      * @return Form_Element_Select
 96:      */
 97:     public function enableJQPlugin($bool=true)
 98:     {
 99:         $this->jQuerymultiple = $bool;
100:         return $this;
101:     }
102:     
103:     /**
104:      * Traduit les éléments textuels du plugin Jquery
105:      * Le tableau doit contenir les clés checkAll,unCheckAll,selected,noneSelected
106:      * @param array $texts
107:      * @return Form_Element_Select
108:      */
109:     public function translateJQPlugin(array $texts)
110:     {
111:         if(is_array($texts))
112:             array_merge($this->jQueryTexts,$texts);
113:         else
114:             throw new InvalidArgumentException('La traduction doit se faire via un array');
115:             
116:         return $this;
117:     }
118:     
119:     /**
120:      * Défini le nombre de choix sélectionner à afficher.
121:      * Par défaut n'afifchue que le nombre sélectionner et non le valeur.
122:      * @param int $num
123:      * @return Form_Element_Select
124:      */
125:     public function setJQSelectedList($num)
126:     {
127:         $this->jQuerySelectedList = intval($num);
128:         return $this;
129:     }
130:     
131:     /**
132:      * Ecriture de l'objet
133:      *
134:      * @access public
135:      * @return string
136:      */
137:     public function __toString()
138:     {
139:         $css = $this->cssClass();
140:         $label='';  
141:         $options = '';
142:         
143:         if(!empty($this->label))
144:         {
145:             $label = "\t".'<label for="'.$this->attrs['id'].'" class="'.$this->cssLabel.'">'.$this->label.'</label>'."\n";
146:             if($this->labelNewLine)
147:                 $label.="\t".'<br />'."\n";
148:         }
149:         $attributs = $this->attrsToString();
150:         //Posted value ou value par défaut
151:         $value = $this->form->getPostedvalue($this->name);
152:         if($value=='')
153:             $value = $this->value;
154:             
155:         foreach($this->choix as $itemHtml=>$itemAffichage)
156:         {
157:             if(is_array($itemAffichage)) // Cas d'un optgroup
158:             {
159:                 $options.="\t\t".'<optgroup label="'.$itemHtml.'">'."\n";
160:                 foreach($itemAffichage as $cle=>$valeur)
161:                 {
162:                     if(isset($this->attrs['multiple']) && is_array($value))
163:                     {
164:                         if(in_array($cle,$value))
165:                             $selected = 'selected="selected"';
166:                         else
167:                             $selected='';
168:                     }
169:                     else
170:                     {
171:                         if($value == $cle)
172:                             $selected = 'selected="selected"';
173:                         else
174:                             $selected='';
175:                     }
176:                     
177:                     $options .="\t\t".'<option value="'.htmlspecialchars($cle).'" '.$selected.'>'.$valeur.'</option>'."\n";
178:                 }
179:                 $options.="\t\t".'</optgroup>'."\n";
180:                 
181:             }
182:             else
183:             {
184:                 if(isset($this->attrs['multiple']) && is_array($value))
185:                 {
186:                     if(in_array($itemHtml,$value))
187:                         $selected = 'selected="selected"';
188:                     else
189:                         $selected='';
190:                 }
191:                 else
192:                 {
193:                     if($value == $itemHtml)
194:                         $selected = 'selected="selected"';
195:                     else
196:                         $selected='';
197:                 }
198:                 
199:                 $options .="\t\t".'<option value="'.htmlspecialchars($itemHtml).'" '.$selected.'>'.$itemAffichage.'</option>'."\n";
200:             }
201:         }
202:         $error = '';
203:         if(!is_null($this->errorMsg))
204:         {
205:             $error='<span class="'.$this->errorClass.'">'.$this->errorMsg.'</span><br />';
206:         }
207:         $field = "\t".'<select '.$attributs.' '.$css.' >'."\n".$options."\n\t".'</select>'."\n";
208:         if(!empty($this->info))
209:             $field.="\t".'<img src="'.$this->imgInfo.'" id="'.$this->attrs['name'].'_tooltip" class="form_tooltip" title="'.$this->info.'" alt="" style="cursor:help;" />'."\n";
210:         if($this->fieldNewLine)
211:             $field.="\t".'<br />'."\n";
212: 
213:         if($this->jQuerymultiple)
214:         {
215:             $this->form->javascript .= '$(\'#'.$this->attrs['id'].'\').multiSelect({selectedList:'.$this->jQuerySelectedList.',
216:                                                         checkAllText:\''.$this->jQueryTexts['checkAll'].'\',
217:                                                         unCheckAllText:\''.$this->jQueryTexts['unCheckAll'].'\',
218:                                                         selectedText:\''.$this->jQueryTexts['selected'].'\',
219:                                                         noneSelected:\''.$this->jQueryTexts['noneSelected'].'\'});';
220:         }
221:         return $label.$field.$error;
222:     }
223: }
224:  ?>
Pry Framework API documentation generated by ApiGen 2.6.1