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

source: OpenPNE3/trunk/lib/form/MemberImageForm.class.php @ 10582

Last change on this file since 10582 was 10582, checked in by ebihara, 12 years ago

#3544:changed the execution filter catches opRuntimeException now

File size: 1.4 KB
Line 
1<?php
2
3/**
4 * This file is part of the OpenPNE package.
5 * (c) OpenPNE Project (http://www.openpne.jp/)
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file and the NOTICE file that were distributed with this source code.
9 */
10
11/**
12 * MemberImageForm
13 *
14 * @package    OpenPNE
15 * @subpackage form
16 * @author     Kousuke Ebihara <ebihara@tejimaya.com>
17 */
18class MemberImageForm extends sfForm
19{
20  public function configure()
21  {
22    $this->member = $this->getOption('member');
23    $this->setWidget('file', new sfWidgetFormInputFile());
24    $this->setValidator('file', new opValidatorImageFile());
25    $this->widgetSchema->setNameFormat('member_image[%s]');
26  }
27
28  public function bindAndSave(array $taintedValues = null, array $taintedFiles = null)
29  {
30    $this->bind($taintedValues, $taintedFiles);
31    if ($this->isValid())
32    {
33      return $this->save();
34    }
35    return false;
36  }
37
38  public function save()
39  {
40    $count = $this->member->countMemberImages();
41    if ($count >= 3)
42    {
43      throw new opRuntimeException('Cannot add an image any more.');
44    }
45
46    $file = new File();
47    $file->setFromValidatedFile($this->getValue('file'));
48    $file->setName('m_'.$this->member->getId().'_'.$file->getName());
49
50    $memberImage = new MemberImage();
51    $memberImage->setMember($this->member);
52    $memberImage->setFile($file);
53    if (!$count)
54    {
55      $memberImage->setIsPrimary(true);
56    }
57    $memberImage->save();
58  }
59}
Note: See TracBrowser for help on using the repository browser.