-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.php
More file actions
134 lines (115 loc) · 3.92 KB
/
widget.php
File metadata and controls
134 lines (115 loc) · 3.92 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
<?php
define('SCHEDULE_NAME_LAB_ASSISTANT', 'Lab Assistant');
define('SCHEDULE_NAME_TEACHING_ASSISTANT', 'Teaching Assistant');
include("modules/simple_html_dom.php");
$html = file_get_html("http://work.cias.rit.edu/ist/widgets/unifiedschedule");
/*
* <table><tr> in the widgetContent
* The result should be a <td> which contains tables
* Each table is a schedule
*/
$widgetCells = $html->find("table#widgetContent tr td");
foreach ($widgetCells as $widgetCell) {
/* Retrieve Lab Assistant Schedule */
/* The title should be in the <th> */
$title = $widgetCell->find('th', 0)->plaintext;
/* Test to see if this is the lab assistant table */
if (stripos($title, SCHEDULE_NAME_LAB_ASSISTANT, 0) !== false) {
/*
* A span that contains the lab assistant's name should look like this
* <di class='list-group-item' style='background-color: #B39EB5'>
* <strong>
* <span id='replaceme' />Kyle Bansavage
* </strong>
*/
$labAssistants = $widgetCell->find('div.list-group-item');
foreach ($labAssistants as $labAssistant) {
$labAssistantName = $labAssistant->plaintext;
if(stripos($labAssistantName, 'am -') OR stripos($labAssistantName, 'pm -')){
//do nothing - don't display the time
}
else if(stripos($labAssistantName, 'Covered by:')){
$labAssistantName = trim($labAssistantName);
$coveredPieces = explode(" ", $labAssistantName);
$coveredPieces = array_filter($coveredPieces, 'trim');
$coveredPieces = array_values($coveredPieces);
//the key that 'by:' is found in
$byKey = array_search('by:', $coveredPieces);
for($i= 0; $i <= $byKey; $i++){
array_shift($coveredPieces);
}
$labAssistantNameClean = implode(" ", $coveredPieces);
$labAssistantResults[] = $labAssistantNameClean;
}
else if(stripos($labAssistantName, 'NOT COVERED')){
//do nothing -- shift not covered
}
else{
$labAssistantResults[] = $labAssistantName;
}
}
}
/* Retrieve Teaching Assistant Schedule */
/* The title should be in the <th> */
$title = $widgetCell->find('th', 0)->plaintext;
/* Test to see if this is the teaching assistant table */
if (stripos($title, SCHEDULE_NAME_TEACHING_ASSISTANT, 0) !== false) {
/* TA Names */
$TAs = $widgetCell->find('div.list-group-item');
foreach ($TAs as $TA) {
$TAName = $TA->plaintext;
if(stripos($TAName, 'am -') OR stripos($TAName, 'pm -')){
//do nothing - don't display the time
}
else if(stripos($TAName, 'Covered by:')){
$TAName = trim($TAName);
$coveredPieces = explode(" ", $TAName);
$coveredPieces = array_filter($coveredPieces, 'trim');
$coveredPieces = array_values($coveredPieces);
//the key that 'by:' is found in
$byKey = array_search('by:', $coveredPieces);
for($i= 0; $i <= $byKey; $i++){
array_shift($coveredPieces);
}
$TANameClean = implode(" ", $coveredPieces);
$teachingAssistantResults[] = $TANameClean;
}
else if(stripos($TAName, 'NOT COVERED')){
//do nothing -- shift not covered
}
else{
$teachingAssistantResults[] = $TAName;
}
}
}
}
function createLabStaff($labStaffResults, $staffType){
$labStaffTableStr = '';
if(!empty($labStaffResults)){
foreach($labStaffResults as $v){
$labStaffTableStr .= '<tr><td>'.$v.'</td></tr>';
}
}
else{
if($staffType === 'LA'){
$labStaffTableStr .= '<tr><td>No Labbie Available</td></tr>';
}
else{
$labStaffTableStr .= '<tr><td>No TA Available</td></tr>';
}
}
return $labStaffTableStr;
}//end of function createLabStaff
echo '<table id="labAssistantTable">
<tr>
<th>Lab Assistants</th>
</tr>';
echo createLabStaff($labAssistantResults, 'LA');
echo '</table>
<table id="teachingAssistantTable">
<tr>
<th>Teaching Assistants</th>
</tr>';
echo createLabStaff($teachingAssistantResults, 'TA');
echo '</table>';
?>