dbmsv4/app/Controllers/Admin/SearchController.php
2025-11-24 14:23:08 +09:00

49 lines
1.8 KiB
PHP

<?php
namespace App\Controllers\Admin;
use App\Entities\Customer\ServiceEntity;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class SearchController extends AdminController
{
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
if ($this->service === null) {
$this->service = service('customer_serviceservice');
}
$this->addActionPaths('service');
}
//Action작업관련
protected function getEntityClass(): string
{
return ServiceEntity::class;
}
//기본 함수 작업
//Custom 추가 함수
protected function index_entities_process(array $entities = []): array
{
$keyword = $this->request->getGet('keyword'); // 검색어
if (!$keyword) {
throw new \Exception("[{$keyword}] 검색어가 지정되지 않았습니다. ");
}
//검색어에 따른 서버정보를 검색 후 해당하는 서비스리스트를 가져온다.
$rows = service('equipment_serverservice')->getSearchServices($keyword);
$uids = [];
foreach ($rows as $row) {
$uids[] = "'{$row->serviceinfo_uid}'";
}
//서비스별 서버리스트
// $childServers = [];
foreach ($this->service->getEntities([sprintf("uid IN (%s)", implode(",", $uids)) => null]) as $entity) {
$entities[] = $entity;
// $childServers[$entity->getPK()] = $this->getService()->getServerService()->getEntities(['serviceinfo_uid' => $entity->getPK()]);
}
// $this->childServers = $childServers;
return $entities;
}
}