/** * Summary of update * Update existing rows in the database associated with this curriculum model with newly modified information * * @return boolean True if all rows associated with this model were successfully modified in the database, false otherwise */ public function update() { if ($this->curriculumID != null && $this->name != null && $this->curriculumType != null && filter_var($this->curriculumType, FILTER_VALIDATE_INT)) { $arr = array(); foreach ($this->curriculumCourseSlots as $slot) { array_push($arr, $slot->getCurriculumCourseSlotID()); } $data = array('Name' => $this->name, 'CurriculumTypeID' => $this->curriculumType); $this->db->where('CurriculumID', $this->curriculumID); $this->db->update('Curriculums', $data); $results = $this->db->get_where('CurriculumCourseSlots', array('CurriculumID' => $this->curriculumID)); foreach ($results->result_array() as $row) { $courseSlot = new Curriculum_course_slot_model(); if ($courseSlot->loadPropertiesFromPrimaryKey($row['CurriculumCourseSlotID'])) { if (in_array($courseSlot->getCurriculumCourseSlotID(), $arr)) { $index = array_search($courseSlot->getCurriculumCourseSlotID(), $arr); unset($arr[$index]); foreach ($this->curriculumCourseSlots as $_courseSlot) { if ($_courseSlot->getCurriculumCourseSlotID() == $courseSlot->getCurriculumCourseSlotID()) { $_courseSlot->update(); break; } } } else { $courseSlot->delete(); } } } foreach ($arr as $id) { foreach ($this->curriculumCourseSlots as $slot) { if ($slot->getCurriculumCourseSlotID() == $id) { $slot->create(); break; } } } return true; } return false; }
private function loadCurriculumCourseSlotEdit($courseSlotIndex = NULL) { ///get arguments if ($courseSlotIndex == NULL) { $courseSlotIndex = $this->input->post('courseSlot'); } $curriculum = new Curriculum_model(); $curriculum->fromSerializedString($_SESSION['curriculum']); $courseSlots = $curriculum->getCurriculumCourseSlots(); $courseSlot = new Curriculum_course_slot_model(); //find selected course slot foreach ($courseSlots as $slot) { $index = $slot->getCurriculumIndex(); if ($index == $courseSlotIndex) { //set values manually for clone so it doesn't copy courseSlotID if (strcmp($_SESSION['curriculumCourseSlotMethod'], "clone") == 0) { $courseSlot->setMinimumGrade($slot->getMinimumGrade()); $courseSlot->setName($slot->getName()); $courseSlot->setRecommendedQuarter($slot->getRecommendedQuarter()); $courseSlot->setRecommendedYear($slot->getRecommendedYear()); $courseSlot->setNotes($slot->getNotes()); $courseSlot->setCurriculum($curriculum); $courseSlot->setCurriculumIndex($slot->getCurriculumIndex()); $slotValids = $slot->getValidCourseIDs(); foreach ($slotValids as $valid) { $courseSlot->addValidCourseID($valid); } } else { //copy entire slot for edit $courseSlot = $slot; } break; } } //set the name to if ($courseSlot->getName() == NULL) { $courseSlot->setName("New Curriculum Course Slot"); } $courses = new Course_model(); //set default values for data array if it's a new slot if (strcmp($_SESSION['curriculumCourseSlotMethod'], "new") == 0) { $courseSlot = new Curriculum_course_slot_model(); $data = array('name' => "New Curriculum Course Slot", 'courses' => array(), 'recommendedQuarter' => "Fall", 'recommendedYear' => "Freshman", 'minimumGrade' => "F", 'notes' => " ", 'index' => $courseSlotIndex, 'prereqs' => array(), 'coreqs' => array()); } else { $data = array('name' => $courseSlot->getName(), 'courses' => array(), 'recommendedQuarter' => $courseSlot->getRecommendedQuarter(), 'recommendedYear' => $courseSlot->getRecommendedYear(), 'minimumGrade' => $courseSlot->getMinimumGrade(), 'notes' => $courseSlot->getNotes(), 'index' => $courseSlotIndex, 'prereqs' => array(), 'coreqs' => array()); } //find if the co or pre reqs have been edited in this session $prereqsEdited = FALSE; $coreqsEdited = FALSE; if (!empty($_SESSION['reqs'])) { foreach ($_SESSION['reqs'] as $reqs) { foreach ($courseSlots as $slot) { $reqsSlot = new Curriculum_course_slot_model(); $reqsSlot->fromSerializedString($reqs['slot']); //find the right course slot if ($slot->getCurriculumIndex() == $reqsSlot->getCurriculumIndex()) { $prereqsEdited = TRUE; $coreqsEdited = TRUE; } } } } //Pass possible and chosen prereq slots $currentIndex = $courseSlot->getCurriculumIndex(); $courseSlotIndex = $courseSlot->getCurriculumIndex(); $slotPrereqs = $courseSlot->getPrequisiteCourseSlots(); foreach ($courseSlots as $slot) { $arr = ['name' => $slot->getName(), 'id' => $slot->getCurriculumCourseSlotID(), 'index' => $slot->getCurriculumIndex(), 'selected' => FALSE]; if (!$prereqsEdited) { //normal prereq functionality if (!empty($slotPrereqs)) { foreach ($slotPrereqs as $prereq) { if ($prereq->getCurriculumIndex() == $arr['index']) { $arr['selected'] = TRUE; } } } } else { //grabbing prereqs from session $currReq = new Curriculum_course_slot_model(); foreach ($_SESSION['reqs'] as $reqs) { foreach ($reqs['prereqs'] as $preRekts) { $currReq->fromSerializedString($preRekts); if ($currReq->getCurriculumIndex() == $arr['index']) { $arr['selected'] = TRUE; } } } } if ($currentIndex != $arr['index']) { array_push($data['prereqs'], $arr); } } //Pass possible and chosen coreq slots $slotCoreqs = $courseSlot->getCorequisiteCourseSlots(); foreach ($courseSlots as $slot) { $arr = ['name' => $slot->getName(), 'id' => $slot->getCurriculumCourseSlotID(), 'index' => $slot->getCurriculumIndex(), 'selected' => FALSE]; if (!$prereqsEdited) { //normal coreq functionality if (isset($slotCoreqs)) { foreach ($slotCoreqs as $coreq) { if ($coreq->getCurriculumIndex() == $arr['index']) { $arr['selected'] = TRUE; } } } } else { //grabbing coreqs from session $currReq = new Curriculum_course_slot_model(); foreach ($_SESSION['reqs'] as $reqs) { foreach ($reqs['coreqs'] as $coRekts) { $currReq->fromSerializedString($coRekts); if ($currReq->getCurriculumIndex() == $arr['index']) { $arr['selected'] = TRUE; } } } } if ($currentIndex != $arr['index']) { array_push($data['coreqs'], $arr); } } //get all available courses and pass to data $availableCourses = $courses->getAllCourses(); $validCourse = $courseSlot->getValidCourseIDs(); foreach ($availableCourses as $course) { $arr = ['name' => $course->getCourseName(), 'id' => $course->getCourseID(), 'prereqs' => $course->getPrerequisiteCourses(), 'number' => $course->getCourseNumber(), 'selected' => FALSE]; foreach ($validCourse as $valid) { if (strcmp($valid, $course->getCourseID()) == 0) { $arr['selected'] = TRUE; } } array_push($data['courses'], $arr); } $_SESSION['courseSlot'] = $courseSlot->toSerializedString(); $this->load->view('course_slot_edit', array('data' => $data)); }
/** * Summary of getCorequisiteCourseSlots * Get all of the co-requisite curriculum course slots for this course * * @return Array An array containing all the curriculum course slots that are co-requisites to this curriculum course slot */ public function getCorequisiteCourseSlots() { $models = array(); if ($this->curriculumCourseSlotID != null) { $this->db->select('RequisiteCurriculumCourseSlotID'); $this->db->where('CourseRequisiteTypeID', self::COURSE_REQUISITE_COREQUISITE); $this->db->where('CurriculumCourseSlotID', $this->curriculumCourseSlotID); $results = $this->db->get('CurriculumCourseSlotRequisites'); foreach ($results->result_array() as $row) { $model = new Curriculum_course_slot_model(); if ($model->loadPropertiesFromPrimaryKey($row['RequisiteCurriculumCourseSlotID'])) { array_push($models, $model); } } $this->db->select('CurriculumCourseSlotID'); $this->db->where('CourseRequisiteTypeID', self::COURSE_REQUISITE_COREQUISITE); $this->db->where('RequisiteCurriculumCourseSlotID', $this->curriculumCourseSlotID); $results = $this->db->get('CurriculumCourseSlotRequisites'); foreach ($results->result_array() as $row) { $model = new Curriculum_course_slot_model(); if ($model->loadPropertiesFromPrimaryKey($row['CurriculumCourseSlotID'])) { array_push($models, $model); } } } return $models; }
/** * Summary of getAllCurriculumCourseSlots * Get all of the curriculum course slots that this course is compatible with * * @return Array An array containing curriculum course slot models that are compatible with this course */ public function getAllCurriculumCourseSlots() { $models = array(); if ($this->courseID != null) { $this->db->where("CourseID", $this->courseID); $this->db->select("CurriculumCourseSlotID"); $results = $this->db->get("CurriculumSlotValidCourses"); foreach ($results->result_array() as $row) { $model = new Curriculum_course_slot_model(); if ($model->loadPropertiesFromPrimaryKey($row['CurriculumCourseSlotID'])) { array_push($models, $model); } } } return $models; }
public function addCourseSection() { $this->checkSec(); $sID = $this->input->post('sID'); $sectionID = $this->input->post('sectionID'); $slotID = $this->input->post('slotID'); $slot = new Curriculum_course_slot_model(); $slot->loadPropertiesFromPrimaryKey($slotID); $section = new Course_section_model(); $grade = $this->input->post('grade'); //Cannot add a grade to a slot if it doesn't meet the minimum grade requirement. if (!isset($grade) || strcmp($grade, $slot->getMinimumGrade()) < 0) { redirect('User/prepareAddCourseSection/' . $slotID); } $student = new User_model(); $student->loadPropertiesFromPrimaryKey($sID); if (!$student->addCourseSection($section, $grade)) { show_error('Failed to add Course section: ' . $section . ' with grade ' . $grade); } redirect('User/prepareAddCourses/' . $sID); }