Revize 32b3fe21
Přidáno uživatelem Filip Jani před téměř 6 roky(ů)
app/model/facade/TransliterationFacade.php | ||
---|---|---|
9 | 9 |
use App\Model\Repository\SurfaceRepository; |
10 | 10 |
use App\Model\Repository\SurfaceTypeRepository; |
11 | 11 |
use Nette\Database\Table\ActiveRow; |
12 |
use Nette\Utils\ArrayHash; |
|
12 | 13 |
|
13 | 14 |
class TransliterationFacade |
14 | 15 |
{ |
... | ... | |
44 | 45 |
/** |
45 | 46 |
* Uloží data transliterace |
46 | 47 |
* |
47 |
* @param int $id
|
|
48 |
* @param array $values
|
|
48 |
* @param int|null $id : ID transliterace
|
|
49 |
* @param ArrayHash $formValues
|
|
49 | 50 |
*/ |
50 |
public function saveTransliterationData(int $id, array $values)
|
|
51 |
public function saveTransliterationData(int $id, ArrayHash $formValues)
|
|
51 | 52 |
{ |
52 |
|
|
53 |
// Škaredý zanoření hodnot z formuláře v kontainerech :( |
|
54 |
foreach ($formValues as $objectTypeId => $surfaceContainers) |
|
55 |
{ |
|
56 |
foreach ($surfaceContainers as $surfaceTypeId => $inputs) |
|
57 |
{ |
|
58 |
foreach ($inputs as $key => $values) |
|
59 |
{ |
|
60 |
$lineId = (int)$values->{LineRepository::COLUMN_ID}; |
|
61 |
|
|
62 |
// Editace již existující řádky |
|
63 |
if (!empty($lineId)) |
|
64 |
{ |
|
65 |
$this->lineRepository->fetchById($lineId)->update($values); |
|
66 |
|
|
67 |
} else |
|
68 |
{ |
|
69 |
$surface = $this->surfaceRepository->fetchSurface($id, $objectTypeId, $surfaceTypeId); |
|
70 |
|
|
71 |
if ($surface === FALSE) |
|
72 |
{ |
|
73 |
// TODO: předělat do repository |
|
74 |
$surface = $this->surfaceRepository->insert( |
|
75 |
[ |
|
76 |
SurfaceRepository::COLUMN_SURFACE_TYPE_ID => $surfaceTypeId, |
|
77 |
SurfaceRepository::COLUMN_OBJECT_TYPE_ID => $objectTypeId, |
|
78 |
SurfaceRepository::COLUMN_TRANSLITERATION_ID => $id |
|
79 |
] |
|
80 |
); |
|
81 |
} |
|
82 |
|
|
83 |
$values->{LineRepository::COLUMN_SURFACE_ID} = $surface->{SurfaceRepository::COLUMN_ID}; |
|
84 |
$this->lineRepository->insert($values); |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
} |
|
53 | 89 |
} |
54 | 90 |
|
55 | 91 |
/** |
... | ... | |
62 | 98 |
{ |
63 | 99 |
$surfaces = $this->surfaceRepository->findByTransliterationId($id)->fetchAll(); |
64 | 100 |
|
65 |
$surfaceTypes = $this->surfaceTypeRepository->fetchSurfaceTypes(); |
|
66 |
$objectTypes = $this->objectTypeRepository->fetchObjectTypes(); |
|
67 |
|
|
68 | 101 |
$defaults = array(); |
69 | 102 |
|
70 | 103 |
/** @var ActiveRow $surface */ |
... | ... | |
77 | 110 |
continue; |
78 | 111 |
} |
79 | 112 |
|
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($surfaceType); |
|
113 |
$objectId = $surface->{SurfaceRepository::COLUMN_OBJECT_TYPE_ID}; |
|
114 |
$surfaceId = $surface->{SurfaceRepository::COLUMN_SURFACE_TYPE_ID}; |
|
86 | 115 |
|
87 |
$defaults[$objectName][$surfaceName] = $lineRows;
|
|
116 |
$defaults[$objectId][$surfaceId] = $lineRows;
|
|
88 | 117 |
} |
89 | 118 |
|
90 | 119 |
return $defaults; |
Také k dispozici: Unified diff
Re #7505 možnost editace záznamů