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

Changeset 10030


Ignore:
Timestamp:
Jan 7, 2009, 9:50:04 PM (11 years ago)
Author:
ebihara
Message:

#3324:changed the SnsConfigForm? class to comformity the OpenPNEFormAutoGenerate class

Location:
OpenPNE3/trunk/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/lib/config/config/sns_config.yml

    r9916 r10030  
    11general:
    22  sns_name:
    3     caption:  "SNS名"
    4     type:     "input"
    5     default:  "MySNS"
    6     option:
    7       required: true
     3    Name:     "sns_name"
     4    Caption:  "SNS名"
     5    FormType: "input"
     6    ValueType: "text"
     7    Default:   "MySNS"
     8    IsRequired: true
    89
    910  admin_mail_address:
    10     caption: "管理者メールアドレス"
    11     type:    "input"
    12     default: "sns@example.com"
    13     option:
    14       required: true
     11    Name:      "admin_mail_address"
     12    Caption:   "管理者メールアドレス"
     13    FormType:  "input"
     14    ValueType:  "mail_address"
     15    Default:    "sns@example.com"
     16    IsRequired: true
     17
  • OpenPNE3/trunk/lib/form/SnsConfigForm.class.php

    r10025 r10030  
    1212 * SnsConfig form.
    1313 *
    14  * @package    form
    15  * @subpackage sns_config
     14 * @package    OpenPNE
     15 * @subpackage form
    1616 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    1717 */
    18 class SnsConfigForm extends sfForm
     18class SnsConfigForm extends OpenPNEFormAutoGenerate
    1919{
    2020  public function configure()
    2121  {
    22     $widgets = array();
    23     $validators = array();
    24     $labels = array();
    25     $defaults = array();
    26 
    2722    foreach (sfConfig::get('openpne_sns_config') as $key => $value)
    2823    {
    29       $widgets[$key] = $this->generateWidget($value);
    30       $validators[$key] = $this->generateValidator($value);
    31       $labels[$key] = $value['caption'];
    32       $defaults[$key] = opConfig::get($key);
     24      $this->setWidget($key, $this->generateWidget($value));
     25      $this->setValidator($key, $this->generateValidator($value));
     26      $this->widgetSchema->setLabel($key, $value['Caption']);
     27      $this->setDefault($key, opConfig::get($key));
    3328    }
    3429
    35     $this->setWidgets($widgets);
    36     $this->setValidators($validators);
    37     $this->widgetSchema->setLabels($labels);
    38     $this->setDefaults($defaults);
    39 
    4030    $this->widgetSchema->setNameFormat('sns_config[%s]');
    41   }
    42 
    43   public function generateWidget($config)
    44   {
    45     switch ($config['type']) {
    46       case 'select':
    47         $obj = new sfWidgetFormSelect(array('choices' => $this->generateChoices($config['choices_type'])));
    48         break;
    49       case 'selectMany':
    50         $obj = new sfWidgetFormSelectMany(array('choices' => $this->generateChoices($config['choices_type'])));
    51         break;
    52       case 'input':
    53       default:
    54         $obj = new sfWidgetFormInput();
    55     }
    56 
    57     return $obj;
    58   }
    59 
    60   public function generateValidator($config)
    61   {
    62     switch ($config['type']) {
    63       case 'select':
    64       case 'selectMany':
    65         $obj = new sfValidatorChoiceMany(array('choices' => $this->generateChoices($config['choices_type'])));
    66         break;
    67       case 'input':
    68       default:
    69         $obj = new sfValidatorString(array_merge($config['option'], array('trim' => true)));
    70     }
    71 
    72     return $obj;
    7331  }
    7432
     
    7634  {
    7735    $config = sfConfig::get('openpne_sns_config');
    78     foreach ($this->getValues() as $key => $value) {
     36    foreach ($this->getValues() as $key => $value)
     37    {
    7938      $snsConfig = SnsConfigPeer::retrieveByName($key);
    80       if (!$snsConfig) {
     39      if (!$snsConfig)
     40      {
    8141        $snsConfig = new SnsConfig();
    8242        $snsConfig->setName($key);
    8343      }
    84 
    8544      $snsConfig->setValue($value);
    8645      $snsConfig->save();
    8746    }
    8847  }
    89 
    90   public function generateChoices($mode)
    91   {
    92   }
    9348}
  • OpenPNE3/trunk/lib/model/SnsConfig.php

    r10003 r10030  
    2525  }
    2626
    27   public function getValue()
    28   {
    29     $value = parent::getValue();
    30 
    31     $config = $this->getConfig();
    32     if ($config && 'selectMany' === $config['type'])
    33     {
    34       $value = unserialize($value);
    35     }
    36 
    37     return $value;
    38   }
    39 
    40   public function setValue($v)
    41   {
    42     $config = $this->getConfig();
    43 
    44     if ($config && 'selectMany' === $config['type'])
    45     {
    46       $v = serialize($v);
    47     }
    48 
    49     parent::setValue($v);
    50   }
    51 
    5227  public function getConfig()
    5328  {
    5429    $name = $this->getName();
    55     if ($name && isset($this->snsConfigSettings[$name])) {
     30    if ($name && isset($this->snsConfigSettings[$name]))
     31    {
    5632      return $this->snsConfigSettings[$name];
    5733    }
Note: See TracChangeset for help on using the changeset viewer.