/** * (non-PHPdoc) * @see Command::execute() */ public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $term = $context->get('term'); // Check if the student has already applied. If so, redirect to the student menu $app = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term); if (isset($result) && $result->getApplicationType == 'offcampus_waiting_list') { NQ::simple('hms', hms\NotificationView::ERROR, 'You have already enrolled on the on-campus housing Open Waiting List for this term.'); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); $menuCmd->redirect(); } // Make sure the student agreed to the terms, if not, send them back to the terms & agreement command $event = $context->get('event'); $_SESSION['application_data'] = array(); // If they haven't agreed, redirect to the agreement if (is_null($event) || !isset($event) || $event != 'signing_complete' && $event != 'viewing_complete') { $onAgree = CommandFactory::getCommand('ShowOffCampusWaitListApplication'); $onAgree->setTerm($term); $agreementCmd = CommandFactory::getCommand('ShowTermsAgreement'); $agreementCmd->setTerm($term); $agreementCmd->setAgreedCommand($onAgree); $agreementCmd->redirect(); } $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); PHPWS_Core::initModClass('hms', 'ReApplicationOffCampusFormView.php'); $view = new ReApplicationOffCampusFormView($student, $term); $context->setContent($view->show()); }
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 getMenuBlockView(Student $student) { PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'ApplicationMenuBlockView.php'); $application = HousingApplication::getApplicationByUser($student->getUsername(), $this->term); return new ApplicationMenuBlockView($this->term, $this->getStartDate(), $this->getEditDate(), $this->getEndDate(), $application); }
public function getMenuBlockView(Student $student) { PHPWS_Core::initModClass('hms', 'ReapplicationWaitingListMenuBlockView.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); $term = PHPWS_Settings::get('hms', 'lottery_term'); $application = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term, 'lottery'); return new ReapplicationWaitingListMenuBlockView($this->term, $this->getStartDate(), $this->getEndDate(), $application); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php'); PHPWS_Core::initModClass('hms', 'RlcAssignmentSelfAssignedState.php'); $requestId = $context->get('requestId'); $mealPlan = $context->get('mealPlan'); $errorCmd = CommandFactory::getCommand('LotteryShowConfirmRoommateRequest'); $errorCmd->setRequestId($requestId); $errorCmd->setMealPlan($mealPlan); // Confirm the captcha PHPWS_Core::initCoreClass('Captcha.php'); $captcha = Captcha::verify(TRUE); if ($captcha === FALSE) { NQ::simple('hms', hms\NotificationView::ERROR, 'The words you entered were incorrect. Please try again.'); $errorCmd->redirect(); } // Check for a meal plan if (!isset($mealPlan) || $mealPlan == '') { NQ::simple('hms', hms\NotificationView::ERROR, 'Please choose a meal plan.'); $errorCmd->redirect(); } $term = PHPWS_Settings::get('hms', 'lottery_term'); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); // Update the meal plan field on the application $app = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term); $app->setMealPlan($mealPlan); try { $app->save(); } catch (Exception $e) { PHPWS_Error::log('hms', $e->getMessage()); NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error confirming your roommate invitation. Please contact University Housing.'); $errorCmd->redirect(); } // Try to actually make the assignment PHPWS_Core::initModClass('hms', 'HMS_Lottery.php'); try { HMS_Lottery::confirm_roommate_request(UserStatus::getUsername(), $requestId, $mealPlan); } catch (Exception $e) { PHPWS_Error::log('hms', $e->getMessage()); NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error confirming your roommate invitation. Please contact University Housing.'); $errorCmd->redirect(); } # Log the fact that the roommate was accepted and successfully assigned HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_CONFIRMED_ROOMMATE, UserStatus::getUsername(), "Captcha: \"{$captcha}\""); // Check for an RLC membership and update status if necessary // If this student was an RLC self-select, update the RLC memberhsip state $rlcAssignment = RlcMembershipFactory::getMembership($student, $term); if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') { $rlcAssignment->changeState(new RlcAssignmentSelfAssignedState($rlcAssignment)); } $invite = HMS_Lottery::get_lottery_roommate_invite_by_id($requestId); $successCmd = CommandFactory::getCommand('LotteryShowConfirmedRoommateThanks'); $successCmd->setRequestId($requestId); $successCmd->redirect(); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php'); PHPWS_Core::initModClass('hms', 'HousingApplicationFormView.php'); // Make sure we have a valid term $term = $context->get('term'); if (is_null($term) || !isset($term)) { throw new InvalidArgumentException('Missing term.'); } // Determine the application type, based on the term $sem = Term::getTermSem($term); switch ($sem) { case TERM_FALL: $appType = 'fall'; break; case TERM_SPRING: $appType = 'spring'; break; case TERM_SUMMER1: case TERM_SUMMER2: $appType = 'summer'; break; } $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); // Make sure the student agreed to the terms, if not, send them back to the terms & agreement command //$event = $context->get('event'); // If they haven't agreed, redirect to the agreement // TODO: actually check via docusign API /* if(is_null($event) || !isset($event) || ($event != 'signing_complete' && $event != 'viewing_complete')){ $agreementCmd = CommandFactory::getCommand('ShowTermsAgreement'); $agreementCmd->setTerm($term); $agreementCmd->setAgreedCommand(CommandFactory::getCommand('ShowHousingApplicationForm')); $agreementCmd->redirect(); } */ // Check to see if the student's PIN is enabled. Don't let the student apply if the PIN is disabled. if ($student->pinDisabled()) { $pinCmd = CommandFactory::getCommand('ShowPinDisabled'); $pinCmd->redirect(); } // Check to see if the user has an existing application for the term in question $existingApplication = HousingApplication::getApplicationByUser($student->getUsername(), $term); // Check for an in-progress application on the context, ignore any exceptions (in case there isn't an application on the context) try { //TODO check to see if it looks like there might be something on the context before trying this $existingApplication = HousingApplicationFactory::getApplicationFromContext($context, $term, $student, $appType); } catch (Exception $e) { // ignored $contextApplication = NULL; } $appView = new HousingApplicationFormView($student, $term, $existingApplication); $context->setContent($appView->show()); }
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 getMenuBlockView(Student $student) { PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_Lottery.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'ReapplicationMenuBlockView.php'); $assignment = HMS_Assignment::getAssignment($student->getUsername(), $this->term); $application = HousingApplication::getApplicationByUser($student->getUsername(), $this->term); if (!$application instanceof LotteryApplication) { $application = null; } $roommateRequests = HMS_Lottery::get_lottery_roommate_invites($student->getUsername(), $this->term); return new ReapplicationMenuBlockView($this->term, $this->getStartDate(), $this->getEndDate(), $assignment, $application, $roommateRequests); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php'); PHPWS_Core::initModClass('hms', 'EmergencyContactFormView.php'); // Make sure we have a valid term $term = $context->get('term'); if (is_null($term) || !isset($term)) { throw new InvalidArgumentException('Missing term.'); } $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); $application = HousingApplication::getApplicationByUser($student->getUsername(), $term); $formView = new EmergencyContactFormView($student, $term, $application); $context->setContent($formView->show()); }
/** * Handles looking up and withdrawing housing applications. * @param Student $student */ private function handleApplication(Student $student) { // Get the application and mark it withdrawn $app = HousingApplication::getApplicationByUser($student->getUsername(), $this->term); if (!is_null($app)) { //$app->setWithdrawn(1); //$app->setStudentType(TYPE_WITHDRAWN); $app->cancel(CANCEL_WITHDRAWN); try { $app->save(); } catch (Exception $e) { // TODO } $this->actions[$student->getUsername()][] = 'Found Housing Application; Student Type: ' . $app->getStudentType() . ' App Term: ' . $app->getApplicationTerm(); $this->actions[$student->getUsername()][] = 'Marked application as cancelled (reason: withdrawn)'; HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_CANCEL_HOUSING_APPLICATION, UserStatus::getUsername(), 'Application automatically cancelled by Withdrawn Search'); } }
public function getMenuBlockView(Student $student) { PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'RlcReapplicationMenuBlockView.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); $application = HousingApplication::getApplicationByUser($student->getUsername(), $this->term); if (!$application instanceof LotteryApplication) { $application = null; } $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $this->term); if (!$rlcApp instanceof HMS_RLC_Application) { $rlcApp = null; } // Check for an assignment $assignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), $this->getTerm()); return new RlcReapplicationMenuBlockView($this->term, $this->getStartDate(), $this->getEndDate(), $application, $rlcApp, $assignment); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HMS_Lottery.php'); PHPWS_Core::initModClass('hms', 'LotteryRoommateRequestView.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php'); $request = HMS_Lottery::get_lottery_roommate_invite_by_id($context->get('requestId')); $term = PHPWS_Settings::get('hms', 'lottery_term'); $housingApp = HousingApplication::getApplicationByUser(UserStatus::getUsername(), $term); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); // Check for a self-select RLC membership for the logged-in student $rlcAssign = RlcMembershipFactory::getMembership($student, $term); if ($rlcAssign == false) { $rlcAssign = null; } $view = new LotteryRoommateRequestView($request, $term, $housingApp, $rlcAssign); $context->setContent($view->show()); }
public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'lottery_admin')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have remove students from the waiting list.'); } $username = $context->get('username'); $cmd = CommandFactory::getCommand('ShowLotteryWaitingList'); if (!is_null($username)) { $app = HousingApplication::getApplicationByUser($username, PHPWS_Settings::get('hms', 'lottery_term')); $app->waiting_list_hide = 1; $result = $app->save(); if (!PHPWS_Error::logIfError($result)) { NQ::simple('hms', hms\NotificationView::SUCCESS, "{$username} removed from the waiting list!"); $cmd->redirect(); } } NQ::simple('hms', hms\NotificationView::SUCCESS, "Unable to remove {$username} from the waiting list!"); $cmd->redirect(); }
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(); }
public function auto_assign($test = 0) { PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); // TODO update this to use HousignAssignment PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); PHPWS_Core::initModClass('hms', 'BannerQueue.php'); $term = Term::get_selected_term(); // In both cases: Random, and include Banner info $f_rooms = HMS_Room::get_all_free_rooms($term, FEMALE, TRUE); $m_rooms = HMS_Room::get_all_free_rooms($term, MALE, TRUE); $roommates = HMS_Roommate::get_all_confirmed_roommates($term, TRUE); $applicants = HousingApplication::getAllFreshmenApplications($term, 'gender', 'hms_fall_application.lifestyle_option', 'hms_fall_application.preferred_bedtime', 'hms_fall_application.room_condition', 'random'); $problems = array(); $rlcs = array(); $assigns = array(); $notices = array(); $successes = array(); $assigned = array(); reset($f_rooms); reset($m_rooms); $i_f_count = count($f_rooms); $i_m_count = count($m_rooms); // Assign Roommates reset($roommates); foreach ($roommates as $pair) { $a = HousingApplication::getApplicationByUser($pair['requestor'], $term); if (in_array($a->username, $assigned)) { $notices[] = "<strong>{$a->username}</strong> already scheduled for assignment."; continue; } $rlc = HMS_RLC_Assignment::checkForAssignment($a->username, $term); if ($rlc !== FALSE) { $rlcs[] = "Skipping <strong>{$a->username}</strong>; assigned to an RLC."; continue; } $b = HousingApplication::getApplicationByUser($pair['requestee'], $term); if (in_array($b->username, $assigned)) { $notices[] = "<strong>{$b->username}</strong> already scheduled for assignment."; continue; } $rlc = HMS_RLC_Assignment::checkForAssignment($b->username, $term); if ($rlc !== FALSE) { $rlcs[] = "Skipping <strong>{$b->username}</strong>; assigned to an RLC."; continue; } if (is_null($a->id)) { $problems[] = "Could not assign <strong>{$a->username}</strong> with roommate <strong>{$b->username}</strong>; {$a->username} does not have an application."; continue; } if (is_null($b->id)) { $problems[] = "Could not assign <strong>{$a->username}</strong> with roommate <strong>{$b->username}</strong>; {$b->username} does not have an application."; continue; } if ($a->gender != $b->gender) { $problems[] = "Epic FAIL... <strong>{$a->username}</strong> and <strong>{$b->username}</strong> are not the same gender."; continue; } $ass = HMS_Assignment::get_assignment($a->username, $term); if (is_a($ass, 'HMS_Assignment')) { $bbc = $ass->get_banner_building_code(); $bed = $ass->get_banner_bed_id(); $assigns[] = "Could not assign <strong>{$a->username}</strong>; already assigned to <strong>{$bbc} {$bed}</strong>"; continue; } $ass = HMS_Assignment::get_assignment($b->username, $term); if (is_a($ass, 'HMS_Assignment')) { $bbc = $ass->get_banner_building_code(); $bed = $ass->get_banner_bed_id(); $assigns[] = "Could not assign <strong>{$b->username}</strong>; already assigned to <strong>{$bbc} {$bed}</strong>"; continue; } $room = $a->gender == FEMALE ? array_shift($f_rooms) : ($a->gender == MALE ? array_shift($m_rooms) : 'badgender'); if (is_null($room)) { $problems[] = "Could not assign <strong>{$a->username}</strong>; out of empty " . ($a->gender ? 'male' : 'female') . ' rooms.'; $problems[] = "Could not assign <strong>{$b->username}</strong>; out of empty " . ($b->gender ? 'male' : 'female') . ' rooms.'; continue; } else { if ($room === 'badgender') { $problems[] = "Could not assign <strong>{$a->username}</strong>; {$a->gender} is not a valid gender."; continue; } } // Prepare for assignment $room =& new HMS_Room($room); $room->loadBeds(); $bed_a_text = $room->_beds[0]->get_banner_building_code() . ' ' . $room->_beds[0]->banner_id; $bed_b_text = $room->_beds[1]->get_banner_building_code() . ' ' . $room->_beds[1]->banner_id; if ($test) { $successes[] = HMS_Autoassigner::record_success('TEST Requested', $a, $b, $bed_a_text); $successes[] = HMS_Autoassigner::record_success('TEST Requested', $b, $a, $bed_b_text); } else { $result = HMS_Autoassigner::assign($a, $room->_beds[0], $term); if ($result === TRUE) { $successes[] = HMS_Autoassigner::record_success('Requested', $a, $b, $bed_a_text); $assigned[] = $a->username; } else { $problems[] = $result; } if (!is_null($b->id)) { $result = HMS_Autoassigner::assign($b, $room->_beds[1], $term); if ($result === TRUE) { $successes[] = HMS_Autoassigner::record_success('Requested', $b, $a, $bed_b_text); $assigned[] = $b->username; } else { $problems[] = $result; } } } } reset($applicants); while (count($applicants) > 0) { $a = array_shift($applicants); if ($a === FALSE) { continue; } if (!isset($a)) { continue; } if (in_array($a->username, $assigned)) { $notices[] = "<strong>{$a->username}</strong> already scheduled for assignment."; continue; } $rlc = HMS_RLC_Assignment::checkForAssignment($a->username, $term); if ($rlc !== FALSE) { $rlcs[] = "Skipping <strong>{$a->username}</strong>; assigned to an RLC."; continue; } $b = array_shift($applicants); if (in_array($b->username, $assigned)) { $notices[] = "<strong>{$b->username}</strong> already scheduled for assignment."; array_unshift($applicants, $a); continue; } $rlc = HMS_RLC_Assignment::checkForAssignment($b->username, $term); if ($rlc !== FALSE) { $rlcs[] = "Skipping <strong>{$b->username}</strong>; assigned to an RLC."; array_unshift($applicants, $a); continue; } if ($a->gender != $b->gender) { array_unshift($applicants, $b); $b = NULL; continue; } $ass = HMS_Assignment::get_assignment($a->username, $term); if (is_a($ass, 'HMS_Assignment')) { $bbc = $ass->get_banner_building_code(); $bed = $ass->get_banner_bed_id(); $assigns[] = "Could not assign <strong>{$a->username}</strong>; already assigned to <strong>{$bbc} {$bed}</strong>"; array_unshift($applicants, $b); continue; } $ass = HMS_Assignment::get_assignment($b->username, $term); if (is_a($ass, 'HMS_Assignment')) { $bbc = $ass->get_banner_building_code(); $bed = $ass->get_banner_bed_id(); $assigns[] = "Could not assign <strong>{$b->username}</strong>; already assigned to <strong>{$bbc} {$bed}</strong>"; array_unshift($applicants, $a); continue; } // Determine Room Gender $room = $a->gender == FEMALE ? array_shift($f_rooms) : ($a->gender == MALE ? array_shift($m_rooms) : 'badgender'); // We could be out of rooms or have database corruption if (is_null($room)) { $problems[] = "Could not assign <strong>{$a->username}</strong>; out of " . ($a->gender ? 'male' : 'female') . ' rooms.'; $problems[] = "Could not assign <strong>{$b->username}</strong>; out of " . ($b->gender ? 'male' : 'female') . ' rooms.'; continue; } else { if ($room === 'badgender') { $problems[] = "Could not assign <strong>{$a->username}</strong>; {$a->gender} is not a valid gender."; continue; } } // Prepare for assignment $room =& new HMS_Room($room); $room->loadBeds(); $bed_a_text = $room->_beds[0]->get_banner_building_code() . ' ' . $room->_beds[0]->banner_id; $bed_b_text = $room->_beds[1]->get_banner_building_code() . ' ' . $room->_beds[1]->banner_id; if ($test) { $successes[] = HMS_Autoassigner::record_success('TEST Auto', $a, $b, $bed_a_text); $successes[] = HMS_Autoassigner::record_success('TEST Auto', $b, $a, $bed_b_text); } else { $result = HMS_Autoassigner::assign($a, $room->_beds[0], $term); if ($result === TRUE) { $successes[] = HMS_Autoassigner::record_success('Auto', $a, $b, $bed_a_text); $assigned[] = $a->username; } else { $problems[] = $result; } if (!is_null($b->id)) { $result = HMS_Autoassigner::assign($b, $room->_beds[1], $term); if ($result === TRUE) { $successes[] = HMS_Autoassigner::record_success('Auto', $b, $a, $bed_b_text); $assigned[] = $b->username; } else { $problems[] = $result; } } } } $f_f_count = count($f_rooms); $f_m_count = count($m_rooms); usort($successes, array('HMS_Autoassigner', 'sort_successes')); $content = '<h1>Autoassigner Results - ' . date('Y-m-d') . '</h1>'; $content .= '<h2>Total Assignments: ' . count($assigned) . '</h2>'; $content .= "<p>Began with {$i_f_count} female rooms and {$i_m_count} male rooms</p>"; $content .= "<p>Ended with {$f_f_count} female rooms and {$f_m_count} male rooms</p>"; $content .= '<h2>Assignment Report (' . count($successes) . ')</h2>'; $content .= '<table><tr>'; $content .= '<th>Type</th><th>Bed A</th><th>Code A</th><th>Bed B</th><th>Code B</th><th>Room</th>'; $content .= '</tr>'; foreach ($successes as $success) { $content .= '<tr>'; $content .= '<td>' . $success['type'] . '</td>'; $content .= '<td>' . $success['a'] . '</td>'; $content .= '<td>' . $success['a_code'] . '</td>'; $content .= '<td>' . $success['room'] . '</td>'; $content .= '<td>' . $success['b'] . '</td>'; $content .= '<td>' . $success['b_code'] . '</td>'; $content .= "</tr>\n"; } $content .= '</tr></table>'; sort($problems); $content .= '<h2>Problems (' . count($problems) . ')</h2>'; $content .= implode("<br />\n", $problems); sort($rlcs); $content .= '<h2>Skipped for RLC (' . count($rlcs) . ')</h2>'; $content .= implode("<br />\n", $rlcs); sort($assigns); $content .= '<h2>Skipped, already assigned (' . count($assigns) . ')</h2>'; $content .= implode("<br />\n", $assigns); sort($notices); $content .= '<h2>Notices (' . count($notices) . ')</h2>'; $content .= implode("<br />\n", $notices); Layout::nakedDisplay($content, NULL, TRUE); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); session_write_close(); session_start(); $menuCmd = CommandFactory::getCommand('ShowStudentMenu'); if (!isset($_SESSION['RLC_REAPP'])) { $menuCmd->redirect(); } $reApp = $_SESSION['RLC_REAPP']; $term = $context->get('term'); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); $errorCmd = CommandFactory::getCommand('ShowRlcReapplicationPageTwo'); $errorCmd->setTerm($term); // Double check the the student is eligible $housingApp = HousingApplication::getApplicationByUser($student->getUsername(), $term); if (!$housingApp instanceof LotteryApplication) { NQ::simple('hms', hms\NotificationView::ERROR, 'You are not eligible to re-apply for a Learning Community.'); $menuCmd->redirect(); } // Make sure the user doesn't already have an application on file for this term $app = HMS_RLC_Application::checkForApplication($student->getUsername(), $term); if ($app !== FALSE) { NQ::simple('hms', hms\NotificationView::WARNING, 'You have already re-applied for a Learning Community for that term.'); $menuCmd->redirect(); } # Look up any existing RLC assignment (for the current term, should be the Spring term) //$rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), Term::getPrevTerm(Term::getCurrentTerm())); $question0 = $context->get('rlc_question_0'); $question1 = $context->get('rlc_question_1'); $question2 = $context->get('rlc_question_2'); $reApp->rlc_question_0 = $question0; $reApp->rlc_question_1 = $question1; $reApp->rlc_question_2 = $question2; $_SESSION['RLC_REAPP'] = $reApp; //$rlcChoice0 = $reApp->rlc_first_choice_id; $rlcChoice1 = $reApp->rlc_second_choice_id; $rlcChoice2 = $reApp->rlc_third_choice_id; if (isset($rlcChoice1) && (!isset($question1) || empty($question1))) { NQ::simple('hms', hms\NotificationView::ERROR, 'Please respond to all of the short answer questions.'); $errorCmd->redirect(); } if (isset($rlcChoice2) && (!isset($question2) || empty($question2))) { NQ::simple('hms', hms\NotificationView::ERROR, 'Please respond to all of the short answer questions.'); $errorCmd->redirect(); } // Check response lengths $wordLimit = 500; if (str_word_count($question0) > $wordLimit) { NQ::simple('hms', hms\NotificationView::ERROR, 'Your answer to question number one is too long. Please limit your response to 500 words or less.'); $errorCmd->redirect(); } if (isset($rlcChoice2) && str_word_count($question1) > $wordLimit) { NQ::simple('hms', hms\NotificationView::ERROR, 'Your answer to question number two is too long. Please limit your response to 500 words or less.'); $errorCmd->redirect(); } if (isset($rlcChoice3) && str_word_count($question2) > $wordLimit) { NQ::simple('hms', hms\NotificationView::ERROR, 'Your answer to question number three is too long. Please limit your response to 500 words or less.'); $errorCmd->redirect(); } $reApp->setDateSubmitted(time()); $reApp->setRLCQuestion0($question0); $reApp->setRLCQuestion1($question1); $reApp->setRLCQuestion2($question2); $reApp->setTerm($term); $reApp->setApplicationType(RLC_APP_RETURNING); $reApp->setDeniedEmailSent(0); $reApp->save(); unset($_SESSION['RLC_REAPP']); // Redirect back to the main menu NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your Residential Learning Community Re-application was saved successfully.'); $menuCmd->redirect(); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'RlcReapplicationView.php'); PHPWS_Core::initModClass('hms', 'HMS_Learning_Community.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); $errorCmd = CommandFactory::getCommand('ShowStudentMenu'); $term = $context->get('term'); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); // Check deadlines PHPWS_Core::initModClass('hms', 'ApplicationFeature.php'); $feature = ApplicationFeature::getInstanceByNameAndTerm('RlcReapplication', $term); if (is_null($feature) || !$feature->isEnabled()) { NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, RLC re-applications are not avaialable for this term."); $errorCmd->redirect(); } if ($feature->getStartDate() > time()) { NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, it is too soon to submit a RLC re-application."); $errorCmd->redirect(); } else { if ($feature->getEndDate() < time()) { NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, the RLC re-application deadline has already passed. Please contact University Housing if you are interested in applying for a RLC."); $errorCmd->redirect(); } } // Double check the the student is eligible $housingApp = HousingApplication::getApplicationByUser($student->getUsername(), $term); if (!$housingApp instanceof LotteryApplication) { NQ::simple('hms', hms\NotificationView::ERROR, 'You are not eligible to re-apply for a Residential Learning Community.'); $errorCmd->redirect(); } // Make sure that the student has not already applied for this term $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $term); if (!is_null($rlcApp)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You have already re-applied for a Residential Learning Community for this term.'); $errorCmd->redirect(); } // Look up any existing RLC assignment (for the fall term; current term should be the Spring term, so the previous term should be the Fall) $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), Term::getPrevTerm(Term::getCurrentTerm())); // Get the list of RLCs that the student is eligible for // Note: hard coded to 'C' because we know they're continuing at this point. // This accounts for freshmen addmitted in the spring, who will still have the 'F' type. $communities = HMS_Learning_Community::getRlcListReapplication(false, 'C'); // If the student has an existing assignment, and that community always allows returning students, then make sure the community is in the list (if it's not already) if (isset($rlcAssignment)) { // Load the RLC $rlc = $rlcAssignment->getRlc(); // If members can always reapply, make sure community id exists as an array index if ($rlc->getMembersReapply() == 1 && !isset($communities[$rlc->get_id()])) { $communities[$rlc->get_id()] = $rlc->get_community_name(); } } session_write_close(); session_start(); if (isset($_SESSION['RLC_REAPP'])) { $reApp = $_SESSION['RLC_REAPP']; } else { $reApp = null; } $view = new RlcReapplicationView($student, $term, $rlcAssignment, $communities, $reApp); $context->setContent($view->show()); }
public function show() { PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'LotteryApplication.php'); PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_Room.php'); javascript('jquery'); $tpl = array(); #TODO: place a temporary reservation on the entire room # Grab all of their preferred roommates $lotteryApplication = HousingApplication::getApplicationByUser($this->student->getUsername(), $this->term); # List each bed in the room and if it's available, assigned, or reserved $room = new HMS_Room($this->roomId); $beds = $room->get_beds(); $tpl['ROOM'] = $room->where_am_i(); $form = new PHPWS_Form(); $submitCmd = CommandFactory::getCommand('LotteryChooseRoommates'); $submitCmd->setRoomId($this->roomId); $submitCmd->initForm($form); $assigned_self = FALSE; // Whether or not we've placed *this* student in a bed yet // Search the request to see if the student has already assigned themselves previously (this is only used if the user is being // set back from a subsequent page after an error). if (isset($_REQUEST['roommates']) && !(array_search($this->student->getUsername(), $_REQUEST['roommates']) === FALSE)) { $assigned_self = TRUE; } $bedCount = count($beds); for ($i = 0; $i < $bedCount; $i++) { $bed = $beds[$i]; $bed_row = array(); $bedLabel = $room->getRoomNumber(); if ($room->get_number_of_beds() == 4) { $bedLabel = $bedLabel . $bed->getBedroomLabel(); } $bedLabel = $bedLabel . $bed->getLetter(); $bed_row['BED_LABEL'] = $bedLabel; # Check for an assignment $bed->loadAssignment(); # Check for a reservation $reservation = $bed->get_lottery_reservation_info(); if ($bed->_curr_assignment != NULL) { # Bed is assigned, so show who's in it $assignedStudent = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, $this->term); $bed_row['TEXT'] = $assignedStudent->getName() . ' (assigned)'; } else { if ($reservation != NULL) { # Bed is reserved $reservedStudent = StudentFactory::getStudentByUsername($reservation['asu_username'], $this->term); $bed_row['TEXT'] = $reservedStudent->getName() . ' (unconfirmed invitation)'; } else { if ($bed->isInternationalReserved() || $bed->isRaRoommateReserved() || $bed->isRa()) { $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" value=\"Reserved\" disabled>"; } else { # Bed is empty, so decide what we should do with it if (isset($_REQUEST['roommates'][$bed->id])) { # The user already submitted the form once, put the value in the request in the text box by default $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\" value=\"{$_REQUEST['roommates'][$bed->id]}\">"; } else { if (!$assigned_self) { # No value in the request, this bed is empty, and this user hasn't been assigned anywhere yet # So put their user name in this field by default $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\" value=\"{$this->student->getUsername()}\">"; $assigned_self = TRUE; } else { $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\">"; } } } } } $tpl['beds'][] = $bed_row; } # Decide which meal plan drop box to show based on whether or not the chosen room # is in a hall which requires a meal plan $floor = $room->get_parent(); $hall = $floor->get_parent(); if ($hall->meal_plan_required == 0) { $form->addDropBox('meal_plan', array(BANNER_MEAL_NONE => _('None'), BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super'))); $form->addCssClass('meal_plan', 'form-control'); } else { $form->addDropBox('meal_plan', array(BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super'))); $form->addCssClass('meal_plan', 'form-control'); } $form->setMatch('meal_plan', $lotteryApplication->getMealPlan()); $form->addSubmit('submit_form', 'Review Roommate & Room Selection'); $form->mergeTemplate($tpl); $tpl = $form->getTemplate(); Layout::addPageTitle("Lottery Choose Roommate"); return PHPWS_Template::process($tpl, 'hms', 'student/lottery_select_roommate.tpl'); }