accessories = new \Doctrine\Common\Collections\ArrayCollection(); $this->damages = new \Doctrine\Common\Collections\ArrayCollection(); $this->adherence = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Add a new Accessory to this Stock Item. * @param Accessory $accessory * @return \Stock\Entity\Stock */ public function addAccessory(Accessory $accessory) { $this->accessories[] = $accessory; return $this; } /** * Add a new Damage to this Stock Item. * @param Damage $damage * @return \Stock\Entity\Stock */ public function addDamage(Damage $damage) { $this->damages[] = $damage; return $this; } /** * Magic getter to expose protected properties. * * @param string $property * @return mixed */ public function __get($property) { return $this->$property; } /** * Magic setter to save protected properties. * * @param string $property * @param mixed $value */ public function __set($property, $value) { $this->$property = $value; } /** * @ORM\PrePersist */ public function setCreateTime() { if (is_null($this->uvi)) { list($usec, $sec) = explode(" ", microtime()); $this->uvi = $sec . substr($usec, 2, 3); } if (\Utility\Registry::get('IsDeviceApiCall', false)) { // Leave company and createdBy for controller to set. } else if (\Utility\Registry::get('IsBulkImport', false)) { // Leave company and createdBy for controller to set. } else if (\Utility\Registry::isAuthenticated()) { $this->company = \Utility\Registry::resolveCompanyContext($this->company); $this->createdBy = \Utility\Registry::resolveProfileContext($this->createdBy); } else { $em = \Utility\Registry::getEntityManager(); // $companyId = IS_STAGE_ENV ? 1953 : 2283; $companyId = IS_STAGE_ENV ? 1 : 1; if (IS_DEV_ENV) { $companyId = 1; } $this->company = $em->getReference('\Company\Entity\Company', $companyId); $this->createdBy = $em->getReference('\User\Entity\Profile', 1); } $this->created = new \DateTime("now"); if (0.0 != $this->tradePrice && is_null($this->tradePriceDate)) { $this->tradePriceDate = new \DateTime('now'); } if (0.0 != $this->oldTradePrice && is_null($this->oldTradePriceDate)) { $this->oldTradePriceDate = new \DateTime('now'); } if (0.0 != $this->listPrice && is_null($this->listPriceDate)) { $this->listPriceDate = new \DateTime('now'); } if (0.0 != $this->oldListPrice && is_null($this->oldListPriceDate)) { $this->oldListPriceDate = new \DateTime('now'); } } /** * @ORM\PreUpdate */ public function setUpdateTime() { $this->updated = new \DateTime("now"); if (0.0 != $this->tradePrice && is_null($this->tradePriceDate)) { $this->tradePriceDate = new \DateTime('now'); } if (0.0 != $this->oldTradePrice && is_null($this->oldTradePriceDate)) { $this->oldTradePriceDate = new \DateTime('now'); } if (0.0 != $this->listPrice && is_null($this->listPriceDate)) { $this->listPriceDate = new \DateTime('now'); } if (0.0 != $this->oldListPrice && is_null($this->oldListPriceDate)) { $this->oldListPriceDate = new \DateTime('now'); } /* if ('' == $this->jobState && is_null($this->loadedOnPriceGuide)) { $this->loadedOnPriceGuide = new \DateTime("now"); } */ } /** * Automatically called from DataBin if HAVE_POST_INSERT constant is set on entity. * @return boolean */ public function postInsert() { if (is_null($this->id) || !is_numeric($this->id)) { return false; } $this->referenceNumber = 'S' . str_pad($this->id, 7, '0', STR_PAD_LEFT); return true; } /** * Convert the object to an array. * @param array $expand * @param array $intersect * @param boolean $showIdentifiers * @param integer $expandAll * @return array */ public function toArray( array $expand = array(), array $intersect = array(), $showIdentifiers = false, $expandAll = 0 ) { $intersect = array_flip($intersect); $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat'); $includeAll = empty($intersect); $data = array(); ($includeAll || isset($intersect['id'])) && $data['id'] = $this->id; ($includeAll || isset($intersect['uvi'])) && $data['uvi'] = $this->uvi; ($includeAll || isset($intersect['company'])) && $data['company'] = (in_array('company', $expand) || $expandAll || $showIdentifiers) && !is_null($this->company) ? (!$showIdentifiers || in_array('company', $expand) ? $this->company->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->company->id) : null; ($includeAll || isset($intersect['auction'])) && $data['auction'] = (in_array('auction', $expand) || $expandAll || $showIdentifiers) && !is_null($this->auction) ? (!$showIdentifiers || in_array('auction', $expand) ? $this->auction->toArray( array(), array('id','company','soldToCompany','stock','endDate','reservePrice','jobState'), true, ($expandAll - 1) ) : $this->auction->id) : null; if (isset($data['auction'])) { $date = new \DateTime($data['auction']['endDate']); $data['auction']['Within30DaysOfEnd'] = time() < ($date->getTimestamp() + 2592000); } ($includeAll || isset($intersect['createdBy'])) && $data['createdBy'] = (in_array('createdBy', $expand) || $expandAll || $showIdentifiers) && !is_null($this->createdBy) ? (!$showIdentifiers || in_array('createdBy', $expand) ? $this->createdBy->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->createdBy->id) : null; ($includeAll || isset($intersect['valuation'])) && $data['valuation'] = (in_array('valuation_', $expand) || $expandAll || $showIdentifiers) && !is_null($this->valuation) ? (!$showIdentifiers || in_array('valuation_', $expand) ? $this->valuation->toArray( /* $expand, $intersect, $showIdentifiers, ($expandAll - 1) */ ) : $this->valuation->id) : null; ($includeAll || isset($intersect['region'])) && $data['region'] = (in_array('region', $expand) || $expandAll || $showIdentifiers) && !is_null($this->region) ? (!$showIdentifiers || in_array('region', $expand) ? $this->region->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->region->id) : null; (!\Utility\Registry::checkOnce('Stock.IgnorePriceGuide', false) && ($includeAll || isset($intersect['priceGuide']))) && $data['priceGuide'] = (in_array('priceGuide', $expand) || $expandAll || $showIdentifiers) && !is_null($this->priceGuide) ? (!$showIdentifiers || in_array('priceGuide', $expand) ? $this->priceGuide->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->priceGuide->id) : null; if (2 == $showIdentifiers) { $data['mmCode'] = $this->type->mmCode; $data['category'] = $this->type->category->id; $data['make'] = $this->type->model->make->id; $data['model'] = $this->type->model->id; } ($includeAll || isset($intersect['type'])) && $data['type'] = (in_array('type', $expand) || $expandAll || $showIdentifiers) && !is_null($this->type) ? (!$showIdentifiers || in_array('type', $expand) ? $this->type->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->type->id) : null; ($includeAll || isset($intersect['referenceNumber'])) && $data['referenceNumber'] = $this->referenceNumber; ($includeAll || isset($intersect['stockNumber'])) && $data['stockNumber'] = $this->stockNumber; ($includeAll || isset($intersect['registrationNumber'])) && $data['registrationNumber'] = $this->registrationNumber; ($includeAll || isset($intersect['vinNumber'])) && $data['vinNumber'] = $this->vinNumber; ($includeAll || isset($intersect['engineNumber'])) && $data['engineNumber'] = $this->engineNumber; ($includeAll || isset($intersect['fuelType'])) && $data['fuelType'] = (in_array('fuelType', $expand) || $expandAll || $showIdentifiers) && !is_null($this->fuelType) ? (!$showIdentifiers || in_array('fuelType', $expand) ? $this->fuelType->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->fuelType->id) : null; ($includeAll || isset($intersect['transmissionType'])) && $data['transmissionType'] = (in_array('transmissionType', $expand) || $expandAll || $showIdentifiers) && !is_null($this->transmissionType) ? (!$showIdentifiers || in_array('transmissionType', $expand) ? $this->transmissionType->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->transmissionType->id) : null; ($includeAll || isset($intersect['exteriorColour'])) && $data['exteriorColour'] = (in_array('exteriorColour', $expand) || $expandAll || $showIdentifiers) && !is_null($this->exteriorColour) ? (!$showIdentifiers || in_array('exteriorColour', $expand) ? $this->exteriorColour->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->exteriorColour->id) : null; ($includeAll || isset($intersect['interiorColour'])) && $data['interiorColour'] = (in_array('interiorColour', $expand) || $expandAll || $showIdentifiers) && !is_null($this->interiorColour) ? (!$showIdentifiers || in_array('interiorColour', $expand) ? $this->interiorColour->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->interiorColour->id) : null; ($includeAll || isset($intersect['condition'])) && $data['condition'] = (in_array('condition', $expand) || $expandAll || $showIdentifiers) && !is_null($this->condition) ? (!$showIdentifiers || in_array('condition', $expand) ? $this->condition->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->condition->id) : null; ($includeAll || isset($intersect['vehicleYear'])) && $data['vehicleYear'] = (in_array('vehicleYear', $expand) || $expandAll || $showIdentifiers) && !is_null($this->vehicleYear) ? (!$showIdentifiers || in_array('vehicleYear', $expand) ? $this->vehicleYear->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->vehicleYear->id) : null; ($includeAll || isset($intersect['km'])) && $data['km'] = $this->km; ($includeAll || isset($intersect['upholstery'])) && $data['upholstery'] = (in_array('upholstery', $expand) || $expandAll || $showIdentifiers) && !is_null($this->upholstery) ? (!$showIdentifiers || in_array('upholstery', $expand) ? $this->upholstery->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->upholstery->id) : null; ($includeAll || isset($intersect['papers'])) && $data['papers'] = (in_array('papers', $expand) || $expandAll || $showIdentifiers) && !is_null($this->papers) ? (!$showIdentifiers || in_array('papers', $expand) ? $this->papers->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->papers->id) : null; ($includeAll || isset($intersect['papersNotes'])) && $data['papersNotes'] = $this->papersNotes; ($includeAll || isset($intersect['natis'])) && $data['natis'] = (in_array('natis', $expand) || $expandAll || $showIdentifiers) && !is_null($this->natis) ? (!$showIdentifiers || in_array('natis', $expand) ? $this->natis->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->natis->id) : null; ($includeAll || isset($intersect['spareKeys'])) && $data['spareKeys'] = $this->spareKeys; ($includeAll || isset($intersect['fullServiceHistory'])) && $data['fullServiceHistory'] = (in_array('fullServiceHistory', $expand) || $expandAll || $showIdentifiers) && !is_null($this->fullServiceHistory) ? (!$showIdentifiers || in_array('fullServiceHistory', $expand) ? $this->fullServiceHistory->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->fullServiceHistory->id) : null; ($includeAll || isset($intersect['fshNotes'])) && $data['fshNotes'] = $this->fshNotes; ($includeAll || isset($intersect['tradePriceDate'])) && $data['tradePriceDate'] = !is_null($this->tradePriceDate) ? $this->tradePriceDate->format($dateTimeFormat) : null; ($includeAll || isset($intersect['listPriceDate'])) && $data['listPriceDate'] = !is_null($this->listPriceDate) ? $this->listPriceDate->format($dateTimeFormat) : null; ($includeAll || isset($intersect['tradePrice'])) && $data['tradePrice'] = $this->tradePrice; ($includeAll || isset($intersect['retailPrice'])) && $data['retailPrice'] = $this->retailPrice; ($includeAll || isset($intersect['listPrice'])) && $data['listPrice'] = $this->listPrice; ($includeAll || isset($intersect['oldTradePriceDate'])) && $data['oldTradePriceDate'] = !is_null($this->oldTradePriceDate) ? $this->oldTradePriceDate->format($dateTimeFormat) : null; ($includeAll || isset($intersect['oldListPriceDate'])) && $data['oldListPriceDate'] = !is_null($this->oldListPriceDate) ? $this->oldListPriceDate->format($dateTimeFormat) : null; ($includeAll || isset($intersect['oldTradePrice'])) && $data['oldTradePrice'] = $this->oldTradePrice; ($includeAll || isset($intersect['oldRetailPrice'])) && $data['oldRetailPrice'] = $this->oldRetailPrice; ($includeAll || isset($intersect['oldListPrice'])) && $data['oldListPrice'] = $this->oldListPrice; ($includeAll || isset($intersect['retailAmountRequired'])) && $data['retailAmountRequired'] = $this->retailAmountRequired; ($includeAll || isset($intersect['mainImage'])) && $data['mainImage'] = (in_array('mainImage', $expand) || $expandAll || $showIdentifiers) && !is_null($this->mainImage) ? (!$showIdentifiers || in_array('mainImage', $expand) ? $this->mainImage->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->mainImage->id) : null; ($includeAll || isset($intersect['frontImage'])) && $data['frontImage'] = (in_array('frontImage', $expand) || $expandAll || $showIdentifiers) && !is_null($this->frontImage) ? (!$showIdentifiers || in_array('frontImage', $expand) ? $this->frontImage->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->frontImage->id) : null; ($includeAll || isset($intersect['rightImage'])) && $data['rightImage'] = (in_array('rightImage', $expand) || $expandAll || $showIdentifiers) && !is_null($this->rightImage) ? (!$showIdentifiers || in_array('rightImage', $expand) ? $this->rightImage->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->rightImage->id) : null; ($includeAll || isset($intersect['leftImage'])) && $data['leftImage'] = (in_array('leftImage', $expand) || $expandAll || $showIdentifiers) && !is_null($this->leftImage) ? (!$showIdentifiers || in_array('leftImage', $expand) ? $this->leftImage->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->leftImage->id) : null; ($includeAll || isset($intersect['backImage'])) && $data['backImage'] = (in_array('backImage', $expand) || $expandAll || $showIdentifiers) && !is_null($this->backImage) ? (!$showIdentifiers || in_array('backImage', $expand) ? $this->backImage->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->backImage->id) : null; ($includeAll || isset($intersect['interiorImage'])) && $data['interiorImage'] = (in_array('interiorImage', $expand) || $expandAll || $showIdentifiers) && !is_null($this->interiorImage) ? (!$showIdentifiers || in_array('interiorImage', $expand) ? $this->interiorImage->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->interiorImage->id) : null; ($includeAll || isset($intersect['engineImage'])) && $data['engineImage'] = (in_array('engineImage', $expand) || $expandAll || $showIdentifiers) && !is_null($this->engineImage) ? (!$showIdentifiers || in_array('engineImage', $expand) ? $this->engineImage->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->engineImage->id) : null; ($includeAll || isset($intersect['natisImage'])) && $data['natisImage'] = (in_array('natisImage', $expand) || $expandAll || $showIdentifiers) && !is_null($this->natisImage) ? (!$showIdentifiers || in_array('natisImage', $expand) ? $this->natisImage->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->natisImage->id) : null; ($includeAll || isset($intersect['accessories'])) && $data['accessories'] = (in_array('accessories', $expand) || $expandAll || $showIdentifiers) && !is_null($this->accessories) ? $this->accessoriesToArray($showIdentifiers) : null; ($includeAll || isset($intersect['accessoryNotes'])) && $data['accessoryNotes'] = $this->accessoryNotes; ($includeAll || isset($intersect['damages'])) && $data['damages'] = (in_array('damages', $expand) || $expandAll || $showIdentifiers) && !is_null($this->damages) ? $this->damagesToArray($showIdentifiers) : null; ($includeAll || isset($intersect['damageTotal'])) && $data['damageTotal'] = $this->damageTotal; ($includeAll || isset($intersect['damageNotes'])) && $data['damageNotes'] = $this->damageNotes; ($includeAll || isset($intersect['previousRepairsNoted'])) && $data['previousRepairsNoted'] = $this->previousRepairsNoted; ($includeAll || isset($intersect['previousRepairsNotes'])) && $data['previousRepairsNotes'] = $this->previousRepairsNotes; ($includeAll || isset($intersect['coverReceived'])) && $data['coverReceived'] = $this->coverReceived; ($includeAll || isset($intersect['numberOfOffers'])) && $data['numberOfOffers'] = $this->numberOfOffers; ($includeAll || isset($intersect['highestOffer'])) && $data['highestOffer'] = $this->highestOffer; ($includeAll || isset($intersect['loadedOnPriceGuide'])) && $data['loadedOnPriceGuide'] = !is_null($this->loadedOnPriceGuide) ? $this->loadedOnPriceGuide->format($dateTimeFormat) : null; ($includeAll || isset($intersect['timesListed'])) && $data['timesListed'] = $this->timesListed; ($includeAll || isset($intersect['highestBid'])) && $data['highestBid'] = $this->highestBid; ($includeAll || isset($intersect['jobState'])) && $data['jobState'] = $this->jobState; ($includeAll || isset($intersect['created'])) && $data['created'] = !is_null($this->created) ? $this->created->format($dateTimeFormat) : null; ($includeAll || isset($intersect['updated'])) && $data['updated'] = !is_null($this->updated) ? $this->updated->format($dateTimeFormat) : null; ($includeAll || isset($intersect['reset'])) && $data['reset'] = !is_null($this->reset) ? $this->reset->format($dateTimeFormat) : null; return $data; } /** * Internal utility to change accessories collection into array. * @param boolean $showIdentifiers * @return array */ public function accessoriesToArray($showIdentifiers = false) { $data = array(); $iterator = $this->accessories->getIterator(); if (2 == $showIdentifiers) { foreach ($iterator as $accessory) { $data[] = $accessory->accessory->id; } } else { foreach ($iterator as $accessory) { $data[] = $showIdentifiers ? array('id' => $accessory->accessory->id) : $accessory->toArray(); } } return $data; } /** * Internal utility to change damages collection into array. * @param boolean $showIdentifiers * @return array */ public function damagesToArray($showIdentifiers = false) { $data = array(); $iterator = $this->damages->getIterator(); foreach ($iterator as $damage) { $data[] = $damage->toArray(array(), array(), $showIdentifiers); } return $data; } /** * Populate from an array. * @param array $data */ public function fromArray($data = array()) { isset($data['id']) && $this->id = $data['id']; isset($data['uvi']) && $this->uvi = $data['uvi']; isset($data['company']) && $this->company = $data['company']; isset($data['createdBy']) && $this->createdBy = $data['createdBy']; isset($data['region']) && $this->region = $data['region']; isset($data['type']) && $this->type = $data['type']; isset($data['stockNumber']) && $this->stockNumber = $data['stockNumber']; isset($data['registrationNumber']) && $this->registrationNumber = $data['registrationNumber']; isset($data['vinNumber']) && $this->vinNumber = $data['vinNumber']; isset($data['engineNumber']) && $this->engineNumber = $data['engineNumber']; isset($data['fuelType']) && $this->fuelType = $data['fuelType']; isset($data['transmissionType']) && $this->transmissionType = $data['transmissionType']; isset($data['exteriorColour']) && $this->exteriorColour = $data['exteriorColour']; isset($data['interiorColour']) && $this->interiorColour = $data['interiorColour']; isset($data['condition']) && $this->condition = $data['condition']; isset($data['vehicleYear']) && $this->vehicleYear = $data['vehicleYear']; isset($data['km']) && $this->km = $data['km']; isset($data['upholstery']) && $this->upholstery = $data['upholstery']; isset($data['papers']) && $this->papers = $data['papers']; isset($data['papersNotes']) && $this->papersNotes = $data['papersNotes']; isset($data['natis']) && $this->natis = $data['natis']; isset($data['spareKeys']) && $this->spareKeys = $data['spareKeys']; isset($data['fullServiceHistory']) && $this->fullServiceHistory = $data['fullServiceHistory']; isset($data['fshNotes']) && $this->fshNotes = $data['fshNotes']; isset($data['tradePrice']) && $this->tradePrice = $data['tradePrice']; isset($data['retailPrice']) && $this->retailPrice = $data['retailPrice']; isset($data['listPrice']) && $this->listPrice = $data['listPrice']; isset($data['oldTradePrice']) && $this->oldTradePrice = $data['oldTradePrice']; isset($data['oldRetailPrice']) && $this->oldRetailPrice = $data['oldRetailPrice']; isset($data['oldListPrice']) && $this->oldListPrice = $data['oldListPrice']; isset($data['retailAmountRequired']) && $this->retailAmountRequired = $data['retailAmountRequired']; isset($data['mainImage']) && $this->mainImage = $data['mainImage']; isset($data['frontImage']) && $this->frontImage = $data['frontImage']; isset($data['rightImage']) && $this->rightImage = $data['rightImage']; isset($data['leftImage']) && $this->leftImage = $data['leftImage']; isset($data['backImage']) && $this->backImage = $data['backImage']; isset($data['interiorImage']) && $this->interiorImage = $data['interiorImage']; isset($data['engineImage']) && $this->engineImage = $data['engineImage']; isset($data['natisImage']) && $this->natisImage = $data['natisImage']; isset($data['accessoryNotes']) && $this->accessoryNotes = $data['accessoryNotes']; isset($data['damageTotal']) && $this->damageTotal = $data['damageTotal']; isset($data['damageNotes']) && $this->damageNotes = $data['damageNotes']; isset($data['previousRepairsNoted']) && $this->previousRepairsNoted = $data['previousRepairsNoted']; isset($data['previousRepairsNotes']) && $this->previousRepairsNotes = $data['previousRepairsNotes']; isset($data['coverReceived']) && $this->coverReceived = $data['coverReceived']; isset($data['numberOfOffers']) && $this->numberOfOffers = $data['numberOfOffers']; isset($data['highestOffer']) && $this->highestOffer = $data['highestOffer']; isset($data['loadedOnPriceGuide']) && $this->loadedOnPriceGuide = $data['loadedOnPriceGuide']; isset($data['jobState']) && $this->jobState = $data['jobState']; if (isset($data['accessories'])) { $em = \Utility\Registry::getEntityManager(); $newAccs = array(); foreach ($data['accessories'] as $acc) { $newAccs[$acc['id']] = $acc['id']; } $currentAccs = array(); $iterator = $this->accessories->getIterator(); foreach ($iterator as $acc) { $currentAccs[$acc->accessory->id] = $acc->accessory->id; !isset($newAccs[$acc->accessory->id]) && $em->remove($acc); } foreach ($data['accessories'] as $acc) { if (!isset($currentAccs[$acc['id']])) { $stockAcc = new \Stock\Entity\StockAccessory(); $stockAcc->accessory = $em->getReference('\Stock\Entity\Accessory', $acc['id']); $stockAcc->stock = $this; $this->accessories->add($stockAcc); } } } if (isset($data['damages'])) { $em = \Utility\Registry::getEntityManager(); $newDmgs = array(); $total = 0.0; foreach ($data['damages'] as $dmg) { $total += $dmg['amount']; $newDmgs[$dmg['id']] = $dmg['amount']; } $this->damageTotal = $total; $currentDmgs = array(); $iterator = $this->damages->getIterator(); foreach ($iterator as $dmg) { $currentDmgs[$dmg->damage->id] = $dmg->damage->id; if (!isset($newDmgs[$dmg->damage->id])) { $em->remove($dmg); } else { $dmg->amount = $newDmgs[$dmg->damage->id]; } } foreach ($data['damages'] as $dmg) { if (!isset($currentDmgs[$dmg['id']])) { $stockDamage = new \Stock\Entity\StockDamage(); $stockDamage->damage = $em->getReference('\Stock\Entity\Damage', $dmg['id']); $stockDamage->amount = $dmg['amount']; $stockDamage->stock = $this; $this->damages->add($stockDamage); } } } #-> Update de-normalized auction data. \Utility\Registry::getEntityManager()->createQuery( 'UPDATE \Auction\Entity\Auction a ' . "SET a.referenceNumber = :referenceNumber, " . " a.registrationNumber = :registrationNumber, " . " a.makeId = :makeId, " . " a.makeName = :makeName, " . " a.modelName = :modelName, " . " a.typeName = :typeName, " . " a.yearName = :yearName, " . " a.stockKm = :km " . 'WHERE a.jobState = :jobState ' . ' AND IDENTITY(a.stock) = :id' ) ->setParameter('jobState', 'Active') ->setParameter('id', $this->id) ->setParameter('referenceNumber', $this->referenceNumber) ->setParameter('registrationNumber', $this->registrationNumber) ->setParameter('makeId', $this->type->model->make->id) ->setParameter('makeName', $this->type->model->make->name) ->setParameter('modelName', $this->type->model->name) ->setParameter('typeName', $this->type->name) ->setParameter('yearName', $this->vehicleYear->name) ->setParameter('km', $this->km) ->execute(); } }