Zikula_System_Modules
[ class tree: Zikula_System_Modules ] [ index: Zikula_System_Modules ] [ all elements ]

Source for file pnformbaselistselector.php

Documentation is available at pnformbaselistselector.php

  1. <?php
  2. /**
  3.  * Base implementation for checkbox and dropdown list
  4.  *
  5.  * @copyright (c) 2006, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: function.pnformdropdownlist.php 22138 2007-06-01 10:19:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @author Jorn Wildt
  10.  * @package Zikula_System_Modules
  11.  * @subpackage pnForm
  12.  */
  13.  
  14. /**
  15.  * Zikula Application Framework
  16.  *
  17.  * @copyright (c) 2007, Zikula Development Team
  18.  * @link http://www.zikula.org
  19.  * @version $Id: pnversion.php 19260 2006-06-12 13:08:15Z markwest $
  20.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  21.  * @package Zikula_System_Modules
  22.  * @subpackage pnForm
  23.  */
  24. {
  25.     /**
  26.      * Enable or disable read only mode
  27.      * @var bool 
  28.      */
  29.     var $readOnly;
  30.  
  31.     /**
  32.      * CSS class for styling
  33.      */
  34.     var $cssClass;
  35.  
  36.     /**
  37.      * Data field name for looking up initial data
  38.      *
  39.      * The name stored here is used to lookup initial data for the plugin in the render's variables.
  40.      * The value itself depends on the plugin that extends this base class.
  41.      * Defaults to the ID of the plugin. See also tutorials on the Zikula site.
  42.      * @var string 
  43.      */
  44.     var $dataField;
  45.  
  46.     /**
  47.      * Enable or disable use of $dataField
  48.      * @var bool 
  49.      */
  50.     var $dataBased;
  51.  
  52.     /**
  53.      * Group name for this input
  54.      *
  55.      * The group name is used to locate data in the render (when databased) and to restrict which
  56.      * plugins to do validation on (to be implemented).
  57.      * @see pnFormRender::pnFormGetValues()
  58.      * @see pnFormRender::pnFormIsValid()
  59.      * @var string 
  60.      */
  61.     var $group;
  62.  
  63.     /**
  64.      * Data field name for looking up initial item list
  65.      *
  66.      * The name stored here is used to lookup initial item list in the render's variables.
  67.      * The value should be an array as described for the $items variable.
  68.      * Defaults to the data field name concatenated with "Items". See also tutorials on the Zikula site.
  69.      * @var string 
  70.      */
  71.     var $itemsDataField;
  72.  
  73.     /**
  74.      * Validation indicator used by the framework.
  75.      *
  76.      * The true/false value of this variable indicates whether or not the list selection is valid.
  77.      * @var bool 
  78.      */
  79.     var $isValid = true;
  80.  
  81.     /**
  82.      * Enable or disable mandatory check
  83.      *
  84.      * @var bool 
  85.      */
  86.     var $mandatory;
  87.  
  88.     /**
  89.      * Error message to display when selection does not validate
  90.      *
  91.      * @var string 
  92.      */
  93.     var $errorMessage;
  94.  
  95.     /**
  96.      * Text label for this plugin
  97.      *
  98.      * This variable contains the label text for the input. The {@link pnFormLabel} plugin will set
  99.      * this text automatically when it is a label for this list.
  100.      * @var string 
  101.      */
  102.     var $myLabel;
  103.  
  104.     /**
  105.      * The list of selectable items
  106.      *
  107.      * This is an array of arrays like this:
  108.      * array( array('text' => 'A', 'value' => '1'),
  109.      *        array('text' => 'B', 'value' => '2'),
  110.      *        array('text' => 'C', 'value' => '3') )
  111.      */
  112.     var $items = array();
  113.  
  114.     /**
  115.     * HTML input name for this plugin. Defaults to the ID of the plugin.
  116.     * @var string 
  117.     */
  118.     var $inputName;
  119.  
  120.  
  121.     function getFilename()
  122.     {
  123.         return __FILE__;
  124.     }
  125.  
  126.  
  127.     function create(&$render$params)
  128.     {
  129.         $this->inputName = $this->id;
  130.  
  131.         $this->readOnly = (array_key_exists('readOnly'$params$params['readOnly'false);
  132.  
  133.         $this->dataBased = (array_key_exists('dataBased'$params$params['dataBased'true);
  134.         $this->dataField = (array_key_exists('dataField'$params$params['dataField'$this->id);
  135.         $this->itemsDataField = (isset($params['itemsDataField'])) $params['itemsDataField'$this->id . 'Items';
  136.  
  137.         $this->isValid = true;
  138.         $this->mandatory = (array_key_exists('mandatory'$params$params['mandatory'false);
  139.     }
  140.  
  141.  
  142.     function initialize(&$render)
  143.     {
  144.         $render->pnFormAddValidator($this);
  145.     }
  146.  
  147.  
  148.     function load(&$render&$params)
  149.     {
  150.         // The load function expects the plugin to read values from the render.
  151.         // This can be done with the loadValue function (which can be called in other situations than
  152.         // through the onLoad event).
  153.         $this->loadValue($render$render->get_template_vars());
  154.     }
  155.  
  156.  
  157.     function setError($msg)
  158.     {
  159.         $this->isValid = false;
  160.         $this->errorMessage = $msg;
  161.     }
  162.  
  163.  
  164.     function clearValidation(&$render)
  165.     {
  166.         $this->isValid = true;
  167.         $this->errorMessage = null;
  168.     }
  169.  
  170.  
  171.     function saveValue(&$render&$data)
  172.     {
  173.         if ($this->dataBased)
  174.         {
  175.             if ($this->group == null)
  176.             {
  177.                 $data[$this->dataField$this->getSelectedValue();
  178.             }
  179.             else
  180.             {
  181.                 if (!array_key_exists($this->group$data))
  182.                     $data[$this->grouparray();
  183.                 $data[$this->group][$this->dataField$this->getSelectedValue();
  184.             }
  185.         }
  186.     }
  187.  
  188.  
  189.     // Called internally by the plugin itself to load values from the render.
  190.     // Can also by called when some one is calling the render object's pnFormSetValues
  191.     function loadValue(&$render&$values)
  192.     {
  193.         if ($this->dataBased)
  194.         {
  195.             $items null;
  196.             $value null;
  197.  
  198.             if ($this->group == null)
  199.             {
  200.                 if ($this->dataField != null  &&  isset($values[$this->dataField]))
  201.                     $value $values[$this->dataField];
  202.                 if ($this->itemsDataField != null  &&  isset($values[$this->itemsDataField])) 
  203.                     $items $values[$this->itemsDataField];
  204.             }
  205.             else
  206.             {
  207.                 if (isset($values[$this->group]))
  208.                 {
  209.                     $data $values[$this->group];
  210.                     if (isset($data[$this->dataField]))
  211.                     {
  212.                         $value $data[$this->dataField];
  213.                         if ($this->itemsDataField != null  &&  isset($data[$this->itemsDataField]))
  214.                             $items $data[$this->itemsDataField];
  215.                     }
  216.                 }
  217.             }
  218.  
  219.             if ($items !== null)
  220.                 $this->setItems($items);
  221.  
  222.             $this->setSelectedValue($value);
  223.         }
  224.     }
  225.  
  226.  
  227.     function setSelectedValue($value)
  228.     {
  229.       // To be implemented by extending class
  230.       return true;
  231.     }
  232.  
  233.  
  234.     function getSelectedValue()
  235.     {
  236.       // To be implemented by extending class
  237.       return null;
  238.     }
  239.  
  240.  
  241.     function addItem($text$value)
  242.     {
  243.         $item array('text' => $text'value' => $value);
  244.  
  245.         $this->items[$item;
  246.     }
  247.  
  248.  
  249.     function setItems($items)
  250.     {
  251.         // Quicker than copying the items one by one 
  252.         // If addItem() does som special logic in the future then call that for each element in $items
  253.         $this->items = $items;
  254.     }
  255. }

Documentation generated on Fri, 18 Jul 2008 21:52:58 +0200 by phpDocumentor 1.4.1