<?php
namespace App\Form\Input; class Autocomplete_Data_ClientActivityCategoryAndDomain extends \Engine\Form\Input\Autocomplete_Data_GeneralAbstract { protected function getPageResultsBulk() :array { $searchWords = preg_split("/[\s,]+/", $this->searchString); $domainsListObj = new \App\EntityList\ActivityDomains(); $domainsListObj->applyUserRestriction(false); $domainsListObj->setColumns([ 'ad.name' => 'name', 'adc.name' => 'extra', ]); $domainsListObj->setCustomColumn("CONCAT(adc.id, '|', ad.id)", 'code'); foreach ($searchWords as $word) { $domainsListObj->setCustomFilter('ad.name LIKE ? OR adc.name LIKE ?', ["{$word}%", "{$word}%"]); } $domainsArr = $domainsListObj->exportRecords(); $domainsCount = $domainsListObj->getRecordsCount(); $domainsCategoriesListObj = new \App\EntityList\ActivityDomainCategories(); $domainsCategoriesListObj->applyUserRestriction(false); $domainsCategoriesListObj->setColumns(['adc.name' => 'name', "CONCAT(`id`,'|0')" => 'code']); $domainsCategoriesListObj->setFilter('adc.name', 'LIKE', "{$this->searchString}%"); $domainsCategoriesArr = $domainsCategoriesListObj->exportRecords(); $domainsCategoriesCount = $domainsCategoriesListObj->getRecordsCount(); $this->resultsCountTotal = $domainsCount + $domainsCategoriesCount; $resultActivityDomainsCategoriesArr = array_merge($domainsArr, $domainsCategoriesArr); usort($resultActivityDomainsCategoriesArr, function($a, $b) { return strcmp($a['name'], $b['name']); }); $resultActivityDomainsCategoriesArr = array_slice($resultActivityDomainsCategoriesArr, $this->offset, $this->resultsCountPage); return $resultActivityDomainsCategoriesArr; } protected function getPageResultsFormatted(Array $pageResults) { $list = []; foreach($pageResults as $row) { $list[] = $this->getCleanItem($row['code'], $row['name'], $row['extra']); } return $list; } }