|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FlexiPeeHP; |
|
4
|
|
|
|
|
5
|
|
|
define('EASE_APPNAME', 'FlexiPeeHP Formats'); |
|
6
|
|
|
define('EASE_LOGGER', 'console|syslog'); |
|
7
|
|
|
|
|
8
|
|
|
require_once '../testing/bootstrap.php'; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
$outFile = 'Formats.php'; |
|
12
|
|
|
$outJson = 'Formats.json'; |
|
13
|
|
|
$ok = 0; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Obtain Formats for given evidence |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $evidence |
|
19
|
|
|
* @param FlexiBeeRO $syncer Class to read from FlexiBee |
|
20
|
|
|
* @return array Formats structure |
|
21
|
|
|
*/ |
|
22
|
|
|
function getEvidenceFormats($evidence, FlexiBeeRO $syncer) |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
$syncer->setEvidence($evidence); |
|
26
|
|
|
$flexinfo = $syncer->getColumnsFromFlexibee(['id'], ['limit' => 1]); |
|
27
|
|
|
if (is_array($flexinfo) && is_array($flexinfo[0]) && array_key_exists('id', $flexinfo[0])) { |
|
28
|
|
|
$id = is_numeric($flexinfo[0]['id']) ? intval($flexinfo[0]['id']) : $flexinfo[0]['id']; |
|
29
|
|
|
$formats = []; |
|
30
|
|
|
foreach (Formats::$formats as $cancode => $candidate) { |
|
31
|
|
|
$syncer->setFormat($candidate['suffix']); |
|
32
|
|
|
$syncer->loadFromFlexiBee($id); |
|
33
|
|
|
if ($syncer->lastResponseCode == 200) { |
|
34
|
|
|
$formats[$cancode] = $candidate['suffix']; |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
} else { |
|
38
|
|
|
$syncer->addStatusMessage(sprintf('Missing formats for %s', $evidence), |
|
39
|
|
|
'warning'); |
|
40
|
|
|
$formats = ['HTML' => 'html', 'XML' => 'xml', 'JSON' => 'json', 'CSV' => 'csv']; |
|
41
|
|
|
} |
|
42
|
|
|
return $formats; |
|
43
|
|
|
} |
|
44
|
|
|
$evidenceFormats = '<?php |
|
45
|
|
|
/** |
|
46
|
|
|
* FlexiPeeHP - Evidence Formats. |
|
47
|
|
|
* |
|
48
|
|
|
* @author Vítězslav Dvořák <[email protected]> |
|
49
|
|
|
* @copyright (C) 2015-'.date('Y').' Spoje.Net |
|
50
|
|
|
*/ |
|
51
|
|
|
namespace FlexiPeeHP; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Evidence Formats |
|
55
|
|
|
* |
|
56
|
|
|
* @link https://demo.flexibee.eu/devdoc/formats Provádění akcí |
|
57
|
|
|
*/ |
|
58
|
|
|
class Formats |
|
59
|
|
|
{ |
|
60
|
|
|
'; |
|
61
|
|
|
$statuser = new Status(); |
|
62
|
|
|
$evidenceFormats .= ' /** |
|
63
|
|
|
* Source FlexiBee server version. |
|
64
|
|
|
* |
|
65
|
|
|
* @var string |
|
66
|
|
|
*/ |
|
67
|
|
|
'; |
|
68
|
|
|
$evidenceFormats .= ' static public $version = \''.$statuser->getDataValue('version').'\'; |
|
69
|
|
|
|
|
70
|
|
|
'; |
|
71
|
|
|
|
|
72
|
|
|
$evidenceFormats .= ' |
|
73
|
|
|
/** |
|
74
|
|
|
* Availble Formats. |
|
75
|
|
|
* |
|
76
|
|
|
* @see https://www.flexibee.eu/api/dokumentace/ref/format-types/ |
|
77
|
|
|
* @var array formats known to flexibee |
|
78
|
|
|
*/ |
|
79
|
|
|
static public $formats = [ |
|
80
|
|
|
\'JS\' => [\'desc\' => \'JavaScropt\', |
|
81
|
|
|
\'suffix\' => \'js\', \'content-type\' => \'application/javascript\', \'import\' => false], |
|
82
|
|
|
\'PNG\' => [\'desc\' => \'Portable Network Graphics\', |
|
83
|
|
|
\'suffix\' => \'png\', \'content-type\' => \'image/png\', \'import\' => false], |
|
84
|
|
|
\'CSS\' => [\'desc\' => \'Kaskádový styl\', |
|
85
|
|
|
\'suffix\' => \'css\', \'content-type\' => \'text/css\', \'import\' => false], |
|
86
|
|
|
\'HTML\' => [\'desc\' => \'HTML stránka pro zobrazení informací na webové stránce.\', |
|
87
|
|
|
\'suffix\' => \'html\', \'content-type\' => \'text/html\', \'import\' => false], |
|
88
|
|
|
\'XML\' => [\'desc\' => \'Strojově čitelná struktura ve formátu XML.\', \'suffix\' => \'xml\', |
|
89
|
|
|
\'content-type\' => \'application/xml\', \'import\' => true], |
|
90
|
|
|
\'JSON\' => [\'desc\' => \'Strojově čitelná struktura ve formátu JSON. \', \'suffix\' => \'json\', |
|
91
|
|
|
\'content-type\' => \'application/json\', \'import\' => true], |
|
92
|
|
|
\'CSV\' => [\'desc\' => \'Tabulkový výstup do formátu CSV (Column Separated Values).\', |
|
93
|
|
|
\'suffix\' => \'csv\', \'content-type\' => \'text/csv\', \'import\' => true], |
|
94
|
|
|
\'DBF\' => [\'desc\' => \'Databázový výstup ve formátu DBF (dBase).\', \'suffix\' => \'dbf\', |
|
95
|
|
|
\'content-type\' => \'application/dbf\', \'import\' => true], |
|
96
|
|
|
\'XLS\' => [\'desc\' => \'Tabulkový výstup ve formátu Excel.\', \'suffix\' => \'xls\', |
|
97
|
|
|
\'content-type\' => \'application/ms-excel\', \'import\' => true], |
|
98
|
|
|
\'ISDOC\' => [\'desc\' => \'e-faktura ISDOC.\', \'suffix\' => \'isdoc\', \'content-type\' => \'application/x-isdoc\', |
|
99
|
|
|
\'import\' => false], |
|
100
|
|
|
\'ISDOCx\' => [\'desc\' => \'e-faktura ISDOC s PDF přílohou\', \'suffix\' => \'isdocx\', |
|
101
|
|
|
\'content-type\' => \'application/x-isdocx\', |
|
102
|
|
|
\'import\' => false], |
|
103
|
|
|
\'EDI\' => [\'desc\' => \'Elektronická výměna data (EDI) ve formátu INHOUSE.\', |
|
104
|
|
|
\'suffix\' => \'edi\', \'content-type\' => \'application/x-edi-inhouse\', \'import\' => \'objednavka-prijata\'], |
|
105
|
|
|
\'PDF\' => [\'desc\' => \'Generování tiskového reportu. Jedná se o stejnou funkci která je dostupná v aplikaci. Export do PDF\', |
|
106
|
|
|
\'suffix\' => \'pdf\', \'content-type\' => \'application/pdf\', \'import\' => false], |
|
107
|
|
|
\'vCard\' => [\'desc\' => \'Výstup adresáře do formátu elektronické vizitky vCard.\', |
|
108
|
|
|
\'suffix\' => \'vcf\', \'content-type\' => \'text/vcard\', \'import\' => false], |
|
109
|
|
|
\'iCalendar\' => [\'desc\' => \'Výstup do kalendáře ve formátu iCalendar. Lze takto exportovat události, ale také třeba splatnosti u přijatých či vydaných faktur.\', |
|
110
|
|
|
\'suffix\' => \'ical\', \'content-type\' => \'text/calendar\', \'import\' => false], |
|
111
|
|
|
\'TEXT\' => [\'desc\' => \'Prostý text\', \'suffix\' => \'txt\', |
|
112
|
|
|
\'content-type\' => \'text/plain\', \'import\' => false], |
|
113
|
|
|
\'TTF\' => [\'desc\' => \'TrueType font\', \'suffix\' => \'ttf\', |
|
114
|
|
|
\'content-type\' => \'application/x-font-truetype\', \'import\' => false], |
|
115
|
|
|
|
|
116
|
|
|
]; |
|
117
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Array of formats indexed by Content-Type |
|
121
|
|
|
* |
|
122
|
|
|
* @return array |
|
123
|
|
|
*/ |
|
124
|
|
|
static public function byContentType() |
|
125
|
|
|
{ |
|
126
|
|
|
return \Ease\Functions::reindexArrayBy(self::$formats, \'content-type\'); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Array of formats indexed by Suffix |
|
131
|
|
|
* |
|
132
|
|
|
* @return array |
|
133
|
|
|
*/ |
|
134
|
|
|
static public function bySuffix() |
|
135
|
|
|
{ |
|
136
|
|
|
return \Ease\Functions::reindexArrayBy(self::$formats, \'suffix\'); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Obtain Suffix for given content |
|
141
|
|
|
* |
|
142
|
|
|
* @param string $suffix |
|
143
|
|
|
* @return string |
|
144
|
|
|
*/ |
|
145
|
|
|
static public function suffixToContentType($suffix) |
|
146
|
|
|
{ |
|
147
|
|
|
$types = self::bySuffix(); |
|
148
|
|
|
return isset($types[$suffix]) ? $types[$suffix][\'content-type\'] : null; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Obtain Content-Type for given suffix |
|
153
|
|
|
* |
|
154
|
|
|
* @param string $contentType |
|
155
|
|
|
* @return string |
|
156
|
|
|
*/ |
|
157
|
|
|
static public function contentTypeToSuffix($contentType) |
|
158
|
|
|
{ |
|
159
|
|
|
$types = self::byContentType(); |
|
160
|
|
|
return isset($types[$contentType]) ? $types[$contentType][\'suffix\'] : null; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
'; |
|
164
|
|
|
|
|
165
|
|
|
$syncer = new FlexiBeeRO(); |
|
166
|
|
|
$syncer->setObjectName('FlexiBee Evidence Formats'); |
|
167
|
|
|
$syncer->addStatusMessage('Updating Evidences Formats'); |
|
168
|
|
|
|
|
169
|
|
|
$formats = []; |
|
170
|
|
|
|
|
171
|
|
|
$pos = 0; |
|
172
|
|
|
foreach (EvidenceList::$name as $evidencePath => $evidenceName) { |
|
173
|
|
|
$pos++; |
|
174
|
|
|
$structure = getEvidenceFormats($evidencePath, $syncer); |
|
175
|
|
|
|
|
176
|
|
|
$formats[$evidencePath] = $structure; |
|
177
|
|
|
|
|
178
|
|
|
if (count($structure)) { |
|
179
|
|
|
$evidenceFormats .= ' /** |
|
180
|
|
|
* Evidence '.$evidencePath.' ('.$evidenceName.') Formats. |
|
181
|
|
|
* |
|
182
|
|
|
* @var array |
|
183
|
|
|
*/ |
|
184
|
|
|
'; |
|
185
|
|
|
$evidenceFormats .= ' static public $'.lcfirst(FlexiBeeRO::evidenceToClassName($evidencePath)).' = '.var_export($structure, |
|
186
|
|
|
true).'; |
|
187
|
|
|
'; |
|
188
|
|
|
$syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': formats: '.implode(',',$structure), 'success'); |
|
189
|
|
|
$ok++; |
|
190
|
|
|
} else { |
|
191
|
|
|
$syncer->addStatusMessage($pos.' of '.count(EvidenceList::$name).' '.$evidencePath.': obtaining formats problem', |
|
192
|
|
|
'error'); |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
$evidenceFormats .= '} |
|
197
|
|
|
'; |
|
198
|
|
|
|
|
199
|
|
|
$syncer->addStatusMessage('Updating of '.$ok.' Evidences Formats done', |
|
200
|
|
|
'success'); |
|
201
|
|
|
file_put_contents($outFile, $evidenceFormats); |
|
202
|
|
|
|
|
203
|
|
|
file_put_contents($outJson, json_encode($formats)); |
|
204
|
|
|
|