-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathRO.php
More file actions
2952 lines (2523 loc) · 92 KB
/
RO.php
File metadata and controls
2952 lines (2523 loc) · 92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
/**
* This file is part of the SpojeNet\AbraFlexi package.
*
* (c) 2019-2024 SpojeNet s.r.o. <http://spoje.net/>
* (c) 2025-2026 SpojeNetIT s.r.o. <http://spojenet.cz/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AbraFlexi;
/**
* Basic class for reading from AbraFlexi.
*
* @url https://demo.flexibee.eu/devdoc/
*
* @no-named-arguments
*/
class RO extends \Ease\Sand implements \Stringable
{
use \Ease\recordkey;
/**
* Version of AbraFlexi library.
*/
public static string $libVersion = '3.6';
/**
* Basic namespace for communication with AbraFlexi.
*
* @var string Data block namespace in response
*/
public string $nameSpace = 'winstrom';
/**
* URL of object data in AbraFlexi.
*/
public ?string $apiURL = null;
/**
* Data block in response field.
*/
public string $resultField = 'results';
/**
* Communication protocol version used.
*/
public string $protoVersion = '1.0';
/**
* Evidence used by object.
*
* @see https://demo.flexibee.eu/c/demo/evidence-list Evidence overview
*/
public ?string $evidence = null;
/**
* Details of evidence used by object.
*/
public array $evidenceInfo = [];
/**
* Default communication format.
*
* @see https://www.abraflexi.eu/api/dokumentace/ref/format-types Available format types
*/
public string $format = 'json';
/**
* Requested response format.
*
* @see https://www.abraflexi.eu/api/dokumentace/ref/format-types Available format types
*/
public string $responseFormat = 'json';
/**
* Curl Handle.
*/
public ?\CurlHandle $curl = null;
/**
* Company identifier.
*
* @see https://demo.flexibee.eu/devdoc/company-identifier Company identifier
*/
public ?string $company = null;
/**
* [protocol://]Server[:port].
*/
public ?string $url = null;
/**
* REST API Username.
*/
public ?string $user = null;
/**
* REST API Password.
*/
public ?string $password = null;
/**
* Array of HTTP headers sent with each request.
*/
public array $defaultHttpHeaders = [];
/**
* Default additional request URL parameters after question mark.
*
* @see https://www.abraflexi.eu/api/dokumentace/ref/urls Common params
* @see https://www.abraflexi.eu/api/dokumentace/ref/paging Paging params
*/
public array $defaultUrlParams = [];
/**
* Column with name.
*/
public string $nameColumn = 'nazev';
/**
* Column containing record creation date in the system.
*/
public ?string $myCreateColumn = null;
/**
* Column containing date of last record modification in the system.
*/
public ?string $myLastModifiedColumn = 'lastUpdate';
/**
* Information about the last HTTP request.
*/
public ?array $curlInfo;
/**
* Information about the last HTTP error.
*/
public ?string $lastCurlError = null;
/**
* Used codes storage.
*/
public ?array $codes = null;
/**
* Last Inserted ID.
*/
public ?int $lastInsertedID = null;
/**
* Default Line Prefix.
*/
public string $prefix = '/c/';
/**
* Raw Content of last curl response.
*/
public string $lastCurlResponse;
/**
* HTTP Response code of last request.
*/
public ?int $lastResponseCode = null;
/**
* Body data for next curl POST operation.
*/
public ?string $postFields = null;
/**
* Last operation result data or message(s).
*
* @var null|array<mixed>
*/
public ?array $lastResult = null;
/**
* Number from @rowCount in response.
*/
public ?int $rowCount = null;
/**
* Number from @globalVersion.
*/
public ?int $globalVersion = null;
/**
* Filter query for record selection.
*
* @see https://www.abraflexi.eu/api/dokumentace/ref/zamykani-odemykani/
*/
public ?string $filter = null;
/**
* Array of actions that evidence supports.
*
* @see https://demo.flexibee.eu/c/demo/faktura-vydana/actions.json E.g. Invoice actions
*/
public ?array $actionsAvailable = null;
/**
* Parameters for URL.
*
* @see https://www.abraflexi.eu/api/dokumentace/ref/urls/ All supported parameters
*
* @var array<string, array<string, mixed>> List of known URL parameters and their metadata
*/
public array $urlParamsKnown = [
'add-global-version' => ['type' => 'boolean', 'description' => 'The response will contain the global version number of the current export'],
'add-row-count' => ['type' => 'boolean', 'description' => 'Adding Total Records to Output (Pagination)'],
'as-gui' => ['type' => 'boolean', 'description' => 'Turns on functions that complement the GUI processing outputs'],
'auth' => ['type' => 'string', 'description' => 'http: Forces login using HTTP authentication, for example, to change the default WUI login method. html: Force HTML form authentication. This can be useful to suppress automatic SSO authentication.'],
'authSessionId' => ['type' => 'string', 'description' => 'Authentification Session ID'],
'code-as-id' => ['type' => 'boolean', 'description' => 'If an object has unique code, it is also exported (except for the <code> element) as <id> code: ... </id>'],
'code-in-response' => ['type' => 'boolean', 'description' => 'The response will contain not only ID and URL for each object, but also code.'],
'delimeter' => ['type' => 'string', 'description' => 'Specifies the input / output file separator in CSV format.', 'example' => ';'],
'detail' => ['type' => 'string', 'description' => 'Definition of the level of detail'], // See: https://www.abraflexi.eu/api/dokumentace/ref/detail-levels
'dir' => ['type' => 'string', 'description' => 'Sorting direction.', 'example' => 'desc'],
'dry-run' => ['type' => 'boolean', 'description' => 'Test run (dry-run)'], // See: https://www.abraflexi.eu/api/dokumentace/ref/dry-run/
'encoding' => ['type' => 'string', 'description' => 'Specifies the encoding of the input / output file in CSV format.'],
'export-settings' => ['type' => 'boolean', 'description' => 'Export one extra entry with current settings at the beginning'],
'fail-on-warning' => ['type' => 'boolean', 'description' => 'If a warning occurs, do not save a record (Data Validation)'],
'filter' => ['type' => 'string', 'description' => 'filter results by this param'],
'fields' => ['type' => 'string', 'description' => 'sumation field list'],
'format' => ['type' => 'string', 'description' => 'One of the compiled XSL transforms will be applied to the output XML.'],
'idUcetniObdobi' => ['type' => 'string', 'description' => ''], // See: https://www.abraflexi.eu/api/dokumentace/ref/stavy-uctu/
'includes' => ['type' => 'string', 'description' => 'Include related detail level object ', 'example' => 'faktura-vydana/stredisko'],
'inDesktopApp' => ['type' => 'boolean', 'description' => 'Hide menu and navigation in html format'], // Note: Undocumented function (html only)
'limit' => ['type' => 'integer', 'description' => 'number of requested results'],
'mode' => ['type' => 'string', 'description' => 'Support for RubyOnRails', 'example' => 'ruby'],
'no-ext-ids' => ['type' => 'boolean', 'description' => 'The answer will not contain external identifiers (performance optimization)'],
'no-http-errors' => ['type' => 'boolean', 'description' => 'If a 4xx error occurs while processing a request, the server sends 200 OK anyway'],
'no-ids' => ['type' => 'boolean', 'description' => 'The response will not contain any primary identifiers (performance optimization). It only affects the main records.'],
'only-ext-ids' => ['type' => 'boolean', 'description' => 'The primary key will not be exported, the <id> elements will only contain the external ID. Similar no-ids, but also affects subevidences.'],
'order' => ['type' => 'string', 'description' => 'Sorting records', 'example' => 'nazev@A'],
'relations' => ['type' => 'string', 'description' => 'Adding session data (see detail levels) A session overview can be obtained for each record (/ relations).'],
'report-lang' => ['type' => 'string', 'description' => 'The language in which to print the output when exporting to PDF',
'example' => 'en'],
'report-name' => ['type' => 'string', 'description' => 'The name of the printout when exporting to PDF',
'example' => 'invoice'],
'report-sign' => ['type' => 'string', 'description' => 'Whether the PDF should be exported electronically signed'],
'skupina-stitku' => ['type' => 'string', 'description' => 'Enables grouping of labels when exporting by group (multiple labels)'],
'sort' => ['type' => 'string', 'description' => 'Sorting records for ExtJS'],
'start' => ['type' => 'integer', 'description' => 'Pagination'],
'stitky-as-ids' => ['type' => 'boolean', 'description' => 'Labels will be exported and imported not as a code list but as a list of numeric IDs'],
'use-ext-id' => ['type' => 'boolean', 'description' => 'If the object contains an external ESHOP or MY ID, use it as a bind.'],
'use-internal-id' => ['type' => 'boolean', 'description' => 'In addition to the ref and showAs for objects, it also supplies an internalId attribute that contains the internal record ID'],
'xpath' => ['type' => 'string', 'description' => 'Apply XPATH to result',
'example' => '//winstrom/adresar/email/text()'], // See: https://www.abraflexi.eu/api/dokumentace/ref/xpath/
];
/**
* Session ID.
*/
public ?string $authSessionId = null;
/**
* Token obtained during login procedure.
*/
public ?string $refreshToken = null;
/**
* Send Error500 Report to.
*/
public string $reportRecipient = 'podpora@abraflexi.eu';
/**
* Chained Objects.
*/
public array $chained = [];
/**
* Load whole record when id is given ?
*/
public bool $autoload = true;
/**
* We Connect to server by default.
*/
public bool $offline = false;
/**
* Convert server data to its native types ? eg. nubmers to integer
* You can disable it using setUp.
*/
public bool $nativeTypes = true;
/**
* Override cURL timeout in seconds.
*/
public ?int $timeout = 300;
/**
* Throw Exception in case of AbraFlexi error.
*/
public bool $throwException = true;
/**
* Action to be performed.
*
* @see https://demo.flexibee.eu/devdoc/actions Action execution
*/
protected ?string $action = null;
/**
* Save 404 results to log ?
*/
protected bool $ignoreNotFound = false;
/**
* Action messages.
*/
protected array $messages = [];
protected ?bool $success = null;
/**
* Array of errors caused by last request.
*/
protected array $errors = [];
/**
* Last request response statistics.
*/
protected ?array $responseStats = null;
/**
* Performed Operation name.
*/
protected ?string $operation = null;
/**
* List of Error500 reports sent.
*/
private array $reports = [];
/**
* Columns information for several evidences.
*/
private array $columnsInfo = [];
/**
* JSON Decode depth limit.
*/
private int $jsonDepth = 20;
/**
* Class for read only interaction with AbraFlexi.
*
* @param mixed $init Default record ID or initial data. See processInit()
* @param array<string, mixed> $options Connection settings and other options override
*/
public function __construct($init = null, $options = [])
{
parent::setObjectName();
$this->setUp($options);
$this->curlInit();
if (!empty($init)) {
$this->processInit($init);
}
$this->setObjectName(\array_key_exists('objectName', $options) ? $options['objectName'] : null);
}
/**
* Obtain record/object identificator code: or id:
*
* @see https://demo.flexibee.eu/devdoc/identifiers Record identifiers
*
* @return string Record identifier represented by the object
*/
public function __toString()
{
return (string) $this->getRecordIdent();
}
/**
* Unserialize data and restore object state.
*
* @param array<string, mixed> $data Serialized data
*/
public function __unserialize(array $data): void
{
foreach ($data as $key => $value) {
if (\is_string($key) && property_exists($this, $key)) {
$this->{$key} = $value;
}
}
$this->curlInit();
}
/**
* Reconnect after unserialization.
*
* @deprecated Soft deprecated in PHP 8.5
*/
public function __wakeup(): void
{
$this->__unserialize([]);
}
/**
* Variables to keep during serialization.
*
* @return array<string, mixed>
*/
public function __serialize(): array
{
$properties = [
'data',
'objectName',
'nameSpace',
'apiURL',
'resultField',
'protoVersion',
'evidence',
'evidenceInfo',
'format',
'responseFormat',
'company',
'url',
'user',
'password',
'defaultHttpHeaders',
'defaultUrlParams',
'nameColumn',
'myCreateColumn',
'myLastModifiedColumn',
'keyColumn',
'lastCurlError',
'codes',
'lastInsertedID',
'prefix',
'authSessionId',
'refreshToken',
'chained',
'autoload',
'offline',
'nativeTypes',
'timeout',
'throwException',
];
$result = [];
foreach ($properties as $property) {
if (property_exists($this, $property)) {
$result[$property] = $this->{$property};
}
}
return $result;
}
/**
* Variables to keep during serialization.
*
* @deprecated Soft deprecated in PHP 8.5
*
* @return array<int, string>
*/
public function __sleep()
{
return array_keys($this->__serialize());
}
/**
* Set up object to be ready for work.
*
* @param array<string, string> $options Object options (user, password, authSessionId,
* company, url, evidence, prefix, defaultUrlParams,
* debug, autoload, detail, offline, filter, ignore404,
* nativeTypes, timeout, companyUrl, ver, throwException)
*
* @return bool Setup success status
*/
public function setUp(array $options = []): bool
{
if (\array_key_exists('ver', $options)) {
$this->protoVersion = $options['ver'];
$this->prefix = 'v'.round((float) $this->protoVersion).'/c/';
}
if (\array_key_exists('companyUrl', $options)) {
$options = array_merge(
Functions::companyUrlToOptions($options['companyUrl']),
$options,
);
}
$this->setupProperty($options, 'company', 'ABRAFLEXI_COMPANY');
$this->setupProperty($options, 'url', 'ABRAFLEXI_URL');
$this->setupProperty($options, 'user', 'ABRAFLEXI_LOGIN');
$this->setupProperty($options, 'password', 'ABRAFLEXI_PASSWORD');
$this->setupProperty($options, 'authSessionId', 'ABRAFLEXI_AUTHSESSID');
$this->setupProperty($options, 'timeout', 'ABRAFLEXI_TIMEOUT');
$this->setupProperty($options, 'nativeTypes', 'ABRAFLEXI_NATIVE_TYPES');
if (!empty($this->authSessionId)) {
$this->defaultHttpHeaders['X-authSessionId'] = $this->authSessionId;
}
$this->setupProperty($options, 'defaultUrlParams');
if (isset($options['prefix'])) {
$this->setPrefix($options['prefix']);
}
if (\array_key_exists('detail', $options)) {
$this->defaultUrlParams['detail'] = $options['detail'];
}
$this->setupProperty($options, 'filter');
$this->setupBoolProperty($options, 'offline');
if (\array_key_exists('ignore404', $options)) {
$this->ignore404($options['ignore404']);
}
$this->setupBoolProperty($options, 'throwException', 'ABRAFLEXI_EXCEPTIONS');
$this->setupBoolProperty($options, 'debug');
$this->setupBoolProperty($options, 'autoload');
if (isset($options['evidence'])) {
$this->setEvidence($options['evidence']);
} elseif ($this->evidence) { // Use Defaut if specified
$this->setEvidence($this->evidence);
} else {
$this->updateApiURL();
}
return true;
}
/**
* Set internal object name.
*
* @param null|string $objectName Object name to set
*
* @return string Object name
*/
public function setObjectName($objectName = null)
{
return parent::setObjectName(null === $objectName ? (empty($this->getRecordIdent()) ? $this->getObjectName() : $this->getRecordIdent().'@'.$this->getObjectName()) : $objectName);
}
/**
* Get Current connection options for use in another object.
*
* @return array<string, null|int|string> Usable as second constructor parameter
*/
public function getConnectionOptions(): array
{
$conOpts = ['url' => $this->url];
if (empty($this->authSessionId)) {
$conOpts['user'] = $this->user;
$conOpts['password'] = $this->password;
} else {
$conOpts['authSessionId'] = $this->authSessionId;
}
$company = $this->getCompany();
if (!empty($company)) {
$conOpts['company'] = $company;
}
if (null !== $this->timeout) {
$conOpts['timeout'] = $this->timeout;
}
return $conOpts;
}
/**
* Export current/given configuration into environment variables.
*
* @param array<string, null|int|string> $opts Configuration options to export to environment variables
*/
public function configToEnv(array $opts = []): void
{
$options = empty($opts) ? $this->getConnectionOptions() : $opts;
if (\array_key_exists('url', $options)) {
putenv('ABRAFLEXI_URL='.$options['URL']);
}
if (\array_key_exists('user', $options)) {
putenv('ABRAFLEXI_LOGIN='.$options['user']);
}
if (\array_key_exists('password', $options)) {
putenv('ABRAFLEXI_PASSWORD='.$options['password']);
}
if (\array_key_exists('company', $options)) {
putenv('ABRAFLEXI_COMPANY='.$options['company']);
}
if (\array_key_exists('authSessionId', $options)) {
putenv('ABRAFLEXI_AUTHSESSID='.$options['authSessionId']);
}
}
/**
* Initialize CURL.
*
* @return bool Online status
*/
public function curlInit()
{
if ($this->offline === false) {
$this->curl = \curl_init(); // create curl resource
\curl_setopt($this->curl, \CURLOPT_RETURNTRANSFER, true); // return content as a string from curl_exec
\curl_setopt($this->curl, \CURLOPT_FOLLOWLOCATION, true); // follow redirects (compatibility for future changes in AbraFlexi)
\curl_setopt($this->curl, \CURLOPT_HTTPAUTH, true); // HTTP authentication
\curl_setopt($this->curl, \CURLOPT_SSL_VERIFYPEER, false); // AbraFlexi by default uses Self-Signed certificates
\curl_setopt($this->curl, \CURLOPT_SSL_VERIFYHOST, false);
\curl_setopt($this->curl, \CURLOPT_VERBOSE, $this->debug === true); // For debugging
if (empty($this->authSessionId)) {
\curl_setopt(
$this->curl,
\CURLOPT_USERPWD,
$this->user.':'.$this->password,
); // set username and password
}
if (null !== $this->timeout) {
\curl_setopt($this->curl, \CURLOPT_HTTPHEADER, [
'Connection: Keep-Alive',
'Keep-Alive: '.$this->timeout,
]);
\curl_setopt($this->curl, \CURLOPT_TIMEOUT, $this->timeout);
}
\curl_setopt($this->curl, \CURLOPT_USERAGENT, 'phpAbraFlexi v'.self::$libVersion.' https://github.com/Spoje-NET/php-abraflexi');
}
return !$this->offline;
}
/**
* Zinicializuje objekt dle daných dat. Možné hodnoty:
*
* * 234 - interní číslo záznamu k načtení
* * code:LOPATA - kód záznamu
* * BAGR - kód záznamu k načtení
* * ['id'=>24,'nazev'=>'hoblík'] - pole hodnot k předvyplnění
* * 743.json?relations=adresa,vazby - část url s parametry k načtení
*
* @param mixed $init číslo/"(code:)kód"/(část)URI záznamu k načtení | pole hodnot k předvyplnění
*/
public function processInit($init): void
{
if (\is_int($init) && $this->autoload) {
$this->loadFromAbraFlexi($init);
} elseif (\is_array($init)) {
$this->takeData($init);
} elseif (!\is_object($init) && preg_match('/\.(json|xml|csv)/', (string) $init)) {
$this->takeData($this->getFlexiData(($init[0] !== '/') ? $this->evidenceUrlWithSuffix($init) : $init));
} else {
if ($this->autoload === false) {
$this->setMyKey($init);
} else {
$this->loadFromAbraFlexi($init);
}
}
}
/**
* Set data field value.
*
* @param string $columnName Field name
* @param mixed $value Field data value
*
* @return bool Success
*/
public function setDataValue(string $columnName, $value): bool
{
switch ($columnName) {
case 'kod':
$value = $value ? Functions::uncode($value) : ''; // Alwyas uncode "kod" column
// no break
default:
if (\is_object($value)) {
switch ($value::class) {
case 'DateTime':
$columnInfo = $this->getColumnInfo($columnName);
switch ($columnInfo['type']) {
case 'date':
$value = Functions::dateToFlexiDate($value);
break;
case 'datetime':
$value = Functions::dateToFlexiDateTime($value);
break;
}
break;
}
}
$result = parent::setDataValue($columnName, $value);
break;
}
return $result;
}
/**
* Strip all non-identifier data.
*
* @param array<string> $keep Extra columns to be preserved
*
* @return RO Current object state
*/
public function stripBody(array $keep = [])
{
$id = $this->getRecordID();
$code = $this->getRecordCode();
$extIds = $this->getExternalIDs();
$restoreData = [];
$originalData = $this->getData();
foreach ($keep as $column) {
\Ease\Functions::divDataArray($originalData, $restoreData, $column);
}
$this->dataReset();
$this->setData($restoreData);
$this->setMyKey($id);
$columns = $this->getColumnsInfo();
if (\array_key_exists('kod', $columns)) {
$this->setDataValue('kod', $code);
}
if (!empty($extIds)) {
$this->setDataValue('external-ids', $columns);
}
return $this;
}
/**
* Set URL prefix.
*
* @param string $prefix URL prefix to set
*/
public function setPrefix(string $prefix): void
{
switch ($prefix) {
case 'a': // Access
case 'c': // Company
case 'u': // User
case 'g': // License Groups
case 'admin':
case 'status':
case 'login-logout':
$this->prefix = '/'.$prefix.'/';
break;
case null:
case '':
case '/':
$this->prefix = '';
break;
default:
throw new \Exception(sprintf('Unknown prefix %s', $prefix));
}
}
/**
* Set communication format.
* One of html|xml|json|csv|dbf|xls|isdoc|isdocx|edi|pdf|vcf|ical.
*
* @param string $format Format to set
*
* @return bool Format is available
*/
public function setFormat(string $format)
{
$result = true;
if (($this->debug === true) && !empty($this->evidence) && isset(Formats::${$this}->evidence)) {
if (\array_key_exists($format, array_flip(Formats::${$this}->evidence)) === false) {
$result = false;
}
}
if ($result === true) {
$this->format = $format;
$this->updateApiURL();
}
return $result;
}
/**
* Set evidence for communication.
*
* @param string $evidence Evidence pathName to use
*
* @return bool Evidence switching status
*/
public function setEvidence(string $evidence)
{
switch ($this->prefix) {
case '/c/':
if ($this->debug === true) {
if (\array_key_exists($evidence, EvidenceList::$name)) {
$this->evidence = $evidence;
$result = true;
} else {
throw new \Exception(sprintf(
'Try to set unsupported evidence %s',
$evidence,
));
}
} else {
$this->evidence = $evidence;
$result = true;
}
break;
default:
$this->evidence = $evidence;
$result = true;
break;
}
$this->updateApiURL();
$this->evidenceInfo = $this->getEvidenceInfo();
return $result;
}
/**
* Return currently used evidence for communication.
*
* @return null|string Current evidence
*/
public function getEvidence()
{
return $this->evidence;
}
/**
* Set used company.
*
* @param string $company Company identifier
*/
public function setCompany($company): void
{
$this->company = $company;
}
/**
* Obtain company now used.
*
* @return null|string Currently used company
*/
public function getCompany()
{
return $this->company;
}
/**
* Return evidence name used in responses from AbraFlexi.
*
* @return string Evidence name
*/
public function getResponseEvidence()
{
switch ($this->evidence) {
case 'c':
$evidence = 'company';
break;
case 'evidence-list':
$evidence = 'evidence';
break;
default:
$evidence = $this->getEvidence();
break;
}
return $evidence;
}
/**
* Return basic URL for used evidence.
*
* @see https://www.abraflexi.eu/api/dokumentace/ref/urls/ URL composition
*
* @return string Evidence URL
*/
public function getEvidenceURL()
{
$evidenceUrl = $this->url.$this->prefix.$this->company;
$evidence = $this->getEvidence();
if (!empty($evidence)) {
$evidenceUrl .= '/'.$evidence;
}
return $evidenceUrl;
}
/**
* Add suffix to evidence URL.
*
* @param string $urlSuffix URL suffix to append
*
* @return string Complete evidence URL with suffix
*/
public function evidenceUrlWithSuffix($urlSuffix)
{
$evidenceUrl = $this->getEvidenceUrl();
if (!empty($urlSuffix)) {
if (($urlSuffix[0] !== '/') && ($urlSuffix[0] !== ';') && ($urlSuffix[0] !== '?')) {
$evidenceUrl .= '/';
}
$evidenceUrl .= $urlSuffix;
}
return $evidenceUrl;
}
/**
* Update $this->apiURL.
*/
public function updateApiURL(): void
{
$this->apiURL = $this->getEvidenceURL();
$rowIdentifier = $this->getRecordIdent();
if (empty($rowIdentifier)) {
$rowIdentifier = $this->getRecordCode();
if (empty($rowIdentifier)) {
$rowIdentifier = $this->getExternalID();
}
}
if (!empty($rowIdentifier)) {
$this->apiURL .= '/'.Functions::urlEncode((string) $rowIdentifier);
}
$this->apiURL .= '.'.$this->format;
}
/**
* Add default URL params to given URL if not overridden.
*
* @param string $urlRaw Raw URL to add parameters to
*
* @return string URL with default params added
*/
public function addDefaultUrlParams(string $urlRaw)
{
return \Ease\Functions::addUrlParams(
$urlRaw,
$this->defaultUrlParams,
false,
);
}
/**
* Funkce, která provede I/O operaci a vyhodnotí výsledek.
*
* @param string $urlSuffix část URL za identifikátorem firmy
* @param string $method HTTP/REST metoda
* @param string $format Requested format
*
* @return array|bool Výsledek operace
*/