2 namespace Auction\Entity;
4 use Doctrine\ORM\Mapping as ORM;
11 * @ORM\HasLifecycleCallbacks
12 * @ORM\Table(name="auction")
18 * Can archive records.
22 * Pull Synchronization Strategy for this table.
24 const PULL_SYNCH_STRATEGY = false;
26 * Push Synchronization Strategy for this table.
28 const PUSH_SYNCH_STRATEGY = false;
32 /* ------------------------------------ Identification ------------------------------------ */
35 * @ORM\Column(type="integer");
36 * @ORM\GeneratedValue(strategy="AUTO")
41 /* ------------------------------------ Ownership ------------------------------------ */
43 * @ORM\ManyToOne(targetEntity="\User\Entity\Profile")
44 * @ORM\JoinColumn(nullable=false, name="created_by_profile_id")
49 * @ORM\ManyToOne(targetEntity="\Company\Entity\Company")
50 * @ORM\JoinColumn(nullable=false, name="company_id")
55 * @ORM\ManyToOne(targetEntity="\Stock\Entity\Stock")
56 * @ORM\JoinColumn(nullable=false, name="stock_id")
61 * @ORM\ManyToOne(targetEntity="\User\Entity\Profile")
62 * @ORM\JoinColumn(nullable=true, name="sold_to_profile_id")
64 protected $soldToProfile;
67 * @ORM\ManyToOne(targetEntity="\Company\Entity\Company")
68 * @ORM\JoinColumn(nullable=true, name="sold_to_company_id")
70 protected $soldToCompany;
73 /* ------------------------------------ Winning bid ------------------------------------ */
75 * @ORM\OneToOne(targetEntity="\Auction\Entity\Bid", cascade={"all"})
76 * @ORM\JoinColumn(nullable=true, name="auction_bid_id")
78 protected $currentBid;
81 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="bid_price", options={"unsigned"=true});
83 protected $currentBidPrice = 0.0;
86 /* ------------------------------------ Data ------------------------------------ */
88 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="reserve_price",
89 * options={"unsigned"=true});
91 protected $reservePrice = 0.0;
94 * @ORM\Column(type="decimal", scale=2, precision=11, nullable=false, name="bid_increment",
95 * options={"unsigned"=true});
97 protected $bidIncrement = 0.0;
100 * @ORM\Column(type="datetime", name="start_date");
102 protected $startDate;
105 * @ORM\Column(type="datetime", name="end_date");
110 * @ORM\Column(type="integer", nullable=false, name="number_of_bids");
112 protected $numberOfBids = 0;
115 /* ------------------------------------ Linkage ------------------------------------ */
117 * @ORM\OneToMany(targetEntity="Basket", mappedBy="auction", cascade={"all"}, fetch="EXTRA_LAZY")
122 * @ORM\OneToMany(targetEntity="Bid", mappedBy="auction", cascade={"all"}, fetch="EXTRA_LAZY")
127 /* ------------------------------------ De-normalization ------------------------------------ */
128 /* ------------------------------------ Searchable */
131 * @ORM\Column(type="integer", name="region_id", nullable=true);
136 * @ORM\Column(type="integer", name="make_id", nullable=true);
141 * @ORM\Column(type="integer", name="auction_company_id", nullable=true);
143 protected $auctionCompanyId;
146 * @ORM\Column(type="string", name="auction_company_name", length=100, nullable=true)
148 protected $auctionCompanyName;
151 * @ORM\Column(type="string", name="model_name", length=75, nullable=true)
153 protected $modelName;
156 * @ORM\Column(type="string", name="type_name", length=75, nullable=true)
161 * @ORM\Column(type="string", length=12, nullable=true, name="reference_no", nullable=true)
163 protected $referenceNumber;
166 * @ORM\Column(type="string", length=15, name="registration_number", nullable=true)
168 protected $registrationNumber;
171 * @ORM\Column(type="integer", nullable=true, options={"unsigned"=true}, nullable=true)
175 /* ------------------------------------ Not Searchable */
178 * @ORM\Column(type="integer", name="current_bid_company_id", nullable=true);
180 protected $currentBidCompanyId;
183 * @ORM\Column(type="integer", name="stock_company_id", nullable=true);
185 protected $stockCompanyId;
188 * @ORM\Column(type="string", name="region_name", length=75, nullable=true)
190 protected $regionName;
193 * @ORM\Column(type="string", name="make_name", length=75, nullable=true)
198 * @ORM\Column(type="string", name="year_name", length=4, nullable=true)
203 * @ORM\Column(type="datetime", name="stock_created", nullable=true);
205 protected $stockCreated;
209 /* ------------------------------------ Tracking ------------------------------------ */
211 * @ORM\Column(type="boolean", name="email_sent");
213 protected $emailSent = false;
216 * @ORM\Column(nullable=true, type="string", length=25, name="status");
218 protected $jobState = 'Active';
221 * @ORM\Column(type="datetime");
226 * @ORM\Column(type="datetime", nullable=true);
231 * @ORM\Column(type="boolean");
233 protected $archived = false;
238 * Initialize collections.
240 public function __construct()
242 $this->baskets = new \Doctrine\Common\Collections\ArrayCollection();
243 $this->bids = new \Doctrine\Common\Collections\ArrayCollection();
247 * Magic getter to expose protected properties.
249 * @param string $property
252 public function __get($property)
254 return $this->$property;
258 * Magic setter to save protected properties.
260 * @param string $property
261 * @param mixed $value
263 public function __set($property, $value)
265 $this->$property = $value;
271 public function setCreateTime()
273 $this->created = new \DateTime("now");
274 if (is_null($this->startDate))
276 $this->startDate = new \DateTime("now");
278 $this->regionId = $this->company->city->region->id;
279 $this->regionName = $this->company->city->region->name;
280 $this->auctionCompanyId = $this->company->id;
281 $this->auctionCompanyName = $this->company->name;
282 $this->makeId = $this->stock->type->model->make->id;
283 $this->makeName = $this->stock->type->model->make->name;
284 $this->modelName = $this->stock->type->model->name;
285 $this->typeName = $this->stock->type->name;
286 $this->yearName = $this->stock->vehicleYear->name;
287 $this->referenceNumber = $this->stock->referenceNumber;
288 $this->registrationNumber = $this->stock->registrationNumber;
289 $this->stockKm = $this->stock->km;
290 $this->stockCompanyId = $this->stock->company->id;
291 $this->stockCreated = $this->stock->created;
297 public function setUpdateTime()
299 $this->updated = new \DateTime("now");
300 if (!is_null($this->currentBid))
302 $this->currentBidCompanyId = $this->currentBid->company->id;
307 * Convert the object to an array.
308 * @param array $expand
309 * @param array $intersect
310 * @param boolean $showIdentifiers
311 * @param integer $expandAll
314 public function toArray(
315 array $expand = array(), array $intersect = array(),
316 $showIdentifiers = false, $expandAll = 0
319 $intersect = array_flip($intersect);
320 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
321 $includeAll = empty($intersect);
323 ($includeAll || isset($intersect['id']))
324 && $data['id'] = $this->id;
325 ($includeAll || isset($intersect['createdBy']))
326 && $data['createdBy'] = (in_array('createdBy', $expand) || $expandAll || $showIdentifiers)
327 && !is_null($this->createdBy)
328 ? (!$showIdentifiers ? $this->createdBy->toArray(
329 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
330 ) : $this->createdBy->id)
332 ($includeAll || isset($intersect['company']))
333 && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers)
334 && !is_null($this->company)
335 ? (!$showIdentifiers ? $this->company->toArray(
336 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
337 ) : $this->company->id)
339 ($includeAll || isset($intersect['stock']))
340 && $data['stock'] = (in_array('stock', $expand) || $expandAll || $showIdentifiers)
341 && !is_null($this->stock)
342 ? (!$showIdentifiers ? $this->stock->toArray(
343 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
344 ) : $this->stock->id)
346 ($includeAll || isset($intersect['soldToProfile']))
347 && $data['soldToProfile'] = (in_array('soldToProfile', $expand) || $expandAll || $showIdentifiers)
348 && !is_null($this->soldToProfile)
349 ? (!$showIdentifiers ? $this->soldToProfile->toArray(
350 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
351 ) : $this->soldToProfile->id)
353 ($includeAll || isset($intersect['soldToCompany']))
354 && $data['soldToCompany'] = (in_array('soldToCompany', $expand) || $expandAll || $showIdentifiers)
355 && !is_null($this->soldToCompany)
356 ? (!$showIdentifiers ? $this->soldToCompany->toArray(
357 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
358 ) : $this->soldToCompany->id)
360 ($includeAll || isset($intersect['currentBid']))
361 && $data['currentBid'] = (in_array('currentBid', $expand) || $expandAll || $showIdentifiers)
362 && !is_null($this->currentBid)
363 ? (!$showIdentifiers ? $this->currentBid->toArray(
364 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
365 ) : $this->currentBid->id)
367 ($includeAll || isset($intersect['currentBidPrice']))
368 && $data['currentBidPrice'] = $this->currentBidPrice;
369 ($includeAll || isset($intersect['reservePrice']))
370 && $data['reservePrice'] = $this->reservePrice;
371 ($includeAll || isset($intersect['bidIncrement']))
372 && $data['bidIncrement'] = $this->bidIncrement;
373 ($includeAll || isset($intersect['startDate']))
374 && $data['startDate'] = !is_null($this->startDate)
375 ? $this->startDate->format($dateTimeFormat)
377 ($includeAll || isset($intersect['endDate']))
378 && $data['endDate'] = !is_null($this->endDate)
379 ? $this->endDate->format($dateTimeFormat)
381 ($includeAll || isset($intersect['numberOfBids']))
382 && $data['numberOfBids'] = $this->numberOfBids;
383 ($includeAll || isset($intersect['baskets']))
384 && $data['baskets'] = (in_array('baskets', $expand) || $expandAll || $showIdentifiers)
385 && !is_null($this->baskets)
386 ? $this->basketsToArray($showIdentifiers)
388 ($includeAll || isset($intersect['bids']))
389 && $data['bids'] = (in_array('bids', $expand) || $expandAll || $showIdentifiers)
390 && !is_null($this->bids)
391 ? $this->bidsToArray($showIdentifiers)
393 ($includeAll || isset($intersect['jobState']))
394 && $data['jobState'] = $this->jobState;
395 ($includeAll || isset($intersect['created']))
396 && $data['created'] = !is_null($this->created)
397 ? $this->created->format($dateTimeFormat)
399 ($includeAll || isset($intersect['updated']))
400 && $data['updated'] = !is_null($this->updated)
401 ? $this->updated->format($dateTimeFormat)
407 * Internal utility to change auction baskets collection into array.
408 * @param boolean $showIdentifiers
411 protected function basketsToArray($showIdentifiers = false)
414 $iterator = $this->baskets->getIterator();
415 foreach ($iterator as $basket)
417 $data[] = $showIdentifiers
418 ? array('id' => $basket->id)
419 : $basket->toArray();
425 * Internal utility to change auction bids collection into array.
426 * @param boolean $showIdentifiers
429 protected function bidsToArray($showIdentifiers = false)
432 $iterator = $this->bids->getIterator();
433 foreach ($iterator as $bid)
435 $data[] = $showIdentifiers
436 ? array('id' => $bid->id)
443 * Populate from an array.
446 public function fromArray($data = array())
449 && $this->id = $data['id'];
450 isset($data['createdBy'])
451 && $this->createdBy = $data['createdBy'];
452 isset($data['company'])
453 && $this->company = $data['company'];
454 isset($data['stock'])
455 && $this->stock = $data['stock'];
456 isset($data['soldToProfile'])
457 && $this->soldToProfile = $data['soldToProfile'];
458 isset($data['soldToCompany'])
459 && $this->soldToCompany = $data['soldToCompany'];
460 isset($data['currentBid'])
461 && $this->currentBid = $data['currentBid'];
462 isset($data['currentBidPrice'])
463 && $this->currentBidPrice = $data['currentBidPrice'];
464 isset($data['reservePrice'])
465 && $this->reservePrice = $data['reservePrice'];
466 isset($data['bidIncrement'])
467 && $this->bidIncrement = $data['bidIncrement'];
468 isset($data['startDate'])
469 && $this->startDate = $data['startDate'];
470 isset($data['endDate'])
471 && $this->endDate = $data['endDate'];
472 isset($data['numberOfBids'])
473 && $this->numberOfBids = $data['numberOfBids'];