Ejemplo n.º 1
0
 public function showForStudent(Student $student, $term)
 {
     // for freshmen
     if ($student->getApplicationTerm() > Term::getCurrentTerm()) {
         return false;
     }
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     $application = HousingApplication::checkForApplication($student->getUsername(), $term);
     $assignment = HMS_Assignment::checkForAssignment($student->getUsername(), $term);
     // for returning students (summer terms)
     if ($term > $student->getApplicationTerm() && $assignment !== TRUE && $application !== FALSE) {
         return true;
     }
     return false;
 }
 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');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php');
     $roommates = $context->get('roommates');
     $mealPlan = $context->get('meal_plan');
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Check for an RLC assignment in the self-select status
     $rlcAssignment = RlcMembershipFactory::getMembership($student, $term);
     $roomId = $context->get('roomId');
     if (!isset($roomId) || is_null($roomId) || empty($roomId)) {
         throw new InvalidArgumentException('Missing room id.');
     }
     // Put everything into lowercase before we get started
     foreach ($roommates as $key => $username) {
         $roommates[$key] = strtolower($username);
     }
     /**
      * Sanity checking
      */
     $errorCmd = CommandFactory::getCommand('LotteryShowChooseRoommates');
     $errorCmd->setRoomId($roomId);
     // Make sure the student assigned his/her self to a bed
     if (!in_array(UserStatus::getUsername(), $roommates)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You must assign yourself to a bed. Please try again.');
         $errorCmd->redirect();
     }
     // Get a count of how many times each user name appears
     $counts = array_count_values($roommates);
     foreach ($roommates as $roommate) {
         if ($roommate == NULL || $roommate == '') {
             continue;
         }
         // Make sure this user name only appears once
         if ($counts[$roommate] > 1) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} may only be assigned to one bed. Please try again.");
             $errorCmd->redirect();
         }
         try {
             $studentObj = StudentFactory::getStudentByUsername($roommate, $term);
         } catch (StudentNotFoundException $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} is not a valid user name. Please try again.");
             $errorCmd->redirect();
         }
         $bannerId = $studentObj->getBannerId();
         // Make sure every user name is a valid student
         if (is_null($bannerId) || empty($bannerId)) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} is not a valid user name. Please try again.");
             $errorCmd->redirect();
         }
         /*
          * We can't check the student type here, because we're working in the future with students who are possibly still considered freshmen (which will always show up as type F)
          * What we can do is make sure their application term is less than the lottery term
          */
         $roommateAppTerm = $studentObj->getApplicationTerm();
         if (!isset($roommateAppTerm) || is_null($roommateAppTerm) || empty($roommateAppTerm)) {
             NQ::simple('hms', hms\NotificationView::ERROR, "The Housing Management System does not have complete student data for {$roommate}. Please select a different roommate.");
             $errorCmd->redirect();
         }
         // Make sure the student's application term is less than the current term
         if ($studentObj->getApplicationTerm() > Term::getCurrentTerm()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} is not a continuing student. Only continuing students (i.e. not a first semester freshmen) may be selected as roommates. Please select a different roommate.");
             $errorCmd->redirect();
         }
         // Make sure the student is not withdrawn for the lottery term (again, we can't actually check for 'continuing' here)
         if ($studentObj->getType() == TYPE_WITHDRAWN) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} is not a continuing student. Only continuing students (i.e. not a first semester freshmen) may be selected as roommates. Please select a different roommate.");
             $errorCmd->redirect();
         }
         // If this student is an RLC-self-selection, then each roommate much 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($studentObj, $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 entered the lottery and has a valid application (not cancelled)
         } else {
             if (HousingApplication::checkForApplication($roommate, $term) === FALSE) {
                 NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} did not re-apply for housing. Please select a different roommate.");
                 $errorCmd->redirect();
             }
         }
         // Make sure every student's gender matches, and that those are compatible with the room
         if ($studentObj->getGender() != $student->getGender()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} is not the same gender as you. Please choose a roommate of the same gender.");
             $errorCmd->redirect();
         }
         // Make sure none of the students are assigned yet
         if (HMS_Assignment::checkForAssignment($roommate, $term) === TRUE) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} is already assigned to a room. Please choose a different roommate.");
             $errorCmd->redirect();
         }
     }
     // If we've made it this far, then everything is ok.. redirect to the confirmation screen
     $confirmCmd = CommandFactory::getCommand('LotteryShowConfirm');
     $confirmCmd->setRoomId($roomId);
     $confirmCmd->setRoommates($roommates);
     $confirmCmd->setMealPlan($mealPlan);
     $confirmCmd->redirect();
 }
Ejemplo n.º 4
0
 public static function determineEligibility($username)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Eligibility_Waiver.php');
     // First, check for an assignment in the current term
     if (HMS_Assignment::checkForAssignment($username, Term::getCurrentTerm())) {
         return true;
         // If that didn't work, check for a waiver in the lottery term
     } elseif (HMS_Eligibility_Waiver::checkForWaiver($username, PHPWS_Settings::get('hms', 'lottery_term'))) {
         return true;
         // If that didn't work either, then the student is not elibible, so return false
     } else {
         return false;
     }
 }
Ejemplo n.º 5
0
 public function execute(CommandContext $context)
 {
     $currentTerm = Term::getCurrentTerm();
     $username = UserStatus::getUsername();
     # Create a contact form command, redirect to it in case of error.
     $contactCmd = CommandFactory::getCommand('ShowContactForm');
     //TODO add try catch blocks here for StudentNotFound exception
     $student = StudentFactory::getStudentByUsername($username, $currentTerm);
     $applicationTerm = $student->getApplicationTerm();
     // In case this is a new freshmen, they'll likely have no student type in the "current" term.
     // So, instead, we need to lookup the student in their application term.
     if ($applicationTerm > $currentTerm) {
         $student = StudentFactory::getStudentByUsername($username, $applicationTerm);
     }
     $studentType = $student->getType();
     $studentClass = $student->getClass();
     $dob = $student->getDob();
     # Check for banner errors in any of these calls
     if (empty($applicationTerm) || empty($studentType) || empty($studentClass) || empty($dob) || is_null($dob)) {
         # TODO: HMS_Mail here
         PHPWS_Error::log('Initial banner lookup failed', 'hms', 'show_welcome_screen', "username: "******"too early" message
             if (!Term::isValidTerm($applicationTerm)) {
                 PHPWS_Core::initModClass('hms', 'WelcomeScreenViewInvalidTerm.php');
                 $view = new WelcomeScreenViewInvalidTerm($applicationTerm, $contactCmd);
                 $context->setContent($view->show());
                 return;
             }
             # Make sure the student doesn't already have an assignment on file for the current term
             if (HMS_Assignment::checkForAssignment($username, $currentTerm)) {
                 # No idea what's going on here, send to a contact page
                 $contactCmd->redirect();
             }
             # Check to see if the user has an application on file already for every required term
             # If so, forward to main menu
             $requiredTerms = HousingApplication::checkAppliedForAllRequiredTerms($student);
             if (count($requiredTerms) > 0) {
                 # Student is missing a required application, so redirect to the application form for that term
                 $appCmd = CommandFactory::getCommand('ShowHousingApplicationWelcome');
                 $appCmd->setTerm($requiredTerms[0]);
                 $appCmd->redirect();
             } else {
                 $menuCmd = CommandFactory::getCommand('ShowFreshmenMainMenu');
                 $menuCmd->redirect();
             }
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Removes/unassignes a student
  *
  * Valid values for $reason are defined in defines.php.
  *
  * @param Student $student Student to un-assign.
  * @param String $term The term of the assignment to remove.
  * @param String $notes Additional notes for the ActivityLog.
  * @param String $reason Reason string, defined in defines.php
  * @param Integer $refund Percentage of original charges student should be refunded
  * @throws PermissionException
  * @throws InvalidArgumentException
  * @throws AssignmentException
  * @throws DatabaseException
  */
 public static function unassignStudent(Student $student, $term, $notes = "", $reason, $refund)
 {
     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 unassign students.');
     }
     PHPWS_Core::initModClass('hms', 'BannerQueue.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'AssignmentHistory.php');
     PHPWS_Core::initModClass('hms', 'exception/AssignmentException.php');
     $username = $student->getUsername();
     // Make sure a username was entered
     if (!isset($username) || $username == '') {
         throw new InvalidArgumentException('Bad username.');
     }
     $username = strtolower($username);
     // Check refund field, required field
     if (!isset($refund) || $refund == '') {
         throw new InvalidArgumentException('Please enter a refund percentage.');
     }
     // Refund must be numeric
     if (!is_numeric($refund) || $refund < 0 || $refund > 100) {
         throw new InvalidArgumentException('The refund percentage must be between 0 and 100 percent.');
     }
     // Must be whole number
     if (is_float($refund)) {
         throw new InvalidArgumentException('Only whole number refund percentages are supported, no decimal place is allowed.');
     }
     // Make sure the requested username is actually assigned
     if (!HMS_Assignment::checkForAssignment($username, $term)) {
         throw new AssignmentException('Student is not assigned.');
     }
     $assignment = HMS_Assignment::getAssignment($username, $term);
     if ($assignment == FALSE || $assignment == NULL) {
         throw new AssignmentException('Could not load assignment object.');
     }
     $bed = $assignment->get_parent();
     $room = $bed->get_parent();
     $floor = $room->get_parent();
     $building = $floor->get_parent();
     // Attempt to unassign the student in Banner though SOAP
     $banner_result = BannerQueue::queueRemoveAssignment($student, $term, $building, $bed, $refund);
     // Show an error and return if there was an error
     if ($banner_result !== TRUE) {
         throw new AssignmentException('Error while adding the assignment removal to the Banner queue.');
     }
     // Record this before we delete from the db
     $banner_bed_id = $bed->getBannerId();
     $banner_building_code = $building->getBannerBuildingCode();
     // Attempt to delete the assignment in HMS
     $result = $assignment->delete();
     if (!$result) {
         throw new DatabaseException($result->toString());
     }
     // Log in the activity log
     HMS_Activity_Log::log_activity($username, ACTIVITY_REMOVED, UserStatus::getUsername(), $term . ' ' . $banner_building_code . ' ' . $banner_bed_id . ' ' . $notes . 'Refund: ' . $refund);
     // Insert into history table
     AssignmentHistory::makeUnassignmentHistory($assignment, $reason);
     // Generate assignment notices for old roommates
     $assignees = $room->get_assignees();
     // get an array of student objects for those assigned to this room
     if (sizeof($assignees) > 1) {
         foreach ($assignees as $roommate) {
             // Skip this student
             if ($roommate->getUsername() == $username) {
                 continue;
             }
             $roommate_assign = HMS_Assignment::getAssignment($roommate->getUsername(), Term::getSelectedTerm());
             $roommate_assign->letter_printed = 0;
             $roommate_assign->email_sent = 0;
             $roommate_assign->save();
         }
     }
     // Show a success message
     return true;
 }
Ejemplo n.º 7
0
 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();
 }