Completed
Push — master ( a54a4b...bbfdca )
by Adam
15:54
created

ClientController::detailsAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\AppBundle\Controller\Admin;
14
15
use Symfony\Component\HttpFoundation\Request;
16
use Symfony\Component\HttpFoundation\Response;
17
use WellCommerce\Bundle\AppBundle\Entity\Client;
18
use WellCommerce\Bundle\CoreBundle\Controller\Admin\AbstractAdminController;
19
20
/**
21
 * Class ClientController
22
 *
23
 * @author  Adam Piotrowski <[email protected]>
24
 */
25
class ClientController extends AbstractAdminController
26
{
27
    public function addAction(Request $request): Response
28
    {
29
        /** @var Client $resource */
30
        $resource = $this->getManager()->initResource();
31
        $form     = $this->formBuilder->createForm($resource, [
32
            'validation_groups' => ['client_admin_registration']
33
        ]);
34
        
35
        if ($form->handleRequest()->isSubmitted()) {
36
            if ($form->isValid()) {
37
                $this->getManager()->createResource($resource);
38
                $password = $form->getValue()['required_data']['clientDetails']['clientDetails.hashedPassword'];
39
                
40
                $this->getMailerHelper()->sendEmail([
41
                    'recipient'     => $resource->getContactDetails()->getEmail(),
42
                    'subject'       => $this->getTranslatorHelper()->trans('client.email.heading.register'),
43
                    'template'      => 'WellCommerceAppBundle:Email:register_admin.html.twig',
44
                    'parameters'    => [
45
                        'client'   => $resource,
46
                        'password' => $password,
47
                    ],
48
                    'configuration' => $resource->getShop()->getMailerConfiguration(),
49
                ]);
50
            }
51
            
52
            return $this->createFormDefaultJsonResponse($form);
53
        }
54
        
55
        return $this->displayTemplate('add', [
56
            'form' => $form,
57
        ]);
58
    }
59
    
60
    public function detailsAction(Client $client): Response
61
    {
62
        $data = $this->get('serializer')->serialize($client, 'json', ['group' => 'client']);
63
        
64
        return new Response($data);
65
    }
66
}
67