public function execute(CommandContext $context) { $requestId = $context->get('requestId'); $reason = $context->get('cancel-reason'); // Load the request $request = RoomChangeRequestFactory::getRequestById($requestId); // TODO Check permissions, based on state // Command for redirecting back to the request view on success or error $cmd = CommandFactory::getCommand('ShowManageRoomChange'); $cmd->setRequestId($request->getId()); // Make sure user gave a reason if (!isset($reason) or $reason == '') { NQ::simple('hms', hms\NotificationView::ERROR, 'Please enter a cancellation reason.'); $cmd->redirect(); } // Set the denied reason $request->setDeniedReasonPublic($reason); $request->save(); // Transition request to cancelled status $request->transitionTo(new RoomChangeStateCancelled($request, time(), null, UserStatus::getUsername())); // Transition all participants to cancelled // TODO... Do this in the cancelled transition? $participants = $request->getParticipants(); foreach ($participants as $p) { $p->transitionTo(new ParticipantStateCancelled($p, time(), null, UserStatus::getUsername())); //Release the bed reservation, if any $bedId = $p->getToBed(); if ($bedId != null) { $bed = new HMS_Bed($bedId); $bed->clearRoomChangeReserved(); $bed->save(); } } // Notify everyone involved try { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $request->getTerm()); } catch (StudentNotFoundException $e) { $student = null; } PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::sendRoomChangeCancelledNotice($request, $student); $cmd->redirect(); }
public function execute(CommandContext $context) { if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_attributes')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to edit beds.'); } PHPWS_Core::initModClass('hms', 'HMS_Bed.php'); $bedId = $context->get('bedId'); $viewCmd = CommandFactory::getCommand('EditBedView'); $viewCmd->setBedId($bedId); // Check that the Banner bed ID is valid (five digits) $bannerBedId = trim($context->get('banner_id')); if (!is_numeric($bannerBedId) || !preg_match("/\\d{5}/", $bannerBedId)) { NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid Banner bed ID. No changes were saved.'); $viewCmd->redirect(); } # Create the bed object given the bed_id $bed = new HMS_Bed($bedId); if (!$bed) { NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid bed.'); $viewCmd->redirect(); } $bed->bedroom_label = $context->get('bedroom_label'); $bed->phone_number = $context->get('phone_number'); $bed->banner_id = $context->get('banner_id'); $context->get('ra_roommate') == 1 ? $bed->ra_roommate = 1 : ($bed->ra_roommate = 0); $context->get('international_reserved') == 1 ? $bed->international_reserved = 1 : ($bed->international_reserved = 0); $context->get('ra') == 1 ? $bed->ra = 1 : ($bed->ra = 0); $result = $bed->save(); if (!$result || PHPWS_Error::logIfError($result)) { NQ::simple('hms', hms\NotificationView::ERROR, 'Error: There was a problem while saving the bed. No changes were made'); $viewCmd->redirect(); } NQ::simple('hms', hms\NotificationView::SUCCESS, 'The room was updated successfully.'); $viewCmd->redirect(); }
public static function addBed($roomId, $term, $bedLetter, $bedroomLabel, $phoneNumber, $bannerId, $raRoommate, $intlReserved, $raBed, $persistentId) { // Check permissions if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_structure')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to add a bed.'); } if ($raBed != 0 && $raBed != 1) { throw new InvalidArgumentException('Invalid RA bed flag.'); } // Create a new bed object $bed = new HMS_Bed(); $bed->room_id = $roomId; $bed->term = $term; $bed->bed_letter = $bedLetter; $bed->bedroom_label = $bedroomLabel; $bed->banner_id = $bannerId; $bed->phone_number = $phoneNumber; $bed->ra = $raBed; $bed->ra_roommate = $raRoommate; $bed->international_reserved = $intlReserved; $bed->persistent_id = $persistentId; try { $bed->save(); } catch (DatabaseException $e) { throw $e; } return true; }
public function execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); $participantId = $context->get('participantId'); // destinationBedId - This can be null for "swap" requests, because it's already known $toBedSelected = $context->get('bed_select'); // Command for showing the request, redirected to on success/error $cmd = CommandFactory::getCommand('ShowManageRoomChange'); $cmd->setRequestId($requestId); // Load the request $request = RoomChangeRequestFactory::getRequestById($requestId); // Load the participant $participant = RoomChangeParticipantFactory::getParticipantById($participantId); // Check permissions. Must be an RD for current bed, or an admin $rds = $participant->getCurrentRdList(); if (!in_array(UserStatus::getUsername(), $rds) && !Current_User::allow('hms', 'admin_approve_room_change')) { throw new PermissionException('You do not have permission to approve this room change.'); } // Check that a destination bed has already been set, or that the RD // has just selected a bed $toBedId = $participant->getToBed(); if (is_null($toBedId) && $toBedSelected == '-1') { NQ::simple('hms', hms\NotificationView::ERROR, 'Please select a destination bed.'); $cmd->redirect(); } // Set the selected bed, if needed if (is_null($toBedId) && $toBedSelected != '-1') { $bed = new HMS_Bed($toBedSelected); // 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(); // Save the bed to this participant $participant->setToBed($bed); $participant->save(); } // Transition to CurrRdApproved $participant->transitionTo(new ParticipantStateCurrRdApproved($participant, time(), null, UserStatus::getUsername())); // If the future RD is the same as the current user Logged in, then go ahead and transition to FutureRdApproved too. //TODO if ($request->isApprovedByAllCurrentRDs()) { // If all Current RDs have approved, notify Future RDs HMS_Email::sendRoomChangeFutureRDNotice($request); // If all Current RDs have approved, notify future roommates foreach ($request->getParticipants() as $p) { $bed = new HMS_Bed($p->getToBed()); $room = $bed->get_parent(); foreach ($room->get_assignees() as $a) { if ($a instanceof Student && $a->getBannerID() != $p->getBannerID()) { HMS_Email::sendRoomChangePreliminaryRoommateNotice($a); } } } } // Redirect to the manage request page $cmd->redirect(); }
public function execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); // Get the current term $term = Term::getCurrentTerm(); // Load the request $request = RoomChangeRequestFactory::getRequestById($requestId); // Load the participants $participants = $request->getParticipants(); // Make sure everyone is checked into their current assignments if (!$request->allParticipantsCheckedIn()) { // Return the user to the room change request page // NB, don't need an error message here because it should already be printed // by the RoomChangeParticipantView. $cmd = CommandFactory::getCommand('ShowManageRoomChange'); $cmd->setRequestId($requestId); $cmd->redirect(); } // Transition the request to 'Approved' $request->transitionTo(new RoomChangeStateApproved($request, time(), null, UserStatus::getUsername())); // Remove each participants existing assignment foreach ($participants as $participant) { $bannerId = $participant->getBannerId(); // Lookup the student $student = StudentFactory::getStudentByBannerId($bannerId, $term); // Save student object for later $this->students[$bannerId] = $student; // Save student's current assignment reason for later re-use $assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $term); //TODO - Student might not be assigned!! $this->assignmentReasons[$bannerId] = $assignment->getReason(); // Remove existing assignment // TODO: Don't hard code refund percentage HMS_Assignment::unassignStudent($student, $term, 'Room Change Request Approved', UNASSIGN_CHANGE, 100); } // Create new assignments for each participant foreach ($participants as $participant) { // Grab the student object which was previously saved $student = $this->students[$participant->getBannerId()]; // Create each new assignment HMS_Assignment::assignStudent($student, $term, null, $participant->getToBed(), BANNER_MEAL_STD, 'Room Change Approved', FALSE, $this->assignmentReasons[$bannerId]); // Release bed reservation $bed = new HMS_Bed($participant->getToBed()); $bed->clearRoomChangeReserved(); $bed->save(); } // Transition each participant to 'In Process' foreach ($participants as $participant) { $participant->transitionTo(new ParticipantStateInProcess($participant, time(), null, UserStatus::getUsername())); // TODO: Send notifications } // Notify everyone that they can do the move HMS_Email::sendRoomChangeInProcessNotice($request); // Notify roommates that their circumstances are going to change foreach ($request->getParticipants() as $p) { $student = $this->students[$p->getBannerId()]; // New Roommate $newbed = new HMS_Bed($p->getToBed()); $newroom = $newbed->get_parent(); foreach ($newroom->get_assignees() as $a) { if ($a instanceof Student && $a->getBannerID() != $p->getBannerID()) { HMS_Email::sendRoomChangeApprovedNewRoommateNotice($a, $student); } } // Old Roommate $oldbed = new HMS_Bed($p->getFromBed()); $oldroom = $oldbed->get_parent(); foreach ($oldroom->get_assignees() as $a) { if ($a instanceof Student && $a->getBannerID() != $p->getBannerID()) { HMS_Email::sendRoomChangeApprovedOldRoommateNotice($a, $student); } } } // Return the user to the room change request page $cmd = CommandFactory::getCommand('ShowManageRoomChange'); $cmd->setRequestId($requestId); $cmd->redirect(); }