Overview

Namespaces

  • None
  • PHP
  • Pry
    • Auth
      • Interfaces
    • Config
    • Controller
    • Date
    • Db
    • Feed
      • Abstracts
      • Writers
    • File
      • Decorator
    • Form
      • Element
    • Image
    • Log
      • Writer
    • Net
      • Exception
    • Session
    • Util
    • Validate
      • Validator
    • View

Classes

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