diff --git a/application/modules/courses/models/CourseModel.php b/application/modules/courses/models/CourseModel.php index 44796820229525040f67dd256c57185e218f2a61..d2843dcd2628633f1966e6f380f2365901f2ac32 100644 --- a/application/modules/courses/models/CourseModel.php +++ b/application/modules/courses/models/CourseModel.php @@ -2293,11 +2293,22 @@ class Courses_CourseModel extends Unl_Model $db->query('DROP TABLE creqCoursesUpdate'); } + /** + * This function will create new generations of any courses with references to $oldCode and replace + * them with $newCode. All current official generations will have a new official generation created + * the change, and all in-progress requests will have new generations created with the change. + * This method should only be called !!ONCE!! for such a change. + * I recommend against having this method publicly available, except when needed. + * + * @param string $oldCode + * @param string $newCode + */ static public function updateSubjectCode($oldCode, $newCode) { $db = Zend_Registry::get('db'); $generationIds = array(); + // Get current official generation with crosslistings $select = new Zend_Db_Select($db); $select->from(array('c' => 'creqCourseCodes'), array()); $select->join(array('x' => 'creqCourseCrosslistings'), 'c.courseCodeId = x.courseCode', array('generation')); @@ -2313,6 +2324,7 @@ class Courses_CourseModel extends Unl_Model } + // Get current official generation with prereq, notes, description, title $select = new Zend_Db_Select($db); $select->from(array('d' => 'creqCourseDetails'), array('prerequisite')); $select->join(array('g' => 'creqCourseGenerations'), 'd.generation = g.courseGenerationId', array('course', 'type')); @@ -2331,6 +2343,35 @@ class Courses_CourseModel extends Unl_Model } + // Get current official generation with ace outcomes + $select = new Zend_Db_Select($db); + $select->from(array('d' => 'creqCourseAceOutcomes')); + $select->join(array('g' => 'creqCourseGenerations'), 'd.generation = g.courseGenerationId', array('course', 'type')); + $select->join(array('s' => 'creqCourses'), 'g.course = s.courseId', array('currentGeneration')); + $select->where( + $db->quoteInto('d.justification LIKE ? OR ', '%' . $oldCode . '%') . + $db->quoteInto('d.studentWork LIKE ? OR ', '%' . $oldCode . '%') . + $db->quoteInto('d.assesmentPlan LIKE ?', '%' . $oldCode . '%') + ); + + + // Get current official generation with ace reinforcements + $select = new Zend_Db_Select($db); + $select->from(array('d' => 'creqCourseAceReinforcements')); + $select->join(array('g' => 'creqCourseGenerations'), 'd.generation = g.courseGenerationId', array('course', 'type')); + $select->join(array('s' => 'creqCourses'), 'g.course = s.courseId', array('currentGeneration')); + $select->where( + $db->quoteInto('d.description LIKE ?', '%' . $oldCode . '%') + ); + + $data = $select->query()->fetchAll(); + + foreach ($data as $row) { + $generationIds[] = $row['currentGeneration']; + } + + + // Get in-progress requests with crosslistings $select = new Zend_Db_Select($db); $select->from(array('c' => 'creqCourseCodes'), array()); $select->join(array('x' => 'creqCourseCrosslistings'), 'c.courseCodeId = x.courseCode', array('generation')); @@ -2345,13 +2386,15 @@ class Courses_CourseModel extends Unl_Model } + // Get in-progress requests with prereq, notes, description, title $select = new Zend_Db_Select($db); $select->from(array('d' => 'creqCourseDetails'), array('prerequisite')); $select->join(array('g' => 'creqCourseGenerations'), 'd.generation = g.courseGenerationId', array('course', 'type')); $select->where( $db->quoteInto('d.prerequisite LIKE ? OR ', '%' . $oldCode . '%') . $db->quoteInto('d.notes LIKE ? OR ', '%' . $oldCode . '%') . - $db->quoteInto('d.description LIKE ?', '%' . $oldCode . '%') + $db->quoteInto('d.description LIKE ? OR ', '%' . $oldCode . '%') . + $db->quoteInto('d.title LIKE ?', '%' . $oldCode . '%') ); $select->where('g.courseGenerationId NOT IN (SELECT parent FROM creqCourseGenerations WHERE parent IS NOT NULL)'); @@ -2362,6 +2405,34 @@ class Courses_CourseModel extends Unl_Model } + // Get in-progress requests with ace outcomes + $select = new Zend_Db_Select($db); + $select->from(array('d' => 'creqCourseAceOutcomes')); + $select->join(array('g' => 'creqCourseGenerations'), 'd.generation = g.courseGenerationId', array('course', 'type')); + $select->where( + $db->quoteInto('d.justification LIKE ? OR ', '%' . $oldCode . '%') . + $db->quoteInto('d.studentWork LIKE ? OR ', '%' . $oldCode . '%') . + $db->quoteInto('d.assesmentPlan LIKE ?', '%' . $oldCode . '%') + ); + $select->where('g.courseGenerationId NOT IN (SELECT parent FROM creqCourseGenerations WHERE parent IS NOT NULL)'); + + + // Get in-progress requests with ace reinforcements + $select = new Zend_Db_Select($db); + $select->from(array('d' => 'creqCourseAceReinforcements')); + $select->join(array('g' => 'creqCourseGenerations'), 'd.generation = g.courseGenerationId', array('course', 'type')); + $select->where( + $db->quoteInto('d.description LIKE ?', '%' . $oldCode . '%') + ); + $select->where('g.courseGenerationId NOT IN (SELECT parent FROM creqCourseGenerations WHERE parent IS NOT NULL)'); + + $data = $select->query()->fetchAll(); + + foreach ($data as $row) { + $generationIds[] = $row['currentGeneration']; + } + + sort($generationIds); $generationIds = array_unique($generationIds); @@ -2381,6 +2452,22 @@ class Courses_CourseModel extends Unl_Model $newCourse->setNotes(strtr($newCourse->getNotes(), array($oldCode => $newCode))); $newCourse->setDescription(strtr($newCourse->getDescription(), array($oldCode => $newCode))); $newCourse->setTitle(strtr($newCourse->getTitle(), array($oldCode => $newCode))); + $aceOutcomes = $newCourse->getAceOutcomes(); + foreach($aceOutcomes as $aceOutcome) { + $newCourse->setAceOutcome( + $aceOutcome['name'], + strtr($aceOutcome['justification'], array($oldCode => $newCode)), + strtr($aceOutcome['studentWork'], array($oldCode => $newCode)), + strtr($aceOutcome['assesmentPlan'], array($oldCode => $newCode)) + ); + } + $aceReinforcements = $newCourse->getAceReinforcements(); + foreach ($aceReinforcements as $aceReinforcement) { + $newCourse->setAceReinforcement( + $aceReinforcement['name'], + strtr($aceReinforcement['description'], array($oldCode => $newCode)) + ); + } $newCourse->setEffectiveSemester('20092'); if ($newCourse->getType() == 'official') {