/** * 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; }