public function executePost(sfWebRequest $request) { $this->forward400If('' === (string) $request['body'], 'body parameter is not specified.'); $this->forward400If('' === (string) $request['toMember'], 'toMember parameter is not specified.'); $body = $request['body']; $this->myMember = $this->member; $toMember = Doctrine::getTable('Member')->find($request['toMember']); $this->forward400Unless($toMember, 'invalid member'); $relation = Doctrine_Core::getTable('MemberRelationship')->retrieveByFromAndTo($toMember->getId(), $this->member->getId()); $this->forward400If($relation && $relation->getIsAccessBlock(), 'Cannot send the message.'); $message = Doctrine::getTable('SendMessageData')->sendMessage($toMember, SendMessageData::SMARTPHONE_SUBJECT, $body, array()); $file = $request->getFiles('message_image'); try { $validator = new opValidatorImageFile(array('required' => false)); $clean = $validator->clean($file); if (is_null($clean)) { // if empty. return sfView::SUCCESS; } } catch (Exception $e) { $this->logMessage($e->getMessage()); $this->forward400('This image file is invalid.'); } $file = new File(); $file->setFromValidatedFile($clean); $file->save(); $messageFile = new MessageFile(); $messageFile->setMessageId($message->getId()); $messageFile->setFile($file); $messageFile->save(); }
public function setup() { parent::setup(); unset($this['created_at'], $this['updated_at'], $this['foreign_id']); unset($this->widgetSchema['member_id'], $this->widgetSchema['is_deleted'], $this->widgetSchema['is_send'], $this->widgetSchema['message_type_id']); $this->widgetSchema['subject'] = new sfWidgetFormInput(); $this->widgetSchema['thread_message_id'] = new sfWidgetFormInputHidden(); $this->widgetSchema['return_message_id'] = new sfWidgetFormInputHidden(); $this->validatorSchema['subject']->setOption('trim', true); $this->validatorSchema['subject']->setOption('required', true); $this->validatorSchema['body']->setOption('trim', true); $this->validatorSchema['body']->setOption('required', true); $this->widgetSchema->setNameFormat('message[%s]'); if (sfConfig::get('app_message_is_upload_images', true)) { $images = array(); if (!$this->isNew()) { $images = $this->getObject()->getMessageFile(); } $max = (int) sfConfig::get('app_message_max_image_file_num', 3); for ($i = 1; $i <= $max; $i++) { $key = 'image' . $i; if (isset($images[$i - 1])) { $image = $images[$i - 1]; } else { $image = new MessageFile(); $image->setSendMessageData($this->getObject()); } $imageForm = new MessageFileForm($image); $imageForm->getWidgetSchema()->setFormFormatterName('list'); $this->embedForm($key, $imageForm, '<ul id="message_' . $key . '">%content%</ul>'); } } }
/** * Load all messages */ public static function loadAllMessages() { global $_path, $MMORPG_Language; $files = glob($_path . 'message*.php'); foreach ($files as $file) { $base = basename($file); if ($base == "message.php") { $messageFile = new MessageFile(); $messageFile->load($file); self::$messages['default'] = $messageFile; } else { $phpPos = strpos($base, '.php'); $language = substr($base, 8, $phpPos - 8); $messageFile = new MessageFile(); $messageFile->load($file); self::$messages[$language] = $messageFile; } } }