|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace h4kuna\Ares; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime, |
|
6
|
|
|
DateTimeZone; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @author Milan Matějček |
|
10
|
|
|
*/ |
|
11
|
|
|
class DataProvider |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** @var IDataFactory */ |
|
15
|
|
|
private $dataFactory; |
|
16
|
|
|
|
|
17
|
|
|
/** @var array */ |
|
18
|
|
|
private $data = []; |
|
19
|
|
|
|
|
20
|
|
|
public function __construct(IDataFactory $dataFactory) |
|
21
|
|
|
{ |
|
22
|
|
|
$this->dataFactory = $dataFactory; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** @return Data */ |
|
26
|
|
|
public function getData() |
|
27
|
|
|
{ |
|
28
|
|
|
if (is_array($this->data)) { |
|
29
|
|
|
$this->setFileNumberAndCourt(); |
|
30
|
|
|
$this->data = $this->dataFactory->create($this->data); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
return $this->data; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function prepareData() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->data = []; |
|
38
|
|
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $active |
|
43
|
|
|
* @return self |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setActive($active) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->data['active'] = is_bool($active) ? $active : (((string) $active) == 'Aktivní'); // == |
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function setCity($city) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->data['city'] = self::toNull($city); |
|
54
|
|
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function setCompany($company) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->data['company'] = self::toNull($company); |
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function setCourt($court) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->data['court'] = self::toNull($court); |
|
66
|
|
|
return $this; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function setCreated($date) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->data['created'] = new DateTime((string) $date, new DateTimeZone('Europe/Prague')); |
|
72
|
|
|
return $this; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function setFileNumber($fileNumber) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->data['file_number'] = self::toNull($fileNumber); |
|
78
|
|
|
return $this; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function setIN($in) |
|
82
|
|
|
{ |
|
83
|
|
|
$this->data['in'] = self::toNull($in); |
|
84
|
|
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function setIsPerson($s) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->data['is_person'] = ((string) $s) <= '108'; |
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
private function setFileNumberAndCourt() |
|
94
|
|
|
{ |
|
95
|
|
|
$this->data['court_all'] = NULL; |
|
96
|
|
|
if ($this->data['file_number'] && $this->data['court']) { |
|
97
|
|
|
$this->data['court_all'] = $this->data['file_number'] . ', ' . $this->data['court']; |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function setCityDistrict($district) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->data['city_district'] = self::toNull($district); |
|
104
|
|
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function setCityPost($district) |
|
108
|
|
|
{ |
|
109
|
|
|
$this->data['city_post'] = self::toNull($district); |
|
110
|
|
|
return $this; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function setStreet($street) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->data['street'] = self::toNull($street); |
|
116
|
|
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function setHouseNumber($cd, $co) |
|
120
|
|
|
{ |
|
121
|
|
|
$this->data['house_number'] = self::toNull(trim($cd . '/' . $co, '/')); |
|
122
|
|
|
return $this; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function setTIN($s) |
|
126
|
|
|
{ |
|
127
|
|
|
$tin = strval($s); |
|
128
|
|
|
$this->data['tin'] = self::toNull($tin); |
|
129
|
|
|
$this->data['vat_payer'] = (bool) $tin; |
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function setZip($zip) |
|
134
|
|
|
{ |
|
135
|
|
|
$this->data['zip'] = self::toNull($zip); |
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
private static function toNull($v) |
|
140
|
|
|
{ |
|
141
|
|
|
$string = trim((string) $v); |
|
142
|
|
|
if ($string === '') { |
|
143
|
|
|
return NULL; |
|
144
|
|
|
} |
|
145
|
|
|
return $string; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
} |
|
149
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..