This repository was archived by the owner on Dec 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMember.php
More file actions
249 lines (218 loc) · 8.19 KB
/
Copy pathMember.php
File metadata and controls
249 lines (218 loc) · 8.19 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
<?php
require_once "Database.php";
require_once "MembershipType.php";
require_once "Institution.php";
class Member {
private $memberId;
private $camdramId;
private $crsid;
private $lastName;
private $otherNames;
private $primaryEmail;
private $secondaryEmail;
private $institutionId;
private $graduationYear;
private $membershipId;
private $expiry;
private function __construct($memberId, $camdramId, $crsid, $lastName, $otherNames,
$primaryEmail, $secondaryEmail, $institutionId,
$graduationYear, $membershipId, $expiry) {
$this->memberId = $memberId;
$this->setCamdramId($camdramId);
$this->setCrsid($crsid);
$this->setLastName($lastName);
$this->setOtherNames($otherNames);
$this->setPrimaryEmail($primaryEmail);
$this->setSecondaryEmail($secondaryEmail);
$this->setInstitutionId($institutionId);
$this->setGraduationYear($graduationYear);
$this->setMembershipId($membershipId);
$this->setExpiry($expiry);
}
public static function searchByLastname($query) {
$conn = Database::getInstance()->getConn();
$stmt = $conn->prepare('SELECT * FROM members
WHERE last_name LIKE ?');
$query = "%" . $query . "%";
$stmt->bind_param('s', $query);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public static function memberFromCamdramId($id) {
$conn = Database::getInstance()->getConn();
$stmt = $conn->prepare('SELECT * FROM ((members
INNER JOIN institutions
ON members.institution_id =
institutions.institution_id)
INNER JOIN membership
ON members.membership_id =
membership.membership_id)
WHERE camdram_id = ?');
$stmt->bind_param('s', $id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 0) {
throw new Exception("Member does not exist.");
}
$row = $result->fetch_assoc();
$member = new Member($row['member_id'], $row['camdram_id'], $row['crsid'],
$row['last_name'], $row['other_names'],
$row['primary_email'], $row['secondary_email'],
$row['institution_id'], $row['graduation_year'],
$row['membership_id'], $row['expiry']);
return $member;
}
public static function memberFromPrimaryEmail($email) {
$conn = Database::getInstance()->getConn();
$stmt = $conn->prepare('SELECT * FROM ((members
INNER JOIN institutions
ON members.institution_id =
institutions.institution_id)
INNER JOIN membership
ON members.membership_id =
membership.membership_id)
WHERE primary_email = ?');
$stmt->bind_param('s', $email);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 0) {
throw new Exception("Member does not exist.");
}
$row = $result->fetch_assoc();
$member = new Member($row['member_id'], $row['camdram_id'], $row['crsid'],
$row['last_name'], $row['other_names'],
$row['primary_email'], $row['secondary_email'],
$row['institution_id'], $row['graduation_year'],
$row['membership_id'], $row['expiry']);
return $member;
}
public static function memberFromCrsid($crsid) {
$conn = Database::getInstance()->getConn();
$stmt = $conn->prepare('SELECT * FROM ((members
INNER JOIN institutions
ON members.institution_id =
institutions.institution_id)
INNER JOIN membership
ON members.membership_id =
membership.membership_id)
WHERE crsid = ?');
$stmt->bind_param('s', $crsid);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows == 0) {
throw new Exception("Member does not exist.");
}
$row = $result->fetch_assoc();
$member = new Member($row['member_id'], $row['camdram_id'], $row['crsid'],
$row['last_name'], $row['other_names'],
$row['primary_email'], $row['secondary_email'],
$row['institution_id'], $row['graduation_year'],
$row['membership_id'], $row['expiry']);
return $member;
}
public function flushToDatabase() {
$conn = Database::getInstance()->getConn();
$stmt = $conn->prepare('UPDATE members SET camdram_id = ?,
crsid = ?,
last_name = ?,
other_names = ?,
primary_email = ?,
secondary_email = ?,
institution_id = ?,
graduation_year = ?,
membership_id = ?
expiry = ?
WHERE member_id = ?');
$stmt->bind_param('ssssssssss', $this->camdramId, $this->crsid,
$this->lastName, $this->otherNames,
$this->primaryEmail, $this->secondaryEmail,
$this->institutionId, $this->graduationYear,
$this->membershipType, $this->expiry);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function getMemberId() {
return $this->memberId;
}
public function getCamdramId() {
return $this->camdramId;
}
public function getCrsid() {
return $this->crsid;
}
public function getLastName() {
return $this->lastName;
}
public function getOtherNames() {
return $this->otherNames;
}
public function getPrimaryEmail() {
return $this->primaryEmail;
}
public function getSecondaryEmail() {
return $this->secondaryEmail;
}
public function getInstitutionId() {
return $this->institutionId;
}
public function getGraduationYear() {
return $this->graduationYear;
}
public function getMembershipId() {
return $this->membershipId;
}
public function getExpiry() {
if ($this->expiry === "01-01-1970") {
return "LIFE";
} else {
return $this->expiry;
}
}
public function setMemberId($memberId) {
// member_id is the primary key
throw new Exception('You cannot change a membership ID.');
}
public function setCamdramId($camdramId) {
$this->camdramId = $camdramId;
}
public function setCrsid($crsid) {
$this->crsid = $crsid;
}
public function setLastName($lastName) {
$this->lastName = $lastName;
}
public function setOtherNames($otherNames) {
$this->otherNames = $otherNames;
}
public function setPrimaryEmail($primaryEmail) {
$this->primaryEmail = $primaryEmail;
}
public function setSecondaryEmail($secondaryEmail) {
$this->secondaryEmail = $secondaryEmail;
}
public function setInstitutionId($institutionId) {
// Check ID is valid
Institution::fromId($institutionId);
$this->institutionId = $institutionId;
}
public function setGraduationYear($graduationYear) {
// Alumni can adjust their graduation dates so don't validate beyond checking it's numeric
if (is_numeric($graduationYear)) {
$this->graduationYear = $graduationYear;
} else {
throw new Exception('Graduation date was not recognised as a valid year.');
}
}
public function setMembershipId($membershipId) {
// Check ID is valid
MembershipType::fromId($membershipId);
$this->membershipId = $membershipId;
}
public function setExpiry($expiry) {
$time = strtotime($expiry);
$format = date('d-m-Y', $time);
$this->expiry = $format;
}
}