예제 #1
0
//List of sections that have already been updated, will be used in case one section fails to update, will revert
$SectionsUpdated = new SectionList();
//Create section list out of courses return by client
foreach ($coursesObject->children() as $course) {
    $Sections->addItem(new Section($course->children()[0]->__toString(), $course->children()[1]->__toString(), $course->children()[2]->__toString(), $course->children()[3]->__toString(), $course->children()[4]->__toString(), $course->children()[5]->__toString(), $course->children()[6]->__toString(), $course->children()[7]->__toString(), $course->children()[8]->__toString(), $course->children()[9]->__toString(), $course->children()[10]->__toString(), $course->children()[11]->__toString()));
}
//Query to lock table during transaction
$lockSectionTable = "LOCK TABLE Section WRITE;";
//Query to unlock table once completed transaction
$unlockSectionTable = "UNLOCK TABLES;";
$revert = false;
//boolean to flag if revert required
$db->execute($lockSectionTable);
//lock DB
for ($i = 0; $i < count($Sections->SectionItems) && $revert == false; $i = $i + 1) {
    $subID = $Sections->itemAt($i)->subjectID;
    $CN = $Sections->itemAt($i)->courseNum;
    $SC = $Sections->itemAt($i)->sectionCode;
    $year = $Sections->itemAt($i)->year;
    $term = $Sections->itemAt($i)->term;
    //Query to retrieve given course, used to check that course is not already full
    $getSection = "SELECT * FROM Section \n\t\t\t\t\t\tWHERE SubjectID LIKE '%{$subID}%' AND \n\t\t\t\t\t\tCourseNumber LIKE '%{$CN}%' AND \n\t\t\t\t\t\tSectionCode = '{$SC}' AND\n\t\t\t\t\t\tYear = {$year} AND\n\t\t\t\t\t\tTerm LIKE '%{$term}%';";
    $row = $db->execute($getSection);
    //get section to be updated
    if ($row->num_rows != 1) {
        $revert = true;
    } else {
        $sec = $row->fetch_object();
        if (!is_null($sec->Capacity)) {
            //check if course has capacity
            $result = $sec->Capacity <= $sec->NumberOfStudents;
예제 #2
0
 function calculateConflictFreeSchedules()
 {
     //break apart courses into lists per course
     $classlist1 = null;
     if (count($this->courses->SectionItems) > 0) {
         $classlist1 = new SectionList();
         $classlist1->addItem($this->courses->itemAt(0));
         //Add first course to list (this will be what will be matched in loop)
         $this->courses->removeItem(0);
         //Delete that item from original list
         for ($i = 0; $i < count($this->courses->SectionItems); $i = $i + 1) {
             //go through rest of list
             //If course is of same type as on in classlist then add it
             if ($this->courses->itemAt($i)->subjectID == $classlist1->itemAt(0)->subjectID && $this->courses->itemAt($i)->courseNum == $classlist1->itemAt(0)->courseNum) {
                 $classlist1->addItem($this->courses->itemAt($i));
                 //add to class list
                 $this->courses->removeItem($i);
                 //remove from original list
                 $i = $i - 1;
                 //set i back 1 to accomidate deleted item
             }
         }
     }
     $classlist2 = null;
     if (count($this->courses->SectionItems) > 0) {
         $classlist2 = new SectionList();
         $classlist2->addItem($this->courses->itemAt(0));
         $this->courses->removeItem(0);
         for ($i = 0; $i < count($this->courses->SectionItems); $i = $i + 1) {
             if ($this->courses->itemAt($i)->subjectID == $classlist2->itemAt(0)->subjectID && $this->courses->itemAt($i)->courseNum == $classlist2->itemAt(0)->courseNum) {
                 $classlist2->addItem($this->courses->itemAt($i));
                 $this->courses->removeItem($i);
                 $i = $i - 1;
             }
         }
     }
     $classlist3 = null;
     if (count($this->courses->SectionItems) > 0) {
         $classlist3 = new SectionList();
         $classlist3->addItem($this->courses->itemAt(0));
         $this->courses->removeItem(0);
         for ($i = 0; $i < count($this->courses->SectionItems); $i = $i + 1) {
             if ($this->courses->itemAt($i)->subjectID == $classlist3->itemAt(0)->subjectID && $this->courses->itemAt($i)->courseNum == $classlist3->itemAt(0)->courseNum) {
                 $classlist3->addItem($this->courses->itemAt($i));
                 $this->courses->removeItem($i);
                 $i = $i - 1;
             }
         }
     }
     $classlist4 = null;
     if (count($this->courses->SectionItems) > 0) {
         $classlist4 = new SectionList();
         $classlist4->addItem($this->courses->itemAt(0));
         $this->courses->removeItem(0);
         for ($i = 0; $i < count($this->courses->SectionItems); $i = $i + 1) {
             if ($this->courses->itemAt($i)->subjectID == $classlist4->itemAt(0)->subjectID && $this->courses->itemAt($i)->courseNum == $classlist4->itemAt(0)->courseNum) {
                 $classlist4->addItem($this->courses->itemAt($i));
                 $this->courses->removeItem($i);
                 $i = $i - 1;
             }
         }
     }
     $classlist5 = null;
     if (count($this->courses->SectionItems) > 0) {
         $classlist5 = new SectionList();
         $classlist5->addItem($this->courses->itemAt(0));
         $this->courses->removeItem(0);
         for ($i = 0; $i < count($this->courses->SectionItems); $i = $i + 1) {
             if ($this->courses->itemAt($i)->subjectID == $classlist5->itemAt(0)->subjectID && $this->courses->itemAt($i)->courseNum == $classlist5->itemAt(0)->courseNum) {
                 $classlist5->addItem($this->courses->itemAt($i));
                 $this->courses->removeItem($i);
                 $i = $i - 1;
             }
         }
     }
     $classlist6 = null;
     if (count($this->courses->SectionItems) > 0) {
         $classlist6 = new SectionList();
         $classlist6->addItem($this->courses->itemAt(0));
         $this->courses->removeItem(0);
         for ($i = 0; $i < count($this->courses); $i = $i + 1) {
             if ($this->courses->itemAt($i)->subjectID == $classlist6->itemAt(0)->subjectID && $this->courses->itemAt($i)->courseNum == $classlist6->itemAt(0)->courseNum) {
                 $classlist6->addItem($this->courses->itemAt($i));
                 $this->courses->removeItem($i);
                 $i = $i - 1;
             }
         }
     }
     //Create arrays to keep track of what times are booked
     $this->monday = array("8:00-8:30" => 0, "8:30-9:00" => 0, "9:00-9:30" => 0, "9:30-10:00" => 0, "10:00-10:30" => 0, "10:30-11:00" => 0, "11:00-11:30" => 0, "11:30-12:00" => 0, "12:00-12:30" => 0, "12:30-13:00" => 0, "13:00-13:30" => 0, "13:30-14:00" => 0, "14:00-14:30" => 0, "14:30-15:00" => 0, "15:00-15:30" => 0, "15:30-16:00" => 0, "16:00-16:30" => 0, "16:30-17:00" => 0, "17:00-17:30" => 0, "17:30-18:00" => 0, "18:00-18:30" => 0, "18:30-19:00" => 0, "19:00-19:30" => 0, "19:30-20:00" => 0, "20:00-20:30" => 0, "20:30-21:00" => 0, "21:00-21:30" => 0, "21:30-22:00" => 0, "22:00-22:30" => 0, "22:30-23:00" => 0, "23:00-23:30" => 0, "23:30-24:00" => 0);
     $this->tuesday = array("8:00-8:30" => 0, "8:30-9:00" => 0, "9:00-9:30" => 0, "9:30-10:00" => 0, "10:00-10:30" => 0, "10:30-11:00" => 0, "11:00-11:30" => 0, "11:30-12:00" => 0, "12:00-12:30" => 0, "12:30-13:00" => 0, "13:00-13:30" => 0, "13:30-14:00" => 0, "14:00-14:30" => 0, "14:30-15:00" => 0, "15:00-15:30" => 0, "15:30-16:00" => 0, "16:00-16:30" => 0, "16:30-17:00" => 0, "17:00-17:30" => 0, "17:30-18:00" => 0, "18:00-18:30" => 0, "18:30-19:00" => 0, "19:00-19:30" => 0, "19:30-20:00" => 0, "20:00-20:30" => 0, "20:30-21:00" => 0, "21:00-21:30" => 0, "21:30-22:00" => 0, "22:00-22:30" => 0, "22:30-23:00" => 0, "23:00-23:30" => 0, "23:30-24:00" => 0);
     $this->wednesday = array("8:00-8:30" => 0, "8:30-9:00" => 0, "9:00-9:30" => 0, "9:30-10:00" => 0, "10:00-10:30" => 0, "10:30-11:00" => 0, "11:00-11:30" => 0, "11:30-12:00" => 0, "12:00-12:30" => 0, "12:30-13:00" => 0, "13:00-13:30" => 0, "13:30-14:00" => 0, "14:00-14:30" => 0, "14:30-15:00" => 0, "15:00-15:30" => 0, "15:30-16:00" => 0, "16:00-16:30" => 0, "16:30-17:00" => 0, "17:00-17:30" => 0, "17:30-18:00" => 0, "18:00-18:30" => 0, "18:30-19:00" => 0, "19:00-19:30" => 0, "19:30-20:00" => 0, "20:00-20:30" => 0, "20:30-21:00" => 0, "21:00-21:30" => 0, "21:30-22:00" => 0, "22:00-22:30" => 0, "22:30-23:00" => 0, "23:00-23:30" => 0, "23:30-24:00" => 0);
     $this->thursday = array("8:00-8:30" => 0, "8:30-9:00" => 0, "9:00-9:30" => 0, "9:30-10:00" => 0, "10:00-10:30" => 0, "10:30-11:00" => 0, "11:00-11:30" => 0, "11:30-12:00" => 0, "12:00-12:30" => 0, "12:30-13:00" => 0, "13:00-13:30" => 0, "13:30-14:00" => 0, "14:00-14:30" => 0, "14:30-15:00" => 0, "15:00-15:30" => 0, "15:30-16:00" => 0, "16:00-16:30" => 0, "16:30-17:00" => 0, "17:00-17:30" => 0, "17:30-18:00" => 0, "18:00-18:30" => 0, "18:30-19:00" => 0, "19:00-19:30" => 0, "19:30-20:00" => 0, "20:00-20:30" => 0, "20:30-21:00" => 0, "21:00-21:30" => 0, "21:30-22:00" => 0, "22:00-22:30" => 0, "22:30-23:00" => 0, "23:00-23:30" => 0, "23:30-24:00" => 0);
     $this->friday = array("8:00-8:30" => 0, "8:30-9:00" => 0, "9:00-9:30" => 0, "9:30-10:00" => 0, "10:00-10:30" => 0, "10:30-11:00" => 0, "11:00-11:30" => 0, "11:30-12:00" => 0, "12:00-12:30" => 0, "12:30-13:00" => 0, "13:00-13:30" => 0, "13:30-14:00" => 0, "14:00-14:30" => 0, "14:30-15:00" => 0, "15:00-15:30" => 0, "15:30-16:00" => 0, "16:00-16:30" => 0, "16:30-17:00" => 0, "17:00-17:30" => 0, "17:30-18:00" => 0, "18:00-18:30" => 0, "18:30-19:00" => 0, "19:00-19:30" => 0, "19:30-20:00" => 0, "20:00-20:30" => 0, "20:30-21:00" => 0, "21:00-21:30" => 0, "21:30-22:00" => 0, "22:00-22:30" => 0, "22:30-23:00" => 0, "23:00-23:30" => 0, "23:30-24:00" => 0);
     //Now create possible schedules
     if (!is_null($classlist1)) {
         $nextclassesarray = array();
         if (!is_null($classlist2)) {
             array_push($nextclassesarray, $classlist2);
         }
         if (!is_null($classlist3)) {
             array_push($nextclassesarray, $classlist3);
         }
         if (!is_null($classlist4)) {
             array_push($nextclassesarray, $classlist4);
         }
         if (!is_null($classlist5)) {
             array_push($nextclassesarray, $classlist5);
         }
         if (!is_null($classlist6)) {
             array_push($nextclassesarray, $classlist6);
         }
         $this->generateSchedules($classlist1, new SectionList(), $nextclassesarray);
     }
     //Now have a list of all possible schedules for given courses
 }