<?php
 namespace App\ImportedDocument; class City extends EntityAbstract { protected $country; public $idTina; public $idSystem; public $code3; public $name; public function setCountry(Country $country) { $this->country = $country; } public function getCountry() { return $this->country; } protected function validateEntityFields(\App\MessagesCollector $messagesCollector) { if (!$this->country) { $messagesCollector->addInfo('The city does not contain country details.'); } if ( $this->idTina and (!is_numeric($this->idTina) or $this->idTina<0) ) { $messagesCollector->addInfo('The TINA id is invalid - it should be a positive integer.'); } if ( $this->code3 and (mb_strlen($this->code3)!=3) ) { $messagesCollector->addInfo('The code3 should have exactly 3 chars.'); } if (!$this->idTina and !$this->idSystem and !$this->code3 and !$this->name) { $messagesCollector->addInfo('The city does not contain any details for matching.'); } if ($this->country) { $this->country->validateEntityFields($messagesCollector); } } public function getMatchedId($idExternalSystem) { $matchObj = new \App\ImportedDocument\EntityMatch\City('intersect'); if ($this->idTina) { $matchObj->setId($this->idTina); } if ($idExternalSystem and $this->idSystem) { $matchObj->setIdInExtSys($this->idSystem, $idExternalSystem); } if ($this->code3) { $matchObj->setCode3($this->code3); } if ($this->name) { $matchObj->setName($this->name, true); } if ($this->country) { $countryCode = $this->country->getMatchedId(); if ($countryCode) { $matchObj->filterByCountryCode($countryCode); } } $matchObj->search(); if ($matchObj->getResultsCount()==1) { return $matchObj->getFirstMatchId(); } return 0; } } 