Beispiel #1
0
 public function executeCreate(opMailRequest $request)
 {
     if (!Doctrine::getTable('SnsConfig')->get('op_diary_plugin_use_email_post', true)) {
         return sfView::NONE;
     }
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $mailMessage = $request->getMailMessage();
     $title = $this->getSubject($mailMessage, '(no title)');
     $validator = new opValidatorString(array('rtrim' => true));
     try {
         $body = $validator->clean($mailMessage->getContent());
     } catch (Exception $e) {
         return sfView::ERROR;
     }
     $diary = new Diary();
     $diary->setMember($member);
     $diary->setTitle($title);
     $diary->setBody($body);
     $diary->setPublicFlag($this->getDefaultPublicFlag($member));
     $diaryImages = array();
     if (sfConfig::get('app_diary_is_upload_images', true)) {
         $num = (int) sfConfig::get('app_diary_max_image_file_num', 3);
         $files = $this->getImageFiles($mailMessage, $num);
         $i = 1;
         foreach ($files as $file) {
             $diaryImage = new DiaryImage();
             $diaryImage->setDiary($diary);
             $diaryImage->setFile($file);
             $diaryImage->setNumber($i++);
             $diaryImages[] = $diaryImage;
             $diary->setHasImages(true);
         }
     }
     $diary->save();
     foreach ($diaryImages as $diaryImage) {
         $diaryImage->save();
     }
     return sfView::NONE;
 }
 public function setup()
 {
     parent::setup();
     unset($this['id']);
     $this->useFields(array('title', 'body', 'public_flag'));
     $this->widgetSchema['title'] = new sfWidgetFormInput();
     $this->widgetSchema['body'] = new opWidgetFormRichTextareaOpenPNE();
     $this->validatorSchema['title'] = new opValidatorString(array('trim' => true));
     $this->validatorSchema['body'] = new opValidatorString(array('rtrim' => true));
     $this->widgetSchema['public_flag'] = new sfWidgetFormChoice(array('choices' => Doctrine::getTable('Diary')->getPublicFlags(), 'expanded' => true));
     $this->validatorSchema['public_flag'] = new sfValidatorChoice(array('choices' => array_keys(Doctrine::getTable('Diary')->getPublicFlags())));
     if ($this->isNew() && ($config = sfContext::getInstance()->getUser()->getMember()->getConfig(MemberConfigDiaryForm::PUBLIC_FLAG))) {
         $this->setDefault('public_flag', $config);
     }
     if ($this->getObject()->is_open) {
         $this->getObject()->setPublicFlag(DiaryTable::PUBLIC_FLAG_OPEN);
     }
     if (sfConfig::get('app_diary_is_upload_images', true)) {
         $images = array();
         if (!$this->isNew()) {
             $images = $this->getObject()->getDiaryImages();
         }
         $max = (int) sfConfig::get('app_diary_max_image_file_num', 3);
         for ($i = 1; $i <= $max; $i++) {
             $key = 'photo_' . $i;
             if (isset($images[$i])) {
                 $image = $images[$i];
             } else {
                 $image = new DiaryImage();
                 $image->setDiary($this->getObject());
                 $image->setNumber($i);
             }
             $imageForm = new DiaryImageForm($image);
             $imageForm->getWidgetSchema()->setFormFormatterName('list');
             $this->embedForm($key, $imageForm, '<ul id="diary_' . $key . '">%content%</ul>');
         }
     }
 }