Revize 175d726f
Přidáno uživatelem Filip Jani před více než 5 roky(ů)
app/model/facade/TransportFacade.php | ||
---|---|---|
55 | 55 |
public function saveImportedData($data) |
56 | 56 |
{ |
57 | 57 |
// Škaredý zanoření hodnot z dat v importu :( Tohle bude pro db náročný |
58 |
foreach ($data as $book => $chapters) { |
|
59 |
try { |
|
58 |
foreach ($data as $book => $chapters) |
|
59 |
{ |
|
60 |
try |
|
61 |
{ |
|
60 | 62 |
$bookId = $this->getBookIdByName($book); |
61 |
if (!$bookId) { |
|
63 |
if (!$bookId) |
|
64 |
{ |
|
62 | 65 |
$bookId = $this->bookRepository->insert([BookRepository::COLUMN_BOOK_ABREV => $book])->getPrimary(); |
63 | 66 |
} |
64 |
} catch (\Exception $exception) { |
|
67 |
} |
|
68 |
catch (\Exception $exception) |
|
69 |
{ |
|
65 | 70 |
\Tracy\Debugger::log('Nepodařila se uložit nová kniha. Chyba: ' . $exception->getMessage(), 'transport-facade'); |
66 | 71 |
return FALSE; |
67 | 72 |
} |
68 |
foreach ($chapters as $chapter => $surfaces) { |
|
69 |
try { |
|
73 |
foreach ($chapters as $chapter => $surfaces) |
|
74 |
{ |
|
75 |
try |
|
76 |
{ |
|
70 | 77 |
$transliterationId = $this->getTransliterationIdCurrentBookChapter($bookId, trim(explode(" ", $chapter)[0])); |
71 |
if (!$transliterationId) { |
|
78 |
if (!$transliterationId) |
|
79 |
{ |
|
72 | 80 |
$chapterReg = explode(" ", $chapter); |
73 |
if (isset($chapterReg[1])) { |
|
81 |
if (isset($chapterReg[1])) |
|
82 |
{ |
|
74 | 83 |
$chapterReg[1] = str_replace(array('(', ')'), '', $chapterReg[1]); |
75 | 84 |
$this->transliterationRepository->insert([ |
76 | 85 |
TransliterationRepository::COLUMN_BOOK_ID => $bookId, |
... | ... | |
78 | 87 |
TransliterationRepository::COLUMN_REG_NO => $chapterReg[1] |
79 | 88 |
]); |
80 | 89 |
$transliterationId = $this->context->getInsertId(TransliterationRepository::COLUMN_ID); |
81 |
} else { |
|
90 |
} else |
|
91 |
{ |
|
82 | 92 |
$this->transliterationRepository->insert([ |
83 | 93 |
TransliterationRepository::COLUMN_BOOK_ID => $bookId, |
84 | 94 |
TransliterationRepository::COLUMN_CHAPTER => $chapterReg[0] |
... | ... | |
86 | 96 |
$transliterationId = $this->context->getInsertId(TransliterationRepository::COLUMN_ID); |
87 | 97 |
} |
88 | 98 |
} |
89 |
} catch (\Exception $exception) { |
|
99 |
} |
|
100 |
catch (\Exception $exception) |
|
101 |
{ |
|
90 | 102 |
\Tracy\Debugger::log('Nepodařila se uložit nová transliterace. Chyba: ' . $exception->getMessage(), 'transport-facade'); |
91 | 103 |
return FALSE; |
92 | 104 |
} |
93 |
foreach ($surfaces as $surface => $values) { |
|
94 |
try { |
|
105 |
foreach ($surfaces as $surface => $values) |
|
106 |
{ |
|
107 |
try |
|
108 |
{ |
|
95 | 109 |
$surfaceId = $this->getSurfaceIdByCurrentTransSurfType($transliterationId, $surface); |
96 |
if (!$surfaceId) { |
|
110 |
if (!$surfaceId) |
|
111 |
{ |
|
97 | 112 |
$surfaceId = $this->surfaceRepository->insert([ |
98 | 113 |
SurfaceRepository::COLUMN_TRANSLITERATION_ID => $transliterationId, |
99 | 114 |
SurfaceRepository::COLUMN_SURFACE_TYPE_ID => $surface, |
100 | 115 |
SurfaceRepository::COLUMN_OBJECT_TYPE_ID => 1 |
101 | 116 |
])->getPrimary(); |
102 | 117 |
} |
103 |
} catch (\Exception $exception) { |
|
118 |
} |
|
119 |
catch (\Exception $exception) |
|
120 |
{ |
|
104 | 121 |
\Tracy\Debugger::log('Nepodařil se uložit nový surface. Chyba: ' . $exception->getMessage(), 'transport-facade'); |
105 | 122 |
return FALSE; |
106 | 123 |
} |
107 | 124 |
|
108 |
foreach ($values as $line) { |
|
109 |
try { |
|
125 |
foreach ($values as $line) |
|
126 |
{ |
|
127 |
try |
|
128 |
{ |
|
110 | 129 |
$lineId = $this->getLineIdByCurrentSurfLineNum($surfaceId, (explode(' ', $line)[0])); |
111 |
if (!$lineId) { |
|
130 |
if (!$lineId) |
|
131 |
{ |
|
112 | 132 |
$this->lineRepository->insert([ |
113 | 133 |
LineRepository::COLUMN_SURFACE_ID => $surfaceId, |
114 | 134 |
LineRepository::COLUMN_LINE_NUMBER => (explode(' ', $line)[0]), |
115 | 135 |
LineRepository::COLUMN_TRANSLITERATION => substr(strchr($line, " "), 1), |
116 | 136 |
])->{LineRepository::COLUMN_ID}; |
117 |
} else { |
|
137 |
} else |
|
138 |
{ |
|
118 | 139 |
$this->lineRepository->fetchById($lineId)->update([ |
119 | 140 |
LineRepository::COLUMN_TRANSLITERATION => substr(strchr($line, " "), 1) |
120 | 141 |
]); |
121 | 142 |
} |
122 |
} catch (\Exception $exception) { |
|
143 |
} |
|
144 |
catch (\Exception $exception) |
|
145 |
{ |
|
123 | 146 |
\Tracy\Debugger::log('Nepodařil se uložit nová řádka (line) transliterace. Chyba: ' . $exception->getMessage(), 'transport-facade'); |
124 | 147 |
return FALSE; |
125 | 148 |
} |
... | ... | |
130 | 153 |
return TRUE; |
131 | 154 |
} |
132 | 155 |
|
133 |
|
|
134 | 156 |
/** |
135 | 157 |
* Vrací id knihy podle jména zkratky |
136 | 158 |
* @param $bookName |
137 | 159 |
* @return bool|mixed|ActiveRow |
138 | 160 |
*/ |
139 |
public |
|
140 |
function getBookIdByName(string $bookName) |
|
161 |
public function getBookIdByName(string $bookName) |
|
141 | 162 |
{ |
142 | 163 |
$book = $this->bookRepository->getBookByBookAbbrev($bookName)->fetch(); |
143 |
if (!empty($book)) { |
|
164 |
if (!empty($book)) |
|
165 |
{ |
|
144 | 166 |
return $book->getPrimary(); |
145 |
} else { |
|
167 |
} else |
|
168 |
{ |
|
146 | 169 |
return false; |
147 | 170 |
} |
148 | 171 |
} |
149 | 172 |
|
150 |
|
|
151 |
private |
|
152 |
function getTransliterationIdCurrentBookChapter(int $bookId, string $chapterName) |
|
173 |
private function getTransliterationIdCurrentBookChapter(int $bookId, string $chapterName) |
|
153 | 174 |
{ |
154 | 175 |
$transliteration = $this->transliterationRepository->getTransliterationByChapterNameAndBookId($bookId, $chapterName)->fetch(); |
155 |
if (!empty($transliteration)) { |
|
176 |
if (!empty($transliteration)) |
|
177 |
{ |
|
156 | 178 |
return $transliteration->getPrimary(); |
157 |
} else { |
|
179 |
} else |
|
180 |
{ |
|
158 | 181 |
return false; |
159 | 182 |
} |
160 | 183 |
} |
... | ... | |
163 | 186 |
{ |
164 | 187 |
$surface = $this->surfaceRepository->getSurfaceByTransliterationIdAndSurfaceTypeId($transliterationId, $surfaceId)->fetch(); |
165 | 188 |
|
166 |
if (!empty($surface)) { |
|
189 |
if (!empty($surface)) |
|
190 |
{ |
|
167 | 191 |
return $surface->getPrimary(); |
168 |
} else { |
|
192 |
} else |
|
193 |
{ |
|
169 | 194 |
return false; |
170 | 195 |
} |
171 | 196 |
} |
... | ... | |
173 | 198 |
private function getLineIdByCurrentSurfLineNum(int $surfaceId, $lineNum) |
174 | 199 |
{ |
175 | 200 |
$line = $this->lineRepository->getLineBySurfaceIdAndLineNumber($surfaceId, $lineNum)->fetch(); |
176 |
if (!empty($line)) { |
|
201 |
if (!empty($line)) |
|
202 |
{ |
|
177 | 203 |
return $line->{LineRepository::COLUMN_ID}; |
178 |
} else { |
|
204 |
} else |
|
205 |
{ |
|
179 | 206 |
return false; |
180 | 207 |
} |
181 | 208 |
} |
Také k dispozici: Unified diff
Formátování kódu