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

Changeset 10939


Ignore:
Timestamp:
Mar 3, 2009, 5:10:04 PM (11 years ago)
Author:
ShogoKawahara
Message:

#3604:fixed CommunityForm? doesn't hold the parameter in form when invalid

Location:
OpenPNE3/trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/trunk/apps/mobile_frontend/i18n/messages.ja.xml

    r10900 r10939  
    108108      </trans-unit>
    109109      <trans-unit id="">
     110        <source>Create community</source>
     111        <target>コミュニティの作成</target>
     112      </trans-unit>
     113      <trans-unit id="">
    110114        <source>Join community</source>
    111115        <target>コミュニティに参加する</target>
  • OpenPNE3/trunk/apps/mobile_frontend/modules/community/templates/editSuccess.php

    r10304 r10939  
    1 <?php op_mobile_page_title($community->getName(), __('Edit community')) ?>
     1<?php
     2$subtitle = null;
     3$url = 'community/edit';
     4if($communityForm->isNew())
     5{
     6  $title = __('Create community');
     7}
     8else
     9{
     10  $title = __('Edit community');
     11  $subtitle = $community->getName();
     12  $url .= '?id='.$community->getId();
     13}
     14?>
    215
    3 <?php if ($form->isNew()) : ?>
    4 <form action="<?php echo url_for('community/edit') ?>" method="post">
    5 <?php else : ?>
    6 <form action="<?php echo url_for('community/edit?id=' . $community->getId()) ?>" method="post">
    7 <?php endif; ?>
     16<?php op_mobile_page_title($title, $subtitle) ?>
     17
     18<form action="<?php echo url_for($url) ?>" method="post">
    819<table>
    9 <?php echo $form ?>
     20<?php echo $communityForm ?>
     21<?php echo $communityConfigForm ?>
    1022<tr>
    1123<td colspan="2"><input type="submit" value="<?php echo __('Save') ?>" /></td>
  • OpenPNE3/trunk/apps/pc_frontend/modules/community/templates/editSuccess.php

    r10578 r10939  
    44);
    55
    6 if ($form->isNew())
     6if ($communityForm->isNew())
    77{
    88  $options['title'] = __('Create a new community');
     
    1515}
    1616
    17 op_include_form('formCommunity', $form, $options);
     17op_include_form('formCommunity', array($communityForm, $communityConfigForm, $communityFileForm), $options);
    1818?>
  • OpenPNE3/trunk/lib/action/sfOpenPNECommunityAction.class.php

    r10908 r10939  
    5353
    5454    $this->community = CommunityPeer::retrieveByPk($this->id);
    55     $this->form = new CommunityForm($this->community);
     55
     56    $this->communityForm       = new CommunityForm($this->community);
     57    $this->communityConfigForm = new CommunityConfigForm(array(), array('community' => $this->community));
     58    $this->communityFileForm   = new CommunityFileForm();
    5659
    5760    if ($request->isMethod('post'))
     
    5962      $params = $request->getParameter('community');
    6063      $params['id'] = $this->id;
    61       $this->form->bind($params, $request->getFiles('community'));
    62       if ($this->form->isValid())
     64      $this->communityForm->bind($params);
     65      $this->communityConfigForm->bind($request->getParameter('community_config'));
     66      $this->communityFileForm->bind($request->getParameter('community_file'), $request->getFiles('community_file'));
     67      if ($this->communityForm->isValid() && $this->communityConfigForm->isValid() && $this->communityFileForm->isValid())
    6368      {
    64         $community = $this->form->save();
    65 
     69        $community = $this->communityForm->save();
     70        $this->communityConfigForm->save($community);
     71        $this->communityFileForm->save($community);
    6672        $this->redirect('community/home?id='.$community->getId());
    6773      }
  • OpenPNE3/trunk/lib/form/CommunityConfigForm.class.php

    r10173 r10939  
    2323    $community,
    2424    $isNew = false,
    25     $isAutoGenerate = true,
    26     $fieldName = 'config[%s]';
     25    $isAutoGenerate = true;
    2726
    2827  public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
     
    4746  }
    4847
    49   public function setCommunity(Community $community)
     48  public function setCommunity($community)
    5049  {
     50    if (!($community instanceof Community))
     51    {
     52      if (!$this->community)
     53      {
     54        $community = new Community();
     55      }
     56      else
     57      {
     58        return;
     59      }
     60    }
    5161    $this->community = $community;
    5262  }
     
    6373  {
    6474    $config = $this->configSettings[$name];
    65     $this->widgetSchema[sprintf($this->fieldName, $name)] = opFormItemGenerator::generateWidget($config);
    66     $this->widgetSchema->setLabel(sprintf($this->fieldName, $name), $config['Caption']);
     75    $this->widgetSchema[$name] = opFormItemGenerator::generateWidget($config);
     76    $this->widgetSchema->setLabel($name, $config['Caption']);
    6777    $communityConfig = CommunityConfigPeer::retrieveByNameAndCommunityId($name, $this->community->getId());
    6878    if ($communityConfig)
    6979    {
    70       $this->setDefault(sprintf($this->fieldName, $name), $communityConfig->getValue());
     80      $this->setDefault($name, $communityConfig->getValue());
    7181    }
    72     $this->validatorSchema[sprintf($this->fieldName, $name)] = opFormItemGenerator::generateValidator($config);
     82    $this->validatorSchema[$name] = opFormItemGenerator::generateValidator($config);
    7383  }
    7484
     
    90100  }
    91101
    92   public function save()
     102  public function save(Community $community)
    93103  {
    94104    foreach ($this->getValues() as $key => $value)
    95105    {
    96       $key = $this->getUnformattedFieldName($key);
    97106      $config = CommunityConfigPeer::retrieveByNameAndCommunityId($key, $this->community->getId());
    98107      if (!$config)
    99108      {
    100109        $config = new CommunityConfig();
    101         $config->setCommunity($this->community);
     110        $config->setCommunity($community);
    102111        $config->setName($key);
    103112      }
     
    106115    }
    107116  }
    108 
    109   public function getUnformattedFieldName($field)
    110   {
    111     $regexp = '/'.str_replace(array('%s'), array('(\w+)'), preg_quote($this->fieldName)).'/';
    112     $matches = array();
    113     preg_match($regexp, $field, $matches);
    114     array_shift($matches);
    115 
    116     return implode('', $matches);
    117   }
    118117}
  • OpenPNE3/trunk/lib/form/CommunityForm.class.php

    r10926 r10939  
    2727    $this->setValidator('name', new sfValidatorString(array('max_length' => 64, 'trim' => true)));
    2828
    29     $this->setConfigForm();
    30 
    31     $this->setWidget('file', new sfWidgetFormInputFile());
    32     $this->setValidator('file', new opValidatorImageFile(array('required' => false)));
    33 
    34     $this->widgetSchema->setLabel('file', 'Photo');
    35 
    3629    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form_community');
    37   }
    38 
    39   public function save($con = null)
    40   {
    41     $community = parent::save($con);
    42     $oldFile = $community->getFile();
    43     $this->saveImageFile($community);
    44     $community->save();
    45 
    46     if ($oldFile && $oldFile->getName() !== $community->getFile()->getName())
    47     {
    48       $oldFile->delete();
    49     }
    50 
    51     return $community;
    5230  }
    5331
     
    5735
    5836    $this->saveMember($object);
    59     if ($this->configForm->isValid())
    60     {
    61       $this->configForm->save();
    62     }
    6337
    6438    return $object;
    65   }
    66 
    67   public function bind(array $taintedValues = null, array $taintedFiles = null)
    68   {
    69     parent::bind($taintedValues, $taintedFiles);
    70 
    71     $configs = $this->getValue('config');
    72     if (!$configs)
    73     {
    74       $configs = array();
    75     }
    76 
    77     $params = array();
    78     foreach ($configs as $key => $value)
    79     {
    80       $params['config['.$key.']'] = $value;
    81     }
    82 
    83     $this->configForm->bind($params);
    84     foreach ($this->configForm->getErrorSchema() as $key => $value)
    85     {
    86       $this->getErrorSchema()->addError($value, $key);
    87     }
    88   }
    89 
    90   public function setConfigForm()
    91   {
    92     $this->configForm = new CommunityConfigForm(array(), array('community' => $this->getObject()));
    93     $this->mergeForm($this->configForm);
    94     foreach ($this->configForm->getValidatorSchema()->getFields() as $field => $validator)
    95     {
    96       $this->validatorSchema[$field] = new sfValidatorPass();
    97     }
    98     $this->validatorSchema['config'] = new sfValidatorPass();
    9939  }
    10040
     
    10949    }
    11050  }
    111 
    112   public function saveImageFile(Community $community)
    113   {
    114     if (!$this->getValue('file'))
    115     {
    116       return false;
    117     }
    118 
    119     $file = new File();
    120     $file->setFromValidatedFile($this->getValue('file'));
    121     $file->setName('c_'.$community->getId().'_'.$file->getName());
    122     $community->setFile($file);
    123 
    124     return true;
    125   }
    12651}
Note: See TracChangeset for help on using the changeset viewer.