protected function assign(AssignmentPairing $pair, HMS_Room $room)
 {
     if (!$this->allowed($pair, $room)) {
         PHPWS_Core::initModClass('hms', 'exception/AssignmentException.php');
         throw new AssignmentException('Cannot assign ' . $pair->__tostring() . ' to ' . $room->__tostring());
     }
     echo get_class($this) . " is assigning " . $pair->__tostring() . " to room " . $room->__tostring() . "\n";
     // Actually assign the given pairing to the given room
     try {
         $application = HousingApplication::getApplicationByUser($pair->getStudent1()->getUsername(), $this->term);
         if (is_null($application)) {
             $student1MealPlan = BANNER_MEAL_STD;
         } else {
             $student1MealPlan = $application->getMealPlan();
         }
         HMS_Assignment::assignStudent($pair->getStudent1(), $this->term, $room->id, NULL, $student1MealPlan, 'Auto-assigned', false, ASSIGN_FR_AUTO);
     } catch (Exception $e) {
         echo "Could not assign '{$pair->getStudent1()->getUsername()}': {get_class({$e})}: {$e->getMessage()}<br />\n";
     }
     $pair->setBed1($room->__toString());
     try {
         $application = HousingApplication::getApplicationByUser($pair->getStudent2()->getUsername(), $this->term);
         if (is_null($application)) {
             $student2MealPlan = BANNER_MEAL_STD;
         } else {
             $student2MealPlan = $application->getMealPlan();
         }
         HMS_Assignment::assignStudent($pair->getStudent2(), $this->term, $room->id, NULL, $student2MealPlan, 'Auto-assigned', false, ASSIGN_FR_AUTO);
     } catch (Exception $e) {
         echo "Could not assign '{$pair->getStudent2()->getUsername()}': " . get_class($e) . ": {$e->getMessage()}<br />\n";
     }
     $pair->setBed2($room->__toString());
 }
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'assign_by_floor')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to assign students by floor.');
     }
     $username = $context->get('username');
     $banner_id = (int) $context->get('banner_id');
     $reason = $context->get('reason');
     $meal_plan = $context->get('meal_plan');
     $bed_id = $context->get('bed_id');
     $term = Term::getSelectedTerm();
     try {
         if ($banner_id) {
             $student = StudentFactory::getStudentByBannerID($banner_id, Term::getSelectedTerm());
         } elseif (!empty($username)) {
             $student = StudentFactory::getStudentByUsername($username, Term::getSelectedTerm());
         } else {
             $context->setContent(json_encode(array('status' => 'failure', 'message' => 'Did not receive Banner ID or user name.')));
             return;
         }
         try {
             HMS_Assignment::assignStudent($student, $term, null, $bed_id, $meal_plan, null, null, $reason);
         } catch (AssignmentException $e) {
             $context->setContent(json_encode(array('status' => 'failure', 'message' => $e->getMessage())));
             return;
         }
         $message = $student->first_name . ' ' . $student->last_name;
         $context->setContent(json_encode(array('status' => 'success', 'message' => $message, 'student' => $student)));
     } catch (\StudentNotFoundException $e) {
         $context->setContent(json_encode(array('status' => 'failure', 'message' => $e->getMessage())));
     }
 }
Example #3
0
 public function copy($to_term, $room_id, $assignments)
 {
     if (!$this->id) {
         return false;
     }
     // echo "in hms_beds, making a copy of this bed<br>";
     $new_bed = clone $this;
     $new_bed->reset();
     $new_bed->term = $to_term;
     $new_bed->room_id = $room_id;
     $new_bed->clearRoomChangeReserved();
     try {
         $new_bed->save();
     } catch (Exception $e) {
         throw $e;
     }
     // Copy assignment
     if ($assignments) {
         // echo "loading assignments for this bed<br>";
         PHPWS_Core::initModClass('hms', 'HousingApplication.php');
         PHPWS_Core::initModClass('hms', 'Term.php');
         PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
         PHPWS_Core::initModClass('hms', 'StudentFactory.php');
         try {
             $this->loadAssignment();
         } catch (Exception $e) {
             throw $e;
         }
         if (isset($this->_curr_assignment)) {
             try {
                 try {
                     $student = StudentFactory::getStudentByUsername($this->_curr_assignment->asu_username, Term::getCurrentTerm());
                     $app = HousingApplication::getApplicationByUser($this->_curr_assignment->asu_username, Term::getCurrentTerm());
                 } catch (StudentNotFoundException $e) {
                     NQ::simple('hms', hms\NotificationView::ERROR, 'Could not copy assignment for ' . $this->_curr_assignment->asu_username);
                     return;
                 }
                 // meal option defaults to standard
                 $meal_option = BANNER_MEAL_STD;
                 if (!is_null($app)) {
                     $meal_option = $app->getMealPlan();
                 }
                 $note = "Assignment copied from " . Term::getPrintableCurrentTerm() . " to " . Term::toString($to_term);
                 HMS_Assignment::assignStudent($student, $to_term, null, $new_bed->id, $meal_option, $note, false, $this->_curr_assignment->getReason());
             } catch (Exception $e) {
                 throw $e;
             }
         }
     }
 }
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'assignment_maintenance')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to assign students.');
     }
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $term = Term::getSelectedTerm();
     try {
         if (preg_match('/^[0-9]{9}$/', $context->get('username'))) {
             $student = StudentFactory::getStudentByBannerId($context->get('username'), $term);
         } else {
             $student = StudentFactory::getStudentByUsername(strtolower(trim($context->get('username'))), $term);
         }
     } catch (StudentNotFoundException $e) {
         echo json_encode(array('success' => false, 'message' => $e->getMessage()));
         exit;
     } catch (Exception $e) {
         echo json_encode(array('success' => false, 'message' => $e->getMessage()));
         exit;
     }
     $bed = $context->get('bed');
     $plan = $context->get('mealplan');
     $reason = $context->get('assignmenttype');
     if (HMS_Assignment::checkForAssignment($student->getUsername(), $term)) {
         echo json_encode(array('success' => false, 'message' => 'Error: Student is already assigned elsewhere, please unassign this student first.'));
         exit;
     }
     try {
         HMS_Assignment::assignStudent($student, $term, NULL, $bed, $plan, '', false, $reason);
     } catch (AssignmentException $e) {
         echo json_encode(array('success' => false, 'message' => $e->getMessage()));
         exit;
     }
     echo json_encode(array('success' => true, 'message' => 'Student assigned!'));
     exit;
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $roomId = $context->get('roomId');
     $roommates = $context->get('roommates');
     $mealPlan = $context->get('mealPlan');
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     $errorCmd = CommandFactory::getCommand('LotteryShowConfirm');
     $errorCmd->setRoomId($roomId);
     $errorCmd->setRoommates($roommates);
     $errorCmd->setMealPlan($mealPlan);
     $successCmd = CommandFactory::getCommand('LotteryShowConfirmed');
     $successCmd->setRoomId($roomId);
     PHPWS_Core::initCoreClass('Captcha.php');
     $captcha = Captcha::verify(TRUE);
     // returns the words entered if correct, FALSE otherwise
     //$captcha = TRUE;
     if ($captcha === FALSE) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, the words you eneted were incorrect. Please try again.');
         $errorCmd->redirect();
     }
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Room.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'HMS_Util.php');
     PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcAssignmentSelfAssignedState.php');
     $room = new HMS_Room($roomId);
     // Check for an RLC assignment in the self-select status
     $rlcAssignment = RlcMembershipFactory::getMembership($student, $term);
     // Check roommates for validity
     foreach ($roommates as $bed_id => $username) {
         // Double check the student is valid
         try {
             $roommate = StudentFactory::getStudentByUsername($username, $term);
         } catch (StudentNotFoundException $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is not a valid student. Please choose a different roommate.");
             $errorCmd->redirect();
         }
         // Make sure the bed is still empty
         $bed = new HMS_Bed($bed_id);
         if ($bed->has_vacancy() != TRUE) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'One or more of the beds in the room you selected is no longer available. Please try again.');
             $errorCmd->redirect();
         }
         // Make sure none of the needed beds are reserved
         if ($bed->is_lottery_reserved()) {
             NQ::simple('hms', hms\NotificationView::ERROR, 'One or more of the beds in the room you selected is no longer available. Please try again.');
             $errorCmd->redirect();
         }
         // Double check the genders are all the same as the person logged in
         if ($student->getGender() != $roommate->getGender()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is a different gender. Please choose a roommate of the same gender.");
             $errorCmd->redirect();
         }
         // Double check the genders are the same as the room (as long as the room isn't AUTO)
         if ($room->gender_type != AUTO && $roommate->getGender() != $room->gender_type) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is a different gender. Please choose a roommate of the same gender.");
             $errorCmd->redirect();
         }
         // If this student is an RLC-self-selection, then each roommate must be in the same RLC and in the selfselect-invite state too
         if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') {
             // This student is an RLC-self-select, so check the roommate's RLC status
             $roommateRlcAssign = RlcMembershipFactory::getMembership($roommate, $term);
             // Make sure the roommate is a member of the same RLC and is eligible for self-selection
             if ($roommateRlcAssign == null || $roommateRlcAssign->getStateName() != 'selfselect-invite' || $rlcAssignment->getRlc()->getId() != $roommateRlcAssign->getRlc()->getId()) {
                 NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} must be a member of the same learning community as you, and must also be eligible for self-selction.");
                 $errorCmd->redirect();
             }
             // Otherwise (if not RLC members), make sure each roommate is eligible
         } else {
             if (HMS_Lottery::determineEligibility($username) !== TRUE) {
                 NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is not eligible for assignment.");
                 $errorCmd->redirect();
             }
         }
         // If this student is a self-select RLC member, then this student must also be a self-select RLC member of the same RLC
         if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') {
             $roommateRlcAssign = RlcMembershipFactory::getMembership($roommate, $term);
             if ($roommateRlcAssign == null || $roommateRlcAssign->getStateName() != 'selfselect-invite' || $rlcAssignment->getRlc()->getId() != $roommateRlcAssign->getRlc()->getId()) {
                 NQ::simple('hms', hms\NotificationView::ERROR, "{$username} must be a member of the same learning community as you, and must also be eligible for self-selction.");
                 $errorCmd->redirect();
             }
         }
     }
     // If the room's gender is 'AUTO' and no one is assigned to it yet, switch it to the student's gender
     if ($room->gender_type == AUTO && $room->get_number_of_assignees() == 0) {
         $room->gender_type = $student->getGender();
         $room->save();
     }
     // Assign the student to the requested bed
     $bed_id = array_search(UserStatus::getUsername(), $roommates);
     // Find the bed id of the student who's logged in
     try {
         $result = HMS_Assignment::assignStudent($student, PHPWS_Settings::get('hms', 'lottery_term'), NULL, $bed_id, $mealPlan, 'Confirmed lottery invite', TRUE, ASSIGN_LOTTERY);
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error creating your room assignment. Please try again or contact University Housing.');
         $errorCmd->redirect();
     }
     // Log the assignment
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ROOM_CHOSEN, UserStatus::getUsername(), 'Captcha: ' . $captcha);
     // Update the student's meal plan in the housing application, just for future reference
     $app = HousingApplication::getApplicationByUser($student->getUsername(), $term);
     $app->setMealPlan($mealPlan);
     $app->save();
     // If this student was an RLC self-select, update the RLC memberhsip state
     if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') {
         $rlcAssignment->changeState(new RlcAssignmentSelfAssignedState($rlcAssignment));
     }
     foreach ($roommates as $bed_id => $username) {
         // Skip the current user
         if ($username == $student->getUsername()) {
             continue;
         }
         # Reserve the bed for the roommate
         $expires_on = time() + INVITE_TTL_HRS * 3600;
         $bed = new HMS_Bed($bed_id);
         if (!$bed->lottery_reserve($username, $student->getUsername(), $expires_on)) {
             NQ::smiple('hms', hms\NotificationView::WARNING, "You were assigned, but there was a problem reserving space for your roommates. Please contact University Housing.");
             $successCmd->redirect();
         }
         HMS_Activity_Log::log_activity($username, ACTIVITY_LOTTERY_REQUESTED_AS_ROOMMATE, $student->getUsername(), 'Expires: ' . HMS_Util::get_long_date_time($expires_on));
         # Invite the selected roommates
         $roomie = StudentFactory::getStudentByUsername($username, $term);
         $term = PHPWS_Settings::get('hms', 'lottery_term');
         $year = Term::toString($term) . ' - ' . Term::toString(Term::getNextTerm($term));
         HMS_Email::send_lottery_roommate_invite($roomie, $student, $expires_on, $room->where_am_i(), $year);
     }
     HMS_Email::send_lottery_assignment_confirmation($student, $room->where_am_i(), $term);
     $successCmd->redirect();
 }
Example #6
0
 public static function confirm_roommate_request($username, $requestId, $meal_plan)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     // Get the roommate invite
     $invite = HMS_Lottery::get_lottery_roommate_invite_by_id($requestId);
     // If the invite wasn't found, show an error
     if ($invite === false) {
         return E_LOTTERY_ROOMMATE_INVITE_NOT_FOUND;
     }
     // Check that the reserved bed is still empty
     $bed = new HMS_Bed($invite['bed_id']);
     if (!$bed->has_vacancy()) {
         return E_ASSIGN_BED_NOT_EMPTY;
     }
     // Make sure the student isn't assigned anywhere else
     if (HMS_Assignment::checkForAssignment($username, $term)) {
         return E_ASSIGN_ALREADY_ASSIGNED;
     }
     $student = StudentFactory::getStudentByUsername($username, $term);
     $requestor = StudentFactory::getStudentByUsername($invite['requestor'], $term);
     // Actually make the assignment
     HMS_Assignment::assignStudent($student, $term, null, $invite['bed_id'], $meal_plan, 'Confirmed roommate invite', true, ASSIGN_LOTTERY);
     // return successfully
     HMS_Email::send_roommate_confirmation($student, $requestor);
     return E_SUCCESS;
 }
 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();
 }
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'assignment_maintenance')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to assign students.');
     }
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'FallApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Room.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'BannerQueue.php');
     // NB: Username must be all lowercase
     $username = strtolower(trim($context->get('username')));
     $term = Term::getSelectedTerm();
     // Setup command to redirect to in case of error
     $errorCmd = CommandFactory::getCommand('ShowAssignStudent');
     $errorCmd->setUsername($username);
     /***
      * Input Sanity Checking
      */
     // Must supply a user name
     if (is_null($username)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid or missing username.');
         $errorCmd->redirect();
     }
     // Must supply at least a room ID
     $roomId = $context->get('room');
     if (is_null($roomId) || $roomId == 0) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must select a room.');
         $errorCmd->redirect();
     }
     // Must choose an assignment type
     $assignmentType = $context->get('assignment_type');
     if (!isset($assignmentType) || is_null($assignmentType) || $assignmentType < 0) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must choose an assignment type.');
         $errorCmd->redirect();
     }
     // Check to make sure the student has an application on file
     $applicationStatus = HousingApplication::checkForApplication($username, $term);
     if ($applicationStatus == FALSE) {
         NQ::simple('hms', hms\NotificationView::WARNING, 'Warning: No housing application found for this student in this term.');
     }
     // If the student is already assigned, redirect to the confirmation screen. If the student is already assigned
     // and the confirmation flag is true, then set a flag and proceed.
     $moveNeeded = FALSE;
     if (HMS_Assignment::checkForAssignment($username, $term)) {
         if ($context->get('moveConfirmed') == 'true') {
             // Move has been confirmed
             $moveNeeded = true;
         } else {
             // Redirect to the move confirmation interface
             $moveConfirmCmd = CommandFactory::getCommand('ShowAssignmentMoveConfirmation');
             $moveConfirmCmd->setUsername($username);
             $moveConfirmCmd->setRoom($context->get('room'));
             $moveConfirmCmd->setBed($context->get('bed'));
             $moveConfirmCmd->setMealPlan($context->get('meal_plan'));
             $moveConfirmCmd->setAssignmentType($assignmentType);
             $moveConfirmCmd->setNotes($context->get('note'));
             $moveConfirmCmd->redirect();
         }
     }
     try {
         $student = StudentFactory::getStudentByUsername($username, $term);
     } catch (StudentNotFoundException $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid user name, no such student found.');
         $errorCmd->redirect();
     }
     // Check age, issue a warning for over 25
     if (strtotime($student->getDOB()) < strtotime("-25 years")) {
         NQ::simple('hms', hms\NotificationView::WARNING, 'Student is 25 years old or older!');
     }
     $gender = $student->getGender();
     if (!isset($gender) || is_null($gender)) {
         throw new InvalidArgumentException('Missing student gender.');
     }
     // Create the room object so we can check gender
     $room = new HMS_Room($roomId);
     if (!$room) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Error creating the room object.');
         $errorCmd->redirect();
     }
     // Create the hall object for later
     $floor = $room->get_parent();
     $hall = $floor->get_parent();
     // If the room is Co-ed, make sure the user has permission to assign to co-ed rooms
     if ($room->getGender() == COED && !Current_User::allow('hms', 'coed_assignment')) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Error: You do not have permission to assign students to co-ed rooms.');
         $errorCmd->redirect();
     }
     // Make sure the student's gender matches the gender of the room, unless the room is co-ed.
     if ($room->getGender() != $gender && $room->getGender() != COED) {
         // Room gender does not match student's gender, so check if we can change it
         if ($room->can_change_gender($gender) && Current_User::allow('hms', 'room_attributes')) {
             $room->setGender($gender);
             $room->save();
             NQ::simple('hms', hms\NotificationView::WARNING, 'Warning: Changing room gender.');
         } else {
             NQ::simple('hms', hms\NotificationView::ERROR, 'Error: The student\'s gender and the room\'s gender do not match and the room could not be changed.');
             $errorCmd->redirect();
         }
     }
     // If the user is attempting to re-assign and has confirmed the move,
     // then unassign the student first.
     if ($moveNeeded) {
         try {
             //TODO don't hard-code refund percentage to 100%
             HMS_Assignment::unassignStudent($student, $term, '(re-assign)', UNASSIGN_REASSIGN, 100);
         } catch (Exception $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, "Error deleting current assignment. {$username} was not removed.");
             $errorCmd->redirect();
         }
     }
     // Actually try to make the assignment, decide whether to use the room id or the bed id
     $bed = $context->get('bed');
     try {
         if (isset($bed) && $bed != 0) {
             HMS_Assignment::assignStudent($student, $term, NULL, $bed, $context->get('meal_plan'), $context->get('note'), false, $context->get('assignment_type'));
         } else {
             HMS_Assignment::assignStudent($student, $term, $context->get('room'), NULL, $context->get('meal_plan'), $context->get('note'), false, $context->get('assignment_type'));
         }
     } catch (AssignmentException $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Assignment error: ' . $e->getMessage());
         $errorCmd->redirect();
     }
     // Show a success message
     if ($context->get('moveConfirmed') == 'true') {
         NQ::simple('hms', hms\NotificationView::SUCCESS, 'Successfully moved ' . $username . ' to ' . $hall->hall_name . ' room ' . $room->room_number);
     } else {
         NQ::simple('hms', hms\NotificationView::SUCCESS, 'Successfully assigned ' . $username . ' to ' . $hall->hall_name . ' room ' . $room->room_number);
     }
     $successCmd = CommandFactory::getCommand('ShowAssignStudent');
     $successCmd->redirect();
 }