ここの情報は古いです。ご理解頂いた上でお取り扱いください。

Changeset 10054


Ignore:
Timestamp:
Jan 9, 2009, 3:53:49 PM (14 years ago)
Author:
ebihara
Message:

#3308:added the opFormItemGenerator class to generate form items(widget and validators) and search items. And marked the OpenPNEFormAutoGenerate class as a deprecated. If you use the OpenPNEFormAutoGenerate class, please replace to use methods of the opFormItemGenerator class.

Location:
OpenPNE3/trunk/lib
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/form/OpenPNEFormAutoGenerate.class.php

    r10003 r10054  
    1212 * OpenPNEFormAutoGenerate is the base class for forms that generate its widgets automatically
    1313 *
     14 * This class is deprecated because it does call the static method of opFormItemGenerator only.
     15 * If you want to generate form items, please use the opFormItemGenerator class.
     16 *
    1417 * @package    OpenPNE
    1518 * @subpackage form
     
    1821abstract class OpenPNEFormAutoGenerate extends sfForm
    1922{
     23  public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
     24  {
     25    parent::__construct($defaults, $options, $CSRFSecret);
     26
     27    $message = 'The OpenPNEFormAutoGenerate is deprecated. '
     28             . 'Please use static methods of the opFormItemGenerator class. '
     29             . 'The OpenPNEFormAutoGenerate will be deleted by OpenPNE3.0beta3.';
     30    sfContext::getInstance()->getConfiguration()->getEventDispatcher()->notify(
     31      new sfEvent(null, 'application.log', array($message, 'priority' => sfLogger::ERR))
     32    );
     33  }
     34
    2035  protected function generateWidget($field, $choices = array())
    2136  {
    22     $params = array();
    23 
    24     if ($field['Caption'])
    25     {
    26       $params['label'] = $field['Caption'];
    27     }
    28 
    29     if ($choices)
    30     {
    31       $params['choices'] = $choices;
    32     }
    33     elseif (!empty($field['Choices']))
    34     {
    35       $params['choices'] = $field['Choices'];
    36     }
    37 
    38     if (!empty($field['Default']))
    39     {
    40       $params['default'] = $field['Default'];
    41     }
    42 
    43     switch ($field['FormType']) {
    44       case 'checkbox':
    45         $obj = new sfWidgetFormSelectCheckbox($params);
    46         break;
    47       case 'select':
    48         $obj = new sfWidgetFormSelect($params);
    49         break;
    50       case 'radio':
    51         $obj = new sfWidgetFormSelectRadio($params);
    52         break;
    53       case 'textarea':
    54         $obj = new sfWidgetFormTextarea($params);
    55         break;
    56       case 'rich_textarea':
    57         $params['config'] = 'theme_advanced_buttons1: "bold, italic, underline, forecolor, hr", theme_advanced_buttons2:"", theme_advanced_buttons3:"", ';
    58         $params['width'] = '200px';
    59         $jsPath = 'tiny_mce/tiny_mce';
    60         sfContext::getInstance()->getResponse()->addJavascript($jsPath);
    61         $obj = new sfWidgetFormTextareaTinyMCE($params, array('class' => 'tinymce'));
    62         break;
    63       case 'password':
    64         $obj = new sfWidgetFormInputPassword($params);
    65         break;
    66       case 'date':
    67         $params['culture'] = sfContext::getInstance()->getUser()->getCulture();
    68         $params['month_format'] = 'number';
    69         $obj = new opWidgetFormDate($params);
    70         break;
    71       case 'increased_input':
    72         $obj = new opWidgetFormInputIncreased($params);
    73         break;
    74       default:
    75         $obj = new sfWidgetFormInput($params);
    76     }
    77 
    78     return $obj;
     37    return opFormItemGenerator::generateWidget($field, $choices);
    7938  }
    8039
    8140  protected function generateValidator($field, $choices = array())
    8241  {
    83     $option = array('required' => $field['IsRequired'], 'trim' => $field['IsRequired']);
    84     if (!$choices && !empty($field['Choices']))
    85     {
    86       $choices = array_keys($field['Choices']);
    87     }
    88 
    89     if ($field['FormType'] === 'checkbox')
    90     {
    91       $option['choices'] = $choices;
    92       $obj = new sfValidatorChoiceMany($option);
    93       return $obj;
    94     }
    95     if ($field['FormType'] === 'select' || $field['FormType'] === 'radio')
    96     {
    97       $obj = new sfValidatorChoice(array('choices' => $choices));
    98       return $obj;
    99     }
    100     if ($field['FormType'] === 'date')
    101     {
    102       $obj = new opValidatorDate();
    103       return $obj;
    104     }
    105 
    106     if ($field['ValueType'] === 'integer')
    107     {
    108         if (isset($field['ValueMin']))
    109         {
    110           $option['min'] = $field['ValueMin'];
    111         }
    112         if (isset($field['ValueMax']))
    113         {
    114           $option['max'] = $field['ValueMax'];
    115         }
    116     }
    117     else
    118     {
    119         if (isset($field['ValueMin']))
    120         {
    121           $option['min_length'] = $field['ValueMin'];
    122         }
    123         if (isset($field['ValueMax']))
    124         {
    125           $option['max_length'] = $field['ValueMax'];
    126         }
    127     }
    128 
    129     switch ($field['ValueType'])
    130     {
    131       case 'email':
    132         $obj = new sfValidatorEmail($option);
    133         break;
    134       case 'pc_email':
    135         $obj = new opValidatorPCEmail($option);
    136         break;
    137       case 'mobile_email':
    138         $obj = new sfValidatorMobileEmail($option);
    139         break;
    140       case 'integer':
    141         $obj = new sfValidatorInteger($option);
    142         break;
    143       case 'regexp':
    144         $option['pattern'] = $field['ValueRegexp'];
    145         $obj = new sfValidatorRegex($option);
    146         break;
    147       case 'url':
    148         $obj = new sfValidatorUrl($option);
    149         break;
    150       case 'password':
    151         $obj = new sfValidatorPassword($option);
    152         break;
    153       case 'pass':
    154         $obj = new sfValidatorPass($option);
    155         break;
    156       default:
    157         $obj = new sfValidatorString($option);
    158     }
    159 
    160     return $obj;
     42    return opFormItemGenerator::generateValidator($field, $choices);
    16143  }
    16244}
Note: See TracChangeset for help on using the changeset viewer.