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\Service; |
15
|
|
|
|
16
|
|
|
use Dealer\Event\DealerEvent; |
17
|
|
|
use Dealer\Event\DealerEvents; |
18
|
|
|
use Dealer\Model\Dealer; |
19
|
|
|
use Dealer\Model\DealerQuery; |
20
|
|
|
use Dealer\Service\Base\AbstractBaseService; |
21
|
|
|
use Dealer\Service\Base\BaseServiceInterface; |
22
|
|
|
use Symfony\Component\EventDispatcher\Event; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class DealerService |
26
|
|
|
* @package Dealer\Service |
27
|
|
|
*/ |
28
|
|
|
class DealerService extends AbstractBaseService implements BaseServiceInterface |
29
|
|
|
{ |
30
|
|
|
const EVENT_CREATE = DealerEvents::DEALER_CREATE; |
31
|
|
|
const EVENT_CREATE_BEFORE = DealerEvents::DEALER_CREATE_BEFORE; |
32
|
|
|
const EVENT_CREATE_AFTER = DealerEvents::DEALER_CREATE_AFTER; |
33
|
|
|
const EVENT_DELETE = DealerEvents::DEALER_DELETE; |
34
|
|
|
const EVENT_DELETE_BEFORE = DealerEvents::DEALER_DELETE_BEFORE; |
35
|
|
|
const EVENT_DELETE_AFTER = DealerEvents::DEALER_DELETE_AFTER; |
36
|
|
|
const EVENT_UPDATE = DealerEvents::DEALER_UPDATE; |
37
|
|
|
const EVENT_UPDATE_BEFORE = DealerEvents::DEALER_UPDATE_BEFORE; |
38
|
|
|
const EVENT_UPDATE_AFTER = DealerEvents::DEALER_UPDATE_AFTER; |
39
|
|
|
|
40
|
|
|
protected function createProcess(Event $event) |
41
|
|
|
{ |
42
|
|
|
$event->getDealer()->save(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function updateProcess(Event $event) |
46
|
|
|
{ |
47
|
|
|
$event->getDealer()->save(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function deleteProcess(Event $event) |
51
|
|
|
{ |
52
|
|
|
$event->getDealer()->delete(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function createFromArray($data, $locale = null) |
56
|
|
|
{ |
57
|
|
|
$dealer = $this->hydrateObjectArray($data, $locale); |
58
|
|
|
|
59
|
|
|
$event = new DealerEvent(); |
60
|
|
|
$event->setDealer($dealer); |
61
|
|
|
|
62
|
|
|
$this->create($event); |
63
|
|
|
|
64
|
|
|
return $event->getDealer(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function updateFromArray($data, $locale = null) |
68
|
|
|
{ |
69
|
|
|
$dealer = $this->hydrateObjectArray($data, $locale); |
70
|
|
|
|
71
|
|
|
$event = new DealerEvent(); |
72
|
|
|
$event->setDealer($dealer); |
73
|
|
|
|
74
|
|
|
$this->update($event); |
75
|
|
|
|
76
|
|
|
return $event->getDealer(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function deleteFromId($id) |
80
|
|
|
{ |
81
|
|
|
$dealer = DealerQuery::create()->findOneById($id); |
82
|
|
|
if ($dealer) { |
83
|
|
|
$event = new DealerEvent(); |
84
|
|
|
$event->setDealer($dealer); |
85
|
|
|
|
86
|
|
|
$this->delete($event); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
public function toggleVisibilityFromId($id) |
92
|
|
|
{ |
93
|
|
|
$dealer = DealerQuery::create()->findOneById($id); |
94
|
|
|
|
95
|
|
|
$dealer->setVisible($dealer->getVisible() ? 0 : 1); |
96
|
|
|
|
97
|
|
|
$event = new DealerEvent(); |
98
|
|
|
$event->setDealer($dealer); |
99
|
|
|
|
100
|
|
|
$this->update($event); |
101
|
|
|
|
102
|
|
|
return $event->getDealer(); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
protected function hydrateObjectArray($data, $locale = null) |
106
|
|
|
{ |
107
|
|
|
$model = new Dealer(); |
108
|
|
|
|
109
|
|
|
if (isset($data['id'])) { |
110
|
|
|
$dealer = DealerQuery::create()->findOneById($data['id']); |
111
|
|
|
if ($dealer) { |
112
|
|
|
$model = $dealer; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
if ($locale) { |
117
|
|
|
$model->setLocale($locale); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
// Require Field |
121
|
|
|
if (isset($data['title'])) { |
122
|
|
|
$model->setTitle($data['title']); |
123
|
|
|
} |
124
|
|
|
if (isset($data['address1'])) { |
125
|
|
|
$model->setAddress1($data['address1']); |
126
|
|
|
} |
127
|
|
|
if (isset($data['zipcode'])) { |
128
|
|
|
$model->setZipcode($data['zipcode']); |
129
|
|
|
} |
130
|
|
|
if (isset($data['city'])) { |
131
|
|
|
$model->setCity($data['city']); |
132
|
|
|
} |
133
|
|
|
if (isset($data['country_id'])) { |
134
|
|
|
$model->setCountryId($data['country_id']); |
135
|
|
|
} |
136
|
|
|
if (isset($data['visible'])) { |
137
|
|
|
$model->setVisible($data['visible']); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// Optionnal Field |
141
|
|
|
if (isset($data['description'])) { |
142
|
|
|
$model->setDescription($data['description']); |
143
|
|
|
} else { |
144
|
|
|
$model->setDescription(null); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if (isset($data['access'])) { |
148
|
|
|
$model->setAccess($data['access']); |
149
|
|
|
} else { |
150
|
|
|
$model->setAccess(null); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
if (isset($data['address2'])) { |
154
|
|
|
$model->setAddress2($data['address2']); |
155
|
|
|
} else { |
156
|
|
|
$model->setAddress2(null); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
if (isset($data['address3'])) { |
160
|
|
|
$model->setAddress3($data['address3']); |
161
|
|
|
} else { |
162
|
|
|
$model->setAddress3(null); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $model; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
} |