Revize ce045025
Přidáno uživatelem Petr Lukašík před téměř 6 roky(ů)
app/utils/TextParser.php | ||
---|---|---|
5 | 5 |
|
6 | 6 |
class TextParser |
7 | 7 |
{ |
8 |
public $textFile;
|
|
8 |
private $textFile;
|
|
9 | 9 |
private $objectTypes; |
10 | 10 |
private $surfaceTypes; |
11 | 11 |
|
... | ... | |
14 | 14 |
$this->textFile = $file; |
15 | 15 |
} |
16 | 16 |
|
17 |
/** Rozparsuje importovaný text */ |
|
17 | 18 |
public function parseText() |
18 | 19 |
{ |
19 | 20 |
$array = explode("\n", file_get_contents($this->textFile)); |
20 | 21 |
$array = array_map('trim', $array); |
21 | 22 |
|
23 |
$nextBook = true; |
|
22 | 24 |
$output = array(); |
23 | 25 |
$currentBook = ""; |
24 | 26 |
$currentChapter = ""; |
... | ... | |
26 | 28 |
|
27 | 29 |
//TODO kontrola a parsovani object types (tablet, envelope) |
28 | 30 |
foreach ($array as $value) { |
29 |
if ($value[0] == '|' && !is_numeric($value[1])) { |
|
31 |
Debugger::barDump($value); |
|
32 |
if (strlen($value)==0){ |
|
33 |
$nextBook = true; |
|
34 |
} |
|
35 |
elseif ($value[0] == '|' && $nextBook) { |
|
30 | 36 |
$currentBook = substr($value, 1); |
31 | 37 |
$currentChapter = ""; |
32 | 38 |
$currentSurface = $this->transformAbbrev("obverse"); |
39 |
$nextBook = false; |
|
33 | 40 |
} |
34 |
elseif ($value[0] == '|' && is_numeric($value[1])){ |
|
35 |
$currentChapter = substr($value, 1); |
|
36 |
$currentSurface = $this->transformAbbrev("obverse"); |
|
37 |
}else{ |
|
41 |
elseif ($value[0] == '|'){ |
|
42 |
// TYPÍIIIIIČO ono to může být i tady... k posrání. Odděleno '-', jakože pro jistotu demence (OBTR => "15 (T.R.4020) - le.e.") |
|
43 |
$withRef = explode(" - ", substr($value, 1)); |
|
44 |
if(isset($withRef[1])){ |
|
45 |
$currentChapter = trim(substr($value, 1, strripos($value, "-")-1)); |
|
46 |
$currentSurface = $this->transformAbbrev(trim($withRef[1])); |
|
47 |
}else{ |
|
48 |
$currentChapter = substr($value, 1); |
|
49 |
$currentSurface = $this->transformAbbrev("obverse"); |
|
50 |
} |
|
51 |
} |
|
52 |
else{ |
|
38 | 53 |
if (strchr($value, '$')) { |
39 | 54 |
$output[$currentBook][$currentChapter][$currentSurface][] = trim(substr($value,0,stripos($value,"&"))); |
40 | 55 |
$currentSurface = $this->transformAbbrev(substr(strchr($value, "&"),1, -1)); |
... | ... | |
47 | 62 |
return $output; |
48 | 63 |
} |
49 | 64 |
|
50 |
/** Nejvíc kontrola souboru*/ |
|
65 |
/** Nejvíc kontrola souboru, kontroluje zda soubor existuje a zda aspoň začátek souboru vyhovuje formátu */
|
|
51 | 66 |
public function isFileParsable() |
52 | 67 |
{ |
53 | 68 |
if (file_exists($this->textFile)) { |
... | ... | |
68 | 83 |
$this->surfaceTypes = $surfaces; |
69 | 84 |
} |
70 | 85 |
|
86 |
/** Funkce pro transformaci zkratek surfaceType na jejich příslušná idčka v db */ |
|
71 | 87 |
private function transformAbbrev($abbrev){ |
72 | 88 |
switch ($abbrev){ |
73 | 89 |
case "rev.": |
... | ... | |
101 | 117 |
return array_search("obverse", $this->surfaceTypes); |
102 | 118 |
} |
103 | 119 |
} |
120 |
|
|
121 |
public function getTextFile(){ |
|
122 |
return $this->textFile; |
|
123 |
} |
|
104 | 124 |
} |
Také k dispozici: Unified diff
Re #7510 kompletní import, bugfixy v parseru+preview, js na anti-spam uploadu