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 execute(CommandContext $context)
 {
     if (!Current_User::allow('withdrawn_search')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to makr applications withdrawn.');
     }
     $id = $context->get('appId');
     if (!isset($id) || is_null($id)) {
         throw new InvalidArugumentException('Missing application id.');
     }
     PHPWS_Core::initModclass('hms', 'HousingApplicationFactory.php');
     $app = HousingApplicationFactory::getApplicationById($context->get('appId'));
     $app->setWithdrawn(1);
     $app->save();
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Application successfully marked as withdrawn.');
     $context->goBack();
 }
 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
     $this->setAppId($context->get('applicationId'));
     if (!isset($this->applicationId) || is_null($this->applicationId)) {
         throw new InvalidArgumentException('Missing housing application id.');
     }
     $application = HousingApplicationFactory::getApplicationById($this->applicationId);
     $application->setCancelled(0);
     $application->setCancelledBy(null);
     $application->setCancelledReason(null);
     $application->setCancelledOn(null);
     $application->save();
     HMS_Activity_Log::log_activity($application->getUsername(), ACTIVITY_REINSTATE_APPLICATION, UserStatus::getUsername());
     $returnCmd = CommandFactory::getCommand('ShowStudentProfile');
     $returnCmd->setBannerId($application->getBannerId());
     $returnCmd->redirect();
 }
 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;
 }
Example #5
0
 /**
  * $roommates is the focus of getProfileView(). It's structure is helpful in
  * StudentProfileView.  It also makes it a little easier to recognize which roommmates
  * are requested ones so they can be emphasized in the template (admin/fancy-student-info.tpl)
  * Note that a student can only have a single pending/confirmed roommate request but multiple
  * assigned roommates!
  *
  */
 public function getProfileView()
 {
     PHPWS_Core::initModClass('hms', 'StudentProfileView.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $studentUsername = $this->student->getUsername();
     $assignment = HMS_Assignment::getAssignmentByBannerId($this->student->getBannerId(), $this->term);
     $pendingRoommate = HMS_Roommate::get_pending_roommate($studentUsername, $this->term);
     $confirmedRoommate = HMS_Roommate::get_confirmed_roommate($studentUsername, $this->term);
     if (!is_null($assignment)) {
         $assignedRoommates = $assignment->get_parent()->get_parent()->get_assignees();
     }
     //
     // If student is assigned to room...
     //
     if (!is_null($assignment)) {
         foreach ($assignedRoommates as $roomie) {
             // make sure $roomie isn't the student being profiled or the requested roomies
             if ($roomie != FALSE && $roomie->getUsername() != $studentUsername) {
                 $roomieUsername = $roomie->getUsername();
                 if (is_null($confirmedRoommate) || $roomieUsername != $confirmedRoommate->getUsername()) {
                     if (is_null($pendingRoommate) || $roomieUsername != $pendingRoommate->getUsername()) {
                         // Get student object and room link
                         $roomLink = $this->getRoommateRoomLink($roomie->getUsername());
                         // if $roomie was assigned but not requested
                         $this->roommates['ASSIGNED'][] = $roomie->getProfileLink() . " - {$roomLink}";
                     }
                 }
             }
         }
     }
     //
     // Check status of requested roommates
     //
     if (!is_null($confirmedRoommate)) {
         if (!is_null($assignment)) {
             $confirmedRmAssignment = HMS_Assignment::getAssignment($confirmedRoommate->getUsername(), $this->term);
             if (!is_null($confirmedRmAssignment)) {
                 // if confirmed roommate is assigned to different room than profile student
                 if ($assignment->get_parent()->room_id != $confirmedRmAssignment->get_parent()->room_id) {
                     $this->setRoommateVar($confirmedRoommate, "confirmed", "mismatched_rooms");
                 } else {
                     $this->setRoommateVar($confirmedRoommate, "confirmed");
                 }
             } else {
                 // if profile student's room is full
                 if (!$assignment->get_parent()->get_parent()->has_vacancy()) {
                     $this->setRoommateVar($confirmedRoommate, "confirmed", "no_bed_available");
                 } else {
                     $this->setRoommateVar($confirmedRoommate, "confirmed");
                 }
             }
         } else {
             $this->setRoommateVar($confirmedRoommate, "confirmed");
         }
     } else {
         if (!is_null($pendingRoommate)) {
             if (!is_null($assignment)) {
                 $pendingRmAssignment = HMS_Assignment::getAssignment($pendingRoommate->getUsername(), $this->term);
                 if (!is_null($pendingRmAssignment)) {
                     // if pending roommate is assigned to different room than profile student
                     if ($assignment->get_parent()->room_id != $pendingRmAssignment->get_parent()->room_id) {
                         $this->setRoommateVar($pendingRoommate, "pending", "mismatched_rooms");
                     } else {
                         $this->setRoommateVar($pendingRoommate, "pending");
                     }
                 } else {
                     // if profile student's room is full
                     if (!$assignment->get_parent()->get_parent()->has_vacancy()) {
                         $this->setRoommateVar($pendingRoommate, "pending", "no_bed_available");
                     } else {
                         $this->setRoommateVar($pendingRoommate, "pending");
                     }
                 }
             } else {
                 $this->setRoommateVar($pendingRoommate, "pending");
             }
         }
     }
     $applications = HousingApplication::getAllApplicationsForStudent($this->student);
     $subTypeApps = array();
     // Convert each of the general HousingApplication objets to its specific sub type (e.g. FallApplication)
     foreach ($applications as $app) {
         $subTypeApps[] = HousingApplicationFactory::getApplicationById($app->id);
     }
     return new StudentProfileView($this->student, $subTypeApps, $assignment, $this->roommates);
 }
 public function show()
 {
     // TODO: Load application in controller and pass it to HousingApplicationView constructor.
     $application = HousingApplicationFactory::getApplicationById($this->id);
     $student = StudentFactory::getStudentByUsername($application->username, $application->term);
     $tpl = array();
     //If the application has been submitted plug in the date it was created
     if (isset($application->created_on)) {
         $tpl['RECEIVED_DATE'] = "Received on: " . date('d-F-Y h:i:s a', $application->created_on);
     }
     if ($application instanceof LotteryApplication && $application->getWaitingListDate() != null) {
         $tpl['WAITING_LIST_DATE'] = date("d-F-y h:i:sa", $application->getWaitingListDate());
     }
     // Check if the application has been cancelled
     // isWithdrawn() has been depricated, but I'm leaving it here just for historical sake
     // on the off-chance that it catches an older application that's withdrawn but not cancelled.
     if ($application->isCancelled() || $application->isWithdrawn()) {
         NQ::simple('hms', hms\NotificationView::WARNING, 'This application has been cancelled.');
     }
     $tpl['STUDENT_NAME'] = $student->getFullName();
     $tpl['GENDER'] = $student->getPrintableGender();
     $tpl['ENTRY_TERM'] = Term::toString($application->term);
     $tpl['CLASSIFICATION_FOR_TERM_LBL'] = $student->getPrintableClass();
     $tpl['STUDENT_STATUS_LBL'] = $student->getPrintableType();
     $tpl['MEAL_OPTION'] = HMS_Util::formatMealOption($application->meal_plan);
     if (isset($application->lifestyle_option)) {
         $tpl['LIFESTYLE_OPTION'] = $application->lifestyle_option == 1 ? 'Single gender' : 'Co-ed';
     } else {
         $tpl['LIFESTYLE_OPTION'] = 'n/a';
     }
     if (isset($application->preferred_bedtime)) {
         $tpl['PREFERRED_BEDTIME'] = $application->preferred_bedtime == 1 ? 'Early' : 'Late';
     } else {
         $tpl['PREFERRED_BEDTIME'] = 'n/a';
     }
     if (isset($application->room_condition)) {
         $tpl['ROOM_CONDITION'] = $application->room_condition == 1 ? 'Neat' : 'Cluttered';
     } else {
         $tpl['ROOM_CONDITION'] = 'n/a';
     }
     if (isset($application->smoking_preference)) {
         $tpl['SMOKING_PREFERENCE'] = $application->smoking_preference == 1 ? 'No' : 'Yes';
     } else {
         $tpl['SMOKING_PREFERENCE'] = 'n/a';
     }
     if (isset($application->room_type)) {
         $tpl['ROOM_TYPE'] = $application->room_type == ROOM_TYPE_DOUBLE ? 'Double' : 'Private (if available)';
     }
     $tpl['CELLPHONE'] = '';
     if (strlen($application->cell_phone) == 10) {
         $tpl['CELLPHONE'] .= '(' . substr($application->cell_phone, 0, 3) . ')';
         $tpl['CELLPHONE'] .= '-' . substr($application->cell_phone, 3, 3);
         $tpl['CELLPHONE'] .= '-' . substr($application->cell_phone, 6, 4);
     }
     /* Emergency Contact */
     $tpl['EMERGENCY_CONTACT_NAME'] = $application->getEmergencyContactName();
     $tpl['EMERGENCY_CONTACT_RELATIONSHIP'] = $application->getEmergencyContactRelationship();
     $tpl['EMERGENCY_CONTACT_PHONE'] = $application->getEmergencyContactPhone();
     $tpl['EMERGENCY_CONTACT_EMAIL'] = $application->getEmergencyContactEmail();
     $tpl['EMERGENCY_MEDICAL_CONDITION'] = $application->getEmergencyMedicalCondition();
     /* Missing Person */
     if (Current_User::allow('hms', 'view_missing_person_info')) {
         $tpl['MISSING_PERSON_NAME'] = $application->getMissingPersonName();
         $tpl['MISSING_PERSON_RELATIONSHIP'] = $application->getMissingPersonRelationship();
         $tpl['MISSING_PERSON_PHONE'] = $application->getMissingPersonPhone();
         $tpl['MISSING_PERSON_EMAIL'] = $application->getMissingPersonEmail();
     }
     /* Special Needs */
     $special_needs = "";
     if ($application->physical_disability == 1) {
         $special_needs = 'Physical disability<br />';
     }
     if ($application->psych_disability) {
         $special_needs .= 'Psychological disability<br />';
     }
     if ($application->medical_need) {
         $special_needs .= 'Medical need<br />';
     }
     if ($application->gender_need) {
         $special_needs .= 'Gender need<br />';
     }
     if ($special_needs == '') {
         $special_needs = 'None';
     }
     $tpl['SPECIAL_NEEDS_RESULT'] = $special_needs;
     if ($application instanceof FallApplication) {
         PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
         $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $application->getTerm());
         if (!is_null($rlcApp)) {
             $tpl['RLC_INTEREST_1'] = 'Yes (Completed - Use the main menu to view/modify.)';
         } else {
             $tpl['RLC_INTEREST_1'] = $application->rlc_interest == 0 ? 'No' : 'Yes';
         }
     }
     if (Current_User::getUsername() == "hms_student") {
         $tpl['MENU_LINK'] = PHPWS_Text::secureLink('Back to main menu', 'hms', array('type' => 'student', 'op' => 'show_main_menu'));
     }
     Layout::addPageTitle("Housing Application");
     return PHPWS_Template::process($tpl, 'hms', 'admin/student_application.tpl');
 }
 /**
  * Returns an array of HousingApplication objects, one object for each application the
  * given student has completed. All parameters are optional.
  * Returns false if the request cannot be compelted for any reason.
  *
  * TODO depricate this and do it better
  *
  * @param string $username
  * @param string $banner_id
  * @param string $term
  *
  * @return mixed <NULL, FallApplication>
  */
 public static function getAllApplications($username = null, $banner_id = null, $term = null)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     $db = new PHPWS_DB('hms_new_application');
     if (!is_null($banner_id)) {
         $db->addWhere('banner_id', $banner_id);
     }
     if (!is_null($username)) {
         $db->addWhere('username', $username, 'ILIKE');
     }
     if (!is_null($term)) {
         $db->addWhere('term', $term);
     }
     $result = $db->select();
     $apps = array();
     foreach ($result as $app) {
         $apps[] = HousingApplicationFactory::getApplicationById($app['id']);
     }
     return $apps;
 }