1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EveryPolitician\EveryPoliticianPopolo\Objects; |
4
|
|
|
|
5
|
|
|
use \DateTime; |
6
|
|
|
|
7
|
|
|
class Membership extends PopoloObject |
8
|
|
|
{ |
9
|
|
|
protected $properties = [ |
10
|
|
|
'role', |
11
|
|
|
'personId', |
12
|
|
|
'person', |
13
|
|
|
'organizationId', |
14
|
|
|
'organization', |
15
|
|
|
'areaId', |
16
|
|
|
'area', |
17
|
|
|
'legislativePeriodId', |
18
|
|
|
'legislativePeriod', |
19
|
|
|
'onBehalfOfId', |
20
|
|
|
'onBehalfOf', |
21
|
|
|
'postId', |
22
|
|
|
'post', |
23
|
|
|
'startDate', |
24
|
|
|
'endDate', |
25
|
|
|
'current', |
26
|
|
|
]; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* String representation of {@link Membership} |
30
|
|
|
* |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
3 |
|
public function __toString() |
34
|
|
|
{ |
35
|
3 |
|
return "<Membership: '".$this->personId."' at '".$this->organizationId."'>"; |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
3 |
|
protected function getRole() |
39
|
|
|
{ |
40
|
3 |
|
return $this->arrGet($this->data, 'role'); |
41
|
|
|
} |
42
|
|
|
|
43
|
12 |
|
protected function getPersonId() |
44
|
|
|
{ |
45
|
12 |
|
return $this->arrGet($this->data, 'person_id'); |
46
|
|
|
} |
47
|
|
|
|
48
|
3 |
|
protected function getPerson() |
49
|
|
|
{ |
50
|
3 |
|
return $this->allPopolo->persons->lookupFromKey[$this->personId]; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
9 |
|
protected function getOrganizationId() |
54
|
|
|
{ |
55
|
9 |
|
return $this->arrGet($this->data, 'organization_id'); |
56
|
|
|
} |
57
|
|
|
|
58
|
3 |
|
protected function getOrganization() |
59
|
|
|
{ |
60
|
3 |
|
return $this->allPopolo->organizations->lookupFromKey[$this->organizationId]; |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
6 |
|
protected function getAreaId() |
64
|
|
|
{ |
65
|
6 |
|
return $this->arrGet($this->data, 'area_id'); |
66
|
|
|
} |
67
|
|
|
|
68
|
3 |
|
protected function getArea() |
69
|
|
|
{ |
70
|
3 |
|
return $this->allPopolo->areas->lookupFromKey[$this->areaId]; |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
6 |
|
protected function getLegislativePeriodId() |
74
|
|
|
{ |
75
|
6 |
|
return $this->arrGet($this->data, 'legislative_period_id'); |
76
|
|
|
} |
77
|
|
|
|
78
|
3 |
|
protected function getLegislativePeriod() |
79
|
|
|
{ |
80
|
3 |
|
return $this->allPopolo->events->lookupFromKey[$this->legislativePeriodId]; |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
6 |
|
protected function getOnBehalfOfId() |
84
|
|
|
{ |
85
|
6 |
|
return $this->arrGet($this->data, 'on_behalf_of_id'); |
86
|
|
|
} |
87
|
|
|
|
88
|
3 |
|
protected function getOnBehalfOf() |
89
|
|
|
{ |
90
|
3 |
|
return $this->allPopolo->organizations->lookupFromKey[$this->onBehalfOfId]; |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
6 |
|
protected function getPostId() |
94
|
|
|
{ |
95
|
6 |
|
return $this->arrGet($this->data, 'post_id'); |
96
|
|
|
} |
97
|
|
|
|
98
|
3 |
|
protected function getPost() |
99
|
|
|
{ |
100
|
3 |
|
return $this->allPopolo->posts->lookupFromKey[$this->postId]; |
|
|
|
|
101
|
|
|
} |
102
|
|
|
|
103
|
12 |
|
protected function getStartDate() |
104
|
|
|
{ |
105
|
|
|
// TODO: Mark uses his magical ApproxDate.PAST here |
106
|
12 |
|
return $this->getDate('start_date'); |
107
|
|
|
} |
108
|
|
|
|
109
|
6 |
|
protected function getEndDate() |
110
|
|
|
{ |
111
|
|
|
// TODO: Mark uses his magical ApproxDate.FUTURE here |
112
|
6 |
|
return $this->getDate('end_date'); |
113
|
|
|
} |
114
|
|
|
|
115
|
54 |
|
protected function getKeyForHash() |
116
|
|
|
{ |
117
|
54 |
|
$sortedData = $this->data; |
118
|
54 |
|
ksort($sortedData); |
119
|
54 |
|
return json_encode($sortedData); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
protected function getCurrent() |
123
|
|
|
{ |
124
|
|
|
return $this->currentAt(new DateTime); |
125
|
|
|
} |
126
|
|
|
|
127
|
9 |
|
public function currentAt($when) |
128
|
|
|
{ |
129
|
9 |
|
return ($when >= $this->startDate && $when <= $this->endDate); |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
9 |
View Code Duplication |
public function equals($other) |
|
|
|
|
133
|
|
|
{ |
134
|
9 |
|
if (is_object($other) && get_class($other) == get_class($this)) { |
135
|
6 |
|
return $this->data == $other->data; |
136
|
|
|
} |
137
|
|
|
// TODO: Throw a custom exception here |
138
|
3 |
|
throw new \BadMethodCallException; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.