1
|
|
|
<?php |
2
|
|
|
namespace Test\TestBundle\Document; |
3
|
|
|
|
4
|
|
|
use Doctrine\Common\Collections\Collection; |
5
|
|
|
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; |
6
|
|
|
use Tpg\ExtjsBundle\Annotation as Extjs; |
7
|
|
|
use JMS\Serializer\Annotation as JMS; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
10
|
|
|
use Test\TestBundle\Document\OrderLineItem; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @Extjs\Model(name="Test.document.Order") |
14
|
|
|
* @ODM\Document(collection="order") |
15
|
|
|
*/ |
16
|
|
|
class Order { |
17
|
|
|
/** |
18
|
|
|
* @ODM\Id |
19
|
|
|
* @JMS\Type("string") |
20
|
|
|
*/ |
21
|
|
|
protected $id; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ODM\Field(type="string") |
25
|
|
|
* @JMS\Type("string") |
26
|
|
|
* @Assert\NotNull |
27
|
|
|
*/ |
28
|
|
|
protected $name; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @ODM\EmbedMany(targetDocument="Test\TestBundle\Document\OrderLineItem") |
32
|
|
|
* @JMS\Type("ArrayCollection<Test\TestBundle\Document\OrderLineItem>") |
33
|
|
|
*/ |
34
|
|
|
protected $lineItems; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @ODM\EmbedOne(targetDocument="Test\TestBundle\Document\OrderLineItem") |
38
|
|
|
* @JMS\Type("Test\TestBundle\Document\OrderLineItem") |
39
|
|
|
*/ |
40
|
|
|
protected $lastLineItem; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @ODM\ReferenceOne(targetDocument="Test\TestBundle\Document\Client", inversedBy="orders", cascade={"persist"}) |
44
|
|
|
* @JMS\Type("Test\TestBundle\Document\Client") |
45
|
|
|
*/ |
46
|
|
|
protected $client; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @ODM\Float |
50
|
|
|
* @JMS\Type("float") |
51
|
|
|
* @Assert\NotNull(groups={"post"}) |
52
|
|
|
*/ |
53
|
|
|
protected $totalPrice; |
54
|
|
|
|
55
|
25 |
|
public function __construct() |
56
|
|
|
{ |
57
|
25 |
|
$this->lineItems = new ArrayCollection(); |
58
|
25 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get id |
62
|
|
|
* |
63
|
|
|
* @return id $id |
64
|
|
|
*/ |
65
|
16 |
|
public function getId() |
66
|
|
|
{ |
67
|
16 |
|
return $this->id; |
68
|
|
|
} |
69
|
|
|
|
70
|
6 |
|
public function setId($id) { |
71
|
6 |
|
$this->id = $id; |
72
|
6 |
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Set name |
77
|
|
|
* |
78
|
|
|
* @param string $name |
79
|
|
|
* @return self |
80
|
|
|
*/ |
81
|
25 |
|
public function setName($name) |
82
|
|
|
{ |
83
|
25 |
|
$this->name = $name; |
84
|
25 |
|
return $this; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get name |
89
|
|
|
* |
90
|
|
|
* @return string $name |
91
|
|
|
*/ |
92
|
6 |
|
public function getName() |
93
|
|
|
{ |
94
|
6 |
|
return $this->name; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Add lineItems |
99
|
|
|
* |
100
|
|
|
* @param OrderLineItem $lineItems |
101
|
|
|
* |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
25 |
|
public function addLineItem(OrderLineItem $lineItems) |
105
|
|
|
{ |
106
|
25 |
|
$this->lineItems[] = $lineItems; |
107
|
25 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Remove lineItems |
112
|
|
|
* |
113
|
|
|
* @param OrderLineItem $lineItems |
114
|
|
|
*/ |
115
|
|
|
public function removeLineItem(OrderLineItem $lineItems) |
116
|
|
|
{ |
117
|
|
|
$this->lineItems->removeElement($lineItems); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Get lineItems |
122
|
|
|
* |
123
|
|
|
* @return ArrayCollection $lineItems |
124
|
|
|
*/ |
125
|
7 |
|
public function getLineItems() |
126
|
|
|
{ |
127
|
7 |
|
return $this->lineItems; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Set totalPrice |
132
|
|
|
* |
133
|
|
|
* @param float $totalPrice |
134
|
|
|
* @return self |
135
|
|
|
*/ |
136
|
25 |
|
public function setTotalPrice($totalPrice) |
137
|
|
|
{ |
138
|
25 |
|
$this->totalPrice = $totalPrice; |
139
|
25 |
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get totalPrice |
144
|
|
|
* |
145
|
|
|
* @return float $totalPrice |
146
|
|
|
*/ |
147
|
5 |
|
public function getTotalPrice() |
148
|
|
|
{ |
149
|
5 |
|
return $this->totalPrice; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Set lastLineItem |
154
|
|
|
* |
155
|
|
|
* @param Test\TestBundle\Document\OrderLineItem $lastLineItem |
156
|
|
|
* @return self |
157
|
|
|
*/ |
158
|
|
|
public function setLastLineItem(\Test\TestBundle\Document\OrderLineItem $lastLineItem) |
159
|
|
|
{ |
160
|
|
|
$this->lastLineItem = $lastLineItem; |
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Get lastLineItem |
166
|
|
|
* |
167
|
|
|
* @return Test\TestBundle\Document\OrderLineItem $lastLineItem |
168
|
|
|
*/ |
169
|
|
|
public function getLastLineItem() |
170
|
|
|
{ |
171
|
|
|
return $this->lastLineItem; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* Set client |
176
|
|
|
* |
177
|
|
|
* @param Test\TestBundle\Document\Client $client |
178
|
|
|
* @return self |
179
|
|
|
*/ |
180
|
25 |
|
public function setClient(\Test\TestBundle\Document\Client $client) |
181
|
|
|
{ |
182
|
25 |
|
$this->client = $client; |
183
|
25 |
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Get client |
188
|
|
|
* |
189
|
|
|
* @return Test\TestBundle\Document\Client $client |
190
|
|
|
*/ |
191
|
6 |
|
public function getClient() |
192
|
|
|
{ |
193
|
6 |
|
return $this->client; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function mergeLineItems(ArrayCollection $list) { |
197
|
|
|
if ($this->lineItems instanceof Collection) { |
198
|
|
|
if ($list->isEmpty()) { |
199
|
|
|
$this->lineItems = $list; |
200
|
|
|
} else { |
201
|
|
|
$this->lineItems = new ArrayCollection(array_merge( |
202
|
|
|
$this->lineItems->toArray(), |
203
|
|
|
$list->toArray() |
204
|
|
|
)); |
205
|
|
|
} |
206
|
|
|
} else { |
207
|
|
|
$this->lineItems = $list; |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|