Ejemplo n.º 1
0
 public function executeCreate(opMailRequest $request)
 {
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $topic = Doctrine::getTable('CommunityEvent')->find($request['id']);
     if (!$topic || !$topic->isCreatableCommunityEventComment($member->id)) {
         return sfView::NONE;
     }
     if ($topic->member_id !== $member->id) {
         $relation = Doctrine::getTable('MemberRelationship')->retrieveByFromAndTo($topic->member_id, $member->id);
         if ($relation && $relation->getIsAccessBlock()) {
             return sfView::NONE;
         }
     }
     $mailMessage = $request->getMailMessage();
     $validator = new opValidatorString(array('rtrim' => true));
     try {
         $body = $validator->clean($mailMessage->getContent());
     } catch (Exception $e) {
         return sfView::ERROR;
     }
     $topicComment = new CommunityEventComment();
     $topicComment->setCommunityEvent($topic);
     $topicComment->setMember($member);
     $topicComment->setBody($body);
     $topicComment->save();
     $num = (int) sfConfig::get('app_community_topic_comment_max_image_file_num', 3);
     $files = $this->getImageFiles($mailMessage, $num);
     $number = 0;
     foreach ($files as $file) {
         $number++;
         $image = new CommunityEventCommentImage();
         $image->setCommunityEventComment($topicComment);
         $image->setFile($file);
         $image->setNumber($number);
         $image->save();
     }
     opCommunityTopicToolkit::sendNotificationMail($topic->getCommunity(), $topic->getId(), 'event', $topicComment->getMember()->getName(), $topic->getName(), $topicComment->getBody());
     return sfView::NONE;
 }
 public function setup()
 {
     parent::setup();
     unset($this['id']);
     unset($this['community_event_id']);
     unset($this['member_id']);
     unset($this['number']);
     unset($this['created_at']);
     unset($this['updated_at']);
     if ('mobile_frontend' == sfConfig::get('sf_app')) {
         $label = sprintf('<font color="%s">*</font>', opColorConfig::get('core_color_22')) . sfContext::getInstance()->getI18N()->__('Comment');
     } else {
         $label = sfContext::getInstance()->getI18N()->__('Comment') . ' <strong>*</strong>';
     }
     $this->widgetSchema->setLabel('body', $label);
     $this->setValidator('body', new opValidatorString(array('rtrim' => true)));
     if (opMobileUserAgent::getInstance()->getMobile()->isNonMobile()) {
         $images = array();
         if (!$this->isNew()) {
             $images = $this->getObject()->getImages();
         }
         $max = (int) sfConfig::get('app_community_topic_max_image_file_num', 3);
         for ($i = 0; $i < $max; $i++) {
             $key = 'photo_' . ($i + 1);
             if (isset($images[$i])) {
                 $image = $images[$i];
             } else {
                 $image = new CommunityEventCommentImage();
                 $image->setCommunityEventComment($this->getObject());
                 $image->setNumber($i + 1);
             }
             $imageForm = new opCommunityTopicPluginImageForm($image);
             $imageForm->getWidgetSchema()->setFormFormatterName('list');
             $this->embedForm($key, $imageForm, '<ul id="community_event_comment_' . $key . '">%content%</ul>');
         }
     }
 }