Revize 32b3fe21
Přidáno uživatelem Filip Jani před téměř 6 roky(ů)
app/AdminModule/component/Transliteration/TransliterationDataEditForm.latte | ||
---|---|---|
53 | 53 |
<div id="{$name}" class="collapse{$show}"> |
54 | 54 |
<div class="card-body"> |
55 | 55 |
<div n:multiplier="$name" n:class="row, mb-2"> |
56 |
<div class="col-5"> |
|
56 |
<input n:name="\App\Model\Repository\LineRepository::COLUMN_ID"> |
|
57 |
<div class="col-2"> |
|
57 | 58 |
<input n:name="\App\Model\Repository\LineRepository::COLUMN_LINE_NUMBER" n:class="form-control, form-control-sm"> |
58 | 59 |
</div> |
59 |
<div class="col-5">
|
|
60 |
<div class="col-8">
|
|
60 | 61 |
<input n:name="\App\Model\Repository\LineRepository::COLUMN_TRANSLITERATION" n:class="form-control, form-control-sm"> |
61 | 62 |
</div> |
62 | 63 |
<div class="col-2"> |
app/AdminModule/component/Transliteration/TransliterationDataEditForm.php | ||
---|---|---|
16 | 16 |
class TransliterationDataEditForm extends Control |
17 | 17 |
{ |
18 | 18 |
/** @var int ID transliterace */ |
19 |
private $id; |
|
19 |
private $id = NULL;
|
|
20 | 20 |
|
21 | 21 |
/** @var array Pole objektů a typu povrch pro strom dat transliterace */ |
22 | 22 |
private $containers; |
23 | 23 |
|
24 |
/** @var array Pole s výchozími hodnotami při upravování */ |
|
24 | 25 |
private $defaults; |
25 | 26 |
|
26 | 27 |
/** |
... | ... | |
52 | 53 |
$containers = []; |
53 | 54 |
|
54 | 55 |
// Načtení typů objektů a typu povrchů do pole pro vykreslení v šabloně |
55 |
foreach ($objectTypes as $objectType) |
|
56 |
foreach ($objectTypes as $oId =>$objectType)
|
|
56 | 57 |
{ |
57 |
$containers[$this->transliterationFacade->getInputName($objectType)]['title'] = $objectType;
|
|
58 |
$containers[$oId]['title'] = $objectType;
|
|
58 | 59 |
|
59 |
foreach ($surfaceTypes as $surfaceType) |
|
60 |
foreach ($surfaceTypes as $sId => $surfaceType)
|
|
60 | 61 |
{ |
61 |
$containers[$this->transliterationFacade->getInputName($objectType)][$this->transliterationFacade->getInputName($surfaceType)] = $surfaceType;
|
|
62 |
$containers[$oId][$sId] = $surfaceType;
|
|
62 | 63 |
} |
63 | 64 |
} |
64 | 65 |
|
... | ... | |
100 | 101 |
{ |
101 | 102 |
$container->addInteger(LineRepository::COLUMN_LINE_NUMBER); |
102 | 103 |
$container->addText(LineRepository::COLUMN_TRANSLITERATION); |
104 |
$container->addHidden(LineRepository::COLUMN_ID); |
|
103 | 105 |
}, 0); |
104 | 106 |
|
105 | 107 |
$multiplier->addCreateButton('Add line', 1, $redrawCallback); |
... | ... | |
118 | 120 |
|
119 | 121 |
public function formSuccess(Form $form) |
120 | 122 |
{ |
121 |
|
|
123 |
$result = $this->transliterationFacade->saveTransliterationData($this->id, $form->getValues()); |
|
122 | 124 |
} |
123 | 125 |
|
124 | 126 |
/** |
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; |
app/model/repository/LineRepository.php | ||
---|---|---|
75 | 75 |
return $adjacentLines; |
76 | 76 |
} |
77 | 77 |
|
78 |
/** |
|
79 |
* Vrací záznam řádku podle ID (z nějakého důvodu mi nefungovalo findRow); |
|
80 |
* |
|
81 |
* @param int $id : ID řádky |
|
82 |
* @return false|\Nette\Database\Table\ActiveRow |
|
83 |
*/ |
|
84 |
public function fetchById(int $id) |
|
85 |
{ |
|
86 |
return $this->findBy([self::COLUMN_ID => $id])->fetch(); |
|
87 |
} |
|
88 |
|
|
78 | 89 |
} |
app/model/repository/ObjectTypeRepository.php | ||
---|---|---|
26 | 26 |
{ |
27 | 27 |
return $this->findAll()->fetchPairs(self::COLUMN_ID, self::COLUMN_OBJECT_TYPE); |
28 | 28 |
} |
29 |
|
|
30 |
/** |
|
31 |
* Vrací typ objektu podle názvu |
|
32 |
* |
|
33 |
* @param string $name |
|
34 |
* @return false|\Nette\Database\Table\ActiveRow |
|
35 |
*/ |
|
36 |
public function fetchObjectTypeByName(string $name) |
|
37 |
{ |
|
38 |
return $this->findBy([self::COLUMN_OBJECT_TYPE => $name])->fetch(); |
|
39 |
} |
|
29 | 40 |
} |
app/model/repository/Repository.php | ||
---|---|---|
94 | 94 |
* @param array $data |
95 | 95 |
* @return bool|int|Nette\Database\Table\ActiveRow |
96 | 96 |
*/ |
97 |
public function insert(array $data)
|
|
97 |
public function insert($data) |
|
98 | 98 |
{ |
99 | 99 |
return $this->getTable()->insert($data); |
100 | 100 |
} |
app/model/repository/SurfaceRepository.php | ||
---|---|---|
30 | 30 |
{ |
31 | 31 |
return $this->findBy([self::COLUMN_TRANSLITERATION_ID => $id]); |
32 | 32 |
} |
33 |
|
|
34 |
public function fetchSurface(int $transliterationId, int $objectTypeId, int $surfaceTypeId){ |
|
35 |
return $this->findBy( |
|
36 |
[ |
|
37 |
self::COLUMN_TRANSLITERATION_ID => $transliterationId, |
|
38 |
self::COLUMN_OBJECT_TYPE_ID => $objectTypeId, |
|
39 |
self::COLUMN_SURFACE_TYPE_ID => $surfaceTypeId |
|
40 |
] |
|
41 |
)->fetch(); |
|
42 |
} |
|
33 | 43 |
} |
Také k dispozici: Unified diff
Re #7505 možnost editace záznamů