<?php
 namespace Modules\RemoteData\EntityManagementWs\Model\Entity\Customer; class Search extends \Modules\RemoteData\EntityManagementWs\Model\Entity\SearchAbstract { protected function search() :void { $words = preg_split("/[\s,]+/", $this->request->searchString); $entityList = new \App\EntityList\Customers(); $entityList->setColumns([ 'firstName', 'middleName', 'lastName', 'firstName2', 'middleName2', 'lastName2', 'nameAlphabet', 'birthday', 'email', 'telephone', 'idCorporate', ]); foreach($words as $word) { if ($this->request->searchMode=='contains') { $entityList->setCustomFilter( "lastName LIKE ? OR lastName2 LIKE ? OR firstName LIKE ? OR firstName2 LIKE ? OR email LIKE ?", ["%{$word}%", "%{$word}%", "%{$word}%", "%{$word}%", "%{$word}%"] ); } else { $entityList->setCustomFilter( "lastName LIKE ? OR lastName2 LIKE ? OR firstName LIKE ? OR firstName2 LIKE ? OR email LIKE ?", ["{$word}%", "{$word}%", "{$word}%", "{$word}%", "{$word}%"] ); } } $entityList->setFilter('idRealCustomer', '=', 0); if ($this->request->idCorporate??null) { $entityList->setFilter('idCorporate', '=', $this->request->idCorporate); } if ($this->request->columnOrder and $this->request->directionOrder) { $entityList->setOrderBy($this->request->columnOrder, $this->request->directionOrder); } elseif ($this->request->columnOrder and !$this->request->directionOrder) { $entityList->setOrderBy($this->request->columnOrder, 'ASC'); } else { $entityList->setOrderBy('lastName', 'ASC'); $entityList->setOrderBy('firstName', 'ASC'); } $entityList->setLimit((Int)$this->request->offset, $this->request->limit); $records = $entityList->exportRecords(); $listResults = []; foreach ($records as $record) { $object = new \stdClass(); $object->id = $record['id']; if ($record['nameAlphabet'] == 'standard') { $object->lastNameStandard = $record['lastName']; $object->firstNameStandard = $record['firstName']; $object->middleNameStandard = $record['middleName']; $object->lastNameLocal = $record['lastName2']; $object->firstNameLocal = $record['firstName2']; $object->middleNameLocal = $record['middleName2']; } else { $object->lastNameStandard = $record['lastName2']; $object->firstNameStandard = $record['firstName2']; $object->middleNameStandard = $record['middleName2']; $object->lastNameLocal = $record['lastName']; $object->firstNameLocal = $record['firstName']; $object->middleNameLocal = $record['middleName']; } $object->idCorporate = $record['idCorporate']; if ($record['email']) { $object->email = $record['email']; } if ($record['telephone']) { $object->telephone = $record['telephone']; } if ($record['birthday']) { $object->birthday = $record['birthday']; } $listResults[] = $object; } $this->populateSearchResponse($listResults, $entityList->getRecordsCount()); } } 