Skip to content
Snippets Groups Projects
Commit 72d25c50 authored by Tim Steiner's avatar Tim Steiner
Browse files

Merge branch 'use-colleges-majors-from-db' into unified-college-router

parents 4b00750d fa594ac3
Branches
No related tags found
No related merge requests found
Showing
with 202 additions and 49 deletions
......@@ -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);
......
......@@ -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);
......
......@@ -205,7 +205,7 @@ class Bulletin_RepositoryModel
public function getFilePathForSection(Bulletin_SectionModel $section)
{
return $this->getFilePathForCollegeMajorYear(
$section->getCollege(),
$section->getCollegeLong(),
$section->getMajor(),
$section->getYear()
);
......
......@@ -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);
......@@ -178,8 +197,8 @@ 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.collegeId = b.collegeId, '
. ' a.majorId = b.majorId, '
. ' a.year = b.year '
. 'WHERE a.bulletinSectionId = b.bulletinSectionId ';
$db->query($sql);
......@@ -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()
{
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()
{
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"?>
......
......@@ -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;
}
}
......@@ -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()); ?>
......
......@@ -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>
......
......@@ -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()); ?>
......
......@@ -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 {
......
......@@ -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()
{
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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment