public function execute(CommandContext $context)
 {
     // Check permissions
     if (!Current_User::allow('hms', 'checkin')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to checkin students.');
     }
     $term = Term::getSelectedTerm();
     $bannerId = $context->get('bannerId');
     $hallId = $context->get('hallId');
     $errorCmd = CommandFactory::getCommand('ShowCheckinStart');
     if (!isset($bannerId) || is_null($bannerId) || $bannerId == '') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing Banner ID.');
         $errorCmd->redirect();
     }
     if (!isset($hallId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing residence hall ID.');
         $errorCmd->redirect();
     }
     // Check the Banner ID
     if (preg_match("/[\\d]{9}/", $bannerId) == false) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Imporperly formatted Banner ID.');
         $errorCmd->redirect();
     }
     // Try to lookup the student in Banner
     try {
         $student = StudentFactory::getStudentByBannerId($bannerId, $term);
     } catch (StudentNotFoundException $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Could not locate a student with that Banner ID.');
         $errorCmd->redirect();
     }
     // Make sure the student is assigned in the current term
     $assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $term);
     if (!isset($assignment) || is_null($assignment)) {
         NQ::simple('hms', hms\NotificationView::ERROR, $student->getName() . ' is not assigned for ' . Term::toString($term) . '. Please contact the University Housing Assignments Office at 828-262-6111.');
         $errorCmd->redirect();
     }
     // Make sure the student's assignment matches the hall the user selected
     $bed = $assignment->get_parent();
     $room = $bed->get_parent();
     $floor = $room->get_parent();
     $hall = $floor->get_parent();
     if ($hallId != $hall->getId()) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Wrong hall! ' . $student->getName() . ' is assigned to ' . $assignment->where_am_i());
         $errorCmd->redirect();
     }
     // Load any existing check-in
     $checkin = CheckinFactory::getLastCheckinByBannerId($bannerId, $term);
     // If there is a checkin for the same bed, and the difference between the current time and the checkin time is
     // greater than 48 hours, then show an error.
     if (!is_null($checkin)) {
         $checkoutDate = $checkin->getCheckoutDate();
         if ($checkin->getBedId() == $bed->getId() && !isset($checkoutDate) && time() - $checkin->getCheckinDate() > Checkin::CHECKIN_TIMEOUT) {
             NQ::simple('hms', hms\NotificationView::ERROR, $student->getName() . ' has already checked in to ' . $assignment->where_am_i());
             $errorCmd->redirect();
         }
     }
     $view = new CheckinFormView($student, $assignment, $hall, $floor, $room, $checkin);
     $context->setContent($view->show());
 }
Esempio n. 2
0
 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())));
     }
 }
Esempio n. 4
0
 public function show_verify_assignment()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Term.php');
     PHPWS_Core::initModClass('hms', 'HMS_SOAP.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Learning_Community.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Movein_Time.php');
     $tpl = array();
     $assignment = HMS_Assignment::get_assignment($_SESSION['asu_username'], $_SESSION['application_term']);
     if ($assignment === NULL || $assignment == FALSE) {
         $tpl['NO_ASSIGNMENT'] = "You do not currently have a housing assignment.";
     } else {
         $tpl['ASSIGNMENT'] = $assignment->where_am_i() . '<br />';
         # Determine the student's type and figure out their movein time
         $type = HMS_SOAP::get_student_type($_SESSION['asu_username'], $_SESSION['application_term']);
         if ($type == TYPE_CONTINUING) {
             $movein_time_id = $assignment->get_rt_movein_time_id();
         } elseif ($type == TYPE_TRANFER) {
             $movein_time_id = $assignment->get_t_movein_time_id();
         } else {
             $movein_time_id = $assignment->get_f_movein_time_id();
         }
         if ($movein_time_id == NULL) {
             $tpl['MOVE_IN_TIME'] = 'To be determined<br />';
         } else {
             $movein_times = HMS_Movein_Time::get_movein_times_array($_SESSION['application_term']);
             $tpl['MOVE_IN_TIME'] = $movein_times[$movein_time_id];
         }
     }
     //get the assignees to the room that the bed that the assignment is in
     $assignees = !is_null($assignment) ? $assignment->get_parent()->get_parent()->get_assignees() : NULL;
     $roommates = array();
     if (!is_null($assignees)) {
         foreach ($assignees as $roommate) {
             if ($roommate->asu_username != $_SESSION['asu_username']) {
                 $roommates[] = $roommate->asu_username;
             }
         }
     }
     if (empty($roommates)) {
         $tpl['roommate'][]['ROOMMATE'] = 'You do not have a roommate.';
     } else {
         foreach ($roommates as $roommate) {
             $tpl['roommate'][]['ROOMMATE'] = '' . HMS_SOAP::get_name($roommate) . ' (<a href="mailto:' . $roommate . '@appstate.edu">' . $roommate . '@appstate.edu</a>)';
         }
     }
     $rlc_assignment = HMS_RLC_Assignment::check_for_assignment($_SESSION['asu_username'], $_SESSION['application_term']);
     if ($rlc_assignment == NULL || $rlc_assignment === FALSE) {
         $tpl['RLC'] = "You have not been accepted to an RLC.";
     } else {
         $rlc_list = HMS_Learning_Community::getRlcList();
         $tpl['RLC'] = 'You have been assigned to the ' . $rlc_list[$rlc_assignment['rlc_id']];
     }
     $tpl['MENU_LINK'] = PHPWS_Text::secureLink('Back to Main Menu', 'hms', array('type' => 'student', 'op' => 'show_main_menu'));
     return PHPWS_Template::process($tpl, 'hms', 'student/verify_assignment.tpl');
 }
Esempio n. 5
0
 public function getMenuBlockView(Student $student)
 {
     PHPWS_Core::initModClass('hms', 'RoomChangeMenuBlockView.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'RoomChangeRequestFactory.php');
     $assignment = HMS_Assignment::getAssignment($student->getUsername(), $this->term);
     $request = RoomChangeRequestFactory::getPendingByStudent($student, $this->term);
     return new RoomChangeMenuBlockView($student, $this->term, $this->getStartDate(), $this->getEndDate(), $assignment, $request);
 }
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'cancel_housing_application')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to cancel housing applications.');
     }
     // Check for a housing application id
     $applicationId = $context->get('applicationId');
     if (!isset($applicationId) || is_null($applicationId)) {
         throw new InvalidArgumentException('Missing housing application id.');
     }
     // Check for a cancellation reason
     $cancelReason = $context->get('cancel_reason');
     if (!isset($cancelReason) || is_null($cancelReason)) {
         throw new InvalidArgumentException('Missing cancellation reason.');
     }
     // Load the housing application
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     $application = HousingApplicationFactory::getApplicationById($applicationId);
     // Load the student
     $student = $application->getStudent();
     $username = $student->getUsername();
     $term = $application->getTerm();
     // Load the cancellation reasons
     $reasons = HousingApplication::getCancellationReasons();
     // Check for an assignment and remove it
     // Decide which term to use - If this application is in a past fall term, then use the current term
     if ($term < Term::getCurrentTerm() && Term::getTermSem($term) == TERM_FALL) {
         $assignmentTerm = Term::getCurrentTerm();
     } else {
         $assignmentTerm = $term;
     }
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     $assignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $assignmentTerm);
     if (isset($assignment)) {
         // TODO: Don't hard code cancellation refund percentage
         HMS_Assignment::unassignStudent($student, $assignmentTerm, 'Application cancellation: ' . $reasons[$cancelReason], UNASSIGN_CANCEL, 100);
     }
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($username, $term);
     if (!is_null($rlcAssignment)) {
         $rlcAssignment->delete();
     }
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     $rlcApplication = HMS_RLC_Application::getApplicationByUsername($username, $term);
     if (!is_null($rlcApplication)) {
         $rlcApplication->denied = 1;
         $rlcApplication->save();
         HMS_Activity_Log::log_activity($username, ACTIVITY_DENIED_RLC_APPLICATION, \Current_User::getUsername(), Term::toString($term) . ' Denied RLC Application due to Contract Cancellation');
     }
     // Cancel the application
     $application->cancel($cancelReason);
     $application->save();
     echo 'success';
     exit;
 }
 public function show()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Learning_Community.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Movein_Time.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     $tpl = array();
     $assignment = HMS_Assignment::getAssignment($this->student->getUsername(), $this->term);
     if ($assignment === NULL || $assignment == FALSE) {
         $tpl['NO_ASSIGNMENT'] = "You do not currently have a housing assignment.";
     } else {
         $tpl['ASSIGNMENT'] = $assignment->where_am_i() . '<br />';
         # Determine the student's type and figure out their movein time
         $type = $this->student->getType();
         if ($type == TYPE_CONTINUING) {
             $movein_time_id = $assignment->get_rt_movein_time_id();
         } elseif ($type == TYPE_TRANSFER) {
             $movein_time_id = $assignment->get_t_movein_time_id();
         } else {
             $movein_time_id = $assignment->get_f_movein_time_id();
         }
         if ($movein_time_id == NULL) {
             $tpl['MOVE_IN_TIME'] = 'To be determined<br />';
         } else {
             $movein_times = HMS_Movein_Time::get_movein_times_array($this->term);
             $tpl['MOVE_IN_TIME'] = $movein_times[$movein_time_id];
         }
     }
     //get the assignees to the room that the bed that the assignment is in
     $assignees = !is_null($assignment) ? $assignment->get_parent()->get_parent()->get_assignees() : NULL;
     if (!is_null($assignees)) {
         foreach ($assignees as $roommate) {
             if ($roommate->getUsername() != $this->student->getUsername()) {
                 $assignment = HMS_Assignment::getAssignment($roommate->getUsername(), $this->term);
                 $assignment->loadBed();
                 $label = $assignment->_bed->bedroom_label;
                 $tpl['roommate'][]['ROOMMATE'] = $roommate->getFullName() . ' - ' . $label . ' (' . $roommate->getEmailLink() . ')';
             }
         }
     } else {
         $tpl['roommate'] = 'You do not have a roommate';
     }
     $rlc_assignment = HMS_RLC_Assignment::checkForAssignment($this->student->getUsername(), $this->term);
     if ($rlc_assignment == NULL || $rlc_assignment === FALSE) {
         $tpl['RLC'] = "You have not been accepted to an RLC.";
     } else {
         $rlc_list = HMS_Learning_Community::getRlcList();
         $tpl['RLC'] = 'You have been assigned to the ' . $rlc_list[$rlc_assignment['rlc_id']];
     }
     $tpl['MENU_LINK'] = PHPWS_Text::secureLink('Back to Main Menu', 'hms', array('type' => 'student', 'op' => 'show_main_menu'));
     Layout::addPageTitle("Verify Assignment");
     return PHPWS_Template::process($tpl, 'hms', 'student/verify_assignment.tpl');
 }
Esempio n. 8
0
 public function getMenuBlockView(Student $student)
 {
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'RlcSelfSelectionMenuBlockView.php');
     PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
     $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), $this->getTerm());
     $roomAssignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $this->getTerm());
     $roommateRequests = HMS_Lottery::get_lottery_roommate_invites($student->getUsername(), $this->term);
     return new RlcSelfSelectionMenuBlockView($this->term, $this->getStartDate(), $this->getEndDate(), $rlcAssignment, $roomAssignment, $roommateRequests);
 }
 /**
  *
  * @param CommandContext $context
  * @throws PermissionException
  */
 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 unassign students.');
     }
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     $username = $context->get('username');
     $unassignReason = $context->get('unassignment_type');
     $cmd = CommandFactory::getCommand('ShowUnassignStudent');
     // $cmd->setUsername($username);
     if (!isset($username) || is_null($username)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid or missing username.');
         $cmd->redirect();
     }
     // Make sure a valid reason was chosen
     if (!isset($unassignReason) || $unassignReason == -1) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please choose a valid reason.');
         $cmd->setUsername($username);
         $cmd->redirect();
     }
     // Check refund percentage field
     $refund = $context->get('refund');
     // Is a required field
     if (!isset($refund) || $refund == '') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please enter a refund percentage.');
         $cmd->redirect();
     }
     // Must be numeric
     if (!is_numeric($refund) || $refund < 0 || $refund > 100) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'The refund percentage must be between 0 and 100 percent.');
         $cmd->redirect();
     }
     // Must be whole number
     if (is_float($refund)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Only whole number refund percentages are supported, no decimal place is allowed.');
         $cmd->redirect();
     }
     $term = Term::getSelectedTerm();
     $student = StudentFactory::getStudentByUsername($username, $term);
     $notes = $context->get('note');
     try {
         HMS_Assignment::unassignStudent($student, $term, $notes, $unassignReason, $refund);
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Error: ' . $e->getMessage());
         $cmd->setUsername($username);
         $cmd->redirect();
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Successfully unassigned ' . $student->getFullName());
     $cmd->redirect();
 }
Esempio n. 10
0
 public function execute()
 {
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $db = new PHPWS_DB('hms_new_application');
     $db->addColumn('hms_new_application.*');
     $db->addWhere('term', $this->term);
     $db->addWhere('cancelled', 0);
     $term = Term::getTermSem($this->term);
     if ($term == TERM_FALL) {
         $db->addJoin('LEFT', 'hms_new_application', 'hms_fall_application', 'id', 'id');
         $db->addColumn('hms_fall_application.*');
     } else {
         if ($term == TERM_SUMMER1 || $term == TERM_SUMMER2) {
             $db->addJoin('LEFT', 'hms_new_application', 'hms_summer_application', 'id', 'id');
             $db->addColumn('hms_summer_application.*');
         }
     }
     $result = $db->select();
     $app = array();
     foreach ($result as $app) {
         $username = $app['username'];
         $bannerId = $app['banner_id'];
         $type = $app['student_type'];
         $cellPhone = $app['cell_phone'];
         $date = date('n/j/Y', $app['created_on']);
         $assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $this->term);
         if (!is_null($assignment)) {
             $room = $assignment->where_am_i();
         } else {
             $room = '';
         }
         $student = StudentFactory::getStudentByBannerId($bannerId, $this->term);
         $first = $student->getFirstName();
         $middle = $student->getMiddleName();
         $last = $student->getLastName();
         $gender = $student->getPrintableGender();
         $birthday = date("m/d/Y", $student->getDobDateTime()->getTimestamp());
         $address = $student->getAddress(NULL);
         if ($term == TERM_SPRING || $term == TERM_FALL) {
             $lifestyle = $app['lifestyle_option'] == 1 ? 'Single Gender' : 'Co-Ed';
         } else {
             $lifestyle = $app['room_type'] == 1 ? 'Single Room' : 'Double Room';
         }
         if (!is_null($address) && $address !== false) {
             $this->rows[] = array($username, $bannerId, $first, $middle, $last, $gender, $type, $cellPhone, $room, $date, $address->line1, $address->line2, $address->line3, $address->city, $address->state, $address->zip, $birthday, $lifestyle);
         } else {
             $this->rows[] = array($username, $bannerId, $first, $middle, $last, '', $type, $cellPhone, $room, $date, '', '', '', '', '', '', $lifestyle);
         }
     }
 }
 public function execute(CommandContext $context)
 {
     if (!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', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'AssignmentMoveConfirmationView.php');
     $student = StudentFactory::getStudentByUsername($context->get('username'), Term::getSelectedTerm());
     $assignment = HMS_Assignment::getAssignment($student->getUsername(), Term::getSelectedTerm());
     $moveConfirmView = new AssignmentMoveConfirmationView($student, $assignment, $context->get('residence_hall'), $context->get('room'), $context->get('bed'), $context->get('meal_plan'), $context->get('assignment_type'), $context->get('notes'));
     $context->setContent($moveConfirmView->show());
 }
Esempio n. 12
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;
             }
         }
     }
 }
Esempio n. 13
0
 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);
 }
Esempio n. 14
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)
 {
     $term = Term::getCurrentTerm();
     // Get the current student
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Check for an assignment
     $assignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $term);
     // If not assigned, then redirect to the main menu with an error
     if (is_null($assignment)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You do not have a room assignment for the current semester.');
         $cmd = CommandFactory::getCommand('ShowStudentMenu');
         $cmd->redirect();
     }
     $tpl['NAME'] = $student->getFullName();
     $tpl['ASSIGNMENT'] = $assignment->where_am_i();
     $tpl['TERM'] = Term::toString($term);
     $context->setContent(\PHPWS_Template::process($tpl, 'hms', 'student/residenceVerification.tpl'));
 }
 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)
 {
     $applicationId = $context->get('applicationId');
     if (!isset($applicationId)) {
         throw new InvalidArgumentException('Missing application id.');
     }
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     $application = HousingApplicationFactory::getApplicationById($applicationId);
     $student = $application->getStudent();
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     // Decide which term to use - If this application is in a past fall term, then use the current term
     $term = $application->getTerm();
     if ($term < Term::getCurrentTerm() && Term::getTermSem($term) == TERM_FALL) {
         $assignmentTerm = Term::getCurrentTerm();
     } else {
         $assignmentTerm = $term;
     }
     $assignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $assignmentTerm);
     PHPWS_Core::initModClass('hms', 'HousingApplicationCancelView.php');
     $view = new HousingApplicationCancelView($student, $application, $assignment);
     echo $view->show();
     exit;
 }
Esempio n. 18
0
 /**
  * Handles looking up and removing assignments
  * @param Student $student
  */
 private function handleAssignment(Student $student)
 {
     // Look for an assignment and delete it
     $assignment = HMS_Assignment::getAssignment($student->getUsername(), $this->term);
     if (!is_null($assignment)) {
         $location = $assignment->where_am_i();
         try {
             //TODO Don't hard-code refund percentage
             HMS_Assignment::unassignStudent($student, $this->term, 'Automatically removed by Withdrawn Search', UNASSIGN_CANCEL, 100);
         } catch (Exception $e) {
             //TODO
         }
         $this->actions[$student->getUsername()][] = 'Removed assignment: ' . $location;
         HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_WITHDRAWN_ASSIGNMENT_DELETED, UserStatus::getUsername(), 'Withdrawn search: ' . $location);
     }
 }
Esempio n. 19
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();
 }
Esempio n. 20
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;
 }
 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();
             }
         }
     }
 }
Esempio n. 22
0
 /**
  * Sends a notification to the Future RD involved in a room change request
  * letting them know they need to log in and approve
  *
  * Template Tags:
  * {STUDENT_NAME}
  * {FUTURE_ASSIGNMENT}
  * {CELL_PHONE}
  *
  * @param $rd string The username of the RD
  * @param $participant RoomChangeParticipant The Participant object involved
  */
 public static function sendRoomChangeFutureRDNotice(RoomChangeRequest $request)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $subject = 'Room Change Approval Required';
     $template = 'email/roomChangeFutureRDNotice.tpl';
     $tags = array('PARTICIPANTS' => array());
     $rds = array();
     $term = Term::getCurrentTerm();
     foreach ($request->getParticipants() as $p) {
         // Add participant's future RD(s) to recipients
         $rds = array_merge($rds, $p->getFutureRdList());
         $bid = $p->getBannerId();
         $student = StudentFactory::getStudentByBannerID($bid, $term);
         $assign = HMS_Assignment::getAssignmentByBannerID($bid, $term);
         $future = new HMS_Bed($p->getToBed());
         $participantTags = array('BANNER_ID' => $student->getBannerId(), 'NAME' => $student->getName(), 'CURRENT' => $assign->where_am_i(), 'DESTINATION' => $future->where_am_i());
         $tags['PARTICIPANTS'][] = $participantTags;
     }
     // In case an RD ends up in here several times, no need for dup emails
     $recips = array_unique($rds);
     $message = self::makeSwiftmailMessage(null, $subject, $tags, $template);
     foreach ($recips as $recip) {
         $message->setTo($recip . TO_DOMAIN);
         self::sendSwiftmailMessage($message);
     }
 }
 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();
 }
Esempio n. 24
0
 /**
  * Fetch a roommate's bedroom label and create a link to that room
  */
 private function getRoommateRoomLink($username)
 {
     // Get link for roommates' room
     $rmAssignment = HMS_Assignment::getAssignment($username, $this->term);
     if (!is_null($rmAssignment)) {
         $rmAssignment->loadBed();
         $editRoomCmd = CommandFactory::getCommand('EditRoomView');
         $editRoomCmd->setRoomId($rmAssignment->_bed->room_id);
         $roomLink = $editRoomCmd->getLink($rmAssignment->_bed->bedroom_label);
         return $roomLink;
     } else {
         return null;
     }
 }
 public function execute(CommandContext $context)
 {
     // Check permissions
     if (!Current_User::allow('hms', 'checkin')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to checkin students.');
     }
     $bannerId = $context->get('bannerId');
     $hallId = $context->get('hallId');
     // Check for key code
     $keyCode = $context->get('key_code');
     if (!isset($keyCode) || $keyCode == '') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please enter a key code.');
         $errorCmd = CommandFactory::getCommand('ShowCheckinForm');
         $errorCmd->setBannerId($bannerId);
         $errorCmd->setHallId($hallId);
         $errorCmd->redirect();
     }
     $term = Term::getSelectedTerm();
     // Lookup the student
     $student = StudentFactory::getStudentByBannerId($bannerId, $term);
     // Get the student's current assignment
     $assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $term);
     $bed = $assignment->get_parent();
     // Get the currently logged in user
     $currUser = Current_User::getUsername();
     // Check for an existing Check-in
     $checkin = CheckinFactory::getCheckinByBed($student, $bed);
     // If there's not already a checkin for this bed, create a new one
     if (is_null($checkin)) {
         $checkin = new Checkin($student, $bed, $term, $currUser, $keyCode);
     } else {
         if ($checkin->getBedId() == $bed->getId() && time() - $checkin->getCheckinDate() < Checkin::CHECKIN_TIMEOUT) {
             // Check-in already exists, and it's within the timout window, so we'll overwrite the existing checkin
             $updatedCheckin = new Checkin($student, $bed, $term, $currUser, $keyCode);
             $updatedCheckin->substitueForExistingCheckin($checkin);
             // Use the old checkin to replace this one
             $checkin = $updatedCheckin;
         } else {
             // There's an existing checkin, but it's after the timeout, so we need to make a new checkin
             $checkin = new Checkin($student, $bed, $term, $currUser, $keyCode);
         }
     }
     $checkin->save();
     // Add this to the activity log
     HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_CHECK_IN, UserStatus::getUsername(), $assignment->where_am_i());
     // Generate the RIC
     PHPWS_Core::initModClass('hms', 'InfoCard.php');
     PHPWS_Core::initModClass('hms', 'InfoCardPdfView.php');
     $infoCard = new InfoCard($checkin);
     $infoCardView = new InfoCardPdfView();
     $infoCardView->addInfoCard($infoCard);
     // Send confirmation Email with the RIC form to the student
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     HMS_Email::sendCheckinConfirmation($student, $infoCard, $infoCardView);
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Checkin successful.');
     // Redirect to success page with option to print check-in document.
     $cmd = CommandFactory::getCommand('ShowCheckinDocument');
     $cmd->setBannerId($student->getBannerId());
     $cmd->setCheckinId($checkin->getId());
     $cmd->redirect();
 }
Esempio n. 26
0
 /**
  * Returns this rlc application (and assignment) as array of fields for CSV export
  *
  * @return Array
  */
 public function viewByRLCExportFields()
 {
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $row = array();
     // Get the Student object
     try {
         $student = StudentFactory::getStudentByUsername($this->username, Term::getSelectedTerm());
     } catch (StudentNotFoundException $e) {
         // Catch the StudentNotFound exception in the odd case that someone doesn't exist.
         // Show a warning message and skip the rest of the method
         NQ::simple('hms', hms\NotificationView::WARNING, "No student found with username: {$this->username}.");
         $row['username'] = $this->username;
         $row['name'] = 'UNKNOWN - INVALID';
         return $tags;
     }
     $row['name'] = $student->getFullName();
     $row['gender'] = $student->getPrintableGender();
     $row['student_type'] = $student->getPrintableType();
     $row['username'] = $student->getUsername();
     $row['banner_id'] = $student->getBannerId();
     /*** Assignment Status/State ***/
     // Lookup the assignmnet (used later as well)
     $assign = HMS_RLC_Assignment::getAssignmentByUsername($this->username, $this->term);
     $state = $assign->getStateName();
     if ($state == 'confirmed') {
         $row['state'] = 'confirmed';
     } else {
         if ($state == 'declined') {
             $row['state'] = 'declined';
         } else {
             if ($state == 'new') {
                 $row['state'] = 'not invited';
             } else {
                 if ($state == 'invited') {
                     $row['state'] = 'pending';
                 } else {
                     $row['state'] = '';
                 }
             }
         }
     }
     // Check for/display room assignment
     $roomAssign = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), Term::getSelectedTerm());
     if (isset($roomAssign)) {
         $row['room_assignment'] = $roomAssign->where_am_i();
     } else {
         $row['room_assignment'] = 'n/a';
     }
     /*** Roommates ***/
     // Show all possible roommates for this application
     PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
     $allRoommates = HMS_Roommate::get_all_roommates($this->username, $this->term);
     $row['roommates'] = 'N/A';
     // Default text
     if (sizeof($allRoommates) > 1) {
         // Don't show all the roommates
         $row['roommates'] = "Multiple Requests";
     } elseif (sizeof($allRoommates) == 1) {
         // Get other roommate
         $otherGuy = StudentFactory::getStudentByUsername($allRoommates[0]->get_other_guy($this->username), $this->term);
         $row['roommates'] = $otherGuy->getFullName();
         // If roommate is pending then show little status message
         if (!$allRoommates[0]->confirmed) {
             $row['roommates'] .= " (Pending)";
         }
     }
     return $row;
 }
 public function execute(CommandContext $context)
 {
     // Cmd to redirect to when we're done or upon error.
     $formCmd = CommandFactory::getCommand('ShowRoomChangeRequestForm');
     $menuCmd = CommandFactory::getCommand('ShowStudentMenu');
     // Get input
     $cellNum = $context->get('cell_num');
     $optOut = $context->get('cell_opt_out');
     $firstHallPref = $context->get('first_choice');
     $secondHallPref = $context->get('second_choice');
     $term = Term::getCurrentTerm();
     // Create the student object
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Make sure the student is currently assigned
     $assignment = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), $term);
     if (is_null($assignment)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You are not currently assigned to a room, so you cannot request a room change.');
         $menuCmd->redirect();
     }
     // Get the HMS_Bed object corresponding to the student's current assignment
     $bed = $assignment->get_parent();
     $room = $bed->get_parent();
     // Check for an existing room change request
     $changeReq = RoomChangeRequestFactory::getPendingByStudent($student, $term);
     if (!is_null($changeReq)) {
         // has pending request
         NQ::simple('hms', hms\NotificationView::ERROR, 'You already have a pending room change request. You cannot submit another request until your pending request is processed.');
         $menuCmd->redirect();
     }
     // Check that a cell phone number was provided, or that the opt-out box was checked.
     if ((!isset($cellNum) || empty($cellNum)) && !isset($optOut)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please provide a cell phone number or check the box indicating you do not wish to provide it.');
         $formCmd->redirect();
     }
     // Check the format of the cell phone number
     if (isset($cellNum)) {
         // Filter out non-numeric characters
         $cellNum = preg_replace("/[^0-9]/", '', $cellNum);
     }
     $reason = $context->get('reason');
     // Make sure a 'reason' was provided.
     if (!isset($reason) || empty($reason)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Please provide a brief explaniation of why you are requesting a room change.');
         $formCmd->redirect();
     }
     $type = $context->get('type');
     // Extra sanity checks if we're doing a switch
     if ($type == 'swap') {
         $switchUsername = $context->get('swap_with');
         // Can't switch with yourself
         if ($student->getUsername() == $switchUsername) {
             NQ::simple('hms', hms\NotificationView::ERROR, "You can't swtich rooms with yourself. Please choose someone other than yourself.");
             $formCmd->redirect();
         }
         // Load the other student
         try {
             $swapStudent = StudentFactory::getStudentByUsername($switchUsername, $term);
         } catch (StudentNotFoundException $e) {
             NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, we could not find a student with the user name '{$switchUsername}'. Please double-check the user name of the student you would like to switch places with.");
             $formCmd->redirect();
         }
         // Make sure the student is assigned
         $swapAssignment = HMS_Assignment::getAssignmentByBannerId($swapStudent->getBannerId(), $term);
         if (is_null($swapAssignment)) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$swapStudent->getName()} is not currently assigned. Please choose another student to switch rooms with.");
             $formCmd->redirect();
         }
         // Make sure the other student's room is the same gender as this room
         $swapBed = $swapAssignment->get_parent();
         $swapRoom = $swapBed->get_parent();
         if ($swapRoom->getGender() != $room->getGender()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$swapStudent->getName()} is assigned to a room of a different gender than you. Please choose student of the same gender as yourself to switch rooms with.");
             $formCmd->redirect();
         }
         // Check to see if the other student is already involved in a room change request
         $swapStudentReq = RoomChangeRequestFactory::getPendingByStudent($swapStudent, $term);
         if (!is_null($swapStudentReq)) {
             // has pending request
             NQ::simple('hms', hms\NotificationView::ERROR, 'The student you are requesting to swap with already has a pending room change request. You cannot request to swap with him/her until the pending request is processed.');
             $menuCmd->redirect();
         }
     }
     //create the request object
     $request = new RoomChangeRequest($term, $reason);
     $request->save();
     // Main participant
     $participant = new RoomChangeParticipant($request, $student, $bed);
     if (isset($cellNum)) {
         $participant->setCellPhone($cellNum);
     }
     // Switching to a different room, so set params on main participant
     if ($type == 'switch') {
         // preferences
         if (!empty($firstHallPref)) {
             $hall = new HMS_Residence_Hall($firstHallPref);
             if (!is_null($hall->getId())) {
                 $participant->setHallPref1($hall);
             }
         }
         if (!empty($secondHallPref)) {
             $hall = new HMS_Residence_Hall($secondHallPref);
             if (!is_null($hall->getId())) {
                 $participant->setHallPref2($hall);
             }
         }
         // Save the main participant and its state
         $participant->save();
         // No further approval is required so we skip a step
         HMS_Email::sendRoomChangeCurrRDNotice($request);
     } else {
         if ($type == 'swap') {
             // Swapping with another student, so handle the other particpant
             // Set main participant's toBed to other student's bed
             $participant->setToBed($swapBed);
             // Create the other participant
             $swapParticipant = new RoomChangeParticipant($request, $swapStudent, $swapBed);
             // Set other student's toBed to main participant's bed
             $swapParticipant->setToBed($bed);
             $swapParticipant->save();
             // Save the main participant and its state
             $participant->save();
             // Send "request needs your approval" to other students
             // TODO: When you add the ability to have many people on this request, you will
             //       need to put a foreach loop here or something.
             HMS_Email::sendRoomChangeParticipantNotice($participant, $swapParticipant);
         }
     }
     // Immediately transition to the StudentApproved state.
     $participant->transitionTo(new ParticipantStateStudentApproved($participant, time(), null, UserStatus::getUsername()));
     HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_ROOM_CHANGE_SUBMITTED, UserStatus::getUsername(FALSE), $reason);
     // Email sender with acknowledgment
     HMS_Email::sendRoomChangeRequestReceivedConfirmation($student);
     if ($type == 'switch') {
         NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your room change request has been received and is pending approval. You will be contacted by your Residence Director (RD) in the next 24-48 hours regarding your request.');
     } else {
         NQ::simple('hms', hms\NotificationView::SUCCESS, 'Your room change request has been received. The student(s) you selected to swap with must sign-in and agree to the request. It will then be forwarded to your Residence Director and the Housing Assignments Office for approval.');
     }
     $menuCmd->redirect();
 }
 public function execute(CommandContext $context)
 {
     // Get input
     $requestId = $context->get('requestId');
     // Get the current term
     $term = Term::getCurrentTerm();
     // Load the request
     $request = RoomChangeRequestFactory::getRequestById($requestId);
     // Load the participants
     $participants = $request->getParticipants();
     // Make sure everyone is checked into their current assignments
     if (!$request->allParticipantsCheckedIn()) {
         // Return the user to the room change request page
         // NB, don't need an error message here because it should already be printed
         // by the RoomChangeParticipantView.
         $cmd = CommandFactory::getCommand('ShowManageRoomChange');
         $cmd->setRequestId($requestId);
         $cmd->redirect();
     }
     // Transition the request to 'Approved'
     $request->transitionTo(new RoomChangeStateApproved($request, time(), null, UserStatus::getUsername()));
     // Remove each participants existing assignment
     foreach ($participants as $participant) {
         $bannerId = $participant->getBannerId();
         // Lookup the student
         $student = StudentFactory::getStudentByBannerId($bannerId, $term);
         // Save student object for later
         $this->students[$bannerId] = $student;
         // Save student's current assignment reason for later re-use
         $assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $term);
         //TODO - Student might not be assigned!!
         $this->assignmentReasons[$bannerId] = $assignment->getReason();
         // Remove existing assignment
         // TODO: Don't hard code refund percentage
         HMS_Assignment::unassignStudent($student, $term, 'Room Change Request Approved', UNASSIGN_CHANGE, 100);
     }
     // Create new assignments for each participant
     foreach ($participants as $participant) {
         // Grab the student object which was previously saved
         $student = $this->students[$participant->getBannerId()];
         // Create each new assignment
         HMS_Assignment::assignStudent($student, $term, null, $participant->getToBed(), BANNER_MEAL_STD, 'Room Change Approved', FALSE, $this->assignmentReasons[$bannerId]);
         // Release bed reservation
         $bed = new HMS_Bed($participant->getToBed());
         $bed->clearRoomChangeReserved();
         $bed->save();
     }
     // Transition each participant to 'In Process'
     foreach ($participants as $participant) {
         $participant->transitionTo(new ParticipantStateInProcess($participant, time(), null, UserStatus::getUsername()));
         // TODO: Send notifications
     }
     // Notify everyone that they can do the move
     HMS_Email::sendRoomChangeInProcessNotice($request);
     // Notify roommates that their circumstances are going to change
     foreach ($request->getParticipants() as $p) {
         $student = $this->students[$p->getBannerId()];
         // New Roommate
         $newbed = new HMS_Bed($p->getToBed());
         $newroom = $newbed->get_parent();
         foreach ($newroom->get_assignees() as $a) {
             if ($a instanceof Student && $a->getBannerID() != $p->getBannerID()) {
                 HMS_Email::sendRoomChangeApprovedNewRoommateNotice($a, $student);
             }
         }
         // Old Roommate
         $oldbed = new HMS_Bed($p->getFromBed());
         $oldroom = $oldbed->get_parent();
         foreach ($oldroom->get_assignees() as $a) {
             if ($a instanceof Student && $a->getBannerID() != $p->getBannerID()) {
                 HMS_Email::sendRoomChangeApprovedOldRoommateNotice($a, $student);
             }
         }
     }
     // Return the user to the room change request page
     $cmd = CommandFactory::getCommand('ShowManageRoomChange');
     $cmd->setRequestId($requestId);
     $cmd->redirect();
 }
Esempio n. 29
0
 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();
 }
Esempio n. 30
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;
     }
 }