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

Changeset 10090


Ignore:
Timestamp:
Jan 11, 2009, 6:14:13 PM (11 years ago)
Author:
ogawa
Message:

#3269:fixed diary_image not being able to remove

Location:
OpenPNE3/plugins/opDiaryPlugin/trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • OpenPNE3/plugins/opDiaryPlugin/trunk/config/schema.yml

    r10068 r10090  
    1313    diary_id: { type: integer, required: true, foreignTable: diary, foreignReference: id, onDelete: cascade }
    1414    file_id: { type: integer, required: true, foreignTable: file, foreignReference: id, onDelete: cascade }
     15    number: { type: integer, required: true }
     16    _uniques:
     17      diary_id_number: [diary_id, number]
    1518  diary_comment:
    1619    id: ~
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/form/DiaryForm.class.php

    r10011 r10090  
    3737    if (sfConfig::get('app_diary_is_upload_images', true))
    3838    {
     39      if (!$this->isNew())
     40      {
     41        sfContext::getInstance()->getConfiguration()->loadHelpers('Partial');
     42        $images = $this->getObject()->getDiaryImages();
     43      }
     44
     45      $options = array(
     46        'is_image'     => true,
     47        'with_delete'  => true,
     48        'delete_label' => 'remove the current photo',
     49      );
     50
    3951      $max = (int)sfConfig::get('app_diary_max_image_file_num', 3);
    4052      for ($i = 1; $i <= $max; $i++)
    4153      {
    4254        $key = 'photo_'.$i;
    43         $this->setWidget($key, new sfWidgetFormInputFile());
     55
     56        if (!$this->isNew() && !empty($images[$i]))
     57        {
     58          $options['edit_mode'] = true;
     59          $options['file_src'] = '';
     60          $options['template'] = get_partial('diary/formEditImage', array('image' => $images[$i]));
     61          $this->setValidator($key.'_delete', new sfValidatorBoolean(array('required' => false)));
     62        }
     63        else
     64        {
     65          $options['edit_mode'] = false;
     66        }
     67
     68        $this->setWidget($key, new sfWidgetFormInputFileEditable($options));
    4469        $this->setValidator($key, new opValidatorImageFile(array('required' => false)));
    4570      }
     
    5176    $diary = parent::save();
    5277
     78    if (!$this->isNew())
     79    {
     80      $images = $this->getObject()->getDiaryImages();
     81    }
     82
    5383    if (sfConfig::get('app_diary_is_upload_images', true))
    5484    {
     
    5787      {
    5888        $key = 'photo_'.$i;
     89
     90        if ($this->getValue($key.'_delete'))
     91        {
     92          $images[$i]->delete();
     93        }
     94
    5995        if ($this->getValue($key))
    6096        {
     97          if ($images[$i] && !$images[$i]->isDeleted())
     98          {
     99            $images[$i]->delete();
     100          }
     101
    61102          $file = new File();
    62103          $file->setFromValidatedFile($this->getValue($key));
     
    66107          $image->setDiary($diary);
    67108          $image->setFile($file);
     109          $image->setNumber($i);
    68110          $image->save();
    69111        }
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/model/Diary.php

    r10074 r10090  
    6565    return $this->next;
    6666  }
     67
     68  public function getDiaryImages($criteria = null, PropelPDO $con = null)
     69  {
     70    if (is_null($criteria))
     71    {
     72      $criteria = new Criteria();
     73      $criteria->addAscendingOrderByColumn(DiaryImagePeer::NUMBER);
     74    }
     75
     76    $images = parent::getDiaryImages($criteria, $con);
     77
     78    $result = array();
     79    foreach ($images as $image)
     80    {
     81      $result[$image->getNumber()] = $image;
     82    }
     83
     84    return $result;
     85  }
    6786}
  • OpenPNE3/plugins/opDiaryPlugin/trunk/lib/model/DiaryImage.php

    r10011 r10090  
    1111class DiaryImage extends BaseDiaryImage
    1212{
     13  public function delete(PropelPDO $con = null)
     14  {
     15    $this->getFile()->delete();
     16
     17    parent::delete($con);
     18  }
    1319}
Note: See TracChangeset for help on using the changeset viewer.