<?php
 namespace App\EntityMatch; class City extends \App\EntityMatch\BaseAbstract { protected $exportFields = ['name', 'code3', 'countryCode']; protected $matchingFilteringSQL = ' AND deleted=0'; protected $entityClassName = '\Entity\City'; private $countryCodeFilter; protected function setTableName() { global $DBTCities; $this->tableName = $DBTCities; } public function setName($value, $useWildcard=true) { global $CFG; if ($CFG['useAlternativeNames']['cities']) { $this->setSearchCriterion('name', $value, $useWildcard, ['duplicateColumn'=>'name2']); } else { $this->setSearchCriterion('name', $value, $useWildcard); } } public function setCode3($value) { $this->setSearchCriterion('code3', $value, false, ['duplicateColumn'=>'codeLocal']); } public function setStationCode($value) { $this->setSearchCriterion('stationCode', $value, false); } public function filterByCountryCode($value) { $this->countryCodeFilter = $value; } protected function dispatchSearchRecords($field, $value, $useWildcard, Array $options=[]) { switch ($field) { case 'stationCode': return $this->searchRecords_stationCode($value); break; default: return parent::dispatchSearchRecords($field, $value, $useWildcard, $options); } } private function searchRecords_stationCode($value) { $locObj = \Entity\Station::select($value); if (!$locObj->recordExists()) { return []; } if ($locObj->cityId) { return $this->searchRecord_primaryKey($locObj->cityId); } return []; } protected function cleanMatches() { if ($this->countryCodeFilter) { foreach($this->bulkMatches as $idx=>$matchesList) { foreach($matchesList as $entCode=>$entDet) { if ($entDet['countryCode']!=$this->countryCodeFilter) { unset($this->bulkMatches[$idx][$entCode]); } } } $this->bulkMatches = array_filter($this->bulkMatches); } } } 