Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactify Assignment History & Allow Editing Assignment Reason #1111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions class/StudentProfileView.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,7 @@ public function show()
/*********
* Assignment History *
*********/
$historyArray = StudentAssignmentHistory::getAssignments($this->student->getBannerId());
$historyView = new StudentAssignmentHistoryView($historyArray);
$tpl['HISTORY'] = $historyView->show();
// All done via react now.


/**********
Expand Down
60 changes: 60 additions & 0 deletions class/command/AjaxEditAssignmentHistoryCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

/**
* Controller class for retrieving the assignment history for a student in JSON format
*
* @author Chris Detsch
* @package hms
*/

class AjaxEditAssignmentHistoryCommand {

public function __construct()
{

}

public function execute()
{
$reason = $_REQUEST['reason'];
$banner = $_REQUEST['bannerId'];
$term = $_REQUEST['term'];

$assignment = HMS_Assignment::getAssignmentByBannerId($banner, $term);
$id = $assignment->getId();

$this->updateAssignmentReason($reason, $id);
$this->updateHistoryReason($reason, $id);

echo json_encode("success");
exit;
}

public function updateAssignmentReason($reason, $id)
{
$db = PdoFactory::getPdoInstance();
$query = 'UPDATE hms_assignment set reason = :newReason where id = :id';
$stmt = $db->prepare($query);

$params = array(
'newReason' => $reason,
'id' => $id
);

$stmt->execute($params);
}

public function updateHistoryReason($reason, $id)
{
$db = PdoFactory::getPdoInstance();
$query = 'UPDATE hms_assignment_history set assigned_reason = :newReason where id = :id';
$stmt = $db->prepare($query);

$params = array(
'newReason' => $reason,
'id' => $id
);

$stmt->execute($params);
}
}
107 changes: 107 additions & 0 deletions class/command/AjaxGetAssignmentHistoryCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

/**
* Controller class for retrieving the assignment history for a student in JSON format
*
* @author Chris Detsch
* @package hms
*/

class AjaxGetAssignmentHistoryCommand {

public function __construct()
{

}

public function execute()
{
$banner = $_REQUEST['banner_id'];
$term = Term::getCurrentTerm();

$student = StudentFactory::getStudentByBannerId($banner, $term);

$history = StudentAssignmentHistory::getAssignments($student->getBannerId());
// var_dump($history);exit;

$historyArray = array();
$currentArray = array();

foreach ($history->getHistory() as $hNode)
{
$row = array();
if(defined($hNode->assigned_reason))
{
$assignedReason = constant($hNode->assigned_reason); // for pretty text purposes
}
else
{
$assignedReason = $hNode->assigned_reason;
}
$row['assignedReason'] = $assignedReason;

if(defined($hNode->removed_reason))
{
$removedReason = constant($hNode->removed_reason); // for pretty text purposes
}
else
{
$removedReason = $hNode->removed_reason;
}
$row['removedReason'] = $removedReason;

if(!is_null($hNode->assigned_on))
{
$assignedOn = date('M jS, Y \a\t g:ia', $hNode->assigned_on);
$assignedBy = $hNode->assigned_by;
}
else
{
$assignedOn = null;
$assignedBy = null;
}
$row['assignedOn'] = $assignedOn;
$row['assignedBy'] = $assignedBy;

if(!is_null($hNode->removed_on))
{
$removedOn = date('M jS, Y \a\t g:ia', $hNode->removed_on);
$removedBy = $hNode->removed_by;
}
else
{
$removedOn = null;
$removedBy = null;
}
$row['removedOn'] = $removedOn;
$row['removedBy'] = $removedBy;

$bed = new HMS_Bed($hNode->getBedId());

$row['room'] = $bed->where_am_i();
$row['term'] = Term::toString($hNode->term);
$row['id'] = $hNode->id;

$historyArray[] = $row;
}

$currentArray['term'] = $term;

$assignment = HMS_Assignment::getAssignmentByBannerId($banner, $term);
if($assignment != null)
{
$currentArray['id'] = $assignment->getId();
}
else
{
$currentArray['id'] = null;
}

$returnData = array();
$returnData['history'] = $historyArray;
$returnData['current'] = $currentArray;

echo json_encode($returnData);
exit;
}
}
Loading