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 Julien Issler
  7. @copyright   2006-2009 Laurent Jouanneau
  8. @copyright   2010 Julien Issler
  9. @link        http://www.jelix.org
  10. @licence     http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file
  11. */
  12.  
  13.  
  14. /**
  15.  * choice
  16.  * @package     jelix
  17.  * @subpackage  forms
  18.  */
  19. class jFormsControlChoice extends jFormsControlGroups {
  20.  
  21.     public $type="choice";
  22.  
  23.     /**
  24.      * list of item. Each value is an array which contains corresponding controls of the item
  25.      * an item could not have controls, in this case its value is an empty array
  26.      */
  27.     public $items = array();
  28.  
  29.     public $itemsNames = array();
  30.  
  31.     function check(){
  32.         $val $this->container->data[$this->ref];
  33.  
  34.         if (isset($this->container->privateData[$this->ref][$val])) {
  35.             return $this->container->errors[$this->refjForms::ERRDATA_INVALID;
  36.         }
  37.  
  38.         if($val !== "" && $val !== null && isset($this->items[$val])) {
  39.             $rv null;
  40.             foreach($this->items[$valas $ctrl{
  41.                 if (!$ctrl->isActivated())
  42.                     continue;
  43.                 if (($rv2 $ctrl->check()) !== null{
  44.                     $rv $rv2;
  45.                 }
  46.             }
  47.             return $rv;
  48.         else if ($this->required{
  49.             return $this->container->errors[$this->refjForms::ERRDATA_INVALID;
  50.         }
  51.         return null;
  52.     }
  53.  
  54.     function createItem($value$label{
  55.         $this->items[$valuearray();
  56.         $this->itemsNames[$value]$label;
  57.     }
  58.  
  59.     function deactivateItem($value$deactivation=true{
  60.         if (!isset($this->items[$value]))
  61.             return;
  62.         if ($deactivation{
  63.             $this->container->privateData[$this->ref][$valuetrue;
  64.         }
  65.         else if (isset($this->container->privateData[$this->ref][$value])) {
  66.             unset($this->container->privateData[$this->ref][$value]);
  67.         }
  68.     }
  69.  
  70.     function isItemActivated($value{
  71.         return !(isset($this->container->privateData[$this->ref][$value]));
  72.     }
  73.  
  74.     function addChildControl($control$itemValue ''{
  75.         $this->childControls[$control->ref$control;
  76.         $this->items[$itemValue][$control->ref$control;
  77.     }
  78.  
  79.     function setValueFromRequest($request{
  80.         $value $request->getParam($this->ref,'');
  81.  
  82.         if (isset($this->container->privateData[$this->ref][$value])) {
  83.             $this->setData('');
  84.             return;
  85.         }
  86.         $this->setData($value);
  87.  
  88.         if(isset($this->items[$this->container->data[$this->ref]])){
  89.             foreach($this->items[$this->container->data[$this->ref]] as $name=>$ctrl{
  90.                 $ctrl->setValueFromRequest($request);
  91.             }
  92.         }
  93.     }
  94. }

Documentation generated on Wed, 04 Jan 2017 22:54:46 +0100 by phpDocumentor 1.4.3