Completed
Pull Request — develop (#43)
by A.
09:18
created

AttributeSupportController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4286
cc 1
eloc 13
nc 1
nop 6
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
        $attributeSupportMailFormView = $this->formFactory->create('profile_attribute_support_mail')->createView();
83
84
        return new Response(
85
            $this->templateEngine->render(
86
                'OpenConextProfileBundle:AttributeSupport:overview.html.twig',
87
                [
88
                    'attributes'               => $this->userService->getUser()->getAttributes(),
89
                    'attributeSupportMailForm' => $attributeSupportMailFormView
90
                ]
91
            )
92
        );
93
    }
94
95
    public function sendMailAction()
96
    {
97
        $this->attributeSupportMailService->sendAttributeSupportMail();
98
99
        return new RedirectResponse($this->urlGenerator->generate('profile.attribute_support_confirm_mail_sent'));
100
    }
101
102
    public function confirmMailSentAction()
103
    {
104
        return new Response(
105
            $this->templateEngine->render('OpenConextProfileBundle:AttributeSupport:confirmation.html.twig')
106
        );
107
    }
108
}
109