forked from AppStateESS/InternshipInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFacultyFactory.php
85 lines (62 loc) · 2.54 KB
/
FacultyFactory.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
<?php
namespace Intern;
use \Intern\DataProvider\Student\StudentDataProviderFactory;
use \phpws2\Database;
class FacultyFactory {
public static function getFacultyById($id)
{
$db = Database::newDB();
$pdo = $db->getPDO();
$sql = "SELECT intern_faculty.* FROM intern_faculty WHERE intern_faculty.id = :id";
$sth = $pdo->prepare($sql);
$sth->execute(array('id' => $id));
$result = $sth->fetch(\PDO::FETCH_ASSOC);
// If no results from database, try to lookup the faculty member in Banner
if(!$result){
$provider = StudentDataProviderFactory::getProvider();
$result = $provider->getFacultyMember($id);
$result->id = $result->banner_id;
$result->username = $result->user_name;
}
return $result;
}
public static function getFacultyObjectById($id)
{
if(!isset($id)) {
throw new \InvalidArgumentException('Missing faculty id.');
}
$sql = "SELECT intern_faculty.* FROM intern_faculty WHERE intern_faculty.id = {$id}";
$row = \PHPWS_DB::getRow($sql);
if (\PHPWS_Error::logIfError($row)) {
throw new Exception($row);
}
$faculty = new FacultyDB();
$faculty->setId($row['id']);
$faculty->setUsername($row['username']);
$faculty->setFirstName($row['first_name']);
$faculty->setLastName($row['last_name']);
$faculty->setPhone($row['phone']);
$faculty->setFax($row['fax']);
$faculty->setStreetAddress1($row['street_address1']);
$faculty->setStreetAddress2($row['street_address2']);
$faculty->setCity($row['city']);
$faculty->setState($row['state']);
$faculty->setZip($row['zip']);
return $faculty;
}
/**
* Returns an array of Faculty objects for the given department.
* @param Department $department
* @return Array List of faculty for requested department.
*/
public static function getFacultyByDepartmentAssoc(Department $department)
{
$db = Database::newDB();
$pdo = $db->getPDO();
$sql = "SELECT intern_faculty.* FROM intern_faculty JOIN intern_faculty_department ON intern_faculty.id = intern_faculty_department.faculty_id WHERE intern_faculty_department.department_id = :departmentId ORDER BY last_name ASC";
$sth = $pdo->prepare($sql);
$sth->execute(array('departmentId' => $department->getId()));
$result = $sth->fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
}