ContactController::complete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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;
26
27
use Eccube\Application;
28
use Eccube\Event\EccubeEvents;
29
use Eccube\Event\EventArgs;
30
use Symfony\Component\HttpFoundation\Request;
31
32 5
class ContactController
0 ignored issues
show
introduced by
Missing class doc comment
Loading history...
33
{
34
    /**
35
     * お問い合わせ画面.
36
     *
37
     * @param Application $app
38
     * @param Request $request
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
39
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
40
     */
41
    public function index(Application $app, Request $request)
42
    {
43
        $builder = $app['form.factory']->createBuilder('contact');
44
45
        if ($app->isGranted('ROLE_USER')) {
46
            $user = $app['user'];
47
            $builder->setData(
48
                array(
49
                    'name01' => $user->getName01(),
50
                    'name02' => $user->getName02(),
51
                    'kana01' => $user->getKana01(),
52
                    'kana02' => $user->getKana02(),
53
                    'zip01' => $user->getZip01(),
54
                    'zip02' => $user->getZip02(),
55
                    'pref' => $user->getPref(),
56
                    'addr01' => $user->getAddr01(),
57
                    'addr02' => $user->getAddr02(),
58
                    'tel01' => $user->getTel01(),
59
                    'tel02' => $user->getTel02(),
60
                    'tel03' => $user->getTel03(),
61
                    'email' => $user->getEmail(),
62
                )
63 4
            );
64 4
        }
65
66
        // FRONT_CONTACT_INDEX_INITIALIZE
67
        $event = new EventArgs(
68
            array(
69 1
                'builder' => $builder,
70 1
            ),
71
            $request
72
        );
73 3
        $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CONTACT_INDEX_INITIALIZE, $event);
74
75
        $form = $builder->getForm();
76
        $form->handleRequest($request);
77
78
        if ($form->isSubmitted() && $form->isValid()) {
79
            switch ($request->get('mode')) {
80
                case 'confirm':
81 1
                    $builder->setAttribute('freeze', true);
82 1
                    $form = $builder->getForm();
83
                    $form->handleRequest($request);
84 5
85
                    return $app->render('Contact/confirm.twig', array(
86 1
                        'form' => $form->createView(),
87
                    ));
88
89 1
                case 'complete':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
90
91
                    $data = $form->getData();
92
93
                    $event = new EventArgs(
94
                        array(
95
                            'form' => $form,
96
                            'data' => $data,
97
                        ),
98
                        $request
99
                    );
100
                    $app['eccube.event.dispatcher']->dispatch(EccubeEvents::FRONT_CONTACT_INDEX_COMPLETE, $event);
101
102
                    $data = $event->getArgument('data');
103
104
                    // メール送信
105
                    $app['eccube.service.mail']->sendContactMail($data);
106
107
                    return $app->redirect($app->url('contact_complete'));
108
            }
109
        }
110
111
        return $app->render('Contact/index.twig', array(
112
            'form' => $form->createView(),
113
        ));
114
    }
115
116
    /**
117
     * お問い合わせ完了画面.
118
     *
119
     * @param Application $app
120
     * @return \Symfony\Component\HttpFoundation\Response
121
     */
122
    public function complete(Application $app)
123
    {
124
        return $app->render('Contact/complete.twig');
125
    }
126
}
127