-
Notifications
You must be signed in to change notification settings - Fork 0
/
applicationTable.php
188 lines (148 loc) · 6.88 KB
/
applicationTable.php
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
<?php
require_once 'application.php';
class applicationTable {
const TABLE_NAME = "applications";
const COLUMN_ID = "id";
const COLUMN_SEEKERID = "seekerId";
const COLUMN_EMPID = "empId";
const COLUMN_JOBID = "jobId";
const COLUMN_STATUS = "status";
private $mConnection;
public function __construct($Connection) {
$this->mConnection = $Connection;
}
public function __destruct() {
$this->mConnection = null;
}
public function showAll() {
// construct the SQL SHOWALL statement that will display all applications
$sql = "SELECT * FROM " . applicationTable::TABLE_NAME;
$stmt = $this->mConnection->prepare($sql);
$status = $stmt->execute();
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not display applications: " . $errorInfo[2]);
}
$jobs = array();
$row = $stmt->fetch();
while ($row != null) {
$id = $row[applicationTable::COLUMN_ID];
$seekerId = $row[applicationTable::COLUMN_SEEKERID];
$empId = $row[applicationTable::COLUMN_EMPID];
$jobId = $row[applicationTable::COLUMN_JOBID];
$status = $row[applicationTable::COLUMN_STATUS];
$application = new Application($id, $seekerId, $empId, $jobId, $status);
$applications[$id] = $application;
$row = $stmt->fetch();
}
return $applications;
}
public function addApplicant($application) {
// construct the SQL ADDSEEKER statement with a named placeholder for the seekers details
$sql = "INSERT INTO " . applicationTable::TABLE_NAME . "(" .
applicationTable::COLUMN_SEEKERID . " , " .
applicationTable::COLUMN_EMPID . " , " .
applicationTable::COLUMN_JOBID . " , " .
applicationTable::COLUMN_STATUS . " ) " .
"VALUES (:seekerId, :empId, :jobId, :status)";
$params = array(
'seekerId' => $application->getSeekerId(),
'empId' => $application->getEmpId(),
'jobId' => $application->getJobId(),
'status' => $application->getStatus()
);
$stmt = $this->mConnection->prepare($sql);
$status = $stmt->execute($params);
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not add applicant: " . $errorInfo[2]);
}
$id = $this->mConnection->lastInsertId(applicationTable::TABLE_NAME);
return $id;
}
public function deleteApplicant($applicantId) {
// construct the SQL DELETE statement with a named placeholder for the applicant id
$sql = "DELETE FROM " . applicationTable::TABLE_NAME .
" WHERE " . applicationTable::COLUMN_ID . " = :id";
// the value for the id named placeholder in the SQL DELETE statement
$params = array('id' => $applicantId);
// prepare the statement for execution and execute it
$stmt = $this->mConnection->prepare($sql);
$status = $stmt->execute($params);
// if an error occurred while executing the query then throw an exception
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not delete applicant: " . $errorInfo[2]);
}
// return the number of rows deleted by the SQL DELETE statement
return $stmt->rowCount();
}
public function findById($id) {
// construct the SQL SELECT statement with a named placeholder for the application id
$sql = "SELECT * FROM " . applicationTable::TABLE_NAME .
" WHERE " . applicationTable::COLUMN_ID . " = :id";
// the value for the id named placeholder in the SQL DELETE statement
$params = array('id' => $id);
// prepare the statement for execution and execute it
$stmt = $this->mConnection->prepare($sql);
$status = $stmt->execute($params);
// if an error occurred while executing the query then throw an exception
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not retrieve book: " . $errorInfo[2]);
}
// if exactly one row was returned by the query then retrieve the seekers details
// and store them in a Seeker object
$application = null;
if ($stmt->rowCount() == 1) {
$row = $stmt->fetch();
$id = $row[applicationTable::COLUMN_ID];
$seekerId = $row[applicationTable::COLUMN_SEEKERID];
$empId = $row[applicationTable::COLUMN_EMPID];
$jobId = $row[applicationTable::COLUMN_JOBID];
$status = $row[applicationTable::COLUMN_STATUS];
$application = new Application($id, $seekerId, $empId, $jobId, $status);
}
// return the Application object if a Application with the specified id was found otherwise return null
return $application;
}
/*
public function update($seeker) {
// construct the SQL UPDATE statement with named placeholders for the member details
$sql = "UPDATE " . seekerTable::TABLE_NAME . " SET " .
seekerTable::COLUMN_FNAME . " = :fName, " .
seekerTable::COLUMN_LNAME . " = :lName, " .
seekerTable::COLUMN_DOB . " = :dob, " .
seekerTable::COLUMN_EMAIL . " = :email, " .
seekerTable::COLUMN_PASSWORD . " = :password, " .
seekerTable::COLUMN_LOCATION . " = :location, " .
seekerTable::COLUMN_EXPERIENCE . " = :experience, " .
seekerTable::COLUMN_EDUCATION . " = :education, " .
seekerTable::COLUMN_PICTURE . " = :picture " .
"WHERE " . seekerTable::COLUMN_ID . " = :id";
// the values for the named placeholders in the SQL UPDATE statement
$params = array(
'fName' => $seeker->getFName(),
'lName' => $seeker->getLName(),
'dob' => $seeker->getDob(),
'email' => $seeker->getEmail(),
'password' => $seeker->getPassword(),
'location' => $seeker->getLocation(),
'experience' => $seeker->getExperience(),
'education' => $seeker->getEducation(),
'picture' => $seeker->getPicture()
);
// prepare the statement for execution and execute it
$stmt = $this->mConnection->prepare($sql);
$status = $stmt->execute($params);
// if an error occurred while executing the query then throw an exception
if ($status != true) {
$errorInfo = $stmt->errorInfo();
throw new Exception("Could not update seeker: " . $errorInfo[2]);
}
// return the number of rows updated by the SQL UPDATE statement
return $stmt->rowCount();
}
*/
}
?>