ContentLinkForm   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 52
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildForm() 0 18 1
A getName() 0 4 1
A getAvailableContent() 0 11 2
A getAvailableDealer() 0 10 2
1
<?php
2
/*************************************************************************************/
3
/*      This file is part of the Thelia package.                                     */
4
/*                                                                                   */
5
/*      Copyright (c) OpenStudio                                                     */
6
/*      email : [email protected]                                                       */
7
/*      web : http://www.thelia.net                                                  */
8
/*                                                                                   */
9
/*      For the full copyright and license information, please view the LICENSE.txt  */
10
/*      file that was distributed with this source code.                             */
11
/*************************************************************************************/
12
/*************************************************************************************/
13
14
namespace Dealer\Form;
15
16
use Dealer\Dealer;
17
use Dealer\Model\DealerQuery;
18
use Thelia\Form\BaseForm;
19
use Thelia\Model\ContentQuery;
20
use Thelia\Model\Content;
21
22
/**
23
 * Class ContentLinkForm
24
 * @package Dealer\Form
25
 */
26
class ContentLinkForm extends BaseForm
27
{
28
    /**
29
     * @inheritDoc
30
     */
31
    protected function buildForm()
32
    {
33
        $this->formBuilder
34
            ->add("content_id", "choice", array(
35
                "choices" => $this->getAvailableContent(),
36
                "label" => $this->translator->trans("Content", [], Dealer::MESSAGE_DOMAIN),
37
                "label_attr" => ["for" => "attr-dealer-content-link-content"],
38
                "required" => true,
39
                "attr" => array()
40
            ))
41
            ->add("dealer_id", "choice", array(
42
                "choices" => $this->getAvailableDealer(),
43
                "label" => $this->translator->trans("Dealer", [], Dealer::MESSAGE_DOMAIN),
44
                "label_attr" => ["for" => "attr-dealer-content-link-dealer"],
45
                "required" => true,
46
                "attr" => array()
47
            ));
48
    }
49
50
    public function getName()
51
    {
52
        return "dealer_content_link_create";
53
    }
54
55
    protected function getAvailableContent()
56
    {
57
        $contents = ContentQuery::create()->find();
58
        $choices = [];
59
60
        /** @var Content $content */
61
        foreach ($contents as $content) {
62
            $choices[$content->getId()] = $content->getTitle();
63
        }
64
        return $choices;
65
    }
66
67
    protected function getAvailableDealer()
68
    {
69
        $dealers = DealerQuery::create()->find();
70
        $choices = [];
71
        foreach ($dealers as $dealer) {
72
            $choices[$dealer->getId()] = $dealer->getTitle();
73
        }
74
75
        return $choices;
76
    }
77
}
78