1 |
cdaf3e0a
|
Filip Jani
|
<?php
|
2 |
|
|
|
3 |
|
|
|
4 |
|
|
namespace App\Model\Facade;
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
use App\Model\Repository\LineRepository;
|
8 |
|
|
use App\Model\Repository\ObjectTypeRepository;
|
9 |
|
|
use App\Model\Repository\SurfaceRepository;
|
10 |
|
|
use App\Model\Repository\SurfaceTypeRepository;
|
11 |
|
|
use Nette\Database\Table\ActiveRow;
|
12 |
|
|
|
13 |
|
|
class TransliterationFacade
|
14 |
|
|
{
|
15 |
|
|
/**
|
16 |
|
|
* @var SurfaceRepository
|
17 |
|
|
*/
|
18 |
|
|
private $surfaceRepository;
|
19 |
|
|
/**
|
20 |
|
|
* @var LineRepository
|
21 |
|
|
*/
|
22 |
|
|
private $lineRepository;
|
23 |
|
|
/**
|
24 |
|
|
* @var ObjectTypeRepository
|
25 |
|
|
*/
|
26 |
|
|
private $objectTypeRepository;
|
27 |
|
|
/**
|
28 |
|
|
* @var SurfaceTypeRepository
|
29 |
|
|
*/
|
30 |
|
|
private $surfaceTypeRepository;
|
31 |
|
|
|
32 |
|
|
public function __construct(SurfaceRepository $surfaceRepository,
|
33 |
|
|
LineRepository $lineRepository,
|
34 |
|
|
ObjectTypeRepository $objectTypeRepository,
|
35 |
|
|
SurfaceTypeRepository $surfaceTypeRepository
|
36 |
|
|
)
|
37 |
|
|
{
|
38 |
|
|
$this->surfaceRepository = $surfaceRepository;
|
39 |
|
|
$this->lineRepository = $lineRepository;
|
40 |
|
|
$this->objectTypeRepository = $objectTypeRepository;
|
41 |
|
|
$this->surfaceTypeRepository = $surfaceTypeRepository;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
/**
|
45 |
|
|
* Uloží data transliterace
|
46 |
|
|
*
|
47 |
|
|
* @param int $id
|
48 |
|
|
* @param array $values
|
49 |
|
|
*/
|
50 |
|
|
public function saveTransliterationData(int $id, array $values)
|
51 |
|
|
{
|
52 |
|
|
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Vrací data transliterace pro formulář
|
57 |
|
|
*
|
58 |
|
|
* @param int $id : ID transliterace
|
59 |
|
|
* @return array
|
60 |
|
|
*/
|
61 |
|
|
public function getTransliterationData(int $id)
|
62 |
|
|
{
|
63 |
|
|
$surfaces = $this->surfaceRepository->findByTransliterationId($id)->fetchAll();
|
64 |
|
|
|
65 |
|
|
$surfaceTypes = $this->surfaceTypeRepository->fetchSurfaceTypes();
|
66 |
|
|
$objectTypes = $this->objectTypeRepository->fetchObjectTypes();
|
67 |
|
|
|
68 |
|
|
$defaults = array();
|
69 |
|
|
|
70 |
|
|
/** @var ActiveRow $surface */
|
71 |
|
|
foreach ($surfaces as $surface)
|
72 |
|
|
{
|
73 |
|
|
// Načtení všech řádek
|
74 |
|
|
$lineRows = $surface->related(LineRepository::TABLE_NAME, SurfaceRepository::COLUMN_ID)->fetchAll();
|
75 |
|
|
if ($lineRows === FALSE)
|
76 |
|
|
{
|
77 |
|
|
continue;
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
// Získání názvu typu povrchu a typu objektu
|
81 |
|
|
$surfaceType = $surfaceTypes[$surface->{SurfaceRepository::COLUMN_SURFACE_TYPE_ID}];
|
82 |
|
|
$objectType = $objectTypes[$surface->{SurfaceRepository::COLUMN_OBJECT_TYPE_ID}];
|
83 |
|
|
|
84 |
|
|
$objectName = $this->getInputName($objectType);
|
85 |
|
|
$surfaceName = $this->getInputName($objectType, $surfaceType);
|
86 |
|
|
|
87 |
|
|
$defaults[$objectName][$surfaceName] = $lineRows;
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
return $defaults;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
/**
|
94 |
|
|
* Vrací název inputu pro formulář
|
95 |
|
|
*
|
96 |
|
|
* @param string $container
|
97 |
|
|
* @param string|NULL $name
|
98 |
|
|
* @return string
|
99 |
|
|
*/
|
100 |
|
|
public function getInputName(string $container, string $name = NULL)
|
101 |
|
|
{
|
102 |
|
|
return str_replace(' ', '', $container) . str_replace(' ', '', $name);
|
103 |
|
|
}
|
104 |
|
|
}
|