Overview

Packages

  • None
  • Sesha

Classes

  • Horde_Core_UI_VarRenderer_Stockedit_Html
  • Sesha
  • Sesha_Api
  • Sesha_Driver
  • Sesha_Driver_Sql
  • Sesha_Exception
  • Sesha_Forms_Category
  • Sesha_Forms_CategoryDelete
  • Sesha_Forms_CategoryList
  • Sesha_Forms_Property
  • Sesha_Forms_PropertyDelete
  • Sesha_Forms_PropertyList
  • Sesha_Forms_Search
  • Sesha_Forms_Stock
  • Sesha_Forms_Type_Client
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
  4:  *
  5:  * See the enclosed file LICENSE for license information (GPL). If you
  6:  * did not receive this file, see http://www.horde.org/licenses/gpl.php.
  7:  *
  8:  * @author  Bo Daley <bo@darkwork.net>
  9:  * @package Sesha
 10:  */
 11: class Sesha_Forms_Property extends Horde_Form
 12: {
 13:     function __construct($vars)
 14:     {
 15:         parent::__construct($vars);
 16: 
 17:         $this->appendButtons(_("Save Property"));
 18: 
 19:         $types = array();
 20:         $datatypes = $GLOBALS['conf']['datatypes']['types'];
 21:         foreach ($datatypes as $d) {
 22:             $types[$d] = $d;
 23:         }
 24: 
 25:         $priorities = array();
 26:         for ($i = 0; $i < 100; $i++) {
 27:             $priorities[] = $i;
 28:         }
 29: 
 30:         $this->addHidden('', 'actionID', 'text', false, false, null);
 31:         $this->addHidden('', 'property_id', 'text', false, false, null);
 32:         $this->addVariable(_("Property Name"), 'property', 'text', true);
 33: 
 34:         $action = Horde_Form_Action::factory('submit');
 35:         $v = $this->addVariable(_("Data Type"), 'datatype', 'enum', true, false, null, array($types, true));
 36:         $v->setAction($action);
 37:         $v->setOption('trackchange', true);
 38: 
 39:         $this->addVariable(_("Unit"), 'unit', 'text', false);
 40:         $this->addVariable(_("Description"), 'description', 'longtext', false);
 41:         $this->addVariable(_("Sort Weight"), 'priority', 'enum', false, false, _("When properties are displayed, they will be shown in weight order from highest to lowest"), array($priorities));
 42:     }
 43: 
 44:     /**
 45:      * Validates the form, checking if it really has been submitted by calling
 46:      * isSubmitted() and if true does any onSubmit() calls for variable types
 47:      * in the form. The _submitted variable is then rechecked.
 48:      *
 49:      * @param Variables $vars       A Variables instance, optional since Horde
 50:      *                              3.2.
 51:      * @param boolean $canAutofill  Can the form be valid without being
 52:      *                              submitted?
 53:      *
 54:      * @return boolean  True if the form is valid.
 55:      */
 56: 
 57:     public function validate($vars, $canAutoFill = false)
 58:     {
 59:         $this->_addParameters($vars);
 60:         return parent::validate($vars, $canAutoFill);
 61:     }
 62: 
 63:     /**
 64:      * Renders the form for editing.
 65:      *
 66:      * @param Horde_Form_Renderer $renderer  A renderer instance, optional
 67:      *                                       since Horde 3.2.
 68:      * @param Variables $vars                A Variables instance, optional
 69:      *                                       since Horde 3.2.
 70:      * @param string $action                 The form action (url).
 71:      * @param string $method                 The form method, usually either
 72:      *                                       'get' or 'post'.
 73:      * @param string $enctype                The form encoding type. Determined
 74:      *                                       automatically if null.
 75:      * @param boolean $focus                 Focus the first form field?
 76:      */
 77: 
 78:     public function renderActive($renderer, $vars, $action, $method = 'get', $enctype = null, $focus = true)
 79:     {
 80:         if ($vars->get('old_datatype') === null) {
 81:             $this->_addParameters($vars);
 82:         }
 83:         parent::renderActive($renderer, $vars, $action, $method, $enctype, $focus);
 84:     }
 85: 
 86:     protected function _addParameters($vars)
 87:     {
 88:         $dataType = $vars->get('datatype');
 89:         $className = $this->_buildTypeClassname($dataType);
 90:         if (empty($dataType)) {
 91:             // Noop.
 92:         } elseif (!$className) {
 93:             $GLOBALS['notification']->push(sprintf(_("The form field type \"%s\" doesn't exist."), $dataType), 'horde.error');
 94:         } else {
 95:             $params = call_user_func(array($className, 'about'));
 96:             if (isset($params['params'])) {
 97:                 foreach ($params['params'] as $name => $param) {
 98:                     $field_id = 'parameters[' . $name . ']';
 99:                     $param['required'] = isset($param['required'])
100:                         ? $param['required']
101:                         : null;
102:                     $param['readonly'] = isset($param['readonly'])
103:                         ? $param['readonly']
104:                         : null;
105:                     $param['desc'] = isset($param['desc'])
106:                         ? $param['desc']
107:                         : null;
108:                     $this->insertVariableBefore('unit', $param['label'],
109:                                                 $field_id, $param['type'],
110:                                                 $param['required'],
111:                                                 $param['readonly'],
112:                                                 $param['desc']);
113:                     $vars->set('old_datatype', $dataType);
114:                 }
115:             }
116:         }
117:     }
118: 
119:    /**
120:     * Helper method to build either h3 style class names as seen in Horde_Form_Type_ccc
121:     * or autoloadable class names used in Sesha
122:     *
123:     * @param string $dataType  The type identifier to turn into a class name
124:     *
125:     * @return string  A class name or an empty string
126:     *
127:     */
128: 
129:     protected function _buildTypeClassname($dataType)
130:     {
131:         if (class_exists('Horde_Form_Type_' . $dataType)) {
132:             return 'Horde_Form_Type_' . $dataType;
133:         } elseif (class_exists('Sesha_Forms_Type_' . ucfirst($dataType))) {
134:             return 'Sesha_Forms_Type_' . ucfirst($dataType);
135:         } else {
136:             return '';
137:         }
138:     }
139: }
140: 
API documentation generated by ApiGen