/** * 表示に必要なデータを取得し設定する * * @access private * @param array $input_data 入力データ * @return array * @author ida */ private function setupData($data) { $replace_data = array(); $replace_data['user'] = $this->user; $mail_magazine_type = $data['mail_magazine_type']; switch ($mail_magazine_type) { case \Model_Mail_Magazine::MAIL_MAGAZINE_TYPE_ALL: break; case \Model_Mail_Magazine::MAIL_MAGAZINE_TYPE_REQUEST: $this->set('prefectures', \Config::get('master.prefectures'), false); break; case \Model_Mail_Magazine::MAIL_MAGAZINE_TYPE_RESEVED_ENTRY: $fleamarket_id = $data['reserved_fleamarket_id']; $fleamarket = \Model_Fleamarket::find($fleamarket_id); $replace_data['fleamarket'] = $fleamarket; $this->set('fleamarket', $fleamarket, false); break; case \Model_Mail_Magazine::MAIL_MAGAZINE_TYPE_WAITING_ENTRY: $fleamarket_id = $data['waiting_fleamarket_id']; $fleamarket = \Model_Fleamarket::find($fleamarket_id); $replace_data['fleamarket'] = $fleamarket; $this->set('fleamarket', $fleamarket, false); break; } $users = \Model_Mail_Magazine_User::findListByMailMagazineId($this->mail_magazine_id, null, null); $this->set('users', $users, false); $body = $data['body']; $pattern = \Model_Mail_Magazine::getPatternParameter($mail_magazine_type); list($pattern, $replacement) = \Model_Mail_Magazine::createReplaceParameter($body, $pattern, $replace_data); $body = \Model_Mail_Magazine::replaceByParam($body, $pattern, $replacement); $this->set('body', $body, false); $this->set('input_data', $data, false); }
/** * 表示に必要なデータを取得し設定する * * @access private * @param object $view_model ビューモデル * @param array $input_data 入力データ * @return array * @author ida */ private function setupData($view_model, $data) { $replace_data = array(); $replace_data['user'] = $this->administrator; $mail_magazine_type = $data['mail_magazine_type']; switch ($mail_magazine_type) { case \Model_Mail_Magazine::MAIL_MAGAZINE_TYPE_ALL: $users = \Model_User::getActiveUsers(); break; case \Model_Mail_Magazine::MAIL_MAGAZINE_TYPE_REQUEST: $users = \Model_User::getMailMagazineUserBy($data['prefecture_id'], $data['organization_flag']); $view_model->set('prefectures', \Config::get('master.prefectures'), false); break; case \Model_Mail_Magazine::MAIL_MAGAZINE_TYPE_RESEVED_ENTRY: $fleamarket_id = $data['reserved_fleamarket_id']; $users = \Model_Entry::getEntriesByFleamarketId($fleamarket_id, \Model_Entry::ENTRY_STATUS_RESERVED); $fleamarket = \Model_Fleamarket::find($fleamarket_id); $replace_data['fleamarket'] = $fleamarket; $view_model->set('fleamarket', $fleamarket, false); break; case \Model_Mail_Magazine::MAIL_MAGAZINE_TYPE_WAITING_ENTRY: $fleamarket_id = $data['waiting_fleamarket_id']; $users = \Model_Entry::getEntriesByFleamarketId($fleamarket_id, \Model_Entry::ENTRY_STATUS_WAITING); $fleamarket = \Model_Fleamarket::find($fleamarket_id); $replace_data['fleamarket'] = $fleamarket; $view_model->set('fleamarket', $fleamarket, false); break; } $view_model->set('users', $users, false); $body = $data['body']; $pattern = \Model_Mail_Magazine::getPatternParameter($mail_magazine_type); list($pattern, $replacement) = \Model_Mail_Magazine::createReplaceParameter($body, $pattern, $replace_data); $body = \Model_Mail_Magazine::replaceByParam($body, $pattern, $replacement); $view_model->set('body', $body, false); $view_model->set('input_data', $data, false); return array($view_model, $replace_data); }
/** * メール送信処理 * * @access public * @param array $mail_magazine_user 送信先ユーザ情報 * @param array $mail_magazine メルマガ情報 * @param array $replace_data 本文リプレイス情報 * @return bool/string * @author ida */ private function send($mail_magazine_user, $mail_magazine, $replace_data) { if (empty($mail_magazine_user->email)) { throw new \Exception('email is not registered'); } if ($mail_magazine_user->email === '*****@*****.**') { throw new \Exception('email is anonymous@'); } $mail_magazine_type = $mail_magazine['mail_magazine_type']; $from_name = $mail_magazine['from_name']; $from_email = $mail_magazine['from_email']; $to = $mail_magazine_user->email; $subject = \Model_Mail_Magazine::convertEncoding($mail_magazine['subject']); $body = $mail_magazine['body']; $replace_data['user'] = $mail_magazine_user; $pattern = \Model_Mail_Magazine::getPatternParameter($mail_magazine_type); list($pattern, $replacement) = \Model_Mail_Magazine::createReplaceParameter($body, $pattern, $replace_data); $body = \Model_Mail_Magazine::replaceByParam($body, $pattern, $replacement); $result = \Model_Mail_Magazine::sendMail($from_name, $from_email, $to, $subject, $body); if (true === $result) { $result = \Model_Mail_Magazine_User::SEND_STATUS_NORMAL_END; } elseif (false === $send_result) { $result = \Model_Mail_Magazine_User::SEND_STATUS_UNSENT; } return $result; }