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

Added react components to allow the admin to update the room change b… #1049

Closed
Closed
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
34 changes: 27 additions & 7 deletions class/BedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,44 @@
* @package hms
*/
class BedFactory {

public static function getBedByPersistentId($persistentId, $term)
{
PHPWS_Core::initModClass('hms', 'PdoFactory.php');
PHPWS_Core::initModClass('hms', 'HMS_Bed.php');

$db = PdoFactory::getPdoInstance();

$query = "select * from hms_bed where persistent_id = :persistentId AND term = :term";
$stmt = $db->prepare($query);

$params = array(
'persistentId' => $persistentId,
'term' => $term);
$stmt->execute($params);


$results = $stmt->fetchAll(PDO::FETCH_CLASS, 'BedRestored');

return $results[0];
}

public static function getBedByTermWithId($term, $id)
{
PHPWS_Core::initModClass('hms', 'PdoFactory.php');
PHPWS_Core::initModClass('hms', 'HMS_Bed.php');

$db = PdoFactory::getPdoInstance();

$query = "select * from hms_bed where id = :id AND term = :term";
$stmt = $db->prepare($query);

$params = array(
'id' => $id,
'term' => $term);
$stmt->execute($params);

$results = $stmt->fetchAll(PDO::FETCH_CLASS, 'BedRestored');

return $results[0];
}
}
}
31 changes: 27 additions & 4 deletions class/RoomChangeParticipantView.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ public function show()
$tpl['FROM_ROOM'] = $fromBed->where_am_i();

// To bed
$currentToBed = -1;
$toBedId = $this->participant->getToBed();
if (isset($toBedId)) {
// If there's already a bed set, show the selected bed
$toBed = new HMS_Bed($toBedId);
$tpl['TO_ROOM'] = $toBed->where_am_i();
$currentToBed = $toBed->getId();
}




/**
* Check to see if the state is already approved or completed
*/
Expand All @@ -101,6 +106,8 @@ public function show()

if ($particpantState instanceof ParticipantStateNew) {
// Particpant is in new state, waiting on this student'a approval
javascript('jquery');
javascriptMod('hms', 'roomChangeDestination', array('PARTICIPANT_ID' => $this->participant->getId()));

// If the student is logged in, or the user is an admin, show the approve button
if(UserStatus::getUsername() == $this->student->getUsername()
Expand All @@ -126,6 +133,7 @@ public function show()
// If current user is an RD for the "from bed" or an admin
if (in_array(UserStatus::getUsername(), $rds) || Current_User::allow('hms', 'admin_approve_room_change')) {


if (!isset($toBedId) && count($this->participants) == 1) {
/*
* If there's only one particpant and the toBed is not already set,
Expand All @@ -135,10 +143,14 @@ public function show()
* For swaps, the destination bed is already known and is not editable.
*/
// Show the "select a bed" dialog, values are loaded via AJAX
$form->addDropBox('bed_select', array(
'-1' => 'Loading...'
));
$form->addHidden('gender', $this->student->getGender());

javascript('jquery');
javascriptMod('hms', 'roomChange', array('CURRENT_TO_BED' => $currentToBed, 'GENDER'=>$this->student->getGender(), 'PARTICIPANT_ID' => $this->participant->getId()));
}
else {

javascript('jquery');
javascriptMod('hms', 'roomChangeDestination', array('PARTICIPANT_ID' => $this->participant->getId()));
}

$approveCmd = CommandFactory::getCommand('RoomChangeCurrRdApprove');
Expand All @@ -152,6 +164,8 @@ public function show()
$tpl['APPROVE_BTN'] = ''; // dummy tag for approve button
}
} else if ($particpantState instanceof ParticipantStateCurrRdApproved) {
javascript('jquery');
javascriptMod('hms', 'roomChangeDestination', array('PARTICIPANT_ID' => $this->participant->getId()));
// Current RD has approved, Future RD needs to approve
// If current user if future RD or admin, show the approve button

Expand All @@ -172,6 +186,14 @@ public function show()
$tpl['APPROVE_BTN'] = '';
}
}
else if ($particpantState instanceof ParticipantStateFutureRdApproved)
{
if (count($this->participants) == 1) {
javascript('jquery');
javascriptMod('hms', 'roomChange', array('CURRENT_TO_BED' => $currentToBed, 'GENDER'=>$this->student->getGender(), 'PARTICIPANT_ID' => $this->participant->getId()));
}
}


// Show the edit link for to room if request type is a "switch", user has permissions, and status allows it
// TODO
Expand All @@ -192,6 +214,7 @@ public function show()

$tpl['history_rows'] = $stateRows;


return PHPWS_Template::process($tpl, 'hms', 'admin/roomChangeParticipantView.tpl');
}
}
4 changes: 1 addition & 3 deletions class/command/RoomChangeCurrRdApproveCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function execute(CommandContext $context)
// has just selected a bed
$toBedId = $participant->getToBed();

if (is_null($toBedId) && $toBedSelected == '-1') {
if (is_null($toBedId)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Please select a destination bed.');
$cmd->redirect();
}
Expand Down Expand Up @@ -115,5 +115,3 @@ public function execute(CommandContext $context)
$cmd->redirect();
}
}


64 changes: 64 additions & 0 deletions class/command/RoomChangeListAvailableBedsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* Returns a JSON-encoded list of empty beds.
*
* @author jbooker
* @package hms
*/

class RoomChangeListAvailableBedsCommand extends Command {

public function getRequestVars()
{
return array('action'=>'RoomChangeListAvailableBeds');
}

public function execute(CommandContext $context)
{
$term = Term::getCurrentTerm();

$gender = $context->get('gender');



if(!isset($gender)){
echo "Missing gender!";
}

$db = PdoFactory::getPdoInstance();

$query = "select hms_bed.id, hall_name, room_number
FROM hms_bed
JOIN hms_room ON hms_bed.room_id = hms_room.id
JOIN hms_floor ON hms_room.floor_id = hms_floor.id
JOIN hms_residence_hall ON hms_floor.residence_hall_id = hms_residence_hall.id
LEFT OUTER JOIN hms_assignment ON hms_assignment.bed_id = hms_bed.id
LEFT OUTER JOIN hms_checkin ON hms_checkin.bed_persistent_id = hms_bed.persistent_id
WHERE
hms_bed.term = :term and
hms_assignment.bed_id IS NULL and
(hms_room.default_gender = :gender OR hms_room.default_gender = 3) and
offline = 0 and
overflow = 0 and
parlor = 0 and
ra_roommate = 0 and
private = 0 and
reserved = 0 and
room_change_reserved = 0 and
(checkin_date IS NULL OR checkout_date IS NOT NULL)
ORDER BY hall_name, room_number";

$stmt = $db->prepare($query);

$params = array(
'term' => $term,
'gender' => $gender
);

$stmt->execute($params);

echo json_encode($stmt->fetchAll(PDO::FETCH_ASSOC));
exit;
}
}
69 changes: 69 additions & 0 deletions class/command/RoomChangeRetrieveDetailsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

PHPWS_Core::initModClass('hms', 'RoomChangeRequestFactory.php');
PHPWS_Core::initModClass('hms', 'RoomChangeParticipantFactory.php');
PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
PHPWS_Core::initModClass('hms', 'HMS_Email.php');

/**
* Command to get the data that may change about a room change request
*
* @author Chris Detsch
* @package hms
*/
class RoomChangeRetrieveDetailsCommand extends Command {

private $participantId;

public function setParticipantId($id)
{
$this->participantId = $id;
}

public function getRequestVars()
{
return array('action' => 'RoomChangeRetrieveDetails',
'participantId' => $this->participantId);
}

public function execute(CommandContext $context)
{
$term = Term::getCurrentTerm();

$this->setParticipantId($context->get('participantId'));

$db = PdoFactory::getPdoInstance();

$query = "select from_bed, to_bed from hms_room_change_participant where id = :participantId";

$stmt = $db->prepare($query);

$params = array(
'participantId' => $this->participantId
);

$stmt->execute($params);

$results = $stmt->fetchAll(PDO::FETCH_ASSOC);

$results = $results[0];

$from = $results['from_bed'];
$from = BedFactory::getBedByTermWithId($term, $from)->where_am_i();

if($results['to_bed'] != NULL)
{
$to = $results['to_bed'];
$to = BedFactory::getBedByTermWithId($term, $to)->where_am_i();
}
else {
$to = "TBD";
}

$results['from'] = $from;
$results['to'] = $to;

echo json_encode($results);
exit;
}
}
81 changes: 81 additions & 0 deletions class/command/RoomChangeSetToBedCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

PHPWS_Core::initModClass('hms', 'RoomChangeRequestFactory.php');
PHPWS_Core::initModClass('hms', 'RoomChangeParticipantFactory.php');
PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
PHPWS_Core::initModClass('hms', 'HMS_Email.php');

/**
* Command for current RD or Admin to set the to bed for a room change participant.
*
* @author Chris Detsch
* @package hms
*/
class RoomChangeSetToBedCommand extends Command {

private $participantId;
private $bedId;
private $oldBedId;


public function setParticipantId($id)
{
$this->participantId = $id;
}

public function setBedId($id)
{
$this->bedId = $id;
}

public function setOldBed($id)
{
$this->oldBedId = $id;
}

public function getRequestVars()
{
return array('action' => 'RoomChangeSetToBed',
'participantId' => $this->participantId,
'bedId' => $this->bedId,
'oldBedId' => $this->oldBed);
}

public function execute(CommandContext $context)
{
$this->setParticipantId($context->get('participantId'));
$this->setBedId($context->get('bedId'));
$this->setOldBed($context->get('oldBed'));

$bed = new HMS_Bed($this->bedId);
if($this->oldBedId != -1)
{
$oldBed = new HMS_Bed($this->oldBedId);
}
// Load the participant
$participant = RoomChangeParticipantFactory::getParticipantById($this->participantId);

// Check that the bed isn't already reserved for a room change
if($bed->isRoomChangeReserved()){
NQ::simple('hms' , hms\NotificationView::ERROR, 'The bed you selected is already reserved for a room change. Please choose a different bed.');
$cmd->redirect();
}


// Reserve the bed for room change
$bed->setRoomChangeReserved();
$bed->save();


if($this->oldBedId != -1)
{
$oldBed->clearRoomChangeReserved();
$oldBed->save();
}

// Save the bed to this participant
$participant->setToBed($bed);
$participant->save();
$context->setContent(json_encode(''));
}
}
Loading