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

Update public search to be more user-friendly (part 2)

parent 889f0b86
No related branches found
No related tags found
No related merge requests found
...@@ -226,9 +226,6 @@ class Courses_PublicViewController extends App_Controller_Action { ...@@ -226,9 +226,6 @@ class Courses_PublicViewController extends App_Controller_Action {
public function searchAction() public function searchAction()
{ {
$this->view->colleges = Courses_CourseModel::getCollegeNames();
$this->view->departments = Courses_CourseModel::getDepartments();
$this->view->subjects = Courses_CourseModel::getSubjectsFull();
$this->view->activityTypes = array( $this->view->activityTypes = array(
1 => 'Lec - Lecture', 1 => 'Lec - Lecture',
2 => 'Lab - Lab', 2 => 'Lab - Lab',
...@@ -282,6 +279,30 @@ class Courses_PublicViewController extends App_Controller_Action { ...@@ -282,6 +279,30 @@ class Courses_PublicViewController extends App_Controller_Action {
$this->view->data = $data; $this->view->data = $data;
$this->view->criteria = $criteria; $this->view->criteria = $criteria;
$this->view->hasSearched = isset($criteria['college']); $this->view->hasSearched = isset($criteria['college']);
$hierarchy = Courses_CourseModel::getSubjectDepartmentCollegeHierarchy();
$colleges = array();
$departments = array();
$departmentsSerial = array();
$subjects = array();
$subjectsSerial = array();
foreach ($hierarchy as $collegeId => $college) {
$colleges[$collegeId] = $college['name'];
foreach ($college['departments'] as $departmentId => $department) {
$departments[$college['name']][$departmentId] = $department['name'];
$departmentsSerial[$departmentId] = $department['name'];
foreach ($department['subjects'] as $subjectCode => $subjectName) {
$subjects[$department['name']][$subjectCode] = $subjectCode . ' - ' . $subjectName;
$subjectsSerial[$subjectCode] = $subjectCode . ' - ' . $subjectName;
}
}
}
$this->view->colleges = $colleges;
$this->view->departments = $departments;
$this->view->departmentsSerial = $departmentsSerial;
$this->view->subjects = $subjects;
$this->view->subjectsSerial = $subjectsSerial;
} }
public function viewAction() public function viewAction()
......
...@@ -1580,14 +1580,16 @@ class Courses_CourseModel extends Unl_Model ...@@ -1580,14 +1580,16 @@ class Courses_CourseModel extends Unl_Model
if (count(self::$_hierarchy) == 0) { if (count(self::$_hierarchy) == 0) {
$db = Zend_Registry::get('db'); $db = Zend_Registry::get('db');
$select = new Zend_Db_Select($db); $select = new Zend_Db_Select($db);
$select->from(array('c' => 'creqColleges'), array('college' => 'description')); $select->from(array('c' => 'creqColleges'), array('collegeId', 'college' => 'description'));
$select->join(array('d' => 'creqDepartments'), 'c.collegeId = d.college', array('department' => 'name')); $select->join(array('d' => 'creqDepartments'), 'c.collegeId = d.college', array('departmentId', 'department' => 'name'));
$select->join(array('s' => 'creqSubjects'), 'd.departmentId = s.department', array('code' => 'name', 'subject' => 'description')); $select->join(array('s' => 'creqSubjects'), 'd.departmentId = s.department', array('code' => 'name', 'subject' => 'description'));
$select->order(array('college', 'department', 'subject')); $select->order(array('college', 'department', 'subject'));
$records = $select->query()->fetchAll(); $records = $select->query()->fetchAll();
$hierarchy = array(); $hierarchy = array();
foreach ($records as $record) { foreach ($records as $record) {
$hierarchy[$record['college']][$record['department']][$record['code']] = $record['subject']; $hierarchy[$record['collegeId']]['name'] = $record['college'];
$hierarchy[$record['collegeId']]['departments'][$record['departmentId']]['name'] = $record['department'];
$hierarchy[$record['collegeId']]['departments'][$record['departmentId']]['subjects'][$record['code']] = $record['subject'];
} }
self::$_hierarchy = $hierarchy; self::$_hierarchy = $hierarchy;
} }
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
$summary[] = 'College - ' . $this->colleges[$this->criteria['college']]; $summary[] = 'College - ' . $this->colleges[$this->criteria['college']];
} }
if ($this->criteria['department']) { if ($this->criteria['department']) {
$summary[] = 'Department - ' . $this->departments[$this->criteria['department']]; $summary[] = 'Department - ' . $this->departmentsSerial[$this->criteria['department']];
} }
if ($this->criteria['subject']) { if ($this->criteria['subject']) {
$summary[] = 'Subject - ' . $this->subjects[$this->criteria['subject']]; $summary[] = 'Subject - ' . $this->subjectsSerial[$this->criteria['subject']];
} }
if ($this->criteria['courseNumber']) { if ($this->criteria['courseNumber']) {
$summary[] = 'Course # - ' . $this->criteria['courseNumber']; $summary[] = 'Course # - ' . $this->criteria['courseNumber'];
......
...@@ -2,11 +2,68 @@ addLoadEvent(onLoadPublicViewSearch); ...@@ -2,11 +2,68 @@ addLoadEvent(onLoadPublicViewSearch);
function onLoadPublicViewSearch() function onLoadPublicViewSearch()
{ {
if (document.getElementById('refineSearchLink')) {
document.getElementById('refineSearchLink').onclick = handleRefineSearchLinkClick; document.getElementById('refineSearchLink').onclick = handleRefineSearchLinkClick;
} }
document.getElementById('college').onchange = handleChangeSelectHierarchy;
document.getElementById('department').onchange = handleChangeSelectHierarchy;
handleChangeSelectHierarchy();
}
function handleRefineSearchLinkClick() function handleRefineSearchLinkClick()
{ {
document.getElementById('searchSummary').style.display = 'none'; document.getElementById('searchSummary').style.display = 'none';
document.getElementById('searchForm').style.display = ''; document.getElementById('searchForm').style.display = '';
} }
function handleChangeSelectHierarchy()
{
var collegeSelect = document.getElementById('college');
var departmentSelect = document.getElementById('department');
var subjectSelect = document.getElementById('subject');
var selectedCollege = collegeSelect.options[collegeSelect.selectedIndex].label;
var optGroups = departmentSelect.getElementsByTagName('optgroup');
for (var i = optGroups.length - 1; i >= 0; i--) {
if (optGroups[i].label == selectedCollege || collegeSelect.value == 0) {
optGroups[i].style.display = ''
} else {
optGroups[i].style.display = 'none';
}
}
var selectedDepartment = departmentSelect.options[departmentSelect.selectedIndex];
if (selectedDepartment.parentNode.style.display == 'none') {
departmentSelect.selectedIndex = 0;
}
var selectedDepartments = new Array();
if (departmentSelect.selectedIndex == 0) {
var options = departmentSelect.getElementsByTagName('option');
for (var i = options.length - 1; i >= 0; i--) {
if (options[i].parentNode.style.display == 'none') {
continue;
}
selectedDepartments.push(options[i].label);
}
} else {
selectedDepartments.push(departmentSelect.options[departmentSelect.selectedIndex].label);
}
optGroups = subjectSelect.getElementsByTagName('optgroup');
for (var i = optGroups.length - 1; i >= 0; i--) {
if (selectedDepartments.inArray(optGroups[i].label) || collegeSelect.value == 0) {
optGroups[i].style.display = ''
} else {
optGroups[i].style.display = 'none';
}
}
var selectedSubject = subjectSelect.options[subjectSelect.selectedIndex];
if (selectedSubject.parentNode.style.display == 'none') {
subjectSelect.selectedIndex = 0;
}
}
...@@ -330,8 +330,17 @@ function showLoading() ...@@ -330,8 +330,17 @@ function showLoading()
} }
//Returns true if the passed value is found in the
//array. Returns false if it is not.
Array.prototype.inArray = function (value)
{
for (var i = this.length - 1; i >= 0; i--) {
if (this[i] == value) {
return true;
}
}
return false;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment