<?php
 namespace App\ImportedOrder; class SupplierProduct extends EntityAbstract { public $idTina; public $idSystem; public ?\App\ImportedOrder\ServiceType $serviceType = null; public $name; public $groupName; public $categoryCode; public ?\App\ImportedOrder\Place $place = null; public $address; public $telephone; public $fax; public $email; public $imageUrl; protected function getMergingFields() :array { return [ 'idTina', 'idSystem', 'serviceType', 'name', 'categoryCode', 'groupName', 'place', 'address', 'telephone', 'fax', 'email', 'imageUrl' ]; } public function getPopulatedMatchObject($idExternalSystem) { $matchObj = new \App\ImportedOrder\EntityMatch\SupplierProduct('intersect'); if ($this->idTina) { $matchObj->setId($this->idTina); } if ($idExternalSystem and $this->idSystem) { $matchObj->setIdInExtSys($this->idSystem, $idExternalSystem); } if ($this->name) { $matchObj->setProductName($this->name, true); } if ($this->serviceType) { $matchedServiceType = $this->serviceType->getMatchedId($idExternalSystem); if ($matchedServiceType) { $matchObj->filterByServiceCode($matchedServiceType); } } if ($this->place and $this->place->station and $this->place->station->city) { $cityObj = $this->place->station->city; $matchedCityId = $cityObj->getMatchedId($idExternalSystem); if ($matchedCityId) { $matchObj->filterByCityId($matchedCityId); } if ($cityObj->country) { $matchedCountryCode = $cityObj->country->getMatchedId($idExternalSystem); if ($matchedCountryCode) { $matchObj->filterByCountryCode($matchedCountryCode); } } } return $matchObj; } public function getMatchedId($idExternalSystem) { $matchObj = $this->getPopulatedMatchObject($idExternalSystem); $matchObj->search(); if ($matchObj->getResultsCount()==1) { return $matchObj->getFirstMatchId(); } return 0; } protected function validateEntityFields(\App\MessagesCollector $messagesCollector): void { 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->place) { $messagesCollector->appendMessages($this->place->getValidatingMessagesCollector(), 'Place: %s'); } if ($this->serviceType) { $messagesCollector->appendMessages($this->serviceType->getValidatingMessagesCollector(), 'Service Type: %s'); } } } 