public function execute(CommandContext $context)
 {
     $term = $context->get('term');
     if (!isset($term) || is_null($term) || empty($term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     $cmd = CommandFactory::getCommand('ShowStudentMenu');
     $feature = ApplicationFeature::getInstanceByNameAndTerm('RlcApplication', $term);
     // Make sure the RLC application feature is enabled
     if (is_null($feature) || !$feature->isEnabled()) {
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, RLC applications are not avaialable for this term.");
         $cmd->redirect();
     }
     // Check feature's deadlines
     if ($feature->getStartDate() > time()) {
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, it is too soon to fill out an RLC application.");
         $cmd->redirect();
     } else {
         if ($feature->getEndDate() < time()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, the RLC application deadline has already passed. Please contact University Housing if you are interested in applying for a RLC.");
             $cmd->redirect();
         }
     }
     // Get the Student object
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), Term::getCurrentTerm());
     $view = new RlcApplicationPage1View($context, $student);
     $context->setContent($view->show());
 }
 public function show()
 {
     $tpl = array();
     $termFeatures = ApplicationFeature::getAllForTerm(Term::getSelectedTerm());
     foreach ($this->features as $feature) {
         //$featureTpl = array();
         //$featureTpl['DESCRIPTION'] = $feature->getDescription();
         $class = $feature->getName();
         if (!isset($termFeatures[$class])) {
             $f = new $class();
             $f->setTerm($this->term);
             $termFeatures[$class] = $f;
         }
         $view = new ApplicationFeatureSettingsView($termFeatures[$class]);
         $tpl['features'][] = array('feature' => $view->show());
     }
     return PHPWS_Template::process($tpl, 'hms', 'admin/ApplicationFeaturesList.tpl');
 }
Ejemplo n.º 3
0
 public function show()
 {
     // Get the enabled features
     $features = ApplicationFeature::getEnabledFeaturesForStudent($this->student, $this->term);
     $tpl = array();
     if (Term::getTermSem($this->term) == TERM_FALL) {
         // If it's fall, then it's really the fall & spring terms
         $tpl['TERM'] = Term::toString($this->term) . ' - ' . Term::toString(Term::getNextTerm($this->term));
     } else {
         $tpl['TERM'] = Term::toString($this->term);
     }
     // In case there are no features enabled for this term
     if (empty($features)) {
         $tpl['BLOCKS'][] = array('BLOCK' => 'There are no options currently available to you for this term.');
     }
     foreach ($features as $feat) {
         $tpl['BLOCKS'][] = array('BLOCK' => $feat->getMenuBlockView($this->student)->show());
     }
     return PHPWS_Template::process($tpl, 'hms', 'student/studentMenuTermBlock.tpl');
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'ApplicationFeature.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'HousingApplicationWelcomeView.php');
     $term = $context->get('term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     $submitCmd = CommandFactory::getCommand('ShowHousingApplicationForm');
     $submitCmd->setTerm($term);
     //TODO get rid of the magic string
     $feature = ApplicationFeature::getInstanceByNameAndTerm('Application', $term);
     // If there is no feature, or if we're not inside the feature's deadlines...
     if (is_null($feature) || $feature->getStartDate() > time() || $feature->getEndDate() < time() || !$feature->isEnabled()) {
         PHPWS_Core::initModClass('hms', 'HousingApplicationNotAvailableView.php');
         $view = new HousingApplicationNotAvailableView($student, $feature, $term);
     } else {
         $requiredTerms = HousingApplication::getAvailableApplicationTermsForStudent($student);
         $view = new HousingApplicationWelcomeView($student, $submitCmd, $requiredTerms);
     }
     $context->setContent($view->show());
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
     PHPWS_Core::initModClass('hms', 'exception/InvalidTermException.php');
     $term = $context->get('term');
     $username = UserStatus::getUsername();
     $student = StudentFactory::getStudentByUsername($username, $term);
     $sem = Term::getTermSem($term);
     // Check for an existing application and delete it
     $app_result = HousingApplication::checkForApplication($username, $term);
     // If there's an existing housing application, handle deleting it
     if ($app_result !== FALSE) {
         switch ($sem) {
             case TERM_SPRING:
                 $application = new SpringApplication($app_result['id']);
                 break;
             case TERM_SUMMER1:
             case TERM_SUMMER2:
                 $application = new SummerApplication($app_result['id']);
                 break;
             case TERM_FALL:
                 $application = new FallApplication($app_result['id']);
                 break;
             default:
                 throw new InvalidTermException('Invalid term specified.');
         }
         // Save the old created on dates for re-use on new application
         $oldCreatedOn = $application->getCreatedOn();
         $oldCreatedBy = $application->getCreatedBy();
         $application->delete();
     }
     switch ($sem) {
         case TERM_FALL:
             $appType = 'fall';
             break;
         case TERM_SPRING:
             $appType = 'spring';
             break;
         case TERM_SUMMER1:
         case TERM_SUMMER2:
             $appType = 'summer';
             break;
         default:
             throw new Exception('Unknown application type');
     }
     $application = HousingApplicationFactory::getApplicationFromSession($_SESSION['application_data'], $term, $student, $appType);
     // If old created dates exist, use them as the 'created on' dates
     if (isset($oldCreatedOn)) {
         $application->setCreatedOn($oldCreatedOn);
         $application->setCreatedBy($oldCreatedBy);
     }
     $application->setCancelled(0);
     // Hard code a summer meal option for all summer applications.
     // Application for other terms use whatever the student selected
     if ($sem == TERM_SUMMER1 || $sem == TERM_SUMMER2) {
         $application->setMealPlan(BANNER_MEAL_5WEEK);
     }
     $result = $application->save();
     if ($result == TRUE) {
         // Log the fact that the application was submitted
         PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
         HMS_Activity_Log::log_activity($username, ACTIVITY_SUBMITTED_APPLICATION, $username);
         try {
             // report the application to banner;
             $application->reportToBanner();
         } catch (Exception $e) {
             // ignore any errors reporting this to banner, they'll be logged and admins notified
             // we've saved the student's application locally, so it's ok if this doesn't work
         }
         // Send the email confirmation
         PHPWS_Core::initModClass('hms', 'HMS_Email.php');
         HMS_Email::send_hms_application_confirmation($student, $application->getTerm());
     }
     $friendly_term = Term::toString($application->getTerm());
     NQ::simple('hms', hms\NotificationView::SUCCESS, "Your application for {$friendly_term} was successfully processed!  You will receive an email confirmation in the next 24 hours.");
     PHPWS_Core::initModClass('hms', 'applicationFeature/RlcApplication.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     $rlcReg = new RLCApplicationRegistration();
     if (ApplicationFeature::isEnabledForStudent($rlcReg, $term, $student) && HMS_RLC_Application::checkForApplication($student->getUsername(), $term) == FALSE && $application->rlc_interest == 1) {
         $rlcCmd = CommandFactory::getCommand('ShowRlcApplicationPage1View');
         $rlcCmd->setTerm($term);
         $rlcCmd->redirect();
     } else {
         $successCmd = CommandFactory::getCommand('ShowStudentMenu');
         $successCmd->redirect();
     }
 }
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'deadlines')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to edit deadlines.');
     }
     PHPWS_Core::initModClass('hms', 'exception/MissingDataException.php');
     if (!isset($this->featureId)) {
         $this->featureId = $context->get('featureId');
     }
     $featureId = $this->featureId;
     if (!isset($this->term)) {
         $this->term = $context->get('term');
     }
     $term = $this->term;
     if (!isset($this->name)) {
         $this->name = $context->get('name');
     }
     $name = $this->name;
     PHPWS_Core::initModClass('hms', 'ApplicationFeature.php');
     if (!is_null($featureId)) {
         $feature = ApplicationFeature::getInstanceById($featureId);
     } else {
         if (!is_null($name) && !is_null($term)) {
             $feature = ApplicationFeature::getInstanceByName($name);
             $feature->setTerm($term);
         } else {
             throw new InvalidArgumentException('You must either provide a featureId, or a name and a term.');
         }
     }
     // Checkboxes are weird.
     $enabled = !is_null($context->get('enabled'));
     $feature->setEnabled($enabled);
     if ($enabled) {
         $startDate = strtotime($context->get('start_date'));
         $editDate = strtotime($context->get('edit_date'));
         $endDate = strtotime($context->get('end_date'));
         if ($startDate && $endDate) {
             if ($startDate >= $endDate) {
                 $e = new MissingDataException('Start date must be before the end date.', array('Start date', 'End date'));
                 echo $e->getJSON();
                 HMS::quit();
             }
             if ($editDate && ($editDate <= $startDate || $editDate >= $endDate)) {
                 $e = new MissingDataException('Edit date must be between the start and end dates.', array('Edit date'));
                 echo $e->getJSON();
                 HMS::quit();
             }
         }
         if (!is_null($startDate)) {
             $feature->setStartDate($startDate);
         }
         $registration = $feature->getRegistration();
         if ($registration->requiresEditDate()) {
             $feature->setEditDate($editDate + 86399);
             // Add 23h23m23s so that the end date is actuall 11:59:59pm on the selected day
         } else {
             $feature->setEditDate(0);
         }
         if ($registration->requiresEndDate()) {
             $feature->setEndDate($endDate + 86399);
             // Add 23h23m23s so that the end date is actuall 11:59:59pm on the selected day
         } else {
             $feature->setEndDate(0);
         }
     }
     try {
         $feature->save();
     } catch (MissingDataException $e) {
         echo json_encode($e);
         HMS::quit();
     }
     echo json_encode($feature);
     HMS::quit();
 }
Ejemplo n.º 7
0
 public static function getAllForTerm($term)
 {
     $db = new PHPWS_DB('hms_application_feature');
     $db->addWhere('term', $term);
     $result = $db->select();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     $features = array();
     foreach ($result as $feature) {
         $f = ApplicationFeature::plugInstance($feature);
         $features[$f->getName()] = $f;
     }
     return $features;
 }
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'HousingApplication.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'RlcReapplicationView.php');
     PHPWS_Core::initModClass('hms', 'HMS_Learning_Community.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
     PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
     $errorCmd = CommandFactory::getCommand('ShowStudentMenu');
     $term = $context->get('term');
     $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
     // Check deadlines
     PHPWS_Core::initModClass('hms', 'ApplicationFeature.php');
     $feature = ApplicationFeature::getInstanceByNameAndTerm('RlcReapplication', $term);
     if (is_null($feature) || !$feature->isEnabled()) {
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, RLC re-applications are not avaialable for this term.");
         $errorCmd->redirect();
     }
     if ($feature->getStartDate() > time()) {
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, it is too soon to submit a RLC re-application.");
         $errorCmd->redirect();
     } else {
         if ($feature->getEndDate() < time()) {
             NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, the RLC re-application deadline has already passed. Please contact University Housing if you are interested in applying for a RLC.");
             $errorCmd->redirect();
         }
     }
     // Double check the the student is eligible
     $housingApp = HousingApplication::getApplicationByUser($student->getUsername(), $term);
     if (!$housingApp instanceof LotteryApplication) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You are not eligible to re-apply for a Residential Learning Community.');
         $errorCmd->redirect();
     }
     // Make sure that the student has not already applied for this term
     $rlcApp = HMS_RLC_Application::getApplicationByUsername($student->getUsername(), $term);
     if (!is_null($rlcApp)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'You have already re-applied for a Residential Learning Community for this term.');
         $errorCmd->redirect();
     }
     // Look up any existing RLC assignment (for the fall term; current term should be the Spring term, so the previous term should be the Fall)
     $rlcAssignment = HMS_RLC_Assignment::getAssignmentByUsername($student->getUsername(), Term::getPrevTerm(Term::getCurrentTerm()));
     // Get the list of RLCs that the student is eligible for
     // Note: hard coded to 'C' because we know they're continuing at this point.
     // This accounts for freshmen addmitted in the spring, who will still have the 'F' type.
     $communities = HMS_Learning_Community::getRlcListReapplication(false, 'C');
     // If the student has an existing assignment, and that community always allows returning students, then make sure the community is in the list (if it's not already)
     if (isset($rlcAssignment)) {
         // Load the RLC
         $rlc = $rlcAssignment->getRlc();
         // If members can always reapply, make sure community id exists as an array index
         if ($rlc->getMembersReapply() == 1 && !isset($communities[$rlc->get_id()])) {
             $communities[$rlc->get_id()] = $rlc->get_community_name();
         }
     }
     session_write_close();
     session_start();
     if (isset($_SESSION['RLC_REAPP'])) {
         $reApp = $_SESSION['RLC_REAPP'];
     } else {
         $reApp = null;
     }
     $view = new RlcReapplicationView($student, $term, $rlcAssignment, $communities, $reApp);
     $context->setContent($view->show());
 }
 public function show()
 {
     PHPWS_Core::initCoreClass('Form.php');
     $form = new PHPWS_Form();
     $submitCmd = CommandFactory::getCommand('HousingApplicationFormSubmit');
     $submitCmd->setTerm($this->term);
     $submitCmd->initForm($form);
     $tpl = array();
     /****************
      * Display Info *
      ****************/
     $tpl['STUDENT_NAME'] = $this->student->getFullName();
     $tpl['GENDER'] = $this->student->getPrintableGender();
     $tpl['ENTRY_TERM'] = Term::toString($this->student->getApplicationTerm());
     $tpl['CLASSIFICATION_FOR_TERM_LBL'] = HMS_Util::formatClass($this->student->getClass());
     $tpl['STUDENT_STATUS_LBL'] = HMS_Util::formatType($this->student->getType());
     $tpl['TERM'] = Term::toString($this->term);
     /**************
      * Cell Phone *
      **************/
     $form->addText('number');
     $form->setSize('number', 10);
     $form->setMaxSize('number', 10);
     $form->addCssClass('number', 'form-control');
     if (!is_null($this->existingApplication)) {
         $form->setValue('number', substr($this->existingApplication->getCellPhone(), 0));
     }
     $form->addCheck('do_not_call', 1);
     if (!is_null($this->existingApplication) && is_null($this->existingApplication->getCellPhone())) {
         $form->setMatch('do_not_call', 1);
     }
     // This is just getting worse and worse.
     // TODO: this, correctly.
     $sem = Term::getTermSem($this->term);
     if ($sem == TERM_SPRING || $sem == TERM_FALL) {
         /*************
          * Lifestyle *
          *************/
         // TODO: get rid of the magic numbers!!!
         $form->addDropBox('lifestyle_option', array('1' => _('Single Gender Building'), '2' => _('Co-Ed Building')));
         if (!is_null($this->existingApplication)) {
             $form->setMatch('lifestyle_option', $this->existingApplication->getLifestyleOption());
         } else {
             $form->setMatch('lifestyle_option', '1');
         }
         $form->addCssClass('lifestyle_option', 'form-control');
         /************
          * Bed time *
          ************/
         // TODO: magic numbers
         $form->addDropBox('preferred_bedtime', array('1' => _('Early'), '2' => _('Late')));
         $form->setClass('preferred_bedtime', 'form-control');
         if (!is_null($this->existingApplication)) {
             $form->setMatch('preferred_bedtime', $this->existingApplication->getPreferredBedtime());
         } else {
             $form->setMatch('preferred_bedtime', '1');
         }
         /******************
          * Room condition *
          ******************/
         //TODO: magic numbers
         $form->addDropBox('room_condition', array('1' => _('Neat'), '2' => _('Cluttered')));
         if (!is_null($this->existingApplication)) {
             $form->setMatch('room_condition', $this->existingApplication->getRoomCondition());
         } else {
             $form->setMatch('room_condition', '1');
         }
         $form->addCssClass('room_condition', 'form-control');
     } else {
         if ($sem == TERM_SUMMER1 || $sem == TERM_SUMMER2) {
             /* Private room option for Summer terms */
             $form->addDropBox('room_type', array(ROOM_TYPE_DOUBLE => 'Two person', ROOM_TYPE_PRIVATE => 'Private (if available)'));
             $form->setClass('room_type', 'form-control');
             if (!is_null($this->existingApplication)) {
                 $form->setMatch('room_type', $this->existingApplication->getRoomType());
             } else {
                 $form->setMatch('room_type', '0');
             }
         }
     }
     /*********************
      * Smoking Preference *
      *********************/
     $form->addDropBox('smoking_preference', array('1' => _('No'), '2' => _('Yes')));
     if (!is_null($this->existingApplication)) {
         $form->setMatch('smoking_preference', $this->existingApplication->getSmokingPreference());
     } else {
         $form->setMatch('smoking_preference', '1');
     }
     $form->addCssClass('smoking_preference', 'form-control');
     /***************
      * Meal Option *
      ***************/
     if ($sem == TERM_FALL || $sem == TERM_SPRING) {
         if ($this->student->getType() == TYPE_FRESHMEN) {
             $mealOptions = array(BANNER_MEAL_STD => 'Standard', BANNER_MEAL_HIGH => 'High', BANNER_MEAL_SUPER => 'Super');
         } else {
             $mealOptions = array(BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super'));
         }
     } else {
         if ($sem == TERM_SUMMER1 || $sem == TERM_SUMMER2) {
             $mealOptions = array(BANNER_MEAL_5WEEK => 'Summer 5-Week Plan');
         }
     }
     $form->addDropBox('meal_option', $mealOptions);
     $form->setClass('meal_option', 'form-control');
     $form->setMatch('meal_option', BANNER_MEAL_STD);
     $form->addCssClass('meal_option', 'form-control');
     if (!is_null($this->existingApplication)) {
         $form->setMatch('meal_option', $this->existingApplication->getMealPlan());
     } else {
         $form->setMatch('meal_option', BANNER_MEAL_STD);
     }
     /*********************
      * Emergency Contact *
      *********************/
     $form->addText('emergency_contact_name');
     $form->addCssClass('emergency_contact_name', 'form-control');
     $form->addText('emergency_contact_relationship');
     $form->addCssClass('emergency_contact_relationship', 'form-control');
     $form->addText('emergency_contact_phone');
     $form->addCssClass('emergency_contact_phone', 'form-control');
     $form->addText('emergency_contact_email');
     $form->addCssClass('emergency_contact_email', 'form-control');
     $form->addTextArea('emergency_medical_condition');
     $form->addCssClass('emergency_medical_condition', 'form-control');
     $form->setRows('emergency_medical_condition', 4);
     if (!is_null($this->existingApplication)) {
         $form->setValue('emergency_contact_name', $this->existingApplication->getEmergencyContactName());
         $form->setValue('emergency_contact_relationship', $this->existingApplication->getEmergencyContactRelationship());
         $form->setValue('emergency_contact_phone', $this->existingApplication->getEmergencyContactPhone());
         $form->setValue('emergency_contact_email', $this->existingApplication->getEmergencyContactEmail());
         $form->setValue('emergency_medical_condition', $this->existingApplication->getEmergencyMedicalCondition());
     }
     /**
      * Missing Person
      */
     $form->addText('missing_person_name');
     $form->addCssClass('missing_person_name', 'form-control');
     $form->addText('missing_person_relationship');
     $form->addCssClass('missing_person_relationship', 'form-control');
     $form->addText('missing_person_phone');
     $form->addCssClass('missing_person_phone', 'form-control');
     $form->addText('missing_person_email');
     $form->addCssClass('missing_person_email', 'form-control');
     if (!is_null($this->existingApplication)) {
         $form->setValue('missing_person_name', $this->existingApplication->getMissingPersonName());
         $form->setValue('missing_person_relationship', $this->existingApplication->getMissingPersonRelationship());
         $form->setValue('missing_person_phone', $this->existingApplication->getMissingPersonPhone());
         $form->setValue('missing_person_email', $this->existingApplication->getMissingPersonEmail());
     }
     /**
      * Special needs
      */
     $tpl['SPECIAL_NEEDS_TEXT'] = '';
     // setting this template variable to anything causes the special needs text to be displayed
     $form->addCheck('special_need', array('special_need'));
     $form->setLabel('special_need', array('Yes, I require special needs housing.'));
     if (isset($this->existingApplication)) {
         if (!is_null($this->existingApplication->physical_disability) && $this->existingApplication->physical_disability != "0" || !is_null($this->existingApplication->psych_disability) && $this->existingApplication->psych_disability != "0" || !is_null($this->existingApplication->medical_need) && $this->existingApplication->medical_need != "0" || !is_null($this->existingApplication->gender_need) && $this->existingApplication->gender_need != "0") {
             $form->setMatch('special_need', 'special_need');
         }
     }
     if (isset($_REQUEST['special_needs'])) {
         $form->addHidden('special_needs', $_REQUEST['special_needs']);
     }
     /*******
      * RLC *
      *******/
     PHPWS_Core::initModClass('hms', 'applicationFeature/RlcApplication.php');
     $rlcReg = new RLCApplicationRegistration();
     if (HMS_RLC_Application::checkForApplication($this->student->getUsername(), $this->term) == TRUE) {
         // Student has an RLC application on file already
         $tpl['RLC_SUBMITTED'] = '';
         $form->addHidden('rlc_interest', 0);
     } else {
         if (ApplicationFeature::isEnabledForStudent($rlcReg, $this->term, $this->student)) {
             // Feature is enabled, but student hasn't submitted one yet
             $form->addRadio('rlc_interest', array(0, 1));
             $form->setLabel('rlc_interest', array(_("No"), _("Yes")));
             if (!is_null($this->existingApplication) && !is_null($this->existingApplication->getRLCInterest())) {
                 $form->setMatch('rlc_interest', 'rlc_interest');
             } else {
                 $form->setMatch('rlc_interest', '0');
             }
         } else {
             // Feature is not enabled
             $form->addHidden('rlc_interest', 0);
         }
     }
     $tpl['CONTINUE_BTN'] = '';
     $form->mergeTemplate($tpl);
     $tpl = $form->getTemplate();
     Layout::addPageTitle("Housing Application Form");
     return PHPWS_Template::process($tpl, 'hms', 'student/student_application.tpl');
 }