예제 #1
0
 public function setCurriculumCourseSlot($validCourseIDs = NULL, $name = NULL, $minimumGrade = NULL, $recommendedQuarter = NULL, $recommendedYear = NULL, $notes = NULL, $index = NULL, $prereqIDs = NULL, $coreqIDs = NULL)
 {
     //get arguments
     if ($validCourseIDs == NULL) {
         $validCourseIDs = $this->input->post('validCourseIDs');
     }
     if ($name == NULL) {
         $name = $this->input->post('name');
     }
     if ($minimumGrade == NULL) {
         $minimumGrade = $this->input->post('minimumGrade');
     }
     if ($recommendedQuarter == NULL) {
         $recommendedQuarter = $this->input->post('recommendedQuarter');
     }
     if ($recommendedYear == NULL) {
         $recommendedYear = $this->input->post('recommendedYear');
     }
     if ($notes == NULL) {
         $notes = $this->input->post('notes');
     }
     if ($index == NULL) {
         $index = $this->input->post('index');
     }
     if ($prereqIDs == NULL) {
         $prereqIDs = $this->input->post('prereqIDs');
     }
     if ($coreqIDs == NULL) {
         $coreqIDs = $this->input->post('coreqIDs');
     }
     if (!isset($notes)) {
         $notes = " ";
     }
     //add logic to grab arguments
     $courseSlot = new Curriculum_course_slot_model();
     $courseSlot->fromSerializedString($_SESSION['courseSlot']);
     $courseSlot->setMinimumGrade($minimumGrade);
     $courseSlot->setName($name);
     $courseSlot->setRecommendedQuarter($recommendedQuarter);
     $courseSlot->setRecommendedYear($recommendedYear);
     $courseSlot->setNotes($notes);
     $curriculum = new Curriculum_model();
     $curriculum->fromSerializedString($_SESSION['curriculum']);
     $courseSlots = $curriculum->getCurriculumCourseSlots();
     $prerequisites = array();
     $corequisites = array();
     //Handle prereq and coreq duplicates and set to coreq
     if (isset($prereqIDs) and isset($coreqIDs)) {
         foreach ($prereqIDs as $pre) {
             if (($key = array_search($pre, $coreqIDs)) !== false) {
                 unset($prereqIDs[$key]);
             }
         }
     }
     $largestIndex = 1;
     //Handle non-unique curriculum indexes
     foreach ($courseSlots as $slot) {
         $currentIndex = $slot->getCurriculumIndex();
         if ($currentIndex > $largestIndex) {
             $largestIndex = $currentIndex;
         }
         //grab prereq course slots
         if (isset($prereqIDs)) {
             foreach ($prereqIDs as $p) {
                 if ($currentIndex == $p) {
                     array_push($prerequisites, $slot);
                 }
             }
         }
         //grab coreq course slots
         if (isset($coreqIDs)) {
             foreach ($coreqIDs as $c) {
                 if ($currentIndex == $c) {
                     array_push($corequisites, $slot);
                 }
             }
         }
     }
     if ($largestIndex > 1) {
         $_SESSION['maxCurriculumIndex'] = $largestIndex;
     }
     //remove previous valid courses
     $previousValidCourseIDs = $courseSlot->getValidCourseIDs();
     if (isset($previousValidCourseIDs)) {
         foreach ($previousValidCourseIDs as $prevID) {
             $courseSlot->removeValidCourseID($prevID);
         }
     }
     //populate course slot with the new valid course ids
     if (isset($validCourseIDs)) {
         foreach ($validCourseIDs as $validCourse) {
             $courseSlot->addValidCourseID($validCourse);
         }
     }
     //add course slot to the curriculum based on its creation method
     if (strcmp($_SESSION['curriculumCourseSlotMethod'], "edit") == 0) {
         $curriculum->updateCurriculumCourseSlot($courseSlot);
     } else {
         $courseSlot->setCurriculumIndex(++$_SESSION['maxCurriculumIndex']);
         $curriculum->addCurriculumCourseSlot($courseSlot);
     }
     //add pro/coreqs to session
     //be sure to delete old reqs that were altered this session
     if (!empty($_SESSION['reqs'])) {
         $tempReqs = $_SESSION['reqs'];
         $currIndex = $courseSlot->getCurriculumIndex();
         foreach ($tempReqs as $reqs) {
             $reqsSlot = new Curriculum_course_slot_model();
             $reqsSlot->fromSerializedString($reqs['slot']);
             if ($reqsSlot->getCurriculumIndex() == $currIndex) {
                 if (($key = array_search($reqs, $tempReqs)) !== false) {
                     unset($tempReqs[$key]);
                 }
             }
         }
         $_SESSION['reqs'] = $tempReqs;
     }
     $arr = ['slot' => $courseSlot->toSerializedString(), 'prereqs' => array(), 'coreqs' => array()];
     //add any new prereqs
     if (!empty($prerequisites)) {
         foreach ($prerequisites as $p) {
             array_push($arr['prereqs'], $p->toSerializedString());
         }
     }
     //add any new coreqs
     if (!empty($corequisites)) {
         foreach ($corequisites as $c) {
             array_push($arr['coreqs'], $c->toSerializedString());
         }
     }
     //need to make sure reqs is set so the push doesn't error
     if (!isset($_SESSION['reqs'])) {
         $_SESSION['reqs'] = array();
     }
     array_push($_SESSION['reqs'], $arr);
     //set session variables after serializing
     $_SESSION['courseSlot'] = $courseSlot->toSerializedString();
     $_SESSION['curriculum'] = $curriculum->toSerializedString();
     $this->loadCurriculumEdit($curriculum);
 }