-
Notifications
You must be signed in to change notification settings - Fork 1
/
OLDextraclass.php
123 lines (105 loc) · 3.34 KB
/
OLDextraclass.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
<?php
include('includes/dashboard.php');
if(!isset($_POST['submit'])){
die("Fill up the form for extra class first");
}
else{
$extraClass_course = $_POST['course_num'];
$extraClass_slot = intval(explode('-',$_POST['timing'])[0]);
$extraClass_date = $_POST['date'];
date_default_timezone_set('Asia/Calcutta');
$extraClass_day = date('D',strtotime($extraClass_date));
echo "Instructor wants to hold an extra class of ". $extraClass_course. " on ". $extraClass_date ." at ". $extraClass_slot."<br>";
//$extraClass_day = 'Mon';
//$extraClass_slot = 8;
// Configuration
$dbhost = 'localhost';
$dbname = 'acadScheduler';
// Connect to test database
$m = new Mongo("mongodb://$dbhost");
$db = $m->$dbname;
// Get the users collection
$courses = $db->Courses;
$users = $db->Users;
$course_students = $courses->findOne( array('course_name'=>$extraClass_course) )['students'];
$all_courses = array();
if (!empty($course_students)){
//echo 'hi';
//generate list of all courses that could possibly clash
foreach ($course_students as $student) {
$student_courses = $users->findOne( array('username'=>$student) )['courses'];
//echo gettype($student_courses);
if (!empty($student_courses)) {
$all_courses = array_merge($all_courses, $student_courses);
$all_courses = array_unique($all_courses);
}
}
print_r($all_courses);
//check clashes
$clash = 0;
foreach ($all_courses as $course) {
$course_schedule = $courses->findOne( array('course_name'=>$course) )['schedule'];
if (!empty($course_schedule)){
foreach ($course_schedule as $day => $slot) {
if($day == $extraClass_day && $slot == $extraClass_slot){
echo "Clash with ".$course."<br>";
$clash = 1;
break;
}
}
}
}
if($clash == 0){
$courses->update( array('course_name'=>$extraClass_course), array(
'$push'=> array("extra_class"=> array($extraClass_date=>intval($extraClass_slot)))
));
}
}
}
/*if(isset($_POST) and $_POST['submitForm'] == "ExtraClass" ){
$course = $_POST['course_num'];
$timing = $_POST['timing'];
$date = $_POST['date'];
// Day from date should be calculated*/
//
/*$day = "Th";
// code to check whether free or not.
echo "instructor want to held an extra class of ". $course. " on ". $date[0]. "/". $date[1]. "/". $date[2]. " at ". $timing;
echo "students registered in the course are \n";
$con = new MongoClient();
if($con){
$db = $con->acadSchedular;
$col_courses = $db->courses;
$col_schedule = $db->schedule;
$result = $col_courses->find();
$cursor = $col_courses->find(array("course_name" => "eco101"), array("_id" => 0, "students" => 1));
echo "count of cursor is ";
echo $cursor->count();
if($document = $cursor->getNext()){
//echo iterator_to_array($document);
$student_list = $document["students"];
$n = count($student_list);
for($i=0; $i < $n; $i++){
if($cursor = $col_schedule->find(array("name" => $student_list[$i]), array("_id" => 0, $day => 1))){
// this will give the schedule of i'th student on that day.
$doc = $cursor->getNext();
$time_list = $doc[$day];
$m = count($time_list);
for($j=0;$j<$m;$j++){
if($time_list[$j][0] == $timing ){
echo $student_list[$i];
echo " has a clash\n";
}
}
}
else{
echo "query failed";
}
}
} else{
echo "cursor was null";
}
} else{
echo "error in connection with database";
}*/
?>