Source for file jFormsControlChoice.class.php

Documentation is available at jFormsControlChoice.class.php

  1. <?php
  2. /**
  3. * @package     jelix
  4. * @subpackage  forms
  5. * @author      Laurent Jouanneau
  6. * @contributor
  7. * @copyright   2006-2009 Laurent Jouanneau
  8. * @link        http://www.jelix.org
  9. * @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  10. */
  11.  
  12.  
  13. /**
  14.  * choice
  15.  * @package     jelix
  16.  * @subpackage  forms
  17.  */
  18. class jFormsControlChoice extends jFormsControlGroups {
  19.  
  20.     public $type="choice";
  21.  
  22.     /**
  23.      * list of item. Each value is an array which contains corresponding controls of the item
  24.      * an item could not have controls, in this case its value is an empty array
  25.      */
  26.     public $items = array();
  27.  
  28.     public $itemsNames = array();
  29.  
  30.     function check(){
  31.         $val = $this->container->data[$this->ref];
  32.         if($val !== "" && $val !== null && isset($this->items[$val])) {
  33.             $rv = null;
  34.             foreach($this->items[$val] as $ctrl) {
  35.                 if (($rv2 = $ctrl->check()) !== null) {
  36.                     $rv = $rv2;
  37.                 }
  38.             }
  39.             return $rv;
  40.         } else if ($this->required) {
  41.             return $this->container->errors[$this->ref] = jForms::ERRDATA_INVALID;
  42.         }
  43.         return null;
  44.     }
  45.  
  46.     function createItem($value, $label) {
  47.         $this->items[$value] = array();
  48.         $this->itemsNames[$value]= $label;
  49.     }
  50.  
  51.     function addChildControl($control, $itemValue = '') {
  52.         $this->childControls[$control->ref] = $control;
  53.         $this->items[$itemValue][$control->ref] = $control;
  54.     }
  55.  
  56.     function setData($value) {
  57.         parent::setData($value);
  58.         // we deactivate controls which are not selected
  59.         foreach($this->items as $item => $list) {
  60.             $ro = ($item != $value);
  61.             foreach($list as $ref=>$ctrl) {
  62.                 $this->form->setReadOnly($ref, $ro);
  63.             }
  64.         }
  65.     }
  66.  
  67.     function setValueFromRequest($request) {
  68.         $this->setData($request->getParam($this->ref,''));
  69.         if(isset($this->items[$this->container->data[$this->ref]])){
  70.             foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl) {
  71.                 $ctrl->setValueFromRequest($request);
  72.             }
  73.         }
  74.     }
  75. }

Documentation generated on Thu, 22 Mar 2012 22:15:56 +0100 by phpDocumentor 1.4.3