1
|
|
|
<?php |
2
|
|
|
/*************************************************************************************/ |
3
|
|
|
/* This file is part of the module FeatureType */ |
4
|
|
|
/* */ |
5
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
6
|
|
|
/* file that was distributed with this source code. */ |
7
|
|
|
/*************************************************************************************/ |
8
|
|
|
|
9
|
|
|
namespace FeatureType\Action; |
10
|
|
|
|
11
|
|
|
use FeatureType\Event\FeatureTypeAvMetaEvent; |
12
|
|
|
use FeatureType\Model\FeatureFeatureType; |
13
|
|
|
use FeatureType\Model\FeatureFeatureTypeQuery; |
14
|
|
|
use FeatureType\Event\FeatureTypeEvent; |
15
|
|
|
use FeatureType\Event\FeatureTypeEvents; |
16
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class FeatureTypeAction |
20
|
|
|
* @package FeatureType\Action |
21
|
|
|
* @author Gilles Bourgeat <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class FeatureTypeAction implements EventSubscriberInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param FeatureTypeEvent $event |
27
|
|
|
* @throws \Exception |
28
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
29
|
|
|
*/ |
30
|
|
|
public function create(FeatureTypeEvent $event) |
31
|
|
|
{ |
32
|
|
|
$event->getFeatureType()->save($event->getConnectionInterface()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param FeatureTypeEvent $event |
37
|
|
|
* @throws \Exception |
38
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
39
|
|
|
*/ |
40
|
|
|
public function update(FeatureTypeEvent $event) |
41
|
|
|
{ |
42
|
|
|
$event->getFeatureType()->save($event->getConnectionInterface()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param FeatureTypeEvent $event |
47
|
|
|
* @throws \Exception |
48
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
49
|
|
|
*/ |
50
|
|
|
public function delete(FeatureTypeEvent $event) |
51
|
|
|
{ |
52
|
|
|
$event->getFeatureType()->delete($event->getConnectionInterface()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param FeatureTypeEvent $event |
57
|
|
|
* @throws \Exception |
58
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
59
|
|
|
*/ |
60
|
|
|
public function associate(FeatureTypeEvent $event) |
61
|
|
|
{ |
62
|
|
|
(new FeatureFeatureType()) |
63
|
|
|
->setFeatureId($event->getFeature()->getId()) |
64
|
|
|
->setFeatureTypeId($event->getFeatureType()->getId()) |
65
|
|
|
->save($event->getConnectionInterface()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param FeatureTypeEvent $event |
70
|
|
|
* @throws \Exception |
71
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
72
|
|
|
*/ |
73
|
|
|
public function dissociate(FeatureTypeEvent $event) |
74
|
|
|
{ |
75
|
|
|
FeatureFeatureTypeQuery::create() |
76
|
|
|
->filterByFeature($event->getFeature()) |
77
|
|
|
->filterByFeatureType($event->getFeatureType()) |
78
|
|
|
->delete($event->getConnectionInterface()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param FeatureTypeAvMetaEvent $event |
83
|
|
|
* @throws \Exception |
84
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
85
|
|
|
*/ |
86
|
|
|
public function metaCreate(FeatureTypeAvMetaEvent $event) |
87
|
|
|
{ |
88
|
|
|
$event->getFeatureTypeAvMeta()->save($event->getConnectionInterface()); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param FeatureTypeAvMetaEvent $event |
93
|
|
|
* @throws \Exception |
94
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
95
|
|
|
*/ |
96
|
|
|
public function metaUpdate(FeatureTypeAvMetaEvent $event) |
97
|
|
|
{ |
98
|
|
|
$event->getFeatureTypeAvMeta()->save($event->getConnectionInterface()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param FeatureTypeAvMetaEvent $event |
103
|
|
|
* @throws \Exception |
104
|
|
|
* @throws \Propel\Runtime\Exception\PropelException |
105
|
|
|
*/ |
106
|
|
|
public function metaDelete(FeatureTypeAvMetaEvent $event) |
107
|
|
|
{ |
108
|
|
|
$event->getFeatureTypeAvMeta()->delete($event->getConnectionInterface()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns an array of event names this subscriber wants to listen to. |
113
|
|
|
* |
114
|
|
|
* The array keys are event names and the value can be: |
115
|
|
|
* |
116
|
|
|
* * The method name to call (priority defaults to 0) |
117
|
|
|
* * An array composed of the method name to call and the priority |
118
|
|
|
* * An array of arrays composed of the method names to call and respective |
119
|
|
|
* priorities, or 0 if unset |
120
|
|
|
* |
121
|
|
|
* For instance: |
122
|
|
|
* |
123
|
|
|
* * array('eventName' => 'methodName') |
124
|
|
|
* * array('eventName' => array('methodName', $priority)) |
125
|
|
|
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')) |
126
|
|
|
* |
127
|
|
|
* @return array The event names to listen to |
128
|
|
|
* |
129
|
|
|
* @api |
130
|
|
|
*/ |
131
|
|
|
public static function getSubscribedEvents() |
132
|
|
|
{ |
133
|
|
|
return array( |
134
|
|
|
FeatureTypeEvents::FEATURE_TYPE_CREATE => array( |
135
|
|
|
'create', 128 |
136
|
|
|
), |
137
|
|
|
FeatureTypeEvents::FEATURE_TYPE_UPDATE => array( |
138
|
|
|
'update', 128 |
139
|
|
|
), |
140
|
|
|
FeatureTypeEvents::FEATURE_TYPE_DELETE => array( |
141
|
|
|
'delete', 128 |
142
|
|
|
), |
143
|
|
|
FeatureTypeEvents::FEATURE_TYPE_ASSOCIATE => array( |
144
|
|
|
'associate', 128 |
145
|
|
|
), |
146
|
|
|
FeatureTypeEvents::FEATURE_TYPE_DISSOCIATE => array( |
147
|
|
|
'dissociate', 128 |
148
|
|
|
), |
149
|
|
|
FeatureTypeEvents::FEATURE_TYPE_AV_META_CREATE => array( |
150
|
|
|
'metaCreate', 128 |
151
|
|
|
), |
152
|
|
|
FeatureTypeEvents::FEATURE_TYPE_AV_META_UPDATE => array( |
153
|
|
|
'metaUpdate', 128 |
154
|
|
|
), |
155
|
|
|
FeatureTypeEvents::FEATURE_TYPE_AV_META_DELETE => array( |
156
|
|
|
'metaDelete', 128 |
157
|
|
|
) |
158
|
|
|
); |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|