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

Ignore:
Timestamp:
Dec 19, 2008, 9:17:33 PM (14 years ago)
Author:
ebihara
Message:

#3187:added a communityJoinListBox widget

File:
1 edited

Legend:

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

    r9589 r9599  
    44 * Community form.
    55 *
    6  * @package    form
    7  * @subpackage community
    8  * @version    SVN: $Id: sfPropelFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $
     6 * @package    OpenPNE
     7 * @subpackage form
     8 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
    99 */
    1010class CommunityForm extends BaseCommunityForm
     
    1212  public function configure()
    1313  {
    14     unset($this['created_at'], $this['updated_at']);
     14    $this->setWidget('file', new sfWidgetFormInputFile());
     15
     16    unset($this['created_at'], $this['updated_at'], $this['file_id']);
    1517
    1618    $this->setValidator('config', new sfValidatorPass());
     19    $this->setValidator('file', new opValidatorImageFile(array('required' => false)));
    1720  }
    1821
     
    2023  {
    2124    $community = parent::save($con);
    22     $tainted_values = $this->getTaintedValues();
    23     $community_config_array = $tainted_values['config'];
     25    $oldFile = $community->getFile();
     26    $this->saveImageFile($community);
     27    $community->save();
    2428
    25     if ($this->isNew()) {
    26       $communityMember = new CommunityMember();
    27       $communityMember->setPosition('admin');
    28       $communityMember->setMemberId(sfContext::getInstance()->getUser()->getMemberId());
    29       $communityMember->setCommunityId($community->getId());
    30       $communityMember->save();
    31 
    32       foreach ($community_config_array as $community_config_key => $community_config_value)
    33       {
    34         $community_config = new CommunityConfig();
    35         $community_config->setCommunityId($community->getId());
    36         $community_config->setName($community_config_key);
    37         $community_config->setValue($community_config_value);
    38         $community_config->save();
    39       }
    40     }
    41     else
     29    if ($oldFile && $oldFile->getName() !== $community->getFile()->getName())
    4230    {
    43       foreach ($community_config_array as $community_config_key => $community_config_value)
    44       {
    45         $community_config = CommunityConfigPeer::retrieveByNameAndCommunityId($community_config_key, $community->getId());
    46         $community_config->setValue($community_config_value);
    47         $community_config->save();
    48       }
     31      $oldFile->delete();
    4932    }
    5033
    5134    return $community;
    5235  }
     36
     37  public function updateObject($values = null)
     38  {
     39    $object = parent::updateObject($values);
     40
     41    $this->saveMember($object);
     42    $this->saveConfig($object);
     43
     44    return $object;
     45  }
     46
     47  public function saveConfig(Community $community)
     48  {
     49    $configs = $this->getValue('config');
     50    if (!$configs)
     51    {
     52      return false;
     53    }
     54
     55    foreach ($configs as $key => $value)
     56    {
     57      $config = CommunityConfigPeer::retrieveByNameAndCommunityId($key, $community->getId());
     58      if (!$config)
     59      {
     60        $config->setCommunity($community);
     61        $config->setName($key);
     62      }
     63      $config->setValue($value);
     64    }
     65  }
     66
     67  public function saveMember(Community $community)
     68  {
     69    if ($this->isNew())
     70    {
     71      $member = new CommunityMember();
     72      $member->setPosition('admin');
     73      $member->setMemberId(sfContext::getInstance()->getUser()->getMemberId());
     74      $member->setCommunity($community);
     75    }
     76  }
     77
     78  public function saveImageFile(Community $community)
     79  {
     80    if (!$this->getValue('file'))
     81    {
     82      return false;
     83    }
     84
     85    $file = new File();
     86    $file->setFromValidatedFile($this->getValue('file'));
     87    $file->setName('c_'.$community->getId().'_'.$file->getName());
     88    $community->setFile($file);
     89
     90    return true;
     91  }
    5392}
Note: See TracChangeset for help on using the changeset viewer.