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\DealerContactInfoEvent; |
17
|
|
|
use Dealer\Event\DealerEvents; |
18
|
|
|
use Dealer\Model\DealerContactInfo; |
19
|
|
|
use Dealer\Model\DealerContactInfoQuery; |
20
|
|
|
use Dealer\Model\Map\DealerContactInfoTableMap; |
21
|
|
|
use Dealer\Service\Base\AbstractBaseService; |
22
|
|
|
use Dealer\Service\Base\BaseServiceInterface; |
23
|
|
|
use Symfony\Component\EventDispatcher\Event; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class ContactInfoService |
27
|
|
|
* @package Dealer\Service |
28
|
|
|
*/ |
29
|
|
|
class ContactInfoService extends AbstractBaseService implements BaseServiceInterface |
30
|
|
|
{ |
31
|
|
|
|
32
|
|
|
const EVENT_CREATE = DealerEvents::DEALER_CONTACT_INFO_CREATE; |
33
|
|
|
const EVENT_CREATE_BEFORE = DealerEvents::DEALER_CONTACT_INFO_CREATE_BEFORE; |
34
|
|
|
const EVENT_CREATE_AFTER = DealerEvents::DEALER_CONTACT_INFO_CREATE_AFTER; |
35
|
|
|
const EVENT_DELETE = DealerEvents::DEALER_CONTACT_INFO_DELETE; |
36
|
|
|
const EVENT_DELETE_BEFORE = DealerEvents::DEALER_CONTACT_INFO_DELETE_BEFORE; |
37
|
|
|
const EVENT_DELETE_AFTER = DealerEvents::DEALER_CONTACT_INFO_DELETE_AFTER; |
38
|
|
|
const EVENT_UPDATE = DealerEvents::DEALER_CONTACT_INFO_UPDATE; |
39
|
|
|
const EVENT_UPDATE_BEFORE = DealerEvents::DEALER_CONTACT_INFO_UPDATE_BEFORE; |
40
|
|
|
const EVENT_UPDATE_AFTER = DealerEvents::DEALER_CONTACT_INFO_UPDATE_AFTER; |
41
|
|
|
|
42
|
|
|
protected function createProcess(Event $event) |
43
|
|
|
{ |
44
|
|
|
$event->getDealerContactInfo()->save(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function updateProcess(Event $event) |
48
|
|
|
{ |
49
|
|
|
$event->getDealerContactInfo()->save(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function deleteProcess(Event $event) |
53
|
|
|
{ |
54
|
|
|
$event->getDealerContactInfo()->delete(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function createFromArray($data, $locale = null) |
58
|
|
|
{ |
59
|
|
|
$dealer_contact = $this->hydrateObjectArray($data, $locale); |
60
|
|
|
|
61
|
|
|
$event = new DealerContactInfoEvent(); |
62
|
|
|
$event->setDealerContactInfo($dealer_contact); |
63
|
|
|
|
64
|
|
|
$this->create($event); |
65
|
|
|
|
66
|
|
|
return $event->getDealerContactInfo(); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function updateFromArray($data, $locale = null) |
70
|
|
|
{ |
71
|
|
|
$dealer_contact = $this->hydrateObjectArray($data, $locale); |
72
|
|
|
|
73
|
|
|
$event = new DealerContactInfoEvent(); |
74
|
|
|
$event->setDealerContactInfo($dealer_contact); |
75
|
|
|
|
76
|
|
|
$this->update($event); |
77
|
|
|
|
78
|
|
|
return $event->getDealerContactInfo(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function deleteFromId($id) |
82
|
|
|
{ |
83
|
|
|
$dealer = DealerContactInfoQuery::create()->findOneById($id); |
84
|
|
|
|
85
|
|
|
if ($dealer) { |
86
|
|
|
$event = new DealerContactInfoEvent(); |
87
|
|
|
$event->setDealerContactInfo($dealer); |
88
|
|
|
|
89
|
|
|
$this->delete($event); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
protected function hydrateObjectArray($data, $locale = null) |
94
|
|
|
{ |
95
|
|
|
$model = new DealerContactInfo(); |
96
|
|
|
|
97
|
|
|
if (isset($data['id'])) { |
98
|
|
|
$dealer = DealerContactInfoQuery::create()->findOneById($data['id']); |
99
|
|
|
if ($dealer) { |
100
|
|
|
$model = $dealer; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if ($locale) { |
105
|
|
|
$model->setLocale($locale); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// Require Field |
109
|
|
|
if (isset($data['value'])) { |
110
|
|
|
$model->setValue($data['value']); |
111
|
|
|
} |
112
|
|
|
if (isset($data['type'])) { |
113
|
|
|
$model->setContactType(DealerContactInfoTableMap::getValueSet(DealerContactInfoTableMap::CONTACT_TYPE)[$data['type']]); |
114
|
|
|
} |
115
|
|
|
if (isset($data['contact_id'])) { |
116
|
|
|
$model->setContactId($data['contact_id']); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
return $model; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|