<?php
 namespace App\Form\Input; class Autocomplete_Data_SupplierAndProduct extends \Engine\Form\Input\Autocomplete_Data_GeneralAbstract { protected $minLength = 2; protected function getPageResultsBulk() :array { global $DBTSuppliers, $DBTSuppliersProducts; $vars = []; $sql = "(
			SELECT
				CONCAT('0|', id) AS idElement, productName AS display,
				'0' AS idRealSupplier, 'product' AS type, serviceCode,
				'' AS company, '' AS companySuffix, '' AS companyPrefix, '' AS countryCode, '' AS cityId,
				destinationCountryCode, destinationCityId
			FROM `$DBTSuppliersProducts`
			WHERE deleted=0 AND productName!=''
		"; if ($this->searchString) { if ($this->searchType == 'contains') { $sql .= " AND (productName LIKE ? OR productName LIKE ?)"; $vars[] = $this->searchString.'%'; $vars[] = '% '.$this->searchString.'%'; } else { $sql .= " AND productName LIKE ?"; $vars[] = $this->searchString.'%'; } } $sql.=' ) UNION ALL '; $sql .= "(
			SELECT
				CONCAT(id, '|0') AS idElement, alias AS display,
				idRealSupplier, 'supplier' AS type, '' AS serviceCode,
				company, companySuffix, companyPrefix, countryCode, cityId,
				'' AS destinationCountryCode, '' AS destinationCityId
			FROM `$DBTSuppliers`
			WHERE deleted=0
		"; if ($this->searchString) { if ($this->searchType == 'contains') { $sql .= " AND (alias LIKE ? OR company LIKE ?)"; $vars[] = '%'.$this->searchString.'%'; $vars[] = '%'.$this->searchString.'%'; } else { $sql .= " AND (alias LIKE ? OR company LIKE ?)"; $vars[] = $this->searchString.'%'; $vars[] = $this->searchString.'%'; } } $sql .= ' )'; $sqlCountTotal = "SELECT COUNT(*) FROM ($sql) AS total_rows"; $this->executeCountSql($sqlCountTotal, $vars); $sql .= " ORDER BY display ASC LIMIT {$this->offset}, {$this->resultsCountPage}"; return $this->executeSql($sql, $vars); } protected function getPageResultsFormatted(Array $pageResults) { global $_LANG; $list = []; foreach($pageResults as $row) { $extra = ''; if ($row['serviceCode']) { $extra .= \App\Config\Services_Basic::getInstance()->getServiceName($row['serviceCode']); } if ($row['idRealSupplier']) { $extra .= $_LANG['RemoteData']['AutocompleteFieldData']['index']['generalFields']['duplicate']; } $otherFields = []; if ($row['type'] == 'product') { $otherFields['className'] = 'italic'; } $info = ''; if ($row['type'] == 'product') { if ($row['destinationCountryCode']) { $info .= "<div><b>{$_LANG['RemoteData']['AutocompleteFieldData']['index']['generalFields']['countryName']}</b>: ".\Entity\Country::select($row['destinationCountryCode'])->name."</div>"; } if ($row['destinationCityId']) { $info .= "<div><b>{$_LANG['RemoteData']['AutocompleteFieldData']['index']['generalFields']['cityName']}</b>: ".\Entity\City::select($row['destinationCityId'])->name."</div>"; } } else { $info .= "<div><b>{$_LANG['RemoteData']['AutocompleteFieldData']['index']['generalFields']['company']}</b>: ".trim($row['companyPrefix'].' '.$row['company'].' '.$row['companySuffix'])."</div>"; if ($row['countryCode']) { $info .= "<div><b>{$_LANG['RemoteData']['AutocompleteFieldData']['index']['generalFields']['countryName']}</b>: ".\Entity\Country::select($row['countryCode'])->name."</div>"; } if ($row['cityId']) { $info .= "<div><b>{$_LANG['RemoteData']['AutocompleteFieldData']['index']['generalFields']['cityName']}</b>: ".\Entity\City::select($row['cityId'])->name."</div>"; } } $list[] = $this->getCleanItem($row['idElement'], $row['display'], $extra, $info, $otherFields); } return $list; } }