Revize 42c20ae6
Přidáno uživatelem Jan Šedivý před téměř 6 roky(ů)
app/AdminModule/component/Transliteration/TransliterationGrid.php | ||
---|---|---|
15 | 15 |
use App\Utils\DataGrid\DataGrid; |
16 | 16 |
use Nette\Database\Table\ActiveRow; |
17 | 17 |
use Nette\Database\Table\Selection; |
18 |
use Tracy\Debugger; |
|
18 | 19 |
use Ublaboo\DataGrid\Exception\DataGridException; |
19 | 20 | |
20 | 21 |
class TransliterationGrid extends DataGrid |
... | ... | |
249 | 250 |
private function exportData($dataSource, $grid) |
250 | 251 |
{ |
251 | 252 |
$exportData = []; |
252 |
/** @var ActiveRow $activeRow */ |
|
253 |
foreach ($dataSource as $activeRow)
|
|
253 | ||
254 |
try
|
|
254 | 255 |
{ |
255 |
$lines = $this->lineRepository->getAllLinesForTransliteration($activeRow->getPrimary()); |
|
256 |
$chapterLines = []; |
|
257 |
foreach ($lines as $line) |
|
256 |
/** @var ActiveRow $activeRow */ |
|
257 |
foreach ($dataSource as $activeRow) |
|
258 | 258 |
{ |
259 |
$chapterLines[$line->object_type][$line->surface_type][] = array('transliteration' => $line->transliteration, 'line_number' => $line->line_number); |
|
259 |
//Přeskočí transliterace které nejsou přiřazené k žádné knížce |
|
260 |
if(!$activeRow->ref('id_book')) |
|
261 |
{ |
|
262 |
continue; |
|
263 |
} |
|
264 |
$lines = $this->lineRepository->getAllLinesForTransliteration($activeRow->getPrimary()); |
|
265 |
$chapterLines = []; |
|
266 |
foreach ($lines as $line) |
|
267 |
{ |
|
268 |
$chapterLines[$line->object_type][$line->surface_type][] = array('transliteration' => $line->transliteration, 'line_number' => $line->line_number); |
|
269 |
} |
|
270 |
$exportData[] = [ |
|
271 |
'bookName' => $activeRow->ref('id_book')->book_abrev, |
|
272 |
'chapter' => $activeRow->chapter, |
|
273 |
'transliterationData' => $chapterLines |
|
274 |
]; |
|
260 | 275 |
} |
261 |
$exportData[] = [ |
|
262 |
'bookName' => $activeRow->ref('id_book')->book_abrev, |
|
263 |
'chapter' => $activeRow->chapter, |
|
264 |
'transliterationData' => $chapterLines |
|
265 |
]; |
|
266 |
} |
|
267 | 276 | |
268 |
$uniqueBooks = array_unique(array_map(function ($i) { return $i['bookName']; }, $exportData)); |
|
277 |
$uniqueBooks = array_unique(array_map(function ($i) { return $i['bookName']; }, $exportData)); |
|
278 | ||
279 |
$currentDate = new \DateTime(); |
|
280 |
$exportFileName = 'text-export-' . |
|
281 |
$currentDate->format('Y-m-d-H-i-s') . |
|
282 |
self::EXPORT_FILE_TYPE; |
|
269 | 283 | |
270 |
$currentDate = new \DateTime(); |
|
271 |
$exportFileName = 'text-export-' . |
|
272 |
$currentDate->format('Y-m-d-H-i-s') . |
|
273 |
self::EXPORT_FILE_TYPE; |
|
274 |
try |
|
275 |
{ |
|
276 | 284 |
if (!file_exists(self::EXPORT_FILE_PATH)) { |
277 | 285 |
mkdir(self::EXPORT_FILE_PATH, 0777, true); |
278 | 286 |
} |
... | ... | |
321 | 329 |
catch (\Exception $e) |
322 | 330 |
{ |
323 | 331 |
$this->presenter->flashMessage('There was an error creating the export file', EFlashMessage::ERROR); |
332 |
Debugger::log($e, 'export-error'); |
|
324 | 333 |
} |
325 | 334 | |
326 | 335 |
$this->presenter->flashMessage('There was an error downloading the export file', EFlashMessage::ERROR); |
app/AdminModule/component/Transport/ExportForm.latte | ||
---|---|---|
1 |
{control form} |
app/AdminModule/component/Transport/ExportForm.php | ||
---|---|---|
1 |
<?php |
|
2 | ||
3 |
namespace App\AdminModule\Components; |
|
4 | ||
5 |
use App\Utils\Form; |
|
6 |
use Nette\Application\UI\Control; |
|
7 | ||
8 |
class ExportForm extends Control |
|
9 |
{ |
|
10 | ||
11 |
public function __construct() |
|
12 |
{ |
|
13 |
parent::__construct(); |
|
14 |
} |
|
15 | ||
16 | ||
17 |
public function render() |
|
18 |
{ |
|
19 |
$this->template->setFile(__DIR__ . '/ExportForm.latte'); |
|
20 |
$this->template->render(); |
|
21 |
} |
|
22 | ||
23 |
public function createComponentForm() |
|
24 |
{ |
|
25 |
$form = new Form(); |
|
26 | ||
27 |
$form->addButton('export', 'Export něco...'); |
|
28 | ||
29 |
return $form; |
|
30 |
} |
|
31 |
} |
|
32 | ||
33 |
interface IExportFormFactory |
|
34 |
{ |
|
35 |
/** |
|
36 |
* @return ExportForm |
|
37 |
*/ |
|
38 |
public function create(); |
|
39 |
} |
app/AdminModule/presenters/TransportPresenter.php | ||
---|---|---|
16 | 16 |
/** @var IImportFormFactory */ |
17 | 17 |
private $importFormFactory; |
18 | 18 | |
19 |
/** @var IExportFormFactory */ |
|
20 |
private $exportFormFactory; |
|
21 | ||
22 | 19 |
/** @var SurfaceTypeRepository */ |
23 | 20 |
private $surfaceTypeRepository; |
24 | 21 | |
... | ... | |
32 | 29 |
private $transportModel; |
33 | 30 | |
34 | 31 |
public function __construct(IImportFormFactory $importFormFactory, |
35 |
IExportFormFactory $exportFormFactory, |
|
36 | 32 |
SurfaceTypeRepository $surfaceTypeRepository, |
37 | 33 |
ObjectTypeRepository $objectTypeRepository, |
38 | 34 |
TransportFacade $transportFacade, |
... | ... | |
41 | 37 |
{ |
42 | 38 |
parent::__construct(); |
43 | 39 |
$this->importFormFactory = $importFormFactory; |
44 |
$this->exportFormFactory = $exportFormFactory; |
|
45 | 40 |
$this->surfaceTypeRepository = $surfaceTypeRepository; |
46 | 41 |
$this->objectTypeRepository = $objectTypeRepository; |
47 | 42 |
$this->transportFacade = $transportFacade; |
... | ... | |
99 | 94 |
{ |
100 | 95 |
return $this->importFormFactory->create(); |
101 | 96 |
} |
102 | ||
103 |
public function createComponentExportForm() |
|
104 |
{ |
|
105 |
return $this->exportFormFactory->create(); |
|
106 |
} |
|
107 | 97 |
} |
app/AdminModule/templates/Transport/default.latte | ||
---|---|---|
10 | 10 |
</div> |
11 | 11 |
</div> |
12 | 12 | |
13 |
{* <div class="row mt-5">*} |
|
14 |
{* <div class="col-3">*} |
|
15 |
{* <fieldset>*} |
|
16 |
{* <legend>Text export</legend>*} |
|
17 |
{* {control exportForm}*} |
|
18 |
{* </fieldset>*} |
|
19 |
{* </div>*} |
|
20 |
{* </div>*} |
|
13 |
<div class="row mt-5"> |
|
14 |
<span>You can export selected texts using the export button in <a n:href="Transliteration:">Transliteration list</a> (Top right corner of the list).</span> |
|
15 |
</div> |
|
21 | 16 |
{/block} |
app/config/components.neon | ||
---|---|---|
23 | 23 |
- App\AdminModule\Components\ITransliterationEditFormFactory |
24 | 24 |
- App\AdminModule\Components\ITransliterationDataEditFormFactory |
25 | 25 |
- App\AdminModule\Components\IImportFormFactory |
26 |
- App\AdminModule\Components\IExportFormFactory |
|
27 | 26 | |
28 | 27 |
- App\FrontModule\Components\IKeyboard |
29 | 28 |
- App\FrontModule\Components\ITransliterationSearchResultListFactory |
app/enum/ESurfaceTypes.php | ||
---|---|---|
45 | 45 | |
46 | 46 |
return "&" . self::$exportFileAbbrev[$type] . "$"; |
47 | 47 |
} |
48 | ||
49 |
public static function getSurfaceTypeFromAbbrev($abbrev) |
|
50 |
{ |
|
51 |
$type = array_search($abbrev, self::$exportFileAbbrev); |
|
52 |
if(!$type) |
|
53 |
{ |
|
54 |
$type = self::OBVERSE; |
|
55 |
} |
|
56 |
return $type; |
|
57 |
} |
|
48 | 58 |
} |
app/model/facade/TransportFacade.php | ||
---|---|---|
64 | 64 |
{ |
65 | 65 |
$bookId = $this->bookRepository->insert([BookRepository::COLUMN_BOOK_ABREV => $book])->getPrimary(); |
66 | 66 |
} |
67 |
} |
|
68 |
catch (\Exception $exception) |
|
69 |
{ |
|
70 |
\Tracy\Debugger::log('Nepodařila se uložit nová kniha. Chyba: ' . $exception->getMessage(), 'transport-facade'); |
|
71 |
return FALSE; |
|
72 |
} |
|
73 |
foreach ($chapters as $chapter => $surfaces) |
|
74 |
{ |
|
75 |
try |
|
67 |
foreach ($chapters as $chapter => $surfaces) |
|
76 | 68 |
{ |
77 | 69 |
$transliterationId = $this->getTransliterationIdCurrentBookChapter($bookId, trim(explode(" ", $chapter)[0])); |
78 | 70 |
if (!$transliterationId) |
... | ... | |
81 | 73 |
if (isset($chapterReg[1])) |
82 | 74 |
{ |
83 | 75 |
$chapterReg[1] = str_replace(array('(', ')'), '', $chapterReg[1]); |
84 |
$this->transliterationRepository->insert([ |
|
76 |
$transliteration = $this->transliterationRepository->insert([
|
|
85 | 77 |
TransliterationRepository::COLUMN_BOOK_ID => $bookId, |
86 | 78 |
TransliterationRepository::COLUMN_CHAPTER => $chapterReg[0], |
87 | 79 |
TransliterationRepository::COLUMN_REG_NO => $chapterReg[1] |
88 | 80 |
]); |
89 |
$transliterationId = $this->context->getInsertId(TransliterationRepository::COLUMN_ID); |
|
81 |
if($transliteration) |
|
82 |
{ |
|
83 |
$transliterationId = $transliteration->getPrimary(); |
|
84 |
} |
|
85 |
else continue; |
|
86 |
// $transliterationId = $this->context->getInsertId(TransliterationRepository::COLUMN_ID); |
|
90 | 87 |
} else |
91 | 88 |
{ |
92 |
$this->transliterationRepository->insert([ |
|
89 |
$transliteration = $this->transliterationRepository->insert([
|
|
93 | 90 |
TransliterationRepository::COLUMN_BOOK_ID => $bookId, |
94 | 91 |
TransliterationRepository::COLUMN_CHAPTER => $chapterReg[0] |
95 | 92 |
]); |
96 |
$transliterationId = $this->context->getInsertId(TransliterationRepository::COLUMN_ID); |
|
93 |
if($transliteration) |
|
94 |
{ |
|
95 |
$transliterationId = $transliteration->getPrimary(); |
|
96 |
} |
|
97 |
else continue; |
|
98 |
// $transliterationId = $this->context->getInsertId(TransliterationRepository::COLUMN_ID); |
|
97 | 99 |
} |
98 | 100 |
} |
99 |
} |
|
100 |
catch (\Exception $exception) |
|
101 |
{ |
|
102 |
\Tracy\Debugger::log('Nepodařila se uložit nová transliterace. Chyba: ' . $exception->getMessage(), 'transport-facade'); |
|
103 |
return FALSE; |
|
104 |
} |
|
105 |
foreach ($surfaces as $surface => $values) |
|
106 |
{ |
|
107 |
try |
|
101 |
foreach ($surfaces as $surface => $values) |
|
108 | 102 |
{ |
109 | 103 |
$surfaceId = $this->getSurfaceIdByCurrentTransSurfType($transliterationId, $surface); |
110 | 104 |
if (!$surfaceId) |
... | ... | |
115 | 109 |
SurfaceRepository::COLUMN_OBJECT_TYPE_ID => 1 |
116 | 110 |
])->getPrimary(); |
117 | 111 |
} |
118 |
} |
|
119 |
catch (\Exception $exception) |
|
120 |
{ |
|
121 |
\Tracy\Debugger::log('Nepodařil se uložit nový surface. Chyba: ' . $exception->getMessage(), 'transport-facade'); |
|
122 |
return FALSE; |
|
123 |
} |
|
124 | 112 | |
125 |
foreach ($values as $line) |
|
126 |
{ |
|
127 |
try |
|
113 |
foreach ($values as $line) |
|
128 | 114 |
{ |
129 | 115 |
$lineId = $this->getLineIdByCurrentSurfLineNum($surfaceId, (explode(' ', $line)[0])); |
130 | 116 |
if (!$lineId) |
... | ... | |
141 | 127 |
]); |
142 | 128 |
} |
143 | 129 |
} |
144 |
catch (\Exception $exception) |
|
145 |
{ |
|
146 |
\Tracy\Debugger::log('Nepodařil se uložit nová řádka (line) transliterace. Chyba: ' . $exception->getMessage(), 'transport-facade'); |
|
147 |
return FALSE; |
|
148 |
} |
|
149 | 130 |
} |
150 | 131 |
} |
132 |
} catch (\Exception $exception) |
|
133 |
{ |
|
134 |
\Tracy\Debugger::log($exception, 'transport-facade'); |
|
135 |
return FALSE; |
|
151 | 136 |
} |
152 | 137 |
} |
153 | 138 |
return TRUE; |
app/utils/TextParser.php | ||
---|---|---|
3 | 3 | |
4 | 4 |
namespace App\Utils; |
5 | 5 | |
6 |
use App\Enum\ESurfaceTypes; |
|
7 | ||
6 | 8 |
class TextParser |
7 | 9 |
{ |
8 | 10 |
private $textFile; |
... | ... | |
75 | 77 |
/** Funkce pro transformaci zkratek surfaceType na jejich příslušná idčka v db */ |
76 | 78 |
private function transformAbbrev($abbrev) |
77 | 79 |
{ |
78 |
switch ($abbrev) { |
|
79 |
case "rev.": |
|
80 |
return array_search("reverse", $this->surfaceTypes); |
|
81 |
case "u.e.": |
|
82 |
return array_search("upper edge", $this->surfaceTypes); |
|
83 |
case "lo.e.": |
|
84 |
return array_search("lower edge", $this->surfaceTypes); |
|
85 |
case "le.e.": |
|
86 |
return array_search("left edge", $this->surfaceTypes); |
|
87 |
// Domnenky, v test souborech se nenachazi -> udelat podle toho export |
|
88 |
case "r.e.": |
|
89 |
return array_search("right edge", $this->surfaceTypes); |
|
90 |
case "s.i.1": |
|
91 |
return array_search("seal impression 1", $this->surfaceTypes); |
|
92 |
case "s.i.2": |
|
93 |
return array_search("seal impression 2", $this->surfaceTypes); |
|
94 |
case "s.i.3": |
|
95 |
return array_search("seal impression 3", $this->surfaceTypes); |
|
96 |
case "s.i.4": |
|
97 |
return array_search("seal impression 4", $this->surfaceTypes); |
|
98 |
case "s.i.5": |
|
99 |
return array_search("seal impression 5", $this->surfaceTypes); |
|
100 |
case "s.i.6": |
|
101 |
return array_search("seal impression 6", $this->surfaceTypes); |
|
102 |
case "s.i.7": |
|
103 |
return array_search("seal impression 7", $this->surfaceTypes); |
|
104 |
case "s.i.8": |
|
105 |
return array_search("seal impression 8", $this->surfaceTypes); |
|
106 |
default: |
|
107 |
return array_search("obverse", $this->surfaceTypes); |
|
108 |
} |
|
80 |
return array_search(ESurfaceTypes::getSurfaceTypeFromAbbrev($abbrev), $this->surfaceTypes); |
|
109 | 81 |
} |
110 | 82 | |
111 | 83 |
public function getTextFile() |
Také k dispozici: Unified diff
Re #7575 , Re #7572 Refaktoring importu/exportu