diff --git a/application/modules/bulletin/controllers/NewController.php b/application/modules/bulletin/controllers/NewController.php index 1e4d04f2d7d0a4f11455c1efc0c8a270d9184af6..456640c4e2b29c17a388dab32604e75e2e91f4ee 100644 --- a/application/modules/bulletin/controllers/NewController.php +++ b/application/modules/bulletin/controllers/NewController.php @@ -50,7 +50,7 @@ class Bulletin_NewController extends Creq_Controller_Action $section = Bulletin_SectionModel::fetchNew(); $section->setCollege($in['college']); if ($in['major']) { - $section->setMajor($in['major']); + $section->setMajorId($in['major']); } $currentYear = Zend_Date::now()->get(Zend_Date::YEAR); diff --git a/application/modules/bulletin/models/ApprovalActionBulletinCollegeRouterModel.php b/application/modules/bulletin/models/ApprovalActionBulletinCollegeRouterModel.php index b8845b6a778a7d812e481bd78c12f3912c57a685..4f6c9628dbca1d0088a9cb6b12453e146d4ee7ae 100644 --- a/application/modules/bulletin/models/ApprovalActionBulletinCollegeRouterModel.php +++ b/application/modules/bulletin/models/ApprovalActionBulletinCollegeRouterModel.php @@ -105,7 +105,7 @@ class Bulletin_ApprovalActionBulletinCollegeRouterModel extends Requests_Approva $requestSections = Bulletin_SectionModel::findWithRequest($requests); foreach ($requests as $request) { $section = $requestSections[$request->getId()]; - $college = $section->getCollege(); + $college = $section->getCollegeLong(); $request->setState($college); } Requests_RequestModel::save($requests); diff --git a/application/modules/bulletin/models/RepositoryModel.php b/application/modules/bulletin/models/RepositoryModel.php index d82ccca71a1d4946fd44a927c43126dfdd9280f2..e731825f303d3bd7eeb86aadee1b9d820918c13f 100644 --- a/application/modules/bulletin/models/RepositoryModel.php +++ b/application/modules/bulletin/models/RepositoryModel.php @@ -205,7 +205,7 @@ class Bulletin_RepositoryModel public function getFilePathForSection(Bulletin_SectionModel $section) { return $this->getFilePathForCollegeMajorYear( - $section->getCollege(), + $section->getCollegeLong(), $section->getMajor(), $section->getYear() ); diff --git a/application/modules/bulletin/models/SectionModel.php b/application/modules/bulletin/models/SectionModel.php index f9d69e79cf3bf335b429c579dec8f558141e3f68..39e2822cb580e8dc68f145f2d97ed7b1ecc65540 100644 --- a/application/modules/bulletin/models/SectionModel.php +++ b/application/modules/bulletin/models/SectionModel.php @@ -81,12 +81,14 @@ class Bulletin_SectionModel extends Unl_Model $db = Zend_Registry::get('db'); $select = new Zend_Db_Select($db); $select->from(array('b' => 'creqBulletinSections'), array()); + $select->join(array('c' => 'creqColleges'), 'b.collegeId = c.collegeId', array('college' => 'c.description')); $select->join(array('r' => 'creqRequests'), 'b.request = r.requestId', array('requestId')); - $select->where('college = ?', $college); + $select->where('c.description = ?', $college); if ($major) { - $select->where('major = ?', $major); + $select->join(array('m' => 'creqMajors'), 'b.majorId = m.majorId', array('major' => 'm.name')); + $select->where('m.name = ?', $major); } else { - $select->where('major IS NULL'); + $select->where('majorId IS NULL'); } $select->where('r.complete = ?', 'no'); @@ -109,8 +111,8 @@ class Bulletin_SectionModel extends Unl_Model $data = array( 'bulletinSectionId' => NULL, 'request' => NULL, - 'college' => NULL, - 'major' => NULL, + 'collegeId' => NULL, + 'majorId' => NULL, 'year' => NULL, ); @@ -131,6 +133,8 @@ class Bulletin_SectionModel extends Unl_Model $models[$model->getId()] = $model; } + self::_migrateCollegeAndMajorIds($models); + foreach ($models as $model) { if ($model->getId()) { if ($model->_cleanData != $model->_data) { @@ -155,6 +159,21 @@ class Bulletin_SectionModel extends Unl_Model } } + static protected function _migrateCollegeAndMajorIds($models) + { + $colleges = Courses_CourseModel::getCollegeNames(); + $majors = Bulletin_UtilityModel::getAllMajors(); + + foreach ($models as $model) { + if (!$model->_data['collegeId'] && $model->_data['college']) { + $model->_data['collegeId'] = array_search($model->_data['college'], $colleges); + } + if (!$model->_data['majorId'] && $model->_data['major']) { + $model->_data['majorId'] = array_search($model->_data['major'], $majors); + } + } + } + static protected function _update(Unl_Model_Collection $models) { $db = Zend_Registry::get('db'); @@ -168,8 +187,8 @@ class Bulletin_SectionModel extends Unl_Model foreach ($models as $model) { $sqlParts[] = $db->quoteInto('(?, ', $model->_data['bulletinSectionId']) . $db->quoteInto('?, ' , $model->_data['request']) - . $db->quoteInto('?, ' , $model->_data['college']) - . $db->quoteInto('?, ' , $model->_data['major']) + . $db->quoteInto('?, ' , $model->_data['collegeId']) + . $db->quoteInto('?, ' , $model->_data['majorId']) . $db->quoteInto('?) ' , $model->_data['year']); } $sql .= implode(', ', $sqlParts); @@ -177,10 +196,10 @@ class Bulletin_SectionModel extends Unl_Model $sql = 'UPDATE creqBulletinSections AS a, ' . ' creqBulletinSectionsUpdate AS b ' - . 'SET a.request = b.request, ' - . ' a.college = b.college, ' - . ' a.major = b.major, ' - . ' a.year = b.year ' + . 'SET a.request = b.request, ' + . ' a.collegeId = b.collegeId, ' + . ' a.majorId = b.majorId, ' + . ' a.year = b.year ' . 'WHERE a.bulletinSectionId = b.bulletinSectionId '; $db->query($sql); $db->query('DROP TABLE creqBulletinSectionsUpdate'); @@ -190,12 +209,12 @@ class Bulletin_SectionModel extends Unl_Model { $db = Zend_Registry::get('db'); - $sql = 'INSERT INTO creqBulletinSections (`request`, `college`, `major`, `year`) VALUES '; + $sql = 'INSERT INTO creqBulletinSections (`request`, `collegeId`, `majorId`, `year`) VALUES '; $sqlParts = array(); foreach ($models as $model) { $sqlParts[] = $db->quoteInto('(?, ', $model->_data['request']) - . $db->quoteInto('?, ' , $model->_data['college']) - . $db->quoteInto('?, ' , $model->_data['major']) + . $db->quoteInto('?, ' , $model->_data['collegeId']) + . $db->quoteInto('?, ' , $model->_data['majorId']) . $db->quoteInto('?)' , $model->_data['year']); } $sql .= implode(', ', $sqlParts); @@ -253,22 +272,88 @@ class Bulletin_SectionModel extends Unl_Model public function getCollege() { - return $this->_data['college']; + if (!$this->_data['collegeId'] && $this->_data['college']) { + return $this->_data['college']; + } + + $colleges = Courses_CourseModel::getColleges(); + if (isset($colleges[$this->_data['collegeId']])) { + return $colleges[$this->_data['collegeId']]; + } + + return NULL; + } + + public function getCollegeLong() + { + if (!$this->_data['collegeId'] && $this->_data['college']) { + return $this->_data['college']; + } + + $colleges = Courses_CourseModel::getCollegeNames(); + if (isset($colleges[$this->_data['collegeId']])) { + return $colleges[$this->_data['collegeId']]; + } + + return NULL; + } + + public function setCollegeId($collegeId) + { + $colleges = Courses_CourseModel::getCollegeNames(); + if (!isset($colleges[$collegeId])) { + throw new Exception('College not found.'); + } + $this->_data['collegeId'] = $collegeId; } public function setCollege($college) { - $this->_data['college'] = $college; + $colleges = Courses_CourseModel::getCollegeNames(); + $collegeId = array_search($college, $colleges); + + if (!$collegeId) { + throw new Exception('The college "' . $college . '" does not exist.'); + } + + $this->_data['collegeId'] = $collegeId; } public function getMajor() { - return $this->_data['major']; + if (!$this->_data['majorId'] && $this->_data['major']) { + return $this->_data['major']; + } + + $majors = Bulletin_UtilityModel::getAllMajors(); + if (isset($majors[$this->_data['majorId']])) { + return $majors[$this->_data['majorId']]; + } + + return NULL; + } + + public function setMajorId($majorId) + { + $majors = Bulletin_UtilityModel::getAllMajors(); + if (!isset($majors[$majorId])) { + throw new Exception('Major not found.'); + } + $this->_data['majorId'] = $majorId; + $this->_data['major'] = $majors[$majorId]; } public function setMajor($major) { - $this->_data['major'] = $major; + $majors = Bulletin_UtilityModel::getAllMajors(); + $majorId = array_search($major, $majors); + + if (!$majorId) { + throw new Exception ('The major "' . $major . '" does not exist.'); + } + + $this->_data['majorId'] = $majorId; + $this->_data['major'] = $majors[$majorId]; } public function getYear() @@ -388,11 +473,11 @@ class Bulletin_SectionModel extends Unl_Model if ($section->getMajor()) { $title = $section->getMajor() . ' ' . substr($section->getYear(), -2) . '-' . substr($section->getYear() + 1, -2); } else { - $title = $section->getCollege() . ' Main Page ' . substr($section->getYear(), -2) . '-' . substr($section->getYear() + 1, -2); + $title = $section->getCollegeLong() . ' Main Page ' . substr($section->getYear(), -2) . '-' . substr($section->getYear() + 1, -2); } $hyphenatedTitle = preg_replace('/[^a-zA-Z0-9]+/', '-', strtolower($title)); - $majorName = $section->getMajor() ? $section->getMajor() : $section->getCollege(); + $majorName = $section->getMajor() ? $section->getMajor() : $section->getCollegeLong(); $html = <<<EOF <?xml version="1.0" encoding="utf-8"?> diff --git a/application/modules/bulletin/models/UtilityModel.php b/application/modules/bulletin/models/UtilityModel.php index ed65ce2b70b71bc3ce56f9cd044d965e7253886e..22377a1288c13f51458c660a0a8497447fafd4f6 100644 --- a/application/modules/bulletin/models/UtilityModel.php +++ b/application/modules/bulletin/models/UtilityModel.php @@ -13,7 +13,7 @@ class Bulletin_UtilityModel implements Creq_Model_UtilityInterface foreach ($data as $i => &$record) { $section = $requestSections[$record['request']->getId()]; - $record['extra']['Section'] = $section->getMajor() ? $section->getMajor() : $section->getCollege(); + $record['extra']['Section'] = $section->getMajor() ? $section->getMajor() : $section->getCollegeLong(); } unset($record); } @@ -49,19 +49,46 @@ class Bulletin_UtilityModel implements Creq_Model_UtilityInterface return FALSE; } + static protected $_majors; + + /** + * @return array + * + * Returns a two-dimentional array of all Majors, keyed by college, then majorId. + */ static public function getMajors() { - $http = new Zend_Http_Client(); - $colleges = json_decode($http->setUri('http://bulletin.unl.edu/undergraduate/college?format=json')->request()->getBody(), TRUE); - $collegeMajors = array(); - - foreach ($colleges as $college) { - $majors = json_decode($http->setUri($college['uri'] . '/majors?format=json')->request()->getBody(), TRUE); - foreach ($majors as $major) { - $collegeMajors[$college['name']][$major['title']] = $major['title']; - } + if (self::$_majors) { + return self::$_majors; + } + + $db = Zend_Db_Table::getDefaultAdapter(); + $select = $db->select(); + $select->from(array('m' => 'creqMajors'), array('majorId', 'major' => 'name')); + $select->join(array('c' => 'creqColleges'), 'm.college = c.collegeId', array('collegeId', 'college' => 'description')); + + foreach ($select->query()->fetchAll() as $row) { + self::$_majors[$row['college']][$row['majorId']] = $row['major']; + } + + return self::$_majors; + } + + /** + * @return array + * Returns an array of all Majors, keyed by majorId. + */ + static public function getAllMajors() + { + $collegeMajors = self::getMajors(); + $allMajors = array(); + + foreach ($collegeMajors as $majors) + { + $allMajors += $majors; } + asort($allMajors); - return $collegeMajors; + return $allMajors; } } diff --git a/application/modules/bulletin/views/scripts/edit/index.phtml b/application/modules/bulletin/views/scripts/edit/index.phtml index 080fbdfbee7b1c82587151a7645de3f9ecaaef26..c21d2553cbec10f9c470e7cea7a92432764b1114 100644 --- a/application/modules/bulletin/views/scripts/edit/index.phtml +++ b/application/modules/bulletin/views/scripts/edit/index.phtml @@ -20,7 +20,7 @@ $this->headScript()->appendFile($this->baseUrl() . '/ice/src/plugins/IceSmartQuo $this->headScript()->appendFile($this->baseUrl() . '/tinymce/jscripts/tiny_mce/tiny_mce.js'); $this->headScript()->appendFile($this->baseUrl() . '/javascript/bulletin/tinymce.js'); $this->headScript()->appendFile($this->baseUrl() . '/javascript/bulletin/edit.js'); -$this->layout()->pageTitle = 'Editing: ' . ($this->section->getMajor() ? $this->section->getMajor() : $this->section->getCollege()) . ' (' . $this->request->getTypeDescription() . ')'; +$this->layout()->pageTitle = 'Editing: ' . ($this->section->getMajor() ? $this->section->getMajor() : $this->section->getCollegeLong()) . ' (' . $this->request->getTypeDescription() . ')'; ?> <form action="<?php echo $this->baseUrl('/bulletin/edit/edit.post'); ?>" method="post" enctype="multipart/form-data"> @@ -83,7 +83,7 @@ $this->layout()->pageTitle = 'Editing: ' . ($this->section->getMajor() ? $this-> <p>Only used by some Education & Human Sciences and Fine & Performing Arts programs. Please leave blank if there is no information already here for your program. Please contact Brooke Glenn (<a href="mailto:bglenn2@unl.edu">bglenn2@unl.edu</a>, 402-472-6023) if you think you need to add information to this section.</p> <textarea name="other" class="mceEditor"><?php echo $this->other; ?></textarea> - <?php if ($this->section->getCollege() == 'Arts & Sciences') { ?> + <?php if ($this->section->getCollegeLong() == 'Arts & Sciences') { ?> <div> <h2><label for="justification">Justification</label></h2> <?php echo $this->formTextarea('justification', $this->request->getJustification()); ?> diff --git a/application/modules/bulletin/views/scripts/my-requests/saved.phtml b/application/modules/bulletin/views/scripts/my-requests/saved.phtml index e39ace2c1f162403713470f7cd314b8ffbe0d4b9..daaa408e2678c1be2b3b34df08f242e366e6b0d0 100644 --- a/application/modules/bulletin/views/scripts/my-requests/saved.phtml +++ b/application/modules/bulletin/views/scripts/my-requests/saved.phtml @@ -14,7 +14,7 @@ $section = $data['section']; ?> <tr> - <td><?php echo $this->escape($section->getMajor() ? $section->getMajor() : $section->getCollege()); ?></td> + <td><?php echo $this->escape($section->getMajor() ? $section->getMajor() : $section->getCollegeLong()); ?></td> <td><?php echo $this->escape($request->getTypeDescription()); ?></td> <td> <a href="<?php echo $this->baseUrl(); ?>/requests/edit/load/sessionId/<?php echo $savedId; ?>">Edit</a> diff --git a/application/modules/bulletin/views/scripts/view/index.phtml b/application/modules/bulletin/views/scripts/view/index.phtml index 6f522dac88a6366037289b699cff17b1a48124f0..8cf27e2855cb5af4adce7ee270d822522dbc586d 100644 --- a/application/modules/bulletin/views/scripts/view/index.phtml +++ b/application/modules/bulletin/views/scripts/view/index.phtml @@ -7,7 +7,7 @@ if ($this->preview) { } else { $breadcrumb = 'Viewing'; } -$this->layout()->pageTitle = $breadcrumb . ': ' . ($this->section->getMajor() ? $this->section->getMajor() : $this->section->getCollege()) . ' (' . $this->request->getTypeDescription() . ')'; +$this->layout()->pageTitle = $breadcrumb . ': ' . ($this->section->getMajor() ? $this->section->getMajor() : $this->section->getCollegeLong()) . ' (' . $this->request->getTypeDescription() . ')'; $originalSection = Bulletin_SectionModel::parseHtml($this->originalFileContents); $proposedSection = Bulletin_SectionModel::parseHtml($this->proposedFileContents); ?> @@ -50,7 +50,7 @@ $proposedSection = Bulletin_SectionModel::parseHtml($this->proposedFileContents) </div> -<?php if ($this->section->getCollege() == 'Arts & Sciences') { ?> +<?php if ($this->section->getCollegeLong() == 'Arts & Sciences') { ?> <div> <h2>Justification</h2> <?php echo $this->escape($this->request->getJustification()); ?> diff --git a/application/modules/fouryearplans/controllers/NewController.php b/application/modules/fouryearplans/controllers/NewController.php index 0b1fd1a979a0aea9002390186f4e9a5aa8ce1660..a9da7f19e1f68529ac0f8bbed600ec48c68a7de0 100644 --- a/application/modules/fouryearplans/controllers/NewController.php +++ b/application/modules/fouryearplans/controllers/NewController.php @@ -38,7 +38,7 @@ class FourYearPlans_NewController extends Creq_Controller_Action $fourYearPlan = FourYearPlans_FourYearPlanModel::findByMajor($in['major']); if (!$fourYearPlan) { $fourYearPlan = FourYearPlans_FourYearPlanModel::fetchNew(); - $fourYearPlan->setMajor($in['major']); + $fourYearPlan->setMajorId($in['major']); $previousFourYearPlan = NULL; $request->setType('NewFourYearPlan'); } else { diff --git a/application/modules/fouryearplans/models/FourYearPlanModel.php b/application/modules/fouryearplans/models/FourYearPlanModel.php index 34b2749b7e02ba9e16c2027dcee17962c7a43ad9..b734a92819d547f3261f365af3bd8b01c0506bb2 100644 --- a/application/modules/fouryearplans/models/FourYearPlanModel.php +++ b/application/modules/fouryearplans/models/FourYearPlanModel.php @@ -85,7 +85,7 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model 'request' => null, 'type' => 'proposed', 'removed' => 'no', - 'major' => '', + 'majorId' => null, 'courses' => array(), 'notes' => array(), ); @@ -284,8 +284,9 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model $select = new Zend_Db_Select($db); $select->from(array('g' => 'creqFourYearPlanGenerations'), array('fourYearPlanGenerationId')); + $select->join(array('m' => 'creqMajors'), 'g.majorId = m.majorId', array('major' => 'name')); $select->join(array('f' => 'creqFourYearPlans'), 'g.fourYearPlanGenerationId = f.currentGeneration', array()); - $select->where('g.major = ?', $major); + $select->where('m.name = ?', $major); $records = $select->query()->fetchAll(); if (count($records) == 0) { @@ -354,8 +355,9 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model $db = Zend_Registry::get('db'); $select = new Zend_Db_Select($db); $select->from(array('f' => 'creqFourYearPlanGenerations'), array()); + $select->join(array('m' => 'creqMajors'), 'f.majorId = m.majorId', array('major' => 'name')); $select->join(array('r' => 'creqRequests'), 'f.request = r.requestId', array('requestId')); - $select->where('f.major = ?', $major); + $select->where('m.name = ?', $major); $select->where('r.complete = ?', 'no'); $records = $select->query()->fetchAll(); @@ -376,6 +378,8 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model $models = $collection; } + self::_migrateMajorIds($models); + $db = Zend_Registry::get('db'); $db->beginTransaction(); @@ -467,6 +471,17 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model } } + static protected function _migrateMajorIds($models) + { + $majors = Bulletin_UtilityModel::getAllMajors(); + + foreach ($models as $model) { + if (!$model->_data['majorId'] && $model->_data['major']) { + $model->_data['majorId'] = array_search($model->_data['major'], $majors); + } + } + } + static public function _insertBaseRows($models) { if (count($models) == 0) { @@ -513,7 +528,7 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model } } - $sql = 'INSERT INTO creqFourYearPlanGenerations (assetId, parent, fourYearPlan, request, type, removed, major) VALUES '; + $sql = 'INSERT INTO creqFourYearPlanGenerations (assetId, parent, fourYearPlan, request, type, removed, majorId) VALUES '; $sqlParts = array(); foreach ($models as $model) { $sqlParts[] = $db->quoteInto('(?, ', $model->_data['assetId']) @@ -522,7 +537,7 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model . $db->quoteInto('?, ' , $model->_data['request']) . $db->quoteInto('?, ' , $model->_data['type']) . $db->quoteInto('?, ' , $model->_data['removed']) - . $db->quoteInto('?)' , $model->_data['major']); + . $db->quoteInto('?)' , $model->_data['majorId']); } $sql .= implode(', ', $sqlParts); $db->query($sql); @@ -604,7 +619,7 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model . $db->quoteInto('?, ' , $model->_data['request']) . $db->quoteInto('?, ' , $model->_data['type']) . $db->quoteInto('?, ' , $model->_data['removed']) - . $db->quoteInto('?)' , $model->_data['major']); + . $db->quoteInto('?)' , $model->_data['majorId']); } $sql .= implode(', ', $sqlParts); $db->query($sql); @@ -616,7 +631,8 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model . ' a.fourYearPlan = b.fourYearPlan, ' . ' a.request = b.request, ' . ' a.type = b.type, ' - . ' a.removed = b.removed ' + . ' a.removed = b.removed, ' + . ' a.majorId = b.majorId ' . 'WHERE a.fourYearPlanGenerationId = b.fourYearPlanGenerationId '; $db->query($sql); $db->query('DROP TABLE creqFourYearPlanGenerationsUpdate'); @@ -899,12 +915,37 @@ class FourYearPlans_FourYearPlanModel extends Unl_Model public function getMajor() { - return $this->_data['major']; + if (!$this->_data['majorId'] && $this->_data['major']) { + return $this->_data['major']; + } + + $majors = Bulletin_UtilityModel::getAllMajors(); + if (isset($majors[$this->_data['majorId']])) { + return $majors[$this->_data['majorId']]; + } + + return NULL; + } + + public function setMajorId($majorId) + { + $majors = Bulletin_UtilityModel::getAllMajors(); + if (!isset($majors[$majorId])) { + throw new Exception('Major not found.'); + } + $this->_data['majorId'] = $majorId; } public function setMajor($major) { - $this->_data['major'] = $major; + $majors = Bulletin_UtilityModel::getAllMajors(); + $majorId = array_search($major, $majors); + + if (!$majorId) { + throw new Exception ('The major "' . $major . '" does not exist.'); + } + + $this->_data['majorId'] = $majorId; } public function getConcentrations()