Completed
Push — develop ( 4662d2...c4df36 )
by A.
04:33
created

AttributeSupportController::overviewAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 20
rs 9.4286
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
/**
4
 * Copyright 2015 SURFnet B.V.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace OpenConext\ProfileBundle\Controller;
20
21
use OpenConext\ProfileBundle\Security\Guard;
22
use OpenConext\ProfileBundle\Service\AttributeSupportMailService;
23
use OpenConext\ProfileBundle\Service\UserService;
24
use Symfony\Component\Form\FormFactoryInterface;
25
use Symfony\Component\HttpFoundation\RedirectResponse;
26
use Symfony\Component\HttpFoundation\Response;
27
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
28
use Symfony\Component\Templating\EngineInterface;
29
30
class AttributeSupportController
31
{
32
    /**
33
     * @var Guard
34
     */
35
    private $guard;
36
37
    /**
38
     * @var EngineInterface
39
     */
40
    private $templateEngine;
41
42
    /**
43
     * @var FormFactoryInterface
44
     */
45
    private $formFactory;
46
47
    /**
48
     * @var UrlGeneratorInterface
49
     */
50
    private $urlGenerator;
51
52
    /**
53
     * @var UserService
54
     */
55
    private $userService;
56
57
    /**
58
     * @var AttributeSupportMailService
59
     */
60
    private $attributeSupportMailService;
61
62
    public function __construct(
63
        Guard $guard,
64
        EngineInterface $templateEngine,
65
        FormFactoryInterface $formFactory,
66
        UrlGeneratorInterface $urlGenerator,
67
        UserService $userService,
68
        AttributeSupportMailService $attributeSupportMailService
69
    ) {
70
        $this->guard                       = $guard;
71
        $this->templateEngine              = $templateEngine;
72
        $this->formFactory                 = $formFactory;
73
        $this->urlGenerator                = $urlGenerator;
74
        $this->userService                 = $userService;
75
        $this->attributeSupportMailService = $attributeSupportMailService;
76
    }
77
78
    public function overviewAction()
79
    {
80
        $this->guard->userIsLoggedIn();
81
82
        $attributeSupportMailForm = $this->formFactory->create(
83
            'profile_attribute_support_mail',
84
            null,
85
            ['action' => $this->urlGenerator->generate('profile.attribute_support_send_mail')]
86
        );
87
88
        return new Response(
89
            $this->templateEngine->render(
90
                'OpenConextProfileBundle:AttributeSupport:overview.html.twig',
91
                [
92
                    'attributes'               => $this->userService->getUser()->getAttributes(),
93
                    'attributeSupportMailForm' => $attributeSupportMailForm->createView()
94
                ]
95
            )
96
        );
97
    }
98
99
    public function sendMailAction()
100
    {
101
        $this->guard->userIsLoggedIn();
102
103
        $this->attributeSupportMailService->sendAttributeSupportMail();
104
105
        return new RedirectResponse($this->urlGenerator->generate('profile.attribute_support_confirm_mail_sent'));
106
    }
107
108
    public function confirmMailSentAction()
109
    {
110
        $this->guard->userIsLoggedIn();
111
112
        return new Response(
113
            $this->templateEngine->render('OpenConextProfileBundle:AttributeSupport:confirmation.html.twig')
114
        );
115
    }
116
}
117