Beispiel #1
0
 public function setCurriculum($name = NULL, $type = NULL)
 {
     //get arguments
     if ($name == NULL) {
         $name = $this->input->post('name');
     }
     if ($type == NULL) {
         $type = $this->input->post('type');
     }
     //set curriculum name
     $curriculum = new Curriculum_model();
     if (isset($_SESSION['curriculum'])) {
         $curriculum->fromSerializedString($_SESSION['curriculum']);
     }
     $curriculum->setName($name);
     //set curriculum type
     if ($type == "Degree") {
         $curriculum->setCurriculumType(1);
     } else {
         if ($type == "Minor") {
             $curriculum->setCurriculumType(2);
         } else {
             if ($type == "Concentration") {
                 $curriculum->setCurriculumType(3);
             }
         }
     }
     //save curriculum
     if (isset($_SESSION['curriculumCreationMethod'])) {
         if ($_SESSION['curriculumCreationMethod'] == "edit") {
             $curriculum->update();
         } else {
             $curriculum->create();
         }
         //create a new entry for clone/new
     }
     //find all current pre/coreqs and
     $newCurr = new Curriculum_Model();
     $newCurr->loadPropertiesFromPrimaryKey($curriculum->getCurriculumID());
     $courseSlots = $newCurr->getCurriculumCourseSlots();
     //find and delete old reqs and save new ones
     if (isset($_SESSION['reqs'])) {
         foreach ($_SESSION['reqs'] as $reqs) {
             $reqSlot = new Curriculum_course_slot_model();
             $reqSlot->fromSerializedString($reqs['slot']);
             $reqSlotIndex = $reqSlot->getCurriculumIndex();
             foreach ($courseSlots as $slot) {
                 //find the right course slot
                 if ($slot->getCurriculumIndex() == $reqSlotIndex) {
                     $previousPrereqSlots = $slot->getPrequisiteCourseSlots();
                     $previousCoreqSlots = $slot->getCorequisiteCourseSlots();
                     //find and delete old prereqs
                     if (!empty($previousPrereqSlots)) {
                         // and !empty($reqs['prereqs']))
                         foreach ($previousPrereqSlots as $previousSlot) {
                             $slot->removeCourseSlotRequisite($previousSlot);
                         }
                     }
                     //delete any old corequisites
                     if (!empty($previousCoreqSlots)) {
                         // and !empty($reqs['coreqs']))
                         foreach ($previousCoreqSlots as $previousSlot) {
                             $slot->removeCourseSlotRequisite($previousSlot);
                         }
                     }
                     //save new coreqs
                     if (!empty($reqs['coreqs'])) {
                         $co = new Curriculum_course_slot_model();
                         foreach ($reqs['coreqs'] as $r) {
                             $co->fromSerializedString($r);
                             $slot->addCourseSlotCorequisite($co);
                         }
                     }
                     //save new prereqs
                     //need to make sure you can't make one slot a co and pre
                     if (!empty($reqs['prereqs'])) {
                         $pre = new Curriculum_course_slot_model();
                         foreach ($reqs['prereqs'] as $r) {
                             $pre->fromSerializedString($r);
                             $slot->addCourseSlotPrerequisite($pre);
                         }
                     }
                     break;
                 }
             }
         }
     }
     $curriculum->update();
     //update current curriculum for edit
     unset($_SESSION['curriculum']);
     unset($_SESSION['courseSlot']);
     unset($_SESSION['curriculumCreationMethod']);
     unset($_SESSION['curriculumCourseSlotMethod']);
     unset($_SESSION['maxCurriculumIndex']);
     unset($_SESSION['reqs']);
     $this->index();
 }
 /**
  * Summary of setCurriculum
  * Set the curriculum for this curriculum course slot model to be associated with
  * 
  * @param Curriculum_model $curriculum The curriculum to associate with this model
  */
 public function setCurriculum($curriculum)
 {
     if ($curriculum->getCurriculumID() != null && filter_var($curriculum->getCurriculumID(), FILTER_VALIDATE_INT)) {
         $this->curriculumID = $curriculum->getCurriculumID();
     }
 }