48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
|
||
|
|
|
||
|
|
$auth = TaskCertAuthContext::fromGlobals();
|
||
|
|
if (!$auth->hasPermission('r-task-cert-admin')) {
|
||
|
|
TaskCertResponse::error('Keine Berechtigung', 403);
|
||
|
|
}
|
||
|
|
|
||
|
|
$term = TaskCertRequest::queryString('term', '');
|
||
|
|
$limit = TaskCertRequest::queryInt('limit', 15);
|
||
|
|
|
||
|
|
$services = task_cert_services();
|
||
|
|
$lookupRepo = $services['lookupRepo'] ?? null;
|
||
|
|
|
||
|
|
if (!$lookupRepo instanceof TaskLookupRepository) {
|
||
|
|
TaskCertResponse::json(['results' => []]);
|
||
|
|
}
|
||
|
|
|
||
|
|
$contacts = $lookupRepo->searchContacts($term, $limit);
|
||
|
|
|
||
|
|
$results = [];
|
||
|
|
foreach ($contacts as $c) {
|
||
|
|
$id = (int) ($c['id'] ?? 0);
|
||
|
|
if ($id <= 0) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
$name = trim((string) ($c['name'] ?? ''));
|
||
|
|
$email = trim((string) ($c['email'] ?? ''));
|
||
|
|
|
||
|
|
$label = $name;
|
||
|
|
if ($label === '') {
|
||
|
|
$label = $email !== '' ? $email : 'Kontakt #' . $id;
|
||
|
|
} elseif ($email !== '') {
|
||
|
|
$label .= ' (' . $email . ')';
|
||
|
|
}
|
||
|
|
|
||
|
|
$results[] = [
|
||
|
|
'id' => $id,
|
||
|
|
'name' => $name,
|
||
|
|
'email' => $email,
|
||
|
|
'label' => $label,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
TaskCertResponse::json(['results' => $results]);
|