Completed
Push — master ( 7a9a35...ef55ea )
by Adam
06:26
created

ajaxGetCollectionsByProducer()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 15
nc 3
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\CatalogBundle\Controller\Admin;
14
15
use WellCommerce\Bundle\CoreBundle\Controller\Admin\AbstractAdminController;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
19
/**
20
 * Class ProducerCollectionController
21
 *
22
 * @author  Rafał Martonik <[email protected]>
23
 */
24
class ProducerCollectionController extends AbstractAdminController
25
{
26
    public function ajaxGetCollectionsByProducer(Request $request) : Response
27
    {
28
        if (!$request->isXmlHttpRequest()) {
29
            return $this->redirectToAction('index');
30
        }
31
        
32
        $producerId                   = (int)$request->request->get('producerId');
33
        $producerCollectionOptions    = [];
34
        $producerCollections          = $this->getManager()->getRepository()->findBy(['producer' => $producerId]);
35
        $producerCollectionOptions[0] = [
36
            'sValue' => 0,
37
            'sLabel' => $this->trans('common.label.none'),
38
        ];
39
        
40
        foreach ($producerCollections AS $key => $producerCollection) {
41
            $producerCollectionOptions[$key + 1] = [
42
                'sValue' => $producerCollection->getId(),
43
                'sLabel' => $producerCollection->translate()->getName(),
44
            ];
45
        }
46
        
47
        return $this->jsonResponse(
48
            $producerCollectionOptions
49
        );
50
    }
51
}
52