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

Changeset 10980


Ignore:
Timestamp:
Mar 10, 2009, 6:01:01 PM (11 years ago)
Author:
ShogoKawahara
Message:

#3705:added ability to delete community image

Location:
OpenPNE3/trunk
Files:
1 added
4 edited

Legend:

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

    r10927 r10980  
    523523        <target>退会者データ</target>
    524524      </trans-unit>
     525      <trans-unit id="">
     526        <source>Remove the current photo</source>
     527        <target>この写真を削除する</target>
     528      </trans-unit>
    525529    </body>
    526530  </file>
  • OpenPNE3/trunk/lib/action/sfOpenPNECommunityAction.class.php

    r10939 r10980  
    5353
    5454    $this->community = CommunityPeer::retrieveByPk($this->id);
     55    if (!$this->community)
     56    {
     57      $this->community = new Community();
     58    }
     59
    5560
    5661    $this->communityForm       = new CommunityForm($this->community);
    5762    $this->communityConfigForm = new CommunityConfigForm(array(), array('community' => $this->community));
    58     $this->communityFileForm   = new CommunityFileForm();
     63    $this->communityFileForm   = new CommunityFileForm(array(), array('community' => $this->community));
    5964
    6065    if ($request->isMethod('post'))
     
    6772      if ($this->communityForm->isValid() && $this->communityConfigForm->isValid() && $this->communityFileForm->isValid())
    6873      {
    69         $community = $this->communityForm->save();
    70         $this->communityConfigForm->save($community);
    71         $this->communityFileForm->save($community);
    72         $this->redirect('community/home?id='.$community->getId());
     74        $this->communityForm->save();
     75        $this->communityConfigForm->save();
     76        $this->communityFileForm->save();
     77
     78        $this->redirect('community/home?id='.$this->community->getId());
    7379      }
    7480    }
  • OpenPNE3/trunk/lib/form/CommunityConfigForm.class.php

    r10939 r10980  
    5050    if (!($community instanceof Community))
    5151    {
    52       if (!$this->community)
    53       {
    54         $community = new Community();
    55       }
    56       else
    57       {
    58         return;
    59       }
     52      $community = new Community();
    6053    }
    6154    $this->community = $community;
     
    10093  }
    10194
    102   public function save(Community $community)
     95  public function save()
    10396  {
    10497    foreach ($this->getValues() as $key => $value)
     
    108101      {
    109102        $config = new CommunityConfig();
    110         $config->setCommunity($community);
     103        $config->setCommunity($this->community);
    111104        $config->setName($key);
    112105      }
  • OpenPNE3/trunk/lib/form/CommunityFileForm.class.php

    r10939 r10980  
    1919class CommunityFileForm extends sfForm
    2020{
     21  protected
     22    $community;
     23
    2124  public function __construct($defaults = array(), $options = array(), $CSRFSecret = null)
    2225  {
     
    2629  public function configure()
    2730  {
    28     $this->setWidget('file', new sfWidgetFormInputFile());
     31    $this->setCommunity($this->getOption('community'));
     32
     33    $options = array(
     34      'file_src'     => '',
     35      'is_image'     => true,
     36      'with_delete'  => true,
     37      'delete_label' => sfContext::getInstance()->getI18N()->__('Remove the current photo')
     38    );
     39
     40    if (!$this->community->isNew() && $this->community->getFileId())
     41    {
     42      sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
     43      $options['edit_mode'] = true;
     44      $options['template'] = get_partial('default/formEditImage', array('image' => $this->community));
     45      $this->setValidator('file_delete', new sfValidatorBoolean(array('required' => false)));
     46    }
     47    else
     48    {
     49      $options['edit_mode'] = false;
     50    }
     51
     52    $this->setWidget('file', new sfWidgetFormInputFileEditable($options, array('size' => 40)));
    2953    $this->setValidator('file', new opValidatorImageFile(array('required' => false)));
    3054
     
    3458  }
    3559
    36   public function save(Community $community)
     60  public function setCommunity($community)
    3761  {
    38     if (!$this->getValue('file'))
     62    if (!($community instanceof Community))
    3963    {
    40       return false;
     64      $community = new Community();
     65    }
     66    $this->community = $community;
     67  }
     68
     69  public function save()
     70  {
     71    if ($this->getValue('file'))
     72    {
     73      if ($this->community->getFile())
     74      {
     75        $this->community->getFile()->delete();
     76      }
     77
     78      $file = new File();
     79      $file->setFromValidatedFile($this->getValue('file'));
     80      $file->setName('c_'.$this->community->getId().'_'.$file->getName());
     81
     82      $this->community->setFile($file);
     83    }
     84    elseif ($this->getValue('file_delete'))
     85    {
     86      $this->community->getFile()->delete();
     87      $this->community->setFile(null);
     88    }
     89    else
     90    {
     91      return;
    4192    }
    4293
    43     if ($community->getFile())
    44     {
    45       $community->getFile()->delete();
    46     }
    47 
    48     $file = new File();
    49     $file->setFromValidatedFile($this->getValue('file'));
    50     $file->setName('c_'.$community->getId().'_'.$file->getName());
    51 
    52     $community->setFile($file);
    53 
    54     $community->save();
     94    $this->community->save();
    5595  }
    5696}
Note: See TracChangeset for help on using the changeset viewer.