1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace mySociety\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
|
|
|
]; |
24
|
|
|
|
25
|
3 |
|
public function __toString() |
26
|
|
|
{ |
27
|
3 |
|
return "<Membership: '".$this->personId."' at '".$this->organizationId."'>"; |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
3 |
|
protected function getRole() |
31
|
|
|
{ |
32
|
3 |
|
return $this->arrGet($this->data, 'role'); |
33
|
|
|
} |
34
|
|
|
|
35
|
6 |
|
protected function getPersonId() |
36
|
|
|
{ |
37
|
6 |
|
return $this->arrGet($this->data, 'person_id'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function getPerson() |
41
|
|
|
{ |
42
|
|
|
return $this->allPopolo->persons->lookupFromKey[$this->personId]; |
|
|
|
|
43
|
|
|
} |
44
|
|
|
|
45
|
6 |
|
protected function getOrganizationId() |
46
|
|
|
{ |
47
|
6 |
|
return $this->arrGet($this->data, 'organization_id'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function getOrganization() |
51
|
|
|
{ |
52
|
|
|
return $this->allPopolo->organizations->lookupFromKey[$this->organizationId]; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
3 |
|
protected function getAreaId() |
56
|
|
|
{ |
57
|
3 |
|
return $this->arrGet($this->data, 'area_id'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function getArea() |
61
|
|
|
{ |
62
|
|
|
return $this->allPopolo->areas->lookupFromKey[$this->areaId]; |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
3 |
|
protected function getLegislativePeriodId() |
66
|
|
|
{ |
67
|
3 |
|
return $this->arrGet($this->data, 'legislative_period_id'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
protected function getLegislativePeriod() |
71
|
|
|
{ |
72
|
|
|
return $this->allPopolo->events->lookupFromKey[$this->eventId]; |
|
|
|
|
73
|
|
|
} |
74
|
|
|
|
75
|
3 |
|
protected function getOnBehalfOfId() |
76
|
|
|
{ |
77
|
3 |
|
return $this->arrGet($this->data, 'on_behalf_of_id'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function getOnBehalfOf() |
81
|
|
|
{ |
82
|
|
|
return $this->allPopolo->organizations->lookupFromKey[$this->onBehalfOfId]; |
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
3 |
|
protected function getPostId() |
86
|
|
|
{ |
87
|
3 |
|
return $this->arrGet($this->data, 'post_id'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function getPost() |
91
|
|
|
{ |
92
|
|
|
return $this->allPopolo->posts->lookupFromKey[$this->postId]; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
3 |
|
protected function getStartDate() |
96
|
|
|
{ |
97
|
|
|
// TODO: Mark uses his magical ApproxDate.PAST here |
98
|
3 |
|
return $this->getDate('start_date'); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
protected function getEndDate() |
102
|
|
|
{ |
103
|
|
|
// TODO: Mark uses his magical ApproxDate.FUTURE here |
104
|
|
|
return $this->getDate('end_date'); |
105
|
|
|
} |
106
|
|
|
|
107
|
21 |
|
protected function getKeyForHash() |
108
|
|
|
{ |
109
|
21 |
|
$sortedData = $this->data; |
110
|
21 |
|
ksort($sortedData); |
111
|
21 |
|
return json_encode($sortedData); |
112
|
|
|
} |
113
|
|
|
|
114
|
3 |
View Code Duplication |
public function equals($other) |
|
|
|
|
115
|
|
|
{ |
116
|
3 |
|
if (get_class($other) == get_class($this)) { |
117
|
3 |
|
return $this->data == $other->data; |
118
|
|
|
} |
119
|
|
|
throw new \BadMethodCallException; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
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.