nanasess /
ec-cube
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /* |
||
| 3 | * This file is part of EC-CUBE |
||
| 4 | * |
||
| 5 | * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
||
| 6 | * |
||
| 7 | * http://www.lockon.co.jp/ |
||
| 8 | * |
||
| 9 | * This program is free software; you can redistribute it and/or |
||
| 10 | * modify it under the terms of the GNU General Public License |
||
| 11 | * as published by the Free Software Foundation; either version 2 |
||
| 12 | * of the License, or (at your option) any later version. |
||
| 13 | * |
||
| 14 | * This program is distributed in the hope that it will be useful, |
||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 17 | * GNU General Public License for more details. |
||
| 18 | * |
||
| 19 | * You should have received a copy of the GNU General Public License |
||
| 20 | * along with this program; if not, write to the Free Software |
||
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
||
| 22 | */ |
||
| 23 | |||
| 24 | |||
| 25 | namespace Eccube\Controller\Admin\Order; |
||
| 26 | |||
| 27 | use Eccube\Application; |
||
| 28 | use Eccube\Entity\MailHistory; |
||
| 29 | use Eccube\Event\EccubeEvents; |
||
| 30 | use Eccube\Event\EventArgs; |
||
| 31 | use Symfony\Component\HttpFoundation\Request; |
||
| 32 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
||
| 33 | |||
| 34 | 3 | class MailController |
|
| 35 | { |
||
| 36 | public function index(Application $app, Request $request, $id) |
||
| 37 | { |
||
| 38 | $Order = $app['eccube.repository.order']->find($id); |
||
| 39 | |||
| 40 | if (is_null($Order)) { |
||
| 41 | throw new NotFoundHttpException('order not found.'); |
||
| 42 | } |
||
| 43 | |||
| 44 | $MailHistories = $app['eccube.repository.mail_history']->findBy(array('Order' => $id)); |
||
| 45 | |||
| 46 | $builder = $app['form.factory']->createBuilder('mail'); |
||
| 47 | |||
| 48 | $event = new EventArgs( |
||
| 49 | array( |
||
| 50 | 'builder' => $builder, |
||
| 51 | 'Order' => $Order, |
||
| 52 | 'MailHistories' => $MailHistories, |
||
| 53 | ), |
||
| 54 | 2 | $request |
|
| 55 | ); |
||
| 56 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_INITIALIZE, $event); |
||
| 57 | |||
| 58 | $form = $builder->getForm(); |
||
| 59 | |||
| 60 | if ('POST' === $request->getMethod()) { |
||
| 61 | |||
| 62 | $form->handleRequest($request); |
||
| 63 | |||
| 64 | $mode = $request->get('mode'); |
||
| 65 | |||
| 66 | 2 | // テンプレート変更の場合は. バリデーション前に内容差し替え. |
|
| 67 | if ($mode == 'change') { |
||
| 68 | View Code Duplication | if ($form->get('template')->isValid()) { |
|
| 69 | /** @var $data \Eccube\Entity\MailTemplate */ |
||
| 70 | $MailTemplate = $form->get('template')->getData(); |
||
| 71 | $form = $builder->getForm(); |
||
| 72 | $event = new EventArgs( |
||
| 73 | array( |
||
| 74 | 'form' => $form, |
||
| 75 | 'Order' => $Order, |
||
| 76 | 'MailTemplate' => $MailTemplate, |
||
| 77 | ), |
||
| 78 | $request |
||
| 79 | ); |
||
| 80 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_CHANGE, $event); |
||
| 81 | $form->get('template')->setData($MailTemplate); |
||
| 82 | 1 | $form->get('subject')->setData($MailTemplate->getSubject()); |
|
| 83 | 1 | $form->get('header')->setData($MailTemplate->getHeader()); |
|
| 84 | $form->get('footer')->setData($MailTemplate->getFooter()); |
||
| 85 | } |
||
| 86 | } else if ($form->isValid()) { |
||
| 87 | switch ($mode) { |
||
| 88 | 1 | case 'confirm': |
|
| 89 | // フォームをFreezeして再生成. |
||
| 90 | |||
| 91 | $builder->setAttribute('freeze', true); |
||
| 92 | $builder->setAttribute('freeze_display_text', true); |
||
| 93 | |||
| 94 | $data = $form->getData(); |
||
| 95 | $body = $this->createBody($app, $data['header'], $data['footer'], $Order); |
||
| 96 | |||
| 97 | $MailTemplate = $form->get('template')->getData(); |
||
| 98 | |||
| 99 | $form = $builder->getForm(); |
||
| 100 | 1 | ||
| 101 | 1 | $event = new EventArgs( |
|
| 102 | 1 | array( |
|
| 103 | 'form' => $form, |
||
| 104 | 'Order' => $Order, |
||
| 105 | 'MailTemplate' => $MailTemplate, |
||
| 106 | ), |
||
| 107 | $request |
||
| 108 | ); |
||
| 109 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_CONFIRM, $event); |
||
| 110 | |||
| 111 | $form->setData($data); |
||
| 112 | $form->get('template')->setData($MailTemplate); |
||
| 113 | |||
| 114 | |||
| 115 | return $app->render('Order/mail_confirm.twig', array( |
||
| 116 | 'form' => $form->createView(), |
||
| 117 | 1 | 'body' => $body, |
|
| 118 | 1 | 'Order' => $Order, |
|
| 119 | )); |
||
| 120 | break; |
||
| 121 | case 'complete': |
||
| 122 | 3 | ||
| 123 | $data = $form->getData(); |
||
| 124 | $body = $this->createBody($app, $data['header'], $data['footer'], $Order); |
||
| 125 | 1 | ||
| 126 | // メール送信 |
||
| 127 | $app['eccube.service.mail']->sendAdminOrderMail($Order, $data); |
||
| 128 | 1 | ||
| 129 | // 送信履歴を保存. |
||
| 130 | $MailTemplate = $form->get('template')->getData(); |
||
| 131 | 1 | $MailHistory = new MailHistory(); |
|
| 132 | $MailHistory |
||
| 133 | ->setSubject($data['subject']) |
||
| 134 | ->setMailBody($body) |
||
| 135 | ->setMailTemplate($MailTemplate) |
||
| 136 | ->setSendDate(new \DateTime()) |
||
| 137 | ->setOrder($Order); |
||
| 138 | |||
| 139 | $app['orm.em']->persist($MailHistory); |
||
| 140 | $app['orm.em']->flush($MailHistory); |
||
| 141 | |||
| 142 | 1 | $event = new EventArgs( |
|
| 143 | 1 | array( |
|
| 144 | 1 | 'form' => $form, |
|
| 145 | 'Order' => $Order, |
||
| 146 | 'MailTemplate' => $MailTemplate, |
||
| 147 | 'MailHistory' => $MailHistory, |
||
| 148 | 1 | ), |
|
| 149 | $request |
||
| 150 | ); |
||
| 151 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_INDEX_COMPLETE, $event); |
||
| 152 | 3 | ||
| 153 | |||
| 154 | return $app->redirect($app->url('admin_order_mail_complete')); |
||
| 155 | break; |
||
| 156 | default: |
||
| 157 | break; |
||
| 158 | } |
||
| 159 | 3 | } |
|
| 160 | } |
||
| 161 | |||
| 162 | return $app->render('Order/mail.twig', array( |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 163 | 'form' => $form->createView(), |
||
| 164 | 'Order' => $Order, |
||
| 165 | 'MailHistories' => $MailHistories |
||
| 166 | )); |
||
| 167 | } |
||
| 168 | |||
| 169 | 2 | ||
| 170 | public function complete(Application $app) |
||
| 171 | { |
||
| 172 | return $app->render('Order/mail_complete.twig'); |
||
| 173 | } |
||
| 174 | |||
| 175 | |||
| 176 | public function view(Application $app, Request $request) |
||
| 177 | { |
||
| 178 | |||
| 179 | if ($request->isXmlHttpRequest()) { |
||
| 180 | $id = $request->get('id'); |
||
| 181 | 2 | $MailHistory = $app['eccube.repository.mail_history']->find($id); |
|
| 182 | |||
| 183 | if (is_null($MailHistory)) { |
||
| 184 | throw new NotFoundHttpException('history not found.'); |
||
| 185 | } |
||
| 186 | |||
| 187 | $event = new EventArgs( |
||
| 188 | array( |
||
| 189 | 'MailHistory' => $MailHistory, |
||
| 190 | ), |
||
| 191 | $request |
||
| 192 | ); |
||
| 193 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_VIEW_COMPLETE, $event); |
||
| 194 | |||
| 195 | return $app->render('Order/mail_view.twig', array( |
||
|
0 ignored issues
–
show
|
|||
| 196 | 'subject' => $MailHistory->getSubject(), |
||
| 197 | 'body' => $MailHistory->getMailBody() |
||
| 198 | )); |
||
| 199 | } |
||
| 200 | |||
| 201 | } |
||
| 202 | |||
| 203 | |||
| 204 | |||
| 205 | 1 | public function mailAll(Application $app, Request $request) |
|
| 206 | 1 | { |
|
| 207 | |||
| 208 | $builder = $app['form.factory']->createBuilder('mail'); |
||
| 209 | |||
| 210 | $event = new EventArgs( |
||
| 211 | array( |
||
| 212 | 1 | 'builder' => $builder, |
|
| 213 | ), |
||
| 214 | $request |
||
| 215 | ); |
||
| 216 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_INITIALIZE, $event); |
||
| 217 | |||
| 218 | $form = $builder->getForm(); |
||
| 219 | |||
| 220 | $ids = ''; |
||
| 221 | if ('POST' === $request->getMethod()) { |
||
| 222 | |||
| 223 | $form->handleRequest($request); |
||
| 224 | |||
| 225 | $mode = $request->get('mode'); |
||
| 226 | |||
| 227 | $ids = $request->get('ids'); |
||
| 228 | |||
| 229 | // テンプレート変更の場合は. バリデーション前に内容差し替え. |
||
| 230 | if ($mode == 'change') { |
||
| 231 | View Code Duplication | if ($form->get('template')->isValid()) { |
|
| 232 | /** @var $data \Eccube\Entity\MailTemplate */ |
||
| 233 | $MailTemplate = $form->get('template')->getData(); |
||
| 234 | $form = $builder->getForm(); |
||
| 235 | |||
| 236 | $event = new EventArgs( |
||
| 237 | array( |
||
| 238 | 'form' => $form, |
||
| 239 | 'MailTemplate' => $MailTemplate, |
||
| 240 | ), |
||
| 241 | $request |
||
| 242 | ); |
||
| 243 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_CHANGE, $event); |
||
| 244 | |||
| 245 | $form->get('template')->setData($MailTemplate); |
||
| 246 | $form->get('subject')->setData($MailTemplate->getSubject()); |
||
| 247 | $form->get('header')->setData($MailTemplate->getHeader()); |
||
| 248 | $form->get('footer')->setData($MailTemplate->getFooter()); |
||
| 249 | 1 | } |
|
| 250 | } else if ($form->isValid()) { |
||
| 251 | 1 | switch ($mode) { |
|
| 252 | case 'confirm': |
||
| 253 | // フォームをFreezeして再生成. |
||
| 254 | |||
| 255 | 1 | $builder->setAttribute('freeze', true); |
|
| 256 | 1 | $builder->setAttribute('freeze_display_text', true); |
|
| 257 | |||
| 258 | $data = $form->getData(); |
||
| 259 | 3 | ||
| 260 | $tmp = explode(',', $ids); |
||
| 261 | |||
| 262 | 3 | $Order = $app['eccube.repository.order']->find($tmp[0]); |
|
| 263 | |||
| 264 | 3 | if (is_null($Order)) { |
|
| 265 | throw new NotFoundHttpException('order not found.'); |
||
| 266 | } |
||
| 267 | |||
| 268 | $body = $this->createBody($app, $data['header'], $data['footer'], $Order); |
||
| 269 | |||
| 270 | $MailTemplate = $form->get('template')->getData(); |
||
| 271 | |||
| 272 | $form = $builder->getForm(); |
||
| 273 | |||
| 274 | $event = new EventArgs( |
||
| 275 | array( |
||
| 276 | 'form' => $form, |
||
| 277 | 'MailTemplate' => $MailTemplate, |
||
| 278 | 'Order' => $Order, |
||
| 279 | ), |
||
| 280 | $request |
||
| 281 | ); |
||
| 282 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_CONFIRM, $event); |
||
| 283 | |||
| 284 | $form->setData($data); |
||
| 285 | $form->get('template')->setData($MailTemplate); |
||
| 286 | |||
| 287 | return $app->render('Order/mail_all_confirm.twig', array( |
||
| 288 | 'form' => $form->createView(), |
||
| 289 | 'body' => $body, |
||
| 290 | 'ids' => $ids, |
||
| 291 | )); |
||
| 292 | break; |
||
| 293 | |||
| 294 | case 'complete': |
||
| 295 | |||
| 296 | $data = $form->getData(); |
||
| 297 | |||
| 298 | $ids = explode(',', $ids); |
||
| 299 | |||
| 300 | foreach ($ids as $value) { |
||
| 301 | |||
| 302 | $Order = $app['eccube.repository.order']->find($value); |
||
| 303 | |||
| 304 | $body = $this->createBody($app, $data['header'], $data['footer'], $Order); |
||
| 305 | |||
| 306 | // メール送信 |
||
| 307 | $app['eccube.service.mail']->sendAdminOrderMail($Order, $data); |
||
| 308 | |||
| 309 | // 送信履歴を保存. |
||
| 310 | $MailTemplate = $form->get('template')->getData(); |
||
| 311 | $MailHistory = new MailHistory(); |
||
| 312 | $MailHistory |
||
| 313 | ->setSubject($data['subject']) |
||
| 314 | ->setMailBody($body) |
||
| 315 | ->setMailTemplate($MailTemplate) |
||
| 316 | ->setSendDate(new \DateTime()) |
||
| 317 | ->setOrder($Order); |
||
| 318 | $app['orm.em']->persist($MailHistory); |
||
| 319 | } |
||
| 320 | |||
| 321 | $app['orm.em']->flush($MailHistory); |
||
| 322 | |||
| 323 | $event = new EventArgs( |
||
| 324 | array( |
||
| 325 | 'form' => $form, |
||
| 326 | 'MailHistory' => $MailHistory, |
||
| 327 | ), |
||
| 328 | $request |
||
| 329 | ); |
||
| 330 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_ORDER_MAIL_MAIL_ALL_COMPLETE, $event); |
||
| 331 | |||
| 332 | return $app->redirect($app->url('admin_order_mail_complete')); |
||
| 333 | break; |
||
| 334 | default: |
||
| 335 | break; |
||
| 336 | } |
||
| 337 | } |
||
| 338 | } else { |
||
| 339 | foreach ($_GET as $key => $value) { |
||
| 340 | $ids = str_replace('ids', '', $key) . ',' . $ids; |
||
| 341 | } |
||
| 342 | $ids = substr($ids, 0, -1); |
||
| 343 | } |
||
| 344 | |||
| 345 | return $app->render('Order/mail_all.twig', array( |
||
| 346 | 'form' => $form->createView(), |
||
| 347 | 'ids' => $ids, |
||
| 348 | )); |
||
| 349 | } |
||
| 350 | |||
| 351 | |||
| 352 | private function createBody($app, $header, $footer, $Order) |
||
| 353 | { |
||
| 354 | return $app->renderView('Mail/order.twig', array( |
||
| 355 | 'header' => $header, |
||
| 356 | 'footer' => $footer, |
||
| 357 | 'Order' => $Order, |
||
| 358 | )); |
||
| 359 | } |
||
| 360 | } |
||
| 361 |