1 |
cddd4e21
|
Filip Jani
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
namespace App\FrontModule\Components;
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
use App\Model\Repository\LineRepository;
|
8 |
|
|
use App\Model\Repository\LitReferenceRepository;
|
9 |
|
|
use App\Model\Repository\RevHistoryRepository;
|
10 |
|
|
use App\Model\Repository\TransliterationRepository;
|
11 |
c73ae8f7
|
Filip Jani
|
use App\Model\TransliterationSearchModel;
|
12 |
|
|
use App\Utils\WordHighlighter;
|
13 |
cddd4e21
|
Filip Jani
|
use Nette\Application\UI\Control;
|
14 |
|
|
|
15 |
|
|
class TransliterationView extends Control
|
16 |
|
|
{
|
17 |
|
|
/**
|
18 |
|
|
* @var TransliterationRepository
|
19 |
|
|
*/
|
20 |
|
|
private $transliterationRepository;
|
21 |
|
|
/**
|
22 |
|
|
* @var LineRepository
|
23 |
|
|
*/
|
24 |
|
|
private $lineRepository;
|
25 |
|
|
/**
|
26 |
|
|
* @var LitReferenceRepository
|
27 |
|
|
*/
|
28 |
|
|
private $litReferenceRepository;
|
29 |
|
|
/**
|
30 |
|
|
* @var RevHistoryRepository
|
31 |
|
|
*/
|
32 |
|
|
private $revHistoryRepository;
|
33 |
c73ae8f7
|
Filip Jani
|
/**
|
34 |
|
|
* @var WordHighlighter
|
35 |
|
|
*/
|
36 |
|
|
private $wordHighlighter;
|
37 |
|
|
/**
|
38 |
|
|
* @var TransliterationSearchModel
|
39 |
|
|
*/
|
40 |
|
|
private $transliterationSearchModel;
|
41 |
cddd4e21
|
Filip Jani
|
|
42 |
|
|
public function __construct(TransliterationRepository $transliterationRepository,
|
43 |
|
|
LineRepository $lineRepository,
|
44 |
|
|
LitReferenceRepository $litReferenceRepository,
|
45 |
c73ae8f7
|
Filip Jani
|
RevHistoryRepository $revHistoryRepository,
|
46 |
|
|
WordHighlighter $wordHighlighter,
|
47 |
|
|
TransliterationSearchModel $transliterationSearchModel
|
48 |
|
|
)
|
49 |
cddd4e21
|
Filip Jani
|
{
|
50 |
|
|
parent::__construct();
|
51 |
|
|
|
52 |
|
|
$this->transliterationRepository = $transliterationRepository;
|
53 |
|
|
$this->lineRepository = $lineRepository;
|
54 |
|
|
$this->litReferenceRepository = $litReferenceRepository;
|
55 |
|
|
$this->revHistoryRepository = $revHistoryRepository;
|
56 |
c73ae8f7
|
Filip Jani
|
$this->wordHighlighter = $wordHighlighter;
|
57 |
|
|
$this->transliterationSearchModel = $transliterationSearchModel;
|
58 |
cddd4e21
|
Filip Jani
|
}
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* Vykreslení výsledků
|
62 |
|
|
*
|
63 |
|
|
* @param int $id : ID transliterace
|
64 |
|
|
* @param bool $showAll : zobrazení katalogu i transliterací
|
65 |
c73ae8f7
|
Filip Jani
|
* @param bool $isCatalogue : určuje jestli byla komponenta zobrazena z katalogu nebo z vyhledávání textů
|
66 |
|
|
* a podle toho zvýrazňuje texty
|
67 |
cddd4e21
|
Filip Jani
|
* @throws \Nette\Application\AbortException
|
68 |
|
|
*/
|
69 |
c73ae8f7
|
Filip Jani
|
public function render(int $id, bool $showAll = TRUE, $isCatalogue = FALSE)
|
70 |
cddd4e21
|
Filip Jani
|
{
|
71 |
|
|
$this->template->setFile(__DIR__ . '/TransliterationView.latte');
|
72 |
|
|
|
73 |
|
|
$transliteration = $this->transliterationRepository->getTransliterationDetail($id);
|
74 |
|
|
if (!$transliteration)
|
75 |
|
|
{
|
76 |
|
|
$this->presenter->flashMessage('Result was not found.');
|
77 |
|
|
$this->presenter->redirect($this->getPresenter()->getName());
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
// Zobrazujeme i data transliterace
|
81 |
|
|
if($showAll)
|
82 |
|
|
{
|
83 |
|
|
$lines = $this->lineRepository->getAllLinesForTransliteration($id);
|
84 |
c73ae8f7
|
Filip Jani
|
|
85 |
|
|
// Pokud se nejedná o vyhledávání z katalogu, tak zvýrazňujeme výsledky
|
86 |
|
|
if (!$isCatalogue)
|
87 |
|
|
{
|
88 |
|
|
$this->wordHighlighter->highlight($lines, $this->transliterationSearchModel->getSearchTerms());
|
89 |
|
|
}
|
90 |
|
|
|
91 |
cddd4e21
|
Filip Jani
|
$lineArray = [];
|
92 |
|
|
foreach ($lines as $line)
|
93 |
|
|
{
|
94 |
|
|
$lineArray[$line->object_type][$line->surface_type][] = array('transliteration' => $line->transliteration, 'line_number' => $line->line_number);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
$this->template->lineArray = $lineArray;
|
98 |
|
|
$this->template->revisionHistory = $this->revHistoryRepository->findBy([RevHistoryRepository::COLUMN_TRANSLITERATION_ID => $id]);
|
99 |
|
|
}
|
100 |
|
|
|
101 |
|
|
$this->template->transliteration = $transliteration;
|
102 |
|
|
$this->template->litReferences = $this->litReferenceRepository->findBy([LitReferenceRepository::COLUMN_TRANSLITERATION_ID => $id]);
|
103 |
|
|
$this->template->showAll = $showAll;
|
104 |
|
|
|
105 |
|
|
$this->template->render();
|
106 |
|
|
}
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
interface ITransliterationViewFactory
|
110 |
|
|
{
|
111 |
|
|
/**
|
112 |
|
|
* @return TransliterationView
|
113 |
|
|
*/
|
114 |
|
|
public function create();
|
115 |
|
|
}
|