profiles = new \Doctrine\Common\Collections\ArrayCollection(); $this->retailers = new \Doctrine\Common\Collections\ArrayCollection(); $this->owners = new \Doctrine\Common\Collections\ArrayCollection(); } /** * 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() { $this->created = new \DateTime("now"); } /** * @ORM\PreUpdate */ public function setUpdateTime() { $this->updated = new \DateTime("now"); } /** * 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); $recExpand = $expand; foreach ($recExpand as $i => $val) { if ('company' == $val || 'tradeCenter' == $val) { unset($recExpand[$i]); } } $data = array(); ($includeAll || isset($intersect['id'])) && $data['id'] = $this->id; ($includeAll || isset($intersect['name'])) && $data['name'] = $this->name; ($includeAll || isset($intersect['businessName'])) && $data['businessName'] = $this->businessName; ($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; ($includeAll || isset($intersect['city'])) && $data['city'] = (in_array('city', $expand) || $expandAll || $showIdentifiers) && !is_null($this->city) ? (!$showIdentifiers || in_array('city', $expand) ? $this->city->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->city->id) : null; ($includeAll || isset($intersect['postalCode'])) && $data['postalCode'] = $this->postalCode; ($includeAll || isset($intersect['street'])) && $data['street'] = $this->street; ($includeAll || isset($intersect['billingCity'])) && $data['billingCity'] = (in_array('billingCity', $expand) || $expandAll || $showIdentifiers) && !is_null($this->billingCity) ? (!$showIdentifiers || in_array('billingCity', $expand) ? $this->billingCity->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->billingCity->id) : null; ($includeAll || isset($intersect['billingPostalCode'])) && $data['billingPostalCode'] = $this->billingPostalCode; ($includeAll || isset($intersect['billingStreet'])) && $data['billingStreet'] = $this->billingStreet; ($includeAll || isset($intersect['auctionCity'])) && $data['auctionCity'] = (in_array('auctionCity', $expand) || $expandAll || $showIdentifiers) && !is_null($this->auctionCity) ? (!$showIdentifiers || in_array('auctionCity', $expand) ? $this->auctionCity->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->auctionCity->id) : null; ($includeAll || isset($intersect['auctionPostalCode'])) && $data['auctionPostalCode'] = $this->auctionPostalCode; ($includeAll || isset($intersect['auctionStreet'])) && $data['auctionStreet'] = $this->auctionStreet; ($includeAll || isset($intersect['dealerType'])) && $data['dealerType'] = $this->dealerType; ($includeAll || isset($intersect['clientType'])) && $data['clientType'] = $this->clientType; ($includeAll || isset($intersect['companyRegistrationNumber'])) && $data['companyRegistrationNumber'] = $this->companyRegistrationNumber; ($includeAll || isset($intersect['vatNumber'])) && $data['vatNumber'] = $this->vatNumber; ($includeAll || isset($intersect['turmiNumber'])) && $data['turmiNumber'] = $this->turmiNumber; ($includeAll || isset($intersect['dealerStockNumber'])) && $data['dealerStockNumber'] = $this->dealerStockNumber; ($includeAll || isset($intersect['tradeCenter'])) && $data['tradeCenter'] = (in_array('tradeCenter', $expand) || $expandAll || $showIdentifiers) && !is_null($this->tradeCenter) ? (!$showIdentifiers || in_array('tradeCenter', $expand) ? $this->tradeCenter->toArray( array(), array('id', 'name'), $showIdentifiers, 0 ) : $this->tradeCenter->id) : null; ($includeAll || isset($intersect['tradeExchangeLink'])) && $data['tradeExchangeLink'] = $this->tradeExchangeLink; ($includeAll || isset($intersect['group'])) && $data['group'] = (in_array('group', $expand) || $expandAll || $showIdentifiers) && !is_null($this->group) ? (!$showIdentifiers || in_array('group', $expand) ? $this->group->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->group->id) : null; ($includeAll || isset($intersect['groupDivision'])) && $data['groupDivision'] = (in_array('groupDivision', $expand) || $expandAll || $showIdentifiers) && !is_null($this->groupDivision) ? (!$showIdentifiers || in_array('groupDivision', $expand) ? $this->groupDivision->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->groupDivision->id) : null; ($includeAll || isset($intersect['regionalManager'])) && $data['regionalManager'] = (in_array('regionalManager', $expand) || $expandAll || $showIdentifiers) && !is_null($this->regionalManager) ? (!$showIdentifiers || in_array('regionalManager', $expand) ? $this->regionalManager->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->regionalManager->id) : null; ($includeAll || isset($intersect['companyType'])) && $data['companyType'] = $this->companyType; ($includeAll || isset($intersect['turnover'])) && $data['turnover'] = $this->turnover; ($includeAll || isset($intersect['contact'])) && $data['contact'] = (in_array('contact', $expand) || $expandAll || $showIdentifiers) && !is_null($this->contact) ? (!$showIdentifiers || in_array('contact', $expand) ? $this->contact->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->contact->id) : null; ($includeAll || isset($intersect['billingContact'])) && $data['billingContact'] = (in_array('billingContact', $expand) || $expandAll || $showIdentifiers) && !is_null($this->billingContact) ? (!$showIdentifiers || in_array('billingContact', $expand) ? $this->billingContact->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->billingContact->id) : null; ($includeAll || isset($intersect['foundMethod'])) && $data['foundMethod'] = (in_array('foundMethod', $expand) || $expandAll || $showIdentifiers) && !is_null($this->foundMethod) ? (!$showIdentifiers || in_array('foundMethod', $expand) ? $this->foundMethod->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->foundMethod->id) : null; ($includeAll || isset($intersect['foundMethodDetail'])) && $data['foundMethodDetail'] = (in_array('foundMethodDetail', $expand) || $expandAll || $showIdentifiers) && !is_null($this->foundMethodDetail) ? (!$showIdentifiers || in_array('foundMethodDetail', $expand) ? $this->foundMethodDetail->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->foundMethodDetail->id) : null; ($includeAll || isset($intersect['dealershipPhoto'])) && $data['dealershipPhoto'] = (in_array('dealershipPhoto', $expand) || $expandAll || $showIdentifiers) && !is_null($this->dealershipPhoto) ? (!$showIdentifiers || in_array('dealershipPhoto', $expand) ? $this->dealershipPhoto->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->dealershipPhoto->id) : null; ($includeAll || isset($intersect['priceGuide'])) && $data['priceGuide'] = $this->priceGuide; ($includeAll || isset($intersect['publicCentre'])) && $data['publicCentre'] = $this->publicCentre; ($includeAll || isset($intersect['clubInvite'])) && $data['clubInvite'] = $this->clubInvite; ($includeAll || isset($intersect['docStockCertificate'])) && $data['docStockCertificate'] = (in_array('docStockCertificate', $expand) || $expandAll || $showIdentifiers) && !is_null($this->docStockCertificate) ? (!$showIdentifiers || in_array('docStockCertificate', $expand) ? $this->docStockCertificate->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->docStockCertificate->id) : null; ($includeAll || isset($intersect['docAddressProof'])) && $data['docAddressProof'] = (in_array('docAddressProof', $expand) || $expandAll || $showIdentifiers) && !is_null($this->docAddressProof) ? (!$showIdentifiers || in_array('docAddressProof', $expand) ? $this->docAddressProof->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->docAddressProof->id) : null; ($includeAll || isset($intersect['docCopyOfId'])) && $data['docCopyOfId'] = (in_array('docCopyOfId', $expand) || $expandAll || $showIdentifiers) && !is_null($this->docCopyOfId) ? (!$showIdentifiers || in_array('docCopyOfId', $expand) ? $this->docCopyOfId->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->docCopyOfId->id) : null; ($includeAll || isset($intersect['docCopyOfDirectorId'])) && $data['docCopyOfDirectorId'] = (in_array('docCopyOfDirectorId', $expand) || $expandAll || $showIdentifiers) && !is_null($this->docCopyOfDirectorId) ? (!$showIdentifiers || in_array('docCopyOfDirectorId', $expand) ? $this->docCopyOfDirectorId->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->docCopyOfDirectorId->id) : null; ($includeAll || isset($intersect['docCompanyRegistration'])) && $data['docCompanyRegistration'] = (in_array('docCompanyRegistration', $expand) || $expandAll || $showIdentifiers) && !is_null($this->docCompanyRegistration) ? (!$showIdentifiers || in_array('docCompanyRegistration', $expand) ? $this->docCompanyRegistration->toArray( $expand, $intersect, $showIdentifiers, ($expandAll - 1) ) : $this->docCompanyRegistration->id) : null; ($includeAll || isset($intersect['automateFile'])) && $data['automateFile'] = $this->automateFile; ($includeAll || isset($intersect['automateDealerCode'])) && $data['automateDealerCode'] = $this->automateDealerCode; ($includeAll || isset($intersect['autolineFile'])) && $data['autolineFile'] = $this->autolineFile; ($includeAll || isset($intersect['autolineDealerCode'])) && $data['autolineDealerCode'] = $this->autolineDealerCode; ($includeAll || isset($intersect['amhgroupFile'])) && $data['amhgroupFile'] = $this->amhgroupFile; ($includeAll || isset($intersect['amhgroupDealerCode'])) && $data['amhgroupDealerCode'] = $this->amhgroupDealerCode; ($includeAll || isset($intersect['jobState'])) && $data['jobState'] = $this->jobState; ($includeAll || isset($intersect['statusReason'])) && $data['statusReason'] = $this->statusReason; ($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; return $data; } /** * Internal utility to change owners collection into array. * @param boolean $showIdentifiers * @return array */ protected function ownersToArray($showIdentifiers = false) { $data = array(); $iterator = $this->owners->getIterator(); foreach ($iterator as $owner) { $data[] = $showIdentifiers ? array('id' => $owner->id) : $owner->toArray(); } return $data; } /** * Populate from an array. * @param array $data */ public function fromArray($data = array()) { isset($data['id']) && $this->id = $data['id']; if (isset($data['name'])) { $this->name = $data['name']; #-> Update de-normalized auction data. $em = \Utility\Registry::getEntityManager(); if (!is_null($em)) { $em->createQuery( 'UPDATE \Auction\Entity\Auction a ' . "SET a.auctionCompanyName = :name " . 'WHERE a.jobState = :jobState ' . ' AND a.auctionCompanyId = :id' ) ->setParameter('jobState', 'Active') ->setParameter('id', $this->id) ->setParameter('name', $this->name) ->execute(); } } isset($data['businessName']) && $this->businessName = $data['businessName']; isset($data['region']) && $this->region = $data['region']; isset($data['city']) && $this->city = $data['city']; isset($data['publicCentre']) && $this->publicCentre = $data['publicCentre']; isset($data['postalCode']) && $this->postalCode = $data['postalCode']; isset($data['street']) && $this->street = $data['street']; isset($data['billingCity']) && $this->billingCity = $data['billingCity']; isset($data['billingPostalCode']) && $this->billingPostalCode = $data['billingPostalCode']; isset($data['billingStreet']) && $this->billingStreet = $data['billingStreet']; isset($data['auctionCity']) && $this->auctionCity = $data['auctionCity']; isset($data['auctionPostalCode']) && $this->auctionPostalCode = $data['auctionPostalCode']; isset($data['auctionStreet']) && $this->auctionStreet = $data['auctionStreet']; isset($data['dealerType']) && $this->dealerType = $data['dealerType']; isset($data['clientType']) && $this->clientType = $data['clientType']; isset($data['companyRegistrationNumber']) && $this->companyRegistrationNumber = $data['companyRegistrationNumber']; isset($data['vatNumber']) && $this->vatNumber = $data['vatNumber']; isset($data['turmiNumber']) && $this->turmiNumber = $data['turmiNumber']; isset($data['dealerStockNumber']) && $this->dealerStockNumber = $data['dealerStockNumber']; key_exists('tradeCenter', $data) && $this->tradeCenter = $data['tradeCenter']; isset($data['tradeExchangeLink']) && $this->tradeExchangeLink = $data['tradeExchangeLink']; isset($data['group']) && $this->group = $data['group']; isset($data['groupDivision']) && $this->groupDivision = $data['groupDivision']; isset($data['regionalManager']) && $this->regionalManager = $data['regionalManager']; isset($data['companyType']) && $this->companyType = $data['companyType']; isset($data['turnover']) && $this->turnover = $data['turnover']; isset($data['contact']) && $this->contact = $data['contact']; isset($data['foundMethod']) && $this->foundMethod = $data['foundMethod']; isset($data['foundMethodDetail']) && $this->foundMethodDetail = $data['foundMethodDetail']; isset($data['dealershipPhoto']) && $this->dealershipPhoto = $data['dealershipPhoto']; isset($data['priceGuide']) && $this->priceGuide = $data['priceGuide']; isset($data['publicCentre']) && $this->publicCentre = $data['publicCentre']; isset($data['clubInvite']) && $this->clubInvite = $data['clubInvite']; isset($data['statusReason']) && $this->statusReason = $data['statusReason']; isset($data['docCopyOfId']) && $this->docCopyOfId = $data['docCopyOfId']; isset($data['docCopyOfDirectorId']) && $this->docCopyOfDirectorId = $data['docCopyOfDirectorId']; isset($data['docCompanyRegistration']) && $this->docCompanyRegistration = $data['docCompanyRegistration']; isset($data['docStockCertificate']) && $this->docStockCertificate = $data['docStockCertificate']; isset($data['docAddressProof']) && $this->docAddressProof = $data['docAddressProof']; isset($data['automateFile']) && $this->automateFile = $data['automateFile']; isset($data['automateDealerCode']) && $this->automateDealerCode = $data['automateDealerCode']; isset($data['autolineFile']) && $this->autolineFile = $data['autolineFile']; isset($data['autolineDealerCode']) && $this->autolineDealerCode = $data['autolineDealerCode']; isset($data['amhgroupFile']) && $this->amhgroupFile = $data['amhgroupFile']; isset($data['amhgroupDealerCode']) && $this->amhgroupDealerCode = $data['amhgroupDealerCode']; if (isset($data['owners'])) { $em = \Utility\Registry::getEntityManager(); $iterator = $this->owners->getIterator(); foreach ($iterator as $ownr) { $em->remove($ownr); } foreach ($data['owners'] as $ownr) { $companyOwnr = new \Company\Entity\CompanyOwner(); $companyOwnr->firstName = $ownr['firstName']; $companyOwnr->familyName = $ownr['familyName']; $companyOwnr->idNumber = $ownr['idNumber']; $companyOwnr->company = $this; $this->owners->add($companyOwnr); } } } }