1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EveryPolitician\EveryPoliticianPopolo\Objects; |
4
|
|
|
|
5
|
|
|
class Membership extends PopoloObject |
6
|
|
|
{ |
7
|
|
|
protected $properties = [ |
8
|
|
|
'role', |
9
|
|
|
'personId', |
10
|
|
|
'person', |
11
|
|
|
'organizationId', |
12
|
|
|
'organization', |
13
|
|
|
'areaId', |
14
|
|
|
'area', |
15
|
|
|
'legislativePeriodId', |
16
|
|
|
'legislativePeriod', |
17
|
|
|
'onBehalfOfId', |
18
|
|
|
'onBehalfOf', |
19
|
|
|
'postId', |
20
|
|
|
'post', |
21
|
|
|
'startDate', |
22
|
|
|
'endDate', |
23
|
|
|
'current', |
24
|
|
|
]; |
25
|
|
|
|
26
|
3 |
|
public function __toString() |
27
|
|
|
{ |
28
|
3 |
|
return "<Membership: '".$this->personId."' at '".$this->organizationId."'>"; |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
3 |
|
protected function getRole() |
32
|
|
|
{ |
33
|
3 |
|
return $this->arrGet($this->data, 'role'); |
34
|
|
|
} |
35
|
|
|
|
36
|
12 |
|
protected function getPersonId() |
37
|
|
|
{ |
38
|
12 |
|
return $this->arrGet($this->data, 'person_id'); |
39
|
|
|
} |
40
|
|
|
|
41
|
3 |
|
protected function getPerson() |
42
|
|
|
{ |
43
|
3 |
|
return $this->allPopolo->persons->lookupFromKey[$this->personId]; |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
9 |
|
protected function getOrganizationId() |
47
|
|
|
{ |
48
|
9 |
|
return $this->arrGet($this->data, 'organization_id'); |
49
|
|
|
} |
50
|
|
|
|
51
|
3 |
|
protected function getOrganization() |
52
|
|
|
{ |
53
|
3 |
|
return $this->allPopolo->organizations->lookupFromKey[$this->organizationId]; |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
6 |
|
protected function getAreaId() |
57
|
|
|
{ |
58
|
6 |
|
return $this->arrGet($this->data, 'area_id'); |
59
|
|
|
} |
60
|
|
|
|
61
|
3 |
|
protected function getArea() |
62
|
|
|
{ |
63
|
3 |
|
return $this->allPopolo->areas->lookupFromKey[$this->areaId]; |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
6 |
|
protected function getLegislativePeriodId() |
67
|
|
|
{ |
68
|
6 |
|
return $this->arrGet($this->data, 'legislative_period_id'); |
69
|
|
|
} |
70
|
|
|
|
71
|
3 |
|
protected function getLegislativePeriod() |
72
|
|
|
{ |
73
|
3 |
|
return $this->allPopolo->events->lookupFromKey[$this->legislativePeriodId]; |
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
6 |
|
protected function getOnBehalfOfId() |
77
|
|
|
{ |
78
|
6 |
|
return $this->arrGet($this->data, 'on_behalf_of_id'); |
79
|
|
|
} |
80
|
|
|
|
81
|
3 |
|
protected function getOnBehalfOf() |
82
|
|
|
{ |
83
|
3 |
|
return $this->allPopolo->organizations->lookupFromKey[$this->onBehalfOfId]; |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
6 |
|
protected function getPostId() |
87
|
|
|
{ |
88
|
6 |
|
return $this->arrGet($this->data, 'post_id'); |
89
|
|
|
} |
90
|
|
|
|
91
|
3 |
|
protected function getPost() |
92
|
|
|
{ |
93
|
3 |
|
return $this->allPopolo->posts->lookupFromKey[$this->postId]; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
12 |
|
protected function getStartDate() |
97
|
|
|
{ |
98
|
|
|
// TODO: Mark uses his magical ApproxDate.PAST here |
99
|
12 |
|
return $this->getDate('start_date'); |
100
|
|
|
} |
101
|
|
|
|
102
|
6 |
|
protected function getEndDate() |
103
|
|
|
{ |
104
|
|
|
// TODO: Mark uses his magical ApproxDate.FUTURE here |
105
|
6 |
|
return $this->getDate('end_date'); |
106
|
|
|
} |
107
|
|
|
|
108
|
54 |
|
protected function getKeyForHash() |
109
|
|
|
{ |
110
|
54 |
|
$sortedData = $this->data; |
111
|
54 |
|
ksort($sortedData); |
112
|
54 |
|
return json_encode($sortedData); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
protected function getCurrent() |
116
|
|
|
{ |
117
|
|
|
return $this->currentAt(new \DateTime); |
118
|
|
|
} |
119
|
|
|
|
120
|
9 |
|
public function currentAt($when) |
121
|
|
|
{ |
122
|
9 |
|
return ($when >= $this->startDate && $when <= $this->endDate); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
9 |
View Code Duplication |
public function equals($other) |
|
|
|
|
126
|
|
|
{ |
127
|
9 |
|
if (is_object($other) && get_class($other) == get_class($this)) { |
128
|
6 |
|
return $this->data == $other->data; |
129
|
|
|
} |
130
|
3 |
|
throw new \BadMethodCallException; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
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.