public function execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); $participantId = $context->get('participantId'); // 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->getFutureRdList(); 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.'); } // Transition to CurrRdApproved $participant->transitionTo(new ParticipantStateFutureRdApproved($participant, time(), null, UserStatus::getUsername())); //TODO If all participants are approved, send notification to Housing if ($request->isApprovedByAllFutureRDs()) { HMS_Email::sendRoomChangeAdministratorNotice($request); } // Redirect to the manage request page $cmd->redirect(); }
public function execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); $participantId = $context->get('participantId'); // 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); // Load the Student $student = StudentFactory::getStudentByBannerId($participant->getBannerId(), $request->getTerm()); // Check permissions. Must be the participant or an admin if (UserStatus::getUsername() != $student->getUsername() && !Current_User::allow('hms', 'admin_approve_room_change')) { throw new PermissionException('You do not have permission to appove this room change.'); } // Check for CAPTCHA if this is the student; admins don't need a CAPTCHA $captchaResult = Captcha::verify(true); if (UserStatus::getUsername() == $student->getUsername() && $captchaResult === false) { // Failed the captcha NQ::simple('hms', hms\NotificationView::ERROR, "You didn't type the magic words correctly. Please try again."); $cmd = CommandFactory::getCommand('ShowRoomChangeRequestApproval'); $cmd->redirect(); } // If there was a captcha, then log the activity if ($captchaResult !== false) { HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_AGREED, UserStatus::getUsername(FALSE), 'Request id: ' . $requestId . ' Captcha: ' . $captchaResult); } // Transition to StudentApproved state $participant->transitionTo(new ParticipantStateStudentApproved($participant, time(), null, UserStatus::getUsername())); // If all students have approved, notify RDs if ($request->isApprovedByAllParticipants()) { HMS_Email::sendRoomChangeCurrRDNotice($request); } // If the student is logged in, redirect to the main menu, other wise go back to the room change management view if (UserStatus::getUsername() == $student->getUsername()) { NQ::simple('hms', hms\NotificationView::SUCCESS, 'You have agreed to the room change request. You will be notified by email when the reqeust is approved or denied.'); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); $menuCmd->redirect(); } else { $cmd->redirect(); } }
public function execute(CommandContext $context) { // Get input $requestId = $context->get('requestId'); $participantId = $context->get('participantId'); // Load the request $request = RoomChangeRequestFactory::getRequestById($requestId); // Load the participant $participant = RoomChangeParticipantFactory::getParticipantById($participantId); // Load the Student $student = StudentFactory::getStudentByBannerId($participant->getBannerId(), $request->getTerm()); // Check permissions. Must be the participant or an admin if (UserStatus::getUsername() != $student->getUsername() && !Current_User::allow('hms', 'admin_approve_room_change')) { throw new PermissionException('You do not have permission to decline this room change.'); } // Check for CAPTCHA if this is the student; admins don't need a CAPTCHA $captchaResult = Captcha::verify(true); if ($captchaResult === false) { // Failed the captcha NQ::simple('hms', hms\NotificationView::ERROR, "You didn't type the magic words correctly. Please try again."); $cmd = CommandFactory::getCommand('ShowRoomChangeRequestApproval'); $cmd->redirect(); } HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_DECLINE, UserStatus::getUsername(FALSE), 'Request id: ' . $requestId . ' Captcha: ' . $captchaResult); // 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())); } // TODO Notify everyone that the request was cancelled NQ::simple('hms', hms\NotificationView::SUCCESS, 'You have declined the room change request.'); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); $menuCmd->redirect(); }
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(); }