Skip to content

Commit

Permalink
Merge branch 'EditTerms' of https://github.com/oliviaperugini/Interns…
Browse files Browse the repository at this point in the history
…hipInventory into oliviaperugini-EditTerms
  • Loading branch information
Stardog committed Jul 11, 2018
2 parents bfd5106 + 08d45db commit e97cbb0
Show file tree
Hide file tree
Showing 13 changed files with 13,527 additions and 20 deletions.
7 changes: 7 additions & 0 deletions boost/updates/update_00.04.00.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
UPDATE intern_term SET undergrad_overload_hours=18 WHERE ((undergrad_overload_hours IS NULL) AND (semester_type=1 OR semester_type=4));
UPDATE intern_term SET undergrad_overload_hours=7 WHERE ((undergrad_overload_hours IS NULL) AND (semester_type=2 OR semester_type=3));
UPDATE intern_term SET grad_overload_hours=12 WHERE ((grad_overload_hours IS NULL) AND (semester_type=1 OR semester_type=4));
UPDATE intern_term SET grad_overload_hours=6 WHERE ((grad_overload_hours IS NULL) AND (semester_type=2 OR semester_type=3));

ALTER TABLE intern_term ALTER COLUMN undergrad_overload_hours SET NOT NULL;
ALTER TABLE intern_term ALTER COLUMN grad_overload_hours SET NOT NULL;
155 changes: 155 additions & 0 deletions class/Command/TermRest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php

namespace Intern\Command;
use \phpws2\Database;

class TermRest {

public function execute() {

switch ($_SERVER['REQUEST_METHOD']) {
case 'POST':
$this->post();
exit;
case 'GET':
$data = $this->get();
echo (json_encode($data));
exit;
case 'PUT':
$this->put();
exit;
default:
header('HTTP/1.1 405 Method Not Allowed');
exit;
}
}

// For adding a term.
// Need to enter: term_code, census date, description,
// available date, start date, end date, semester type,
// undergrad overload hours, grad overload hours.
public function post() {
$code = $_REQUEST['code'];
$census = $_REQUEST['census'];
$descr = $_REQUEST['descr'];
$available = $_REQUEST['available'];
$start = $_REQUEST['start'];
$end = $_REQUEST['end'];
$type = $_REQUEST['type'];
$ugradOver = $_REQUEST['ugradOver'];
$gradOver = $_REQUEST['gradOver'];


if ($code == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing a term code.");
exit;
}
if ($census == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing a census date.");
exit;
}
if ($descr == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing a term description.");
exit;
}
if ($available == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing an available date.");
exit;
}
if ($start == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing a start date.");
exit;
}
if ($end == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing an end date.");
exit;
}
if ($type == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing a semester type.");
exit;
}
if ($ugradOver == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing undergraduate overload hours.");
exit;
}
if ($gradOver == '') {
header('HTTP/1.1 500 Internal Server Error');
echo("Missing graduate overload hours.");
exit;
}

$db = Database::newDB();
$pdo = $db->getPDO();

$sql = "INSERT INTO intern_term (term, census_date_timestamp,
description, available_on_timestamp, start_timestamp,
end_timestamp, semester_type, undergrad_overload_hours,
grad_overload_hours)
VALUES (:code, :census, :descr, :available, :start, :end_date,
:type, :ugradOver, :gradOver)";

$sth = $pdo->prepare($sql);

$sth->execute(array('code'=>$code, 'census'=>$census, 'descr'=>$descr,
'available'=>$available, 'start'=>$start,
'end_date'=>$end, 'type'=>$type, 'ugradOver'=>$ugradOver,
'gradOver'=>$gradOver));
}

public function get() {

$db = Database::newDB();
$pdo = $db->getPDO();

$sql = "SELECT term, description, available_on_timestamp,
census_date_timestamp, start_timestamp, end_timestamp,
semester_type, undergrad_overload_hours, grad_overload_hours
FROM intern_term ORDER BY term DESC";

$sth = $pdo->prepare($sql);
$sth->execute();
$result = $sth->fetchAll(\PDO::FETCH_ASSOC);

return $result;
}

public function put() {
$newTcode = $_REQUEST['newTcode'];
$newSemtype = $_REQUEST['newSemtype'];
$newDesc = $_REQUEST['newDesc'];
$newCensus = $_REQUEST['newCensus'];
$newAvail = $_REQUEST['newAvail'];
$newStart = $_REQUEST['newStart'];
$newEnd = $_REQUEST['newEnd'];
$newUgradOver = $_REQUEST['newUgradOver'];
$newGradOver = $_REQUEST['newGradOver'];
$oldTcode = $_REQUEST['oldTcode'];

$db = Database::newDB();
$pdo = $db->getPDO();

$sql = "UPDATE intern_term
SET term=:newTcode, semester_type=:newSemtype,
description=:newDesc, census_date_timestamp=:newCensus,
available_on_timestamp=:newAvail, start_timestamp=:newStart,
end_timestamp=:newEnd, undergrad_overload_hours=:newUgradOver,
grad_overload_hours=:newGradOver
WHERE term=:oldTcode";

$sth = $pdo->prepare($sql);
$sth->execute(array('newTcode'=>$newTcode, 'newSemtype'=>$newSemtype, 'newDesc'=>$newDesc,
'newCensus'=>$newCensus, 'newAvail'=>$newAvail, 'newStart'=>$newStart,
'newEnd'=>$newEnd, 'newUgradOver'=>$newUgradOver, 'newGradOver'=>$newGradOver,
'oldTcode'=>$oldTcode));


}
}
26 changes: 22 additions & 4 deletions class/InternshipInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ public function handleRequest()
$view = new UI\StudentLevelUI();
$this->content = $view->display();
break;
case 'edit_terms':
if (!\Current_User::allow('intern', 'edit_terms')) {
disallow();
}
$view = new UI\TermUI();
$this->content = $view->display();
break;
case 'showEditAdmins':
$view = new UI\AdminUI();
$this->content = $view->display();
Expand All @@ -200,6 +207,13 @@ public function handleRequest()
$view = new UI\CoursesUI();
$this->content = $view->display();
break;
case 'edit_terms':
if (!\Current_User::allow('intern', 'edit_terms')) {
disallow();
}
$view = new UI\TermUI();
$this->content = $view->display();
break;
case 'pdf':
$i = InternshipFactory::getInternshipById($_REQUEST['internship_id']);
$emgContacts = EmergencyContactFactory::getContactsForInternship($i);
Expand Down Expand Up @@ -279,6 +293,14 @@ public function handleRequest()
$ctrl = new Command\AdminRest();
$ctrl->execute();
break;
case 'levelRest':
$ctrl = new Command\LevelRest();
$ctrl->execute();
break;
case 'termRest':
$ctrl = new Command\TermRest();
$ctrl->execute();
break;
case 'majorRest':
$ctrl = new Command\MajorRest();
$ctrl->execute();
Expand All @@ -295,10 +317,6 @@ public function handleRequest()
$ctrl = new Command\StateRest();
$ctrl->execute();
break;
case 'levelRest':
$ctrl = new Command\LevelRest();
$ctrl->execute();
break;
case 'emergencyContactRest':
$ctrl = new Command\EmergencyContactRest();
$ctrl->execute();
Expand Down
22 changes: 10 additions & 12 deletions class/Student.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ class Student {
const MAIN_CAMPUS = 'main_campus';
const DISTANCE_ED = 'distance_ed';

const HOURS_LIMIT_UNDERGRAD_REG = 18;
const HOURS_LIMIT_UNDERGRAD_SUMMER = 7;

const HOURS_LIMIT_GRADUATE_REG = 12;
const HOURS_LIMIT_GRADUATE_SUMMER = 6;

// Basic demographics
private $studentId;
private $username;
Expand Down Expand Up @@ -89,19 +83,23 @@ public function isCreditHourLimited(int $internHours, int $existingHours, Term $
$semester = $term->getSemesterType();
$code = $this->getLevel();
$limit = 0;
$level = LevelFactory::getLevelObjectById($code);
if(($semester == Term::FALL || $semester == Term::SPRING)) {
if($level->getLevel() == Level::UNDERGRAD){
/*if(($semester == Term::FALL || $semester == Term::SPRING)) {
if($level == self::UNDERGRAD){
$limit = self::HOURS_LIMIT_UNDERGRAD_REG;
} else if($level->getLevel() == Level::GRADUATE){
} else {
$limit = self::HOURS_LIMIT_GRADUATE_REG;
}
} else if (($semester == Term::SUMMER1 || $semester == Term::SUMMER2)) {
if($level->getLevel() == Level::UNDERGRAD){
if($level == self::UNDERGRAD){
$limit = self::HOURS_LIMIT_UNDERGRAD_SUMMER;
} else if($level->getLevel() == Level::GRADUATE){
} else {
$limit = self::HOURS_LIMIT_GRADUATE_SUMMER;
}
}*/
if ($level == self::UNDERGRAD) {
$limit = $term->getUndergradOverloadHours();
} else if {
$limit = $term->getGradOverloadHours();
}

if($totalHours > $limit){
Expand Down
15 changes: 13 additions & 2 deletions class/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class Term {
public $start_timestamp;
public $end_timestamp;
public $semester_type; // The type of semester this is. E.g. Fall, Spring, Summer 1, Summer 2. See class constants below.

public $undergrad_overload_hours;
public $grad_overload_hours;

// Semester constants. For general "time of year". NB: There can be multiple terms for a given semster.
const SPRING = 1;
Expand All @@ -51,14 +52,16 @@ class Term {
const FALL = 4;


public function __construct(string $term, string $description, int $availableOnTimestamp, int $censusDateTimestamp, int $startTimestamp, int $endTimestamp)
public function __construct(string $term, string $description, int $availableOnTimestamp, int $censusDateTimestamp, int $startTimestamp, int $endTimestamp, int $undergradOverloadHours, int $gradOverloadHours)
{
$this->term = $term;
$this->description = $description;
$this->available_on_timestamp = $availableOnTimestamp;
$this->census_date_timestamp = $censusDateTimestamp;
$this->start_timestamp = $startTimestamp;
$this->end_timestamp = $endTimestamp;
$this->undergrad_overload_hours = $undergradOverloadHours;
$this->grad_overload_hours = $gradOverloadHours;
}

public function getTermCode(): string {
Expand Down Expand Up @@ -94,4 +97,12 @@ public function getSemesterType(): int{
public function getCensusDateTimestamp(): int {
return $this->census_date_timestamp;
}

public function getUndergradOverloadHours(): int {
return $this->undergrad_overload_hours;
}

public function getGradOverloadHours(): int {
return $this->grad_overload_hours;
}
}
28 changes: 28 additions & 0 deletions class/UI/TermUI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Intern\UI;

use \Intern\AssetResolver;

/**
* Class for handing UI for Term editing and creation
* @author Olivia Perugini <peruginioc at appstate dot edu>
**/
class TermUI implements UI {

public function display() {

// permissions, if needed ?
//if(!\Current_User::allow('intern', 'edit_terms')){
// \NQ::simple('intern', NotifyUI::WARNING, 'You do not have permission to edit terms.');
// return false;
//}

$tpl = array();
$tpl['vendor_bundle'] = AssetResolver::resolveJsPath('assets.json', 'vendor');
$tpl['entry_bundle'] = AssetResolver::resolveJsPath('assets.json', 'editTerms');
//$tpl['S']

return \PHPWS_Template::process($tpl, 'intern', 'edit_terms.tpl');
}
}
5 changes: 5 additions & 0 deletions class/UI/TopUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public static function plug()
// Edit list of student levels
if(\Current_User::allow('intern', 'edit_level')){
$adminOptions['EDIT_STUDENT_LEVEL'] = \PHPWS_Text::secureLink('Edit Student Levels','intern',array('action' => 'edit_level'));

}
// Edit terms
if(\Current_User::allow('intern', 'edit_terms')){
$adminOptions['EDIT_TERMS_LINK'] = \PHPWS_Text::secureLink('Edit Terms','intern',array('action' => 'edit_terms'));
}

// Link to the Affiliation Agreements
Expand Down
1 change: 1 addition & 0 deletions entryPoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
editExpectedCourses: JS_DIR + '/editCourses/courseEditor.jsx',
majorSelector: JS_DIR + '/majorSelector/MajorSelector.jsx',
adminSettings: JS_DIR + '/settings/settings.jsx',
editTerms: JS_DIR + '/editTerms/EditTerms.jsx',
vendor: ['jquery', 'react', 'react-dom', 'react-bootstrap']
}
}
Loading

0 comments on commit e97cbb0

Please sign in to comment.