<?php
 namespace App\EntityMatch; class Corporate extends \App\EntityMatch\BaseAbstract { protected $exportFields = ['alias', 'company']; protected $matchingFilteringSQL = 'AND ent.deleted=0 AND ent.idRealCorporate=0'; protected $entityClassName = '\Entity\Corporate'; protected function setTableName() { global $DBTCorporates; $this->tableName = $DBTCorporates; } public function setAlias($value, $useWildcard=true) { $this->setSearchCriterion('alias', $value, $useWildcard); } public function setCompany($value, $useWildcard=true) { global $CFG; if ($CFG['useAlternativeNames']['corporates']) { $this->setSearchCriterion('company', $value, $useWildcard, ['duplicateColumn'=>'company2']); } else { $this->setSearchCriterion('company', $value, $useWildcard); } } public function setFiscalCode($value) { $CFG = \Entity\Corporate::loadCFG(); if ($value!=$CFG['globalEntity']['::Corporate']['fiscalCode']['notUniqueValue']) { $this->setSearchCriterion('fiscalCode', $value, false); } } public function setRegNo($value) { $this->setSearchCriterion('regNo', $value, false); } public function setVatCertificateNumber($value) { $this->setSearchCriterion('vatCertificateNumber', $value, false); } public function setEmail($value) { $this->setSearchCriterion('email', $value, false); } public function setRemark($remarkVar, $value, $useWildcard=false) { $this->setSearchCriterion('remark', $value, $useWildcard, ['remarkVar'=>$remarkVar]); } protected function dispatchSearchRecords($field, $value, $useWildcard, Array $options=[]) { switch ($field) { case 'remark': return $this->searchRecords_remark($value, $useWildcard, $options); break; default: return parent::dispatchSearchRecords($field, $value, $useWildcard, $options); } } private function searchRecords_remark($value, $useWildcard, Array $options=[]) { global $DBTCorporatesRemarks; if (!$options['remarkVar']) throw new \Exception('You did not set the correct remark var for matching in `'.__CLASS__.'`.'); $db=\DB::getInstance(); $fieldsSQL = $this->getSelectingFieldsSQL(); $remarkValue=$value; if ($useWildcard) $remarkValue.='%'; $searchByRmSQL="
			SELECT {$fieldsSQL} FROM `{$this->tableName}` AS ent, `$DBTCorporatesRemarks` AS rm
			WHERE `rm`.`var`=? AND `rm`.`value`=? AND `rm`.`idCorporate`=`ent`.`id` {$this->matchingFilteringSQL}
			LIMIT {$this->limitResultsPerCriterion}
		"; $searchByRmEx = $db->Execute($searchByRmSQL, [$options['remarkVar'], $remarkValue]); if (!$searchByRmEx) { \Log::getInstance()->dbError("Could not execute the matching for corporate remarks"); throw new \Exception('The matching for corporate remarks could not be executed.'); } $return = []; foreach($searchByRmEx as $corp) { $return[$corp['id']] = $corp; } return $return; } } 