Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
eberhardtm committed Jun 27, 2018
2 parents 57fbfc4 + 613200c commit 8965f2b
Show file tree
Hide file tree
Showing 5 changed files with 9,677 additions and 71 deletions.
1 change: 1 addition & 0 deletions boost/install.sql
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ INSERT INTO intern_subject (id, abbreviation, description) VALUES (nextval('inte
INSERT INTO intern_subject (id, abbreviation, description) VALUES (nextval('intern_subject_seq'),'US','University Studies');
INSERT INTO intern_subject (id, abbreviation, description) VALUES (nextval('intern_subject_seq'),'WGC','Watauga Global Community');
INSERT INTO intern_subject (id, abbreviation, description) VALUES (nextval('intern_subject_seq'),'WS','Women’s Studies');
INSERT INTO intern_subject (id, abbreviation, description) VALUES (nextval('intern_subject_seq'),'PHO','Photography');

CREATE TABLE intern_agency (
id INT NOT NULL,
Expand Down
114 changes: 74 additions & 40 deletions class/UI/ResultsUI.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of Internship Inventory.
*
Expand Down Expand Up @@ -34,7 +35,8 @@
*
* @author Robert Bost <bostrt at tux dot appstate dot edu>
*/
class ResultsUI implements UI {
class ResultsUI implements UI
{

public function display()
{
Expand All @@ -60,7 +62,8 @@ public function display()
$courseSect = null;
$oied = null;
$faculty = null;

$startDate = null;
$endDate = null;

/**
* Check if any search fields are set.
Expand Down Expand Up @@ -100,15 +103,25 @@ public function display()
$oied = $_REQUEST['oied'];
if (isset($_REQUEST['faculty_id']))
$faculty = $_REQUEST['faculty_id'];

/* Get Pager */
$pager = self::getPager($name, $dept, $term, $ugradMajor, $gradProg, $level, $type, $campus, $loc, $state, $country, $workflowState, $courseSubject, $courseNum, $courseSect, $oied, $faculty);
if (isset($_REQUEST['start_date'])) {
$startDate = $_REQUEST['start_date'];
}
if (isset($_REQUEST['end_date'])) {
$endDate = $_REQUEST['end_date'];
}
/* Get Pager */
$pager = self::getPager($name, $dept, $term, $ugradMajor, $gradProg,
$level, $type, $campus, $loc, $state, $country,
$workflowState, $courseSubject, $courseNum, $courseSect,
$oied, $faculty, $startDate, $endDate);

$pagerContent = $pager->get();


// If there were no results, send the user back to the search interface
if (sizeof($pager->display_rows) == 0) {
\NQ::simple('intern', NotifyUI::WARNING, "There were no internships that matched your search criteria. If you're looking for a specific student double check the student's name, id number, or email address. Otherwise, try selecting less search criteria and then search again.");
\NQ::simple('intern', NotifyUI::WARNING,
"There were no internships that matched your search criteria. If you're looking for a specific student double check the student's name, id number, or email address. Otherwise, try selecting less search criteria and then search again.");
\NQ::close();

// Rebuild the URL
Expand All @@ -128,9 +141,16 @@ public function display()
* Get the DBPager object.
* Search strings can be passed in too.
*/
private static function getPager($name = null, $deptId = null, $term = null, $ugradMajor = null, $gradProg = null, $level = null, $type = null, $campus = null, $loc = null, $state = null, $country = null, $workflowState = null, $courseSubject = null, $courseNum = null, $courseSect = null, $oied = null, $faculty = null)

private static function getPager($name = null, $deptId = null, $term = null,
$ugradMajor = null, $gradProg = null, $level = null, $type = null,
$campus = null, $loc = null, $state = null, $country = null,
$workflowState = null, $courseSubject = null, $courseNum = null,
$courseSect = null, $oied = null, $faculty = null,
$startDate = null, $endDate = null)
{
$pager = new SubselectPager('intern_internship', '\Intern\InternshipRestored');
$pager = new SubselectPager('intern_internship',
'\Intern\InternshipRestored');

// Pager Settings
$pager->setModule('intern');
Expand All @@ -144,9 +164,12 @@ private static function getPager($name = null, $deptId = null, $term = null, $ug

// If the current user is not a deity and doesn't have the 'all_departments' permission,
// then add a join to limit the results to just the allowed departments
if (!\Current_User::isDeity() && !\Current_User::allow('intern', 'all_departments')) {
$pager->db->addJoin('', 'fuzzy', 'intern_admin', 'department_id', 'department_id');
$pager->addWhere('intern_admin.username', \Current_User::getUsername());
if (!\Current_User::isDeity() && !\Current_User::allow('intern',
'all_departments')) {
$pager->db->addJoin('', 'fuzzy', 'intern_admin', 'department_id',
'department_id');
$pager->addWhere('intern_admin.username',
\Current_User::getUsername());
}

// Limit to requested department
Expand Down Expand Up @@ -179,11 +202,9 @@ private static function getPager($name = null, $deptId = null, $term = null, $ug
* Fuzzy Search Settings
*/
$tokenLimit = 2; // Max number of tokens

// The fields (db column names) to fuzzy match against, in decreasing order of importance
// $fuzzyFields = array('last_name', 'first_name', 'middle_name'); //NB: Unused
$fuzzyTolerance = 3; // Levenshtein distance allowed between the metaphones of a token and a $fuzzyField

// Initalization
$orderByList = array();

Expand All @@ -195,8 +216,8 @@ private static function getPager($name = null, $deptId = null, $term = null, $ug
while ($token !== false && $tokenCount < $tokenLimit) {
$tokenCount++;
$tokens[] = trim(strtolower($token)); // NB: must be lowercase!
// tokenize on newline, tab, comma, space
// NB: Don't pass in the string to strtok after the first call above
// tokenize on newline, tab, comma, space
// NB: Don't pass in the string to strtok after the first call above
$token = strtok("\n\t, ");
}

Expand All @@ -209,8 +230,10 @@ private static function getPager($name = null, $deptId = null, $term = null, $ug
$fuzzyDb->addColumnRaw("LEAST(levenshtein('{$tokens[$i]}', lower(last_name)),levenshtein('{$tokens[$i]}', lower(first_name))) as t{$i}_lev");
$fuzzyDb->addColumnRaw("LEAST(levenshtein(metaphone('{$tokens[$i]}', 10), last_name_meta),levenshtein(metaphone('{$tokens[$i]}', 10), first_name_meta)) as t{$i}_metalev");

$pager->db->addWhere("fuzzy.t{$i}_lev", 3, '<', 'OR', 'lev_where');
$pager->db->addWhere("fuzzy.t{$i}_metalev", $fuzzyTolerance, '<', 'OR', 'metaphone_where');
$pager->db->addWhere("fuzzy.t{$i}_lev", 3, '<', 'OR',
'lev_where');
$pager->db->addWhere("fuzzy.t{$i}_metalev", $fuzzyTolerance,
'<', 'OR', 'metaphone_where');

// Add order for this token's *_metalev fields
$orderByList[] = "fuzzy.t{$i}_lev";
Expand All @@ -224,30 +247,34 @@ private static function getPager($name = null, $deptId = null, $term = null, $ug
$pager->db->addSubSelect($fuzzyDb, 'fuzzy');
}

$pager->db->addJoin('LEFT OUTER', 'fuzzy', 'intern_faculty', 'faculty_id', 'id');
$pager->db->addJOIN('LEFT OUTER', 'fuzzy', 'intern_department', 'department_id', 'id');
$pager->db->addJoin('LEFT OUTER', 'fuzzy', 'intern_faculty',
'faculty_id', 'id');
$pager->db->addJOIN('LEFT OUTER', 'fuzzy', 'intern_department',
'department_id', 'id');

// Student level
if (isset($level)) {
$sLevel = LevelFactory::getLevelObjectByLevel($level);
if($level == Level::UNDERGRAD){
for($i = 0; $i < count($sLevel); $i++) {
$pager->addWhere('level', $sLevel[$i]->code, null, 'OR', 'grad_level');
if ($level == Level::UNDERGRAD) {
for ($i = 0; $i < count($sLevel); $i++) {
$pager->addWhere('level', $sLevel[$i]->code, null, 'OR',
'grad_level');
}
} else if ($level == Level::GRADUATE) {
for($i = 0; $i < count($sLevel); $i++){
$pager->addWhere('level', $sLevel[$i]->code, null, 'OR', 'grad_level');
for ($i = 0; $i < count($sLevel); $i++) {
$pager->addWhere('level', $sLevel[$i]->code, null, 'OR',
'grad_level');
}
}
}

// Major
if ($level == Level::UNDERGRAD && isset($ugradMajor) && $ugradMajor != -1) {
// Undergrad major
$pager->addWhere('major_code', $ugradMajor);
} else if ($level == Level::GRADUATE && isset($gradProg) && $gradProg != -1) {
// Graduate program
$pager->addWhere('major_code', $gradProg);
}
// Major
if ($level == Level::UNDERGRAD && isset($ugradMajor) && $ugradMajor != -1) {
// Undergrad major
$pager->addWhere('major_code', $ugradMajor);
} else if ($level == Level::GRADUATE && isset($gradProg) && $gradProg != -1) {
// Graduate program
$pager->addWhere('major_code', $gradProg);
}

// Experience type
Expand Down Expand Up @@ -296,7 +323,8 @@ private static function getPager($name = null, $deptId = null, $term = null, $ug
if (isset($workflowState)) {
foreach ($workflowState as $s) {
$path = explode('\\', $s);
$pager->db->addWhere('state', $path[2], '=', 'OR', 'workflow_group');
$pager->db->addWhere('state', $path[2], '=', 'OR',
'workflow_group');
}
}

Expand All @@ -305,18 +333,22 @@ private static function getPager($name = null, $deptId = null, $term = null, $ug
$pager->db->addWhere('oied_certified', $oied, '=');
}

if (!empty($faculty)){
if (!empty($faculty)) {
$pager->addWhere('faculty_id', $faculty);
}

//$pager->db->setTable(array('fuzzy'));
if (!empty($startDate)) {
$pager->addWhere('start_date', strtotime($startDate), '>=', 'AND',
'date_group');
}

//var_dump($pager);exit;
//$pager->db->setTestMode();
//$pager->db->select();
if (!empty($endDate)) {
$pager->addWhere('end_date', strtotime($endDate), '<=', 'AND',
'date_group');
}

/**
* * Sort Headers **
* Sort Headers
*/
$pager->setAutoSort(false);
$pager->addSortHeader('term', 'Term');
Expand All @@ -339,11 +371,13 @@ private static function getPager($name = null, $deptId = null, $term = null, $ug
* *** Other Page Tags *****
*/
$pageTags = array();
$pageTags['BACK_LINK_URI'] = \PHPWS_Text::linkAddress('intern', array('action' => 'search'));
$pageTags['BACK_LINK_URI'] = \PHPWS_Text::linkAddress('intern',
array('action' => 'search'));


$pager->addPageTags($pageTags);

return $pager;
}

}
13 changes: 9 additions & 4 deletions class/UI/SearchUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ public function display()
// Hidden field for selected faculty member
$form->addHidden('faculty_id');

// Student level radio button, Undergrad major drop down, Graduate major drop down
// Are all handled in JSX

/*******************
* Internship Type *
*******************/
Expand All @@ -140,10 +137,18 @@ public function display()

// State & Country search handeled in-browser


/*******************
* Workflow States *
*******************/
// Date Range
$form->addText('start_date');
$form->setLabel('start_date', 'Starting After');
$form->addCssClass('start_date', 'form-control');

$form->addText('end_date');
$form->setLabel('end_date', 'Ending Before');
$form->addCssClass('end_date', 'form-control');

$workflowStates = WorkflowStateFactory::getStatesAssoc();
unset($workflowStates['Intern\WorkflowState\CreationState']); // Remove this state, since it's not valid (internal only state for initial creation)
$form->addCheckAssoc('workflow_state', $workflowStates);
Expand Down
Loading

2 comments on commit 8965f2b

@jlbooker
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9k additions? What is 'internlog.txt'?

@eberhardtm
Copy link
Collaborator Author

@eberhardtm eberhardtm commented on 8965f2b Jun 27, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.