39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?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;
|
|
use Nette\Utils\Strings;
|
|
|
|
class TranslationsHandler extends Basehandler
|
|
{
|
|
private $em;
|
|
|
|
public function __construct(EntityManager $em)
|
|
{
|
|
parent::__construct();
|
|
$this->em = $em;
|
|
}
|
|
|
|
public function handle(array $params): ResponseInterface
|
|
{
|
|
$trs = $this->em->getTranslationRepository()->findBy([], ['id' => 'ASC', 'direction' => 'ASC']);
|
|
$translations = [];
|
|
foreach ($trs as $t) {
|
|
$lang1 = $t->getLangName1();
|
|
$lang2 = $t->getLangName2();
|
|
|
|
$lang = mb_substr($lang1, 0, -1);
|
|
$lang .= "o-" . $lang2;
|
|
$slug = Strings::webalize($lang);
|
|
$translations[$t->id]["slug"] = $slug;
|
|
$translations[$t->id]["lang"] = $lang;
|
|
}
|
|
|
|
return new JsonApiResponse(200, ['status' => 'ok', 'translations' => $translations]);
|
|
}
|
|
} |