Source for file jFormsControl.class.php

Documentation is available at jFormsControl.class.php

  1. <?php
  2. /**
  3. @package     jelix
  4. @subpackage  forms
  5. @author      Laurent Jouanneau
  6. @contributor Dominique Papin
  7. @copyright   2006-2008 Laurent Jouanneau, 2008 Dominique Papin
  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.  * base class for all jforms control
  13.  * @package     jelix
  14.  * @subpackage  forms
  15.  */
  16. abstract class jFormsControl {
  17.     public $type = null;
  18.     public $ref='';
  19.     public $datatype;
  20.     public $required = false;
  21.     public $label='';
  22.     public $defaultValue='';
  23.     public $help = '';
  24.     public $hint='';
  25.     public $alertInvalid='';
  26.     public $alertRequired='';
  27.  
  28.     public $initialReadOnly = false;
  29.     public $initialActivation = true;
  30.  
  31.     protected $form;
  32.     protected $container;
  33.  
  34.  
  35.     function __construct($ref){
  36.         $this->ref = $ref;
  37.         $this->datatype = new jDatatypeString();
  38.     }
  39.  
  40.     function setForm($form{
  41.         $this->form = $form;
  42.         $this->container = $form->getContainer();
  43.         if($this->initialReadOnly)
  44.             $this->container->setReadOnly($this->reftrue);
  45.         if(!$this->initialActivation)
  46.             $this->container->deactivate($this->reftrue);
  47.     }
  48.  
  49.     /**
  50.      * says if the control can have multiple values
  51.      */
  52.     function isContainer(){
  53.         return false;
  54.     }
  55.  
  56.     function check(){
  57.         $value $this->container->data[$this->ref];
  58.         if(trim($value== ''{
  59.             if($this->required)
  60.                 return $this->container->errors[$this->refjForms::ERRDATA_REQUIRED;
  61.         }elseif(!$this->datatype->check($value)){
  62.             return $this->container->errors[$this->refjForms::ERRDATA_INVALID;
  63.         }elseif($this->datatype instanceof jIFilteredDatatype{
  64.             $this->container->data[$this->ref$this->datatype->getFilteredValue();
  65.         }
  66.         return null;
  67.     }
  68.  
  69.     function setData($value{
  70.         $this->container->data[$this->ref$value;
  71.     }
  72.  
  73.     function setReadOnly($r true){
  74.         $this->container->setReadOnly($this->ref$r);
  75.     }
  76.  
  77.     function setValueFromRequest($request{
  78.         $this->setData($request->getParam($this->ref,''));
  79.     }
  80.  
  81.     function setDataFromDao($value$daoDatatype{
  82.         $this->setData($value);
  83.     }
  84.  
  85.     function getDisplayValue($value){
  86.         return $value;
  87.     }
  88.  
  89.     public function deactivate($deactivation=true{
  90.         $this->container->deactivate($this->ref$deactivation);
  91.     }
  92.  
  93.     /**
  94.     * check if the control is activated
  95.     * @return boolean true if it is activated
  96.     */
  97.     public function isActivated({
  98.         return $this->container->isActivated($this->ref);
  99.     }
  100.  
  101.     /**
  102.      * check if the control is readonly
  103.      * @return boolean true if it is readonly
  104.      */
  105.     public function isReadOnly({
  106.         return $this->container->isReadOnly($this->ref);
  107.     }
  108. }
  109.  
  110. require(JELIX_LIB_PATH.'forms/controls/jFormsControlDatasource.class.php');
  111. require(JELIX_LIB_PATH.'forms/controls/jFormsControlGroups.class.php');
  112.  
  113. require(JELIX_LIB_PATH.'forms/controls/jFormsControlCaptcha.class.php');
  114. require(JELIX_LIB_PATH.'forms/controls/jFormsControlCheckbox.class.php');
  115. require(JELIX_LIB_PATH.'forms/controls/jFormsControlCheckboxes.class.php');
  116. require(JELIX_LIB_PATH.'forms/controls/jFormsControlChoice.class.php');
  117. require(JELIX_LIB_PATH.'forms/controls/jFormsControlGroup.class.php');
  118. require(JELIX_LIB_PATH.'forms/controls/jFormsControlReset.class.php');
  119. require(JELIX_LIB_PATH.'forms/controls/jFormsControlHidden.class.php');
  120. require(JELIX_LIB_PATH.'forms/controls/jFormsControlHtmlEditor.class.php');
  121. require(JELIX_LIB_PATH.'forms/controls/jFormsControlInput.class.php');
  122. require(JELIX_LIB_PATH.'forms/controls/jFormsControlListbox.class.php');
  123. require(JELIX_LIB_PATH.'forms/controls/jFormsControlRadiobuttons.class.php');
  124. require(JELIX_LIB_PATH.'forms/controls/jFormsControlMenulist.class.php');
  125. require(JELIX_LIB_PATH.'forms/controls/jFormsControlOutput.class.php');
  126. require(JELIX_LIB_PATH.'forms/controls/jFormsControlRepeat.class.php');
  127. require(JELIX_LIB_PATH.'forms/controls/jFormsControlSecret.class.php');
  128. require(JELIX_LIB_PATH.'forms/controls/jFormsControlSecretConfirm.class.php');
  129. require(JELIX_LIB_PATH.'forms/controls/jFormsControlSubmit.class.php');
  130. require(JELIX_LIB_PATH.'forms/controls/jFormsControlSwitch.class.php');
  131. require(JELIX_LIB_PATH.'forms/controls/jFormsControlTextarea.class.php');
  132. require(JELIX_LIB_PATH.'forms/controls/jFormsControlUpload.class.php');
  133. require(JELIX_LIB_PATH.'forms/controls/jFormsControlDate.class.php');
  134. require(JELIX_LIB_PATH.'forms/controls/jFormsControlDatetime.class.php');

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