Implemented new link thing.

This commit is contained in:
James Cole
2019-07-20 06:47:34 +02:00
parent 63832b31f8
commit 6d34cfb940
15 changed files with 581 additions and 390 deletions

View File

@@ -149,7 +149,42 @@ class AutoCompleteController extends Controller
return response()->json($array);
}
/**
* Searches in the titles of all transaction journals.
* The result is limited to the top 15 unique results.
*
* If the query is numeric, it will append the journal with that particular ID.
*
* @param Request $request
* @return JsonResponse
*/
public function allJournalsWithID(Request $request): JsonResponse
{
$search = (string)$request->get('search');
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
$result = $repository->searchJournalDescriptions($search);
$array = [];
if (is_numeric($search)) {
$firstResult = $repository->findNull((int)$search);
if (null !== $firstResult) {
$array[] = $firstResult->toArray();
}
}
// if not numeric, search ahead!
// limit and unique
$limited = $result->slice(0, 15);
$array = array_merge($array, $limited->toArray());
foreach ($array as $index => $item) {
// give another key for consistency
$array[$index]['name'] = sprintf('#%d: %s', $item['id'], $item['description']);
}
return response()->json($array);
}
/**