Example #1
0
 public function fetchCompatible()
 {
     $conn = Propel::getConnection();
     $rawSectionData = CourseSectionPeer::getSectionsForTerm($this->_term, $conn);
     $this->_compatibleSections = array();
     // first we need to group the raw data by courses
     $count = count($rawSectionData);
     $groupedSectionArr = array();
     for ($i = 0; $i < $count; $i++) {
         $sectionObj = $rawSectionData[$i];
         if ($i == 0 || $groupedSectionArr["course"] != $sectionObj->getCourseId()) {
             if ($i != 0) {
                 // now that we know the number of total LEC, TUT and PRA, we can
                 // begin to eliminate the incompatible ones
                 $groupedSectionArr = getCompatibleSlotsForCourse($groupedSectionArr);
                 if (isset($groupedSectionArr)) {
                     $this->_compatibleSections[] = $groupedSectionArr;
                 }
             }
             // get the array ready for the next course
             $groupedSectionArr = array();
             $groupedSectionArr["course"] = $sectionObj->getCourseId();
         } elseif ($i == $count - 1) {
             // store the last row
             $sectionType = $sectionObj->getSectionType();
             if (!isset($groupedSectionArr[$sectionType])) {
                 $groupedSectionArr[$sectionType] = array();
             }
             $sectionNum = $sectionObj->getSectionNum();
             $meetTime = $sectionObj->getMeetTime();
             if (isset($groupedSectionArr[$sectionType][$sectionNum])) {
                 $groupedSectionArr[$sectionType][$sectionNum][] = $meetTime;
             } else {
                 $groupedSectionArr[$sectionType][$sectionNum] = array($meetTime);
             }
             // begin eliminating the incompatible ones
             $groupedSectionArr = getCompatibleSlotsForCourse($groupedSectionArr);
             if (isset($groupedSectionArr)) {
                 $this->_compatibleSections[] = $groupedSectionArr;
             }
         }
         $sectionType = $sectionObj->getSectionType();
         if (!isset($groupedSectionArr[$sectionType])) {
             $groupedSectionArr[$sectionType] = array();
         }
         $sectionNum = $sectionObj->getSectionNum();
         $meetTime = $sectionObj->getMeetTime();
         if (isset($groupedSectionArr[$sectionType][$sectionNum])) {
             $groupedSectionArr[$sectionType][$sectionNum][] = $meetTime;
         } else {
             $groupedSectionArr[$sectionType][$sectionNum] = array($meetTime);
         }
     }
     return $this->_compatibleSections;
 }