1 |
1a669408
|
Petr Lukašík
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace App\AdminModule\Presenters;
|
4 |
|
|
|
5 |
|
|
use App\AdminModule\Components\IExportFormFactory;
|
6 |
|
|
use App\AdminModule\Components\IImportFormFactory;
|
7 |
2d082bc2
|
Petr Lukašík
|
use App\Model\Repository\ObjectTypeRepository;
|
8 |
|
|
use App\Model\Repository\SurfaceTypeRepository;
|
9 |
|
|
use App\Utils\TextParser;
|
10 |
1a669408
|
Petr Lukašík
|
|
11 |
|
|
class TransportPresenter extends BaseUserPresenter
|
12 |
|
|
{
|
13 |
|
|
/** @var IImportFormFactory */
|
14 |
|
|
private $importFormFactory;
|
15 |
|
|
|
16 |
|
|
/** @var IExportFormFactory */
|
17 |
|
|
private $exportFormFactory;
|
18 |
|
|
|
19 |
2d082bc2
|
Petr Lukašík
|
/** @var SurfaceTypeRepository */
|
20 |
|
|
private $surfaceTypeRepository;
|
21 |
|
|
|
22 |
|
|
/** @var ObjectTypeRepository */
|
23 |
|
|
private $objectTypeRepository;
|
24 |
|
|
|
25 |
1a669408
|
Petr Lukašík
|
public function __construct(
|
26 |
|
|
IImportFormFactory $importFormFactory,
|
27 |
2d082bc2
|
Petr Lukašík
|
IExportFormFactory $exportFormFactory,
|
28 |
|
|
SurfaceTypeRepository $surfaceTypeRepository,
|
29 |
|
|
ObjectTypeRepository $objectTypeRepository
|
30 |
1a669408
|
Petr Lukašík
|
)
|
31 |
|
|
{
|
32 |
|
|
parent::__construct();
|
33 |
|
|
$this->importFormFactory = $importFormFactory;
|
34 |
|
|
$this->exportFormFactory = $exportFormFactory;
|
35 |
2d082bc2
|
Petr Lukašík
|
$this->surfaceTypeRepository = $surfaceTypeRepository;
|
36 |
|
|
$this->objectTypeRepository = $objectTypeRepository;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
public function actionPreviewImport(TextParser $parser){
|
40 |
|
|
$objectTypes = $this->objectTypeRepository->fetchObjectTypes();
|
41 |
|
|
$surfaceTypes = $this->surfaceTypeRepository->fetchSurfaceTypes();
|
42 |
|
|
$parser->setTypes($objectTypes, $surfaceTypes);
|
43 |
|
|
|
44 |
|
|
$this->template->fileName = $parser->textFile->getName();
|
45 |
|
|
$this->template->parsedFile = $parser->parseText();
|
46 |
|
|
$this->template->transliterationNum = $this->countTransliterations();
|
47 |
|
|
$this->template->surfaces = $surfaceTypes;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
public function countTransliterations(){
|
51 |
|
|
$num=0;
|
52 |
|
|
foreach ($this->template->parsedFile as $book){
|
53 |
|
|
$num += count($book);
|
54 |
|
|
}
|
55 |
|
|
return $num;
|
56 |
1a669408
|
Petr Lukašík
|
}
|
57 |
|
|
|
58 |
|
|
public function createComponentImportForm()
|
59 |
|
|
{
|
60 |
|
|
return $this->importFormFactory->create();
|
61 |
|
|
}
|
62 |
|
|
|
63 |
|
|
public function createComponentExportForm()
|
64 |
|
|
{
|
65 |
|
|
return $this->exportFormFactory->create();
|
66 |
|
|
}
|
67 |
|
|
}
|