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\DealerAdminLinkEvent; |
17
|
|
|
use Dealer\Event\DealerEvents; |
18
|
|
|
use Dealer\Model\DealerAdmin; |
19
|
|
|
use Dealer\Model\DealerAdminQuery; |
20
|
|
|
use Dealer\Service\Base\AbstractBaseService; |
21
|
|
|
use Dealer\Service\Base\BaseServiceInterface; |
22
|
|
|
use Symfony\Component\EventDispatcher\Event; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class AdminLinkService |
26
|
|
|
* @package Dealer\Service |
27
|
|
|
*/ |
28
|
|
|
class AdminLinkService extends AbstractBaseService implements BaseServiceInterface |
29
|
|
|
{ |
30
|
|
|
|
31
|
|
|
const EVENT_CREATE = DealerEvents::ADMIN_LINK_CREATE; |
32
|
|
|
const EVENT_CREATE_BEFORE = DealerEvents::ADMIN_LINK_CREATE_BEFORE; |
33
|
|
|
const EVENT_CREATE_AFTER = DealerEvents::ADMIN_LINK_CREATE_AFTER; |
34
|
|
|
const EVENT_DELETE = DealerEvents::ADMIN_LINK_DELETE; |
35
|
|
|
const EVENT_DELETE_BEFORE = DealerEvents::ADMIN_LINK_DELETE_BEFORE; |
36
|
|
|
const EVENT_DELETE_AFTER = DealerEvents::ADMIN_LINK_DELETE_AFTER; |
37
|
|
|
const EVENT_UPDATE = DealerEvents::ADMIN_LINK_UPDATE; |
38
|
|
|
const EVENT_UPDATE_BEFORE = DealerEvents::ADMIN_LINK_UPDATE_BEFORE; |
39
|
|
|
const EVENT_UPDATE_AFTER = DealerEvents::ADMIN_LINK_UPDATE_AFTER; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @inheritDoc |
43
|
|
|
*/ |
44
|
|
|
protected function createProcess(Event $event) |
45
|
|
|
{ |
46
|
|
|
/** @var DealerAdminLinkEvent $event */ |
47
|
|
|
$event->getDealerAdminLink()->save(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @inheritDoc |
52
|
|
|
*/ |
53
|
|
|
protected function updateProcess(Event $event) |
54
|
|
|
{ |
55
|
|
|
/** @var DealerAdminLinkEvent $event */ |
56
|
|
|
$event->getDealerAdminLink()->save(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
protected function deleteProcess(Event $event) |
60
|
|
|
{ |
61
|
|
|
/** @var DealerAdminLinkEvent $event */ |
62
|
|
|
$event->getDealerAdminLink()->delete(); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function createFromArray($data, $locale = null) |
66
|
|
|
{ |
67
|
|
|
$link = $this->hydrateObjectArray($data, $locale); |
68
|
|
|
|
69
|
|
|
$event = new DealerAdminLinkEvent(); |
70
|
|
|
$event->setDealerAdminLink($link); |
71
|
|
|
|
72
|
|
|
$this->create($event); |
73
|
|
|
|
74
|
|
|
return $event->getDealerAdminLink(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function updateFromArray($data, $locale = null) |
78
|
|
|
{ |
79
|
|
|
$link = $this->hydrateObjectArray($data, $locale); |
80
|
|
|
|
81
|
|
|
$event = new DealerAdminLinkEvent(); |
82
|
|
|
$event->setDealerAdminLink($link); |
83
|
|
|
|
84
|
|
|
$this->update($event); |
85
|
|
|
|
86
|
|
|
return $event->getDealerAdminLink(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function deleteFromId($id) |
90
|
|
|
{ |
91
|
|
|
$link = DealerAdminQuery::create()->findOneById($id); |
92
|
|
|
if ($link) { |
93
|
|
|
$event = new DealerAdminLinkEvent(); |
94
|
|
|
$event->setDealerAdminLink($link); |
95
|
|
|
|
96
|
|
|
$this->delete($event); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function deleteFromArray($data) |
101
|
|
|
{ |
102
|
|
|
$link = null; |
103
|
|
|
|
104
|
|
|
if (isset($data["admin_id"]) && isset($data["dealer_id"])) { |
105
|
|
|
$link = DealerAdminQuery::create()->filterByDealerId($data["dealer_id"])->filterByAdminId($data["admin_id"])->findOne(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if ($link) { |
109
|
|
|
$event = new DealerAdminLinkEvent(); |
110
|
|
|
$event->setDealerAdminLink($link); |
111
|
|
|
|
112
|
|
|
$this->delete($event); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
protected function hydrateObjectArray($data, $locale = null) |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
$model = new DealerAdmin(); |
119
|
|
|
|
120
|
|
|
if (isset($data['id'])) { |
121
|
|
|
$link = DealerAdminQuery::create()->findOneById($data['id']); |
122
|
|
|
if ($link) { |
123
|
|
|
$model = $link; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if (isset($data["admin_id"]) && isset($data["dealer_id"])) { |
128
|
|
|
$link = DealerAdminQuery::create()->filterByDealerId($data["dealer_id"])->filterByAdminId($data["admin_id"])->findOne(); |
129
|
|
|
if ($link) { |
130
|
|
|
throw new \Exception("A link already exist", 403); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
$model->setAdminId($data["admin_id"]); |
134
|
|
|
$model->setDealerId($data["dealer_id"]); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $model; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.