|
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\Brand; |
|
20
|
|
|
use Thelia\Model\BrandQuery; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class BrandLinkForm |
|
24
|
|
|
* @package Dealer\Form |
|
25
|
|
|
*/ |
|
26
|
|
|
class BrandLinkForm extends BaseForm |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @inheritDoc |
|
30
|
|
|
*/ |
|
31
|
|
|
protected function buildForm() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->formBuilder |
|
34
|
|
|
->add("brand_id", "choice", array( |
|
35
|
|
|
"choices" => $this->getAvailableBrand(), |
|
36
|
|
|
"label" => $this->translator->trans("Brand", [], Dealer::MESSAGE_DOMAIN), |
|
37
|
|
|
"label_attr" => ["for" => "attr-dealer-brand-link-brand"], |
|
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-brand-link-dealer"], |
|
45
|
|
|
"required" => true, |
|
46
|
|
|
"attr" => array() |
|
47
|
|
|
)); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getName() |
|
51
|
|
|
{ |
|
52
|
|
|
return "dealer_brand_link_create"; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function getAvailableBrand() |
|
56
|
|
|
{ |
|
57
|
|
|
$brands = BrandQuery::create()->find(); |
|
58
|
|
|
$choices = []; |
|
59
|
|
|
|
|
60
|
|
|
/** @var Brand $brand */ |
|
61
|
|
|
foreach ($brands as $brand) { |
|
62
|
|
|
$choices[$brand->getId()] = $brand->getTitle(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return $choices; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function getAvailableDealer() |
|
69
|
|
|
{ |
|
70
|
|
|
$dealers = DealerQuery::create()->find(); |
|
71
|
|
|
$choices = []; |
|
72
|
|
|
foreach ($dealers as $dealer) { |
|
73
|
|
|
$choices[$dealer->getId()] = $dealer->getTitle(); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $choices; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|