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