initial commit
[namibia] / module / Company / src / Company / Entity / Company.php
1 <?php
2 namespace Company\Entity;
3
4 use Doctrine\ORM\Mapping as ORM;
5
6
7 /**
8  * A company.
9  *
10  * @ORM\Entity
11  * @ORM\HasLifecycleCallbacks
12  * @ORM\Table(name="company")
13  */
14 class Company
15 {
16
17         /**
18          * Can archive records.
19          */
20         const ARCHIVE = true;
21         /**
22          * Pull Synchronization Strategy for this table.
23          */
24         const PULL_SYNCH_STRATEGY = false;
25         /**
26          * Push Synchronization Strategy for this table.
27          */
28         const PUSH_SYNCH_STRATEGY = false;
29
30         /**
31          * Valid dealer types values.
32          */
33         const DEALERTYPE_DEALER       = 'Dealer';
34         const DEALERTYPE_TRADER       = 'Trader';
35         const DEALERTYPE_TRADE_CENTER = 'Trade Center';
36
37         /**
38          * Valid client types values.
39          */
40         const CLIENTTYPE_BUYER  = 'Buyer';
41         const CLIENTTYPE_SELLER = 'Buyer & Seller';
42
43         /**
44          * Valid company types values.
45          */
46         const COMPANYTYPE_LTD       = 'Limited';
47         const COMPANYTYPE_PTY_LTD   = 'PTY Limited';
48         const COMPANYTYPE_CC        = 'Closed Corporation';
49         const COMPANYTYPE_SOLE_PROP = 'Sole Proprietor';
50
51         /**
52          * @ORM\Id
53          * @ORM\Column(type="integer");
54          * @ORM\GeneratedValue(strategy="AUTO")
55          */
56         protected $id;
57
58         /**
59          * @ORM\Column(type="string", length=100)
60          */
61         protected $name;
62
63         /**
64          * @ORM\Column(type="string", length=100, nullable=true, name="business_name")
65          */
66         protected $businessName;
67
68         /**
69          * @ORM\ManyToOne(targetEntity="\Location\Entity\Region")
70          * @ORM\JoinColumn(nullable=false, name="lib_region_id")
71          **/
72         protected $region;
73
74         /**
75          * @ORM\ManyToOne(targetEntity="\Location\Entity\Town")
76          * @ORM\JoinColumn(nullable=false, name="lib_town_id")
77          **/
78         protected $city;
79
80         /**
81          * @ORM\Column(type="string", length=10, name="postal_code")
82          */
83         protected $postalCode;
84
85         /**
86          * @ORM\Column(type="string", length=75)
87          */
88         protected $street;
89
90         /**
91          * @ORM\ManyToOne(targetEntity="\Location\Entity\Town")
92          * @ORM\JoinColumn(nullable=true, name="billing_lib_town_id")
93          **/
94         protected $billingCity;
95
96         /**
97          * @ORM\Column(type="string", length=10, nullable=true, name="billing_postal_code")
98          */
99         protected $billingPostalCode;
100
101         /**
102          * @ORM\Column(type="string", length=75, nullable=true, name="billing_street")
103          */
104         protected $billingStreet;
105
106         /**
107          * @ORM\ManyToOne(targetEntity="\Location\Entity\Town")
108          * @ORM\JoinColumn(nullable=false, nullable=true, name="auction_lib_town_id")
109          **/
110         protected $auctionCity;
111
112         /**
113          * @ORM\Column(type="string", length=10, nullable=true, name="auction_postal_code")
114          */
115         protected $auctionPostalCode;
116
117         /**
118          * @ORM\Column(type="string", length=75, nullable=true, name="auction_street")
119          */
120         protected $auctionStreet;
121
122         /**
123          * @ORM\Column(type="string", length=25, name="dealer_type")
124          */
125         protected $dealerType = 'Trader';
126
127         /**
128          * @ORM\Column(type="string", length=25, name="client_type")
129          */
130         protected $clientType = 'Seller';
131
132         /**
133          * @ORM\Column(type="string", length=100, nullable=true, name="company_registration_number")
134          */
135         protected $companyRegistrationNumber;
136
137         /**
138          * @ORM\Column(type="string", nullable=true, length=20, name="vat_number")
139          */
140         protected $vatNumber;
141
142         /**
143          * @ORM\Column(type="string", nullable=true, length=50, name="turmi_no")
144          */
145         protected $turmiNumber;
146
147         /**
148          * @ORM\Column(type="string", nullable=true, length=50, name="dealer_stock_number")
149          */
150         protected $dealerStockNumber;
151
152         /**
153          * @ORM\ManyToOne(targetEntity="Company")
154          * @ORM\JoinColumn(nullable=true, name="trade_center_dealer_id")
155          **/
156         protected $tradeCenter;
157
158         /**
159          * @ORM\Column(type="boolean", name="trade_exchange_link");
160          */
161         protected $tradeExchangeLink = false;
162
163         /**
164          * @ORM\ManyToOne(targetEntity="Group")
165          * @ORM\JoinColumn(name="company_group_id")
166          **/
167         protected $group;
168
169         /**
170          * @ORM\ManyToOne(targetEntity="GroupDivision")
171          * @ORM\JoinColumn(nullable=true, name="company_group_division_id")
172          **/
173         protected $groupDivision;
174
175         /**
176          * @ORM\ManyToOne(targetEntity="\Config\Entity\RegionalManager")
177          * @ORM\JoinColumn(nullable=true, name="regional_manager_id")
178          **/
179         protected $regionalManager;
180
181         /**
182          * @ORM\Column(type="string", nullable=true, length=25, name="company_type")
183          */
184         protected $companyType;
185
186         /**
187          * @ORM\Column(type="string", nullable=true, length=25, name="company_turnover")
188          */
189         protected $turnover;
190
191         /**
192          * @ORM\OneToOne(targetEntity="\Person\Entity\Contact")
193          * @ORM\JoinColumn(nullable=true, name="lib_contact_id")
194          **/
195         protected $contact;
196
197         /**
198          * @ORM\OneToOne(targetEntity="\Person\Entity\Contact")
199          * @ORM\JoinColumn(nullable=true, name="billing_lib_contact_id")
200          **/
201         protected $billingContact;
202
203         /**
204          * @ORM\ManyToOne(targetEntity="FoundMethod")
205          * @ORM\JoinColumn(nullable=true, name="company_found_method_id")
206          **/
207         protected $foundMethod;
208
209         /**
210          * @ORM\ManyToOne(targetEntity="FoundMethodDetail")
211          * @ORM\JoinColumn(nullable=true, name="company_found_method_detail_id")
212          **/
213         protected $foundMethodDetail;
214
215         /**
216          * @ORM\OneToOne(targetEntity="\Utility\Entity\Image")
217          * @ORM\JoinColumn(nullable=true, name="lib_photo_id")
218          **/
219         protected $dealershipPhoto;
220
221         /**
222          * @ORM\Column(type="boolean", name="price_guide");
223          */
224         protected $priceGuide = false;
225
226         /**
227          * @ORM\Column(type="boolean", name="club_invite");
228          */
229         protected $clubInvite = false;
230
231         /**
232          * @ORM\ManyToOne(targetEntity="\Utility\Entity\Document")
233          * @ORM\JoinColumn(nullable=true, name="stock_cert_lib_document_id")
234          **/
235         private $docStockCertificate;
236
237         /**
238          * @ORM\ManyToOne(targetEntity="\Utility\Entity\Document")
239          * @ORM\JoinColumn(nullable=true, name="address_proof_lib_document_id")
240          **/
241         private $docAddressProof;
242
243         /**
244          * @ORM\ManyToOne(targetEntity="\Utility\Entity\Document")
245          * @ORM\JoinColumn(nullable=true, name="copy_of_id_lib_document_id")
246          **/
247         private $docCopyOfId;
248
249         /**
250          * @ORM\ManyToOne(targetEntity="\Utility\Entity\Document")
251          * @ORM\JoinColumn(nullable=true, name="copy_of_director_id_lib_document_id")
252          **/
253         private $docCopyOfDirectorId;
254
255         /**
256          * @ORM\ManyToOne(targetEntity="\Utility\Entity\Document")
257          * @ORM\JoinColumn(nullable=true, name="company_reg_lib_document_id")
258          **/
259         private $docCompanyRegistration;
260
261         /**
262          * @ORM\Column(nullable=true, type="string", length=64, name="automate_file")
263          */
264         protected $automateFile;
265
266         /**
267          * @ORM\Column(nullable=true, type="string", length=20, name="automate_dealer_code")
268          */
269         protected $automateDealerCode;
270
271         /**
272          * @ORM\Column(nullable=true, type="string", length=64, name="autoline_file")
273          */
274         protected $autolineFile;
275
276         /**
277          * @ORM\Column(nullable=true, type="string", length=20, name="autoline_dealer_code")
278          */
279         protected $autolineDealerCode;
280
281         /**
282          * @ORM\Column(nullable=true, type="string", length=64, name="amhgroup_file")
283          */
284         protected $amhgroupFile;
285
286         /**
287          * @ORM\Column(nullable=true, type="string", length=20, name="amhgroup_dealer_code")
288          */
289         protected $amhgroupDealerCode;
290
291
292         /**
293          * @ORM\OneToMany(targetEntity="\User\Entity\Profile", mappedBy="company", fetch="EXTRA_LAZY")
294          **/
295         private $profiles;
296
297         /**
298          * @ORM\OneToMany(targetEntity="CompanyRetail", mappedBy="company", fetch="EXTRA_LAZY")
299          **/
300         private $retailers;
301
302         /**
303          * @ORM\OneToMany(targetEntity="CompanyOwner", mappedBy="company", cascade={"all"}, fetch="EXTRA_LAZY")
304          **/
305         private $owners;
306
307         /**
308          * @ORM\Column(type="string", length=10, name="status")
309          */
310         protected $jobState = 'New';
311
312         /**
313          * @ORM\Column(type="string", nullable=true, length=250, name="status_reason")
314          */
315         protected $statusReason;
316
317         /**
318          * @ORM\Column(type="boolean",  name="public_centre");
319          */
320         protected $publicCentre = false;
321
322         /**
323          * @ORM\Column(type="datetime");
324          */
325         protected $created;
326
327         /**
328          * @ORM\Column(type="datetime", nullable=true);
329          */
330         protected $updated;
331
332         /**
333          * @ORM\Column(type="boolean");
334          */
335         protected $archived = false;
336
337
338
339         /**
340          * Initialize collections.
341          */
342         public function __construct()
343         {
344                 $this->profiles  = new \Doctrine\Common\Collections\ArrayCollection();
345                 $this->retailers = new \Doctrine\Common\Collections\ArrayCollection();
346                 $this->owners    = new \Doctrine\Common\Collections\ArrayCollection();
347         }
348
349
350         /**
351          * Magic getter to expose protected properties.
352          * @param string $property
353          * @return mixed
354          */
355         public function __get($property)
356         {
357                 return $this->$property;
358         }
359
360         /**
361          * Magic setter to save protected properties.
362          * @param string $property
363          * @param mixed  $value
364          */
365         public function __set($property, $value)
366         {
367                 $this->$property = $value;
368         }
369
370         /**
371          * @ORM\PrePersist
372          */
373         public function setCreateTime()
374         {
375                 $this->created = new \DateTime("now");
376         }
377
378         /**
379          * @ORM\PreUpdate
380          */
381         public function setUpdateTime()
382         {
383                 $this->updated = new \DateTime("now");
384         }
385
386         /**
387          * Convert the object to an array.
388          * @param array   $expand
389          * @param array   $intersect
390          * @param boolean $showIdentifiers
391          * @param integer $expandAll
392          * @return array
393          */
394         public function toArray(
395                 array $expand = array(), array $intersect = array(),
396                 $showIdentifiers = false, $expandAll = 0
397         )
398         {
399                 $intersect      = array_flip($intersect);
400                 $dateTimeFormat = \Utility\Registry::getConfigParam('DateTimeFormat');
401                 $includeAll     = empty($intersect);
402                 $recExpand      = $expand;
403                 foreach ($recExpand as $i => $val)
404                 {
405                         if ('company' == $val || 'tradeCenter' == $val)
406                         {
407                                 unset($recExpand[$i]);
408                         }
409                 }
410                 $data = array();
411                 ($includeAll || isset($intersect['id']))
412                 && $data['id'] = $this->id;
413                 ($includeAll || isset($intersect['name']))
414                 && $data['name'] = $this->name;
415                 ($includeAll || isset($intersect['businessName']))
416                 && $data['businessName'] = $this->businessName;
417
418                 ($includeAll || isset($intersect['region']))
419                 && $data['region'] = (in_array('region', $expand) || $expandAll || $showIdentifiers)
420                                      && !is_null($this->region)
421                         ? (!$showIdentifiers || in_array('region', $expand) ? $this->region->toArray(
422                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
423                         ) : $this->region->id)
424                         : null;
425                 ($includeAll || isset($intersect['city']))
426                 && $data['city'] = (in_array('city', $expand) || $expandAll || $showIdentifiers)
427                                    && !is_null($this->city)
428                         ? (!$showIdentifiers || in_array('city', $expand) ? $this->city->toArray(
429                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
430                         ) : $this->city->id)
431                         : null;
432
433
434                 ($includeAll || isset($intersect['postalCode']))
435                 && $data['postalCode'] = $this->postalCode;
436                 ($includeAll || isset($intersect['street']))
437                 && $data['street'] = $this->street;
438
439                 ($includeAll || isset($intersect['billingCity']))
440                 && $data['billingCity'] = (in_array('billingCity', $expand) || $expandAll || $showIdentifiers)
441                                           && !is_null($this->billingCity)
442                         ? (!$showIdentifiers || in_array('billingCity', $expand) ? $this->billingCity->toArray(
443                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
444                         ) : $this->billingCity->id)
445                         : null;
446                 ($includeAll || isset($intersect['billingPostalCode']))
447                 && $data['billingPostalCode'] = $this->billingPostalCode;
448                 ($includeAll || isset($intersect['billingStreet']))
449                 && $data['billingStreet'] = $this->billingStreet;
450                 ($includeAll || isset($intersect['auctionCity']))
451                 && $data['auctionCity'] = (in_array('auctionCity', $expand) || $expandAll || $showIdentifiers)
452                                           && !is_null($this->auctionCity)
453                         ? (!$showIdentifiers || in_array('auctionCity', $expand) ? $this->auctionCity->toArray(
454                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
455                         ) : $this->auctionCity->id)
456                         : null;
457                 ($includeAll || isset($intersect['auctionPostalCode']))
458                 && $data['auctionPostalCode'] = $this->auctionPostalCode;
459                 ($includeAll || isset($intersect['auctionStreet']))
460                 && $data['auctionStreet'] = $this->auctionStreet;
461
462                 ($includeAll || isset($intersect['dealerType']))
463                 && $data['dealerType'] = $this->dealerType;
464                 ($includeAll || isset($intersect['clientType']))
465                 && $data['clientType'] = $this->clientType;
466                 ($includeAll || isset($intersect['companyRegistrationNumber']))
467                 && $data['companyRegistrationNumber'] = $this->companyRegistrationNumber;
468                 ($includeAll || isset($intersect['vatNumber']))
469                 && $data['vatNumber'] = $this->vatNumber;
470                 ($includeAll || isset($intersect['turmiNumber']))
471                 && $data['turmiNumber'] = $this->turmiNumber;
472                 ($includeAll || isset($intersect['dealerStockNumber']))
473                 && $data['dealerStockNumber'] = $this->dealerStockNumber;
474                 ($includeAll || isset($intersect['tradeCenter']))
475                 && $data['tradeCenter'] = (in_array('tradeCenter', $expand) || $expandAll || $showIdentifiers)
476                                           && !is_null($this->tradeCenter)
477                         ? (!$showIdentifiers || in_array('tradeCenter', $expand)
478                                 ? $this->tradeCenter->toArray(
479                                         array(), array('id', 'name'), $showIdentifiers, 0
480                                 )
481                                 : $this->tradeCenter->id)
482                         : null;
483                 ($includeAll || isset($intersect['tradeExchangeLink']))
484                 && $data['tradeExchangeLink'] = $this->tradeExchangeLink;
485                 ($includeAll || isset($intersect['group']))
486                 && $data['group'] = (in_array('group', $expand) || $expandAll || $showIdentifiers)
487                                     && !is_null($this->group)
488                         ? (!$showIdentifiers || in_array('group', $expand) ? $this->group->toArray(
489                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
490                         ) : $this->group->id)
491                         : null;
492                 ($includeAll || isset($intersect['groupDivision']))
493                 && $data['groupDivision'] = (in_array('groupDivision', $expand) || $expandAll || $showIdentifiers)
494                                             && !is_null($this->groupDivision)
495                         ? (!$showIdentifiers || in_array('groupDivision', $expand) ? $this->groupDivision->toArray(
496                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
497                         ) : $this->groupDivision->id)
498                         : null;
499                 ($includeAll || isset($intersect['regionalManager']))
500                 && $data['regionalManager'] = (in_array('regionalManager', $expand) || $expandAll || $showIdentifiers)
501                                               && !is_null($this->regionalManager)
502                         ? (!$showIdentifiers || in_array('regionalManager', $expand) ? $this->regionalManager->toArray(
503                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
504                         ) : $this->regionalManager->id)
505                         : null;
506                 ($includeAll || isset($intersect['companyType']))
507                 && $data['companyType'] = $this->companyType;
508                 ($includeAll || isset($intersect['turnover']))
509                 && $data['turnover'] = $this->turnover;
510                 ($includeAll || isset($intersect['contact']))
511                 && $data['contact'] = (in_array('contact', $expand) || $expandAll || $showIdentifiers)
512                                       && !is_null($this->contact)
513                         ? (!$showIdentifiers || in_array('contact', $expand) ? $this->contact->toArray(
514                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
515                         ) : $this->contact->id)
516                         : null;
517                 ($includeAll || isset($intersect['billingContact']))
518                 && $data['billingContact'] = (in_array('billingContact', $expand) || $expandAll || $showIdentifiers)
519                                              && !is_null($this->billingContact)
520                         ? (!$showIdentifiers || in_array('billingContact', $expand) ? $this->billingContact->toArray(
521                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
522                         ) : $this->billingContact->id)
523                         : null;
524                 ($includeAll || isset($intersect['foundMethod']))
525                 && $data['foundMethod'] = (in_array('foundMethod', $expand) || $expandAll || $showIdentifiers)
526                                           && !is_null($this->foundMethod)
527                         ? (!$showIdentifiers || in_array('foundMethod', $expand) ? $this->foundMethod->toArray(
528                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
529                         ) : $this->foundMethod->id)
530                         : null;
531                 ($includeAll || isset($intersect['foundMethodDetail']))
532                 && $data['foundMethodDetail'] = (in_array('foundMethodDetail', $expand) || $expandAll || $showIdentifiers)
533                                                 && !is_null($this->foundMethodDetail)
534                         ? (!$showIdentifiers || in_array('foundMethodDetail', $expand) ? $this->foundMethodDetail->toArray(
535                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
536                         ) : $this->foundMethodDetail->id)
537                         : null;
538                 ($includeAll || isset($intersect['dealershipPhoto']))
539                 && $data['dealershipPhoto'] = (in_array('dealershipPhoto', $expand) || $expandAll || $showIdentifiers)
540                                               && !is_null($this->dealershipPhoto)
541                         ? (!$showIdentifiers || in_array('dealershipPhoto', $expand) ? $this->dealershipPhoto->toArray(
542                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
543                         ) : $this->dealershipPhoto->id)
544                         : null;
545                 ($includeAll || isset($intersect['priceGuide']))
546                 && $data['priceGuide'] = $this->priceGuide;
547
548
549                 ($includeAll || isset($intersect['publicCentre']))
550                 && $data['publicCentre'] = $this->publicCentre;
551
552
553                 ($includeAll || isset($intersect['clubInvite']))
554                 && $data['clubInvite'] = $this->clubInvite;
555
556                 ($includeAll || isset($intersect['docStockCertificate']))
557                 && $data['docStockCertificate'] = (in_array('docStockCertificate', $expand) || $expandAll || $showIdentifiers)
558                                                   && !is_null($this->docStockCertificate)
559                         ? (!$showIdentifiers || in_array('docStockCertificate', $expand) ? $this->docStockCertificate->toArray(
560                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
561                         ) : $this->docStockCertificate->id)
562                         : null;
563                 ($includeAll || isset($intersect['docAddressProof']))
564                 && $data['docAddressProof'] = (in_array('docAddressProof', $expand) || $expandAll || $showIdentifiers)
565                                               && !is_null($this->docAddressProof)
566                         ? (!$showIdentifiers || in_array('docAddressProof', $expand) ? $this->docAddressProof->toArray(
567                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
568                         ) : $this->docAddressProof->id)
569                         : null;
570                 ($includeAll || isset($intersect['docCopyOfId']))
571                 && $data['docCopyOfId'] = (in_array('docCopyOfId', $expand) || $expandAll || $showIdentifiers)
572                                           && !is_null($this->docCopyOfId)
573                         ? (!$showIdentifiers || in_array('docCopyOfId', $expand) ? $this->docCopyOfId->toArray(
574                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
575                         ) : $this->docCopyOfId->id)
576                         : null;
577                 ($includeAll || isset($intersect['docCopyOfDirectorId']))
578                 && $data['docCopyOfDirectorId'] = (in_array('docCopyOfDirectorId', $expand) || $expandAll || $showIdentifiers)
579                                                   && !is_null($this->docCopyOfDirectorId)
580                         ? (!$showIdentifiers || in_array('docCopyOfDirectorId', $expand) ? $this->docCopyOfDirectorId->toArray(
581                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
582                         ) : $this->docCopyOfDirectorId->id)
583                         : null;
584                 ($includeAll || isset($intersect['docCompanyRegistration']))
585                 && $data['docCompanyRegistration'] = (in_array('docCompanyRegistration', $expand) || $expandAll || $showIdentifiers)
586                                                      && !is_null($this->docCompanyRegistration)
587                         ? (!$showIdentifiers || in_array('docCompanyRegistration', $expand) ? $this->docCompanyRegistration->toArray(
588                                 $expand, $intersect, $showIdentifiers, ($expandAll - 1)
589                         ) : $this->docCompanyRegistration->id)
590                         : null;
591
592                 ($includeAll || isset($intersect['automateFile']))
593                 && $data['automateFile'] = $this->automateFile;
594                 ($includeAll || isset($intersect['automateDealerCode']))
595                 && $data['automateDealerCode'] = $this->automateDealerCode;
596
597                 ($includeAll || isset($intersect['autolineFile']))
598                 && $data['autolineFile'] = $this->autolineFile;
599                 ($includeAll || isset($intersect['autolineDealerCode']))
600                 && $data['autolineDealerCode'] = $this->autolineDealerCode;
601
602                 ($includeAll || isset($intersect['amhgroupFile']))
603                 && $data['amhgroupFile'] = $this->amhgroupFile;
604                 ($includeAll || isset($intersect['amhgroupDealerCode']))
605                 && $data['amhgroupDealerCode'] = $this->amhgroupDealerCode;
606
607                 ($includeAll || isset($intersect['jobState']))
608                 && $data['jobState'] = $this->jobState;
609                 ($includeAll || isset($intersect['statusReason']))
610                 && $data['statusReason'] = $this->statusReason;
611                 ($includeAll || isset($intersect['created']))
612                 && $data['created'] = !is_null($this->created)
613                         ? $this->created->format($dateTimeFormat)
614                         : null;
615                 ($includeAll || isset($intersect['updated']))
616                 && $data['updated'] = !is_null($this->updated)
617                         ? $this->updated->format($dateTimeFormat)
618                         : null;
619                 return $data;
620         }
621
622         /**
623          * Internal utility to change owners collection into array.
624          * @param boolean $showIdentifiers
625          * @return array
626          */
627         protected function ownersToArray($showIdentifiers = false)
628         {
629                 $data     = array();
630                 $iterator = $this->owners->getIterator();
631                 foreach ($iterator as $owner)
632                 {
633                         $data[] = $showIdentifiers
634                                 ? array('id' => $owner->id)
635                                 : $owner->toArray();
636                 }
637                 return $data;
638         }
639
640         /**
641          * Populate from an array.
642          * @param array $data
643          */
644         public function fromArray($data = array())
645         {
646                 isset($data['id'])
647                 && $this->id = $data['id'];
648                 if (isset($data['name']))
649                 {
650                         $this->name = $data['name'];
651
652                         #-> Update de-normalized auction data.
653                         $em = \Utility\Registry::getEntityManager();
654                         if (!is_null($em))
655                         {
656                                 $em->createQuery(
657                                         'UPDATE \Auction\Entity\Auction a '
658                                         . "SET a.auctionCompanyName = :name "
659                                         . 'WHERE a.jobState = :jobState '
660                                         . ' AND a.auctionCompanyId = :id'
661                                 )
662                                         ->setParameter('jobState', 'Active')
663                                         ->setParameter('id', $this->id)
664                                         ->setParameter('name', $this->name)
665                                         ->execute();
666                         }
667                 }
668                 isset($data['businessName'])
669                 && $this->businessName = $data['businessName'];
670                 isset($data['region'])
671                 && $this->region = $data['region'];
672                 isset($data['city'])
673                 && $this->city = $data['city'];
674
675
676                 isset($data['publicCentre'])
677                 && $this->publicCentre = $data['publicCentre'];
678
679                 isset($data['postalCode'])
680                 && $this->postalCode = $data['postalCode'];
681                 isset($data['street'])
682                 && $this->street = $data['street'];
683                 isset($data['billingCity'])
684                 && $this->billingCity = $data['billingCity'];
685                 isset($data['billingPostalCode'])
686                 && $this->billingPostalCode = $data['billingPostalCode'];
687                 isset($data['billingStreet'])
688                 && $this->billingStreet = $data['billingStreet'];
689                 isset($data['auctionCity'])
690                 && $this->auctionCity = $data['auctionCity'];
691                 isset($data['auctionPostalCode'])
692                 && $this->auctionPostalCode = $data['auctionPostalCode'];
693                 isset($data['auctionStreet'])
694                 && $this->auctionStreet = $data['auctionStreet'];
695                 isset($data['dealerType'])
696                 && $this->dealerType = $data['dealerType'];
697                 isset($data['clientType'])
698                 && $this->clientType = $data['clientType'];
699                 isset($data['companyRegistrationNumber'])
700                 && $this->companyRegistrationNumber = $data['companyRegistrationNumber'];
701                 isset($data['vatNumber'])
702                 && $this->vatNumber = $data['vatNumber'];
703                 isset($data['turmiNumber'])
704                 && $this->turmiNumber = $data['turmiNumber'];
705                 isset($data['dealerStockNumber'])
706                 && $this->dealerStockNumber = $data['dealerStockNumber'];
707                 key_exists('tradeCenter', $data)
708                 && $this->tradeCenter = $data['tradeCenter'];
709                 isset($data['tradeExchangeLink'])
710                 && $this->tradeExchangeLink = $data['tradeExchangeLink'];
711                 isset($data['group'])
712                 && $this->group = $data['group'];
713                 isset($data['groupDivision'])
714                 && $this->groupDivision = $data['groupDivision'];
715                 isset($data['regionalManager'])
716                 && $this->regionalManager = $data['regionalManager'];
717                 isset($data['companyType'])
718                 && $this->companyType = $data['companyType'];
719                 isset($data['turnover'])
720                 && $this->turnover = $data['turnover'];
721                 isset($data['contact'])
722                 && $this->contact = $data['contact'];
723                 isset($data['foundMethod'])
724                 && $this->foundMethod = $data['foundMethod'];
725                 isset($data['foundMethodDetail'])
726                 && $this->foundMethodDetail = $data['foundMethodDetail'];
727                 isset($data['dealershipPhoto'])
728                 && $this->dealershipPhoto = $data['dealershipPhoto'];
729                 isset($data['priceGuide'])
730                 && $this->priceGuide = $data['priceGuide'];
731
732
733                 isset($data['publicCentre'])
734                 && $this->publicCentre = $data['publicCentre'];
735
736
737                 isset($data['clubInvite'])
738                 && $this->clubInvite = $data['clubInvite'];
739                 isset($data['statusReason'])
740                 && $this->statusReason = $data['statusReason'];
741
742                 isset($data['docCopyOfId'])
743                 && $this->docCopyOfId = $data['docCopyOfId'];
744                 isset($data['docCopyOfDirectorId'])
745                 && $this->docCopyOfDirectorId = $data['docCopyOfDirectorId'];
746                 isset($data['docCompanyRegistration'])
747                 && $this->docCompanyRegistration = $data['docCompanyRegistration'];
748                 isset($data['docStockCertificate'])
749                 && $this->docStockCertificate = $data['docStockCertificate'];
750                 isset($data['docAddressProof'])
751                 && $this->docAddressProof = $data['docAddressProof'];
752
753                 isset($data['automateFile'])
754                 && $this->automateFile = $data['automateFile'];
755                 isset($data['automateDealerCode'])
756                 && $this->automateDealerCode = $data['automateDealerCode'];
757
758                 isset($data['autolineFile'])
759                 && $this->autolineFile = $data['autolineFile'];
760                 isset($data['autolineDealerCode'])
761                 && $this->autolineDealerCode = $data['autolineDealerCode'];
762
763                 isset($data['amhgroupFile'])
764                 && $this->amhgroupFile = $data['amhgroupFile'];
765                 isset($data['amhgroupDealerCode'])
766                 && $this->amhgroupDealerCode = $data['amhgroupDealerCode'];
767
768
769                 if (isset($data['owners']))
770                 {
771                         $em       = \Utility\Registry::getEntityManager();
772                         $iterator = $this->owners->getIterator();
773                         foreach ($iterator as $ownr)
774                         {
775                                 $em->remove($ownr);
776                         }
777                         foreach ($data['owners'] as $ownr)
778                         {
779                                 $companyOwnr             = new \Company\Entity\CompanyOwner();
780                                 $companyOwnr->firstName  = $ownr['firstName'];
781                                 $companyOwnr->familyName = $ownr['familyName'];
782                                 $companyOwnr->idNumber   = $ownr['idNumber'];
783                                 $companyOwnr->company    = $this;
784                                 $this->owners->add($companyOwnr);
785                         }
786                 }
787         }
788
789 }