35 lines
1.1 KiB
PHP
Executable File
35 lines
1.1 KiB
PHP
Executable File
<?php //declare(strict_types = 1);
|
|
|
|
namespace App\MyApi\v1\Handlers;
|
|
|
|
use App\Model\Database\EntityManager;
|
|
use Tomaj\NetteApi\Handlers\BaseHandler;
|
|
use Tomaj\NetteApi\Response\JsonApiResponse;
|
|
use Tomaj\NetteApi\Response\ResponseInterface;
|
|
use App\Model\Database\Facade\TermFacade;
|
|
|
|
class TermsHandler extends Basehandler
|
|
{
|
|
private $em;
|
|
private $termFacade;
|
|
|
|
public function __construct(EntityManager $em, TermFacade $tf)
|
|
{
|
|
parent::__construct();
|
|
$this->em = $em;
|
|
$this->termFacade = $tf;
|
|
}
|
|
|
|
public function handle(array $params): ResponseInterface
|
|
{
|
|
if (mb_strlen($_GET['string']) == 0)
|
|
return new JsonApiResponse(200, ['status' => 'ok', 'terms' => []]);
|
|
|
|
$translation = $this->em->getTranslationRepository()->findOneBy(['id' => $_GET['translation']]);
|
|
$this->termFacade->setDirection($translation->direction);
|
|
$q = $this->termFacade->findByStringFull($_GET['string'], $translation->dictionary, '', mb_strlen($_GET['string']) <= 3 ? false : true);
|
|
$terms = $q->getArrayResult();
|
|
|
|
return new JsonApiResponse(200, ['status' => 'ok', 'terms' => $terms]);
|
|
}
|
|
} |