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();
 }
Exemplo n.º 2
0
 public function allParticipantsCheckedIn()
 {
     // Make sure each participant is checked-into his/her current assignment
     foreach ($this->getParticipants() as $participant) {
         // Load the 'from' Bed object
         $bed = new HMS_Bed($participant->getFromBed());
         // Load the student
         $student = StudentFactory::getStudentByBannerId($participant->getBannerId(), Term::getSelectedTerm());
         // Search for the check-in
         $checkin = CheckinFactory::getCheckinByBed($student, $bed);
         if ($checkin == null || $checkin != null && $checkin->getCheckoutDate() != null) {
             return false;
         }
     }
     return true;
 }
 public function show()
 {
     $tpl = array();
     // Student info
     $tpl['NAME'] = $this->student->getProfileLink();
     $tpl['BANNER_ID'] = $this->student->getBannerId();
     // Participant ID
     // $tpl['PARTICIPANT_ID'] = $this->participant->getId();
     $tpl['CELL_PHONE'] = $this->participant->getCellPhone();
     // Hall Preferences
     $pref1 = $this->participant->getHallPref1();
     $pref2 = $this->participant->getHallPref2();
     if (!is_null($pref1)) {
         $hall1 = new HMS_Residence_Hall($pref1);
         $hallName = $hall1->getHallName();
         // Check if there's also a second hall preference
         if (!is_null($pref2)) {
             $hall2 = new HMS_Residence_Hall($pref2);
             $hallName .= ', ' . $hall2->getHallName();
         }
         $tpl['HALL_PREF'] = $hallName;
     }
     // From bed
     $fromBed = new HMS_Bed($this->participant->getFromBed());
     $tpl['FROM_ROOM'] = $fromBed->where_am_i();
     // To bed
     $toBedId = $this->participant->getToBed();
     if (isset($toBedId)) {
         // If there's already a bed set, show the selected bed
         $toBed = new HMS_Bed($toBedId);
         $tpl['TO_ROOM'] = $toBed->where_am_i();
     }
     /**
      * Check to see if the state is already approved or completed
      */
     $requestState = $this->request->getState();
     if ($requestState instanceof RoomChangeStatePending || $requestState instanceof RoomChangeStateHold) {
         /**
          * Check that the participant is checked into their current assignment
          */
         $checkin = CheckinFactory::getCheckinByBed($this->student, $fromBed);
         if ($checkin == null || $checkin != null && $checkin->getCheckoutDate() != null) {
             NQ::simple('hms', hms\NotificationView::ERROR, "{$this->student->getName()} is not checked-in at his/her current assignment. This must be fixed before this room change can be given final approval.");
         }
     }
     /**
      * **
      * Show approval buttons based on participant's current state
      */
     $particpantState = $this->participant->getState();
     $form = new PHPWS_Form('participant_form');
     if ($particpantState instanceof ParticipantStateNew) {
         // Particpant is in new state, waiting on this student'a approval
         // If the student is logged in, or the user is an admin, show the approve button
         if (UserStatus::getUsername() == $this->student->getUsername() || Current_User::allow('hms', 'admin_approve_room_change')) {
             $approveCmd = CommandFactory::getCommand('RoomChangeStudentApprove');
             $approveCmd->setParticipantId($this->participant->getId());
             $approveCmd->setRequestId($this->request->getId());
             $approveCmd->initForm($form);
             $form->mergeTemplate($tpl);
             $tpl = $form->getTemplate();
             $tpl['APPROVE_BTN'] = '';
             // dummy tag for approve button
         }
     } else {
         if ($particpantState instanceof ParticipantStateStudentApproved) {
             // Participant is in StudentApproved state
             // Get current list of RDs for this participant
             $rds = $this->participant->getCurrentRdList();
             // If current user is an RD for the "from bed" or an admin
             if (in_array(UserStatus::getUsername(), $rds) || Current_User::allow('hms', 'admin_approve_room_change')) {
                 if (!isset($toBedId) && count($this->participants) == 1) {
                     /*
                      * If there's only one particpant and the toBed is not already set,
                      * and the currnent user if the participants current RD, then show the bed selector
                      *
                      * Limit to 1 participant since room selection is for room "switch" requests only, not swaps.
                      * For swaps, the destination bed is already known and is not editable.
                      */
                     // Show the "select a bed" dialog, values are loaded via AJAX
                     $form->addDropBox('bed_select', array('-1' => 'Loading...'));
                     $form->addHidden('gender', $this->student->getGender());
                 }
                 $approveCmd = CommandFactory::getCommand('RoomChangeCurrRdApprove');
                 $approveCmd->setParticipantId($this->participant->getId());
                 $approveCmd->setRequestId($this->request->getId());
                 $approveCmd->initForm($form);
                 $form->mergeTemplate($tpl);
                 $tpl = $form->getTemplate();
                 $tpl['APPROVE_BTN'] = '';
                 // dummy tag for approve button
             }
         } else {
             if ($particpantState instanceof ParticipantStateCurrRdApproved) {
                 // Current RD has approved, Future RD needs to approve
                 // If current user if future RD or admin, show the approve button
                 // Get list of future RDs for "to bed"
                 $rds = $this->participant->getFutureRdList();
                 // Only future RDs and admins can approve
                 if (in_array(UserStatus::getUsername(), $rds) || Current_User::allow('hms', 'admin_approve_room_change')) {
                     $approveCmd = CommandFactory::getCommand('RoomChangeFutureRdApprove');
                     $approveCmd->setParticipantId($this->participant->getId());
                     $approveCmd->setRequestId($this->request->getId());
                     $approveCmd->initForm($form);
                     $form->mergeTemplate($tpl);
                     $tpl = $form->getTemplate();
                     $tpl['APPROVE_BTN'] = '';
                 }
             }
         }
     }
     // Show the edit link for to room if request type is a "switch", user has permissions, and status allows it
     // TODO
     /*** Participant History ***/
     $states = RoomChangeParticipantStateFactory::getStateHistory($this->participant);
     if (!is_null($states)) {
         $stateRows = array();
         foreach ($states as $historyState) {
             $stateRows[] = array('STATE_NAME' => $historyState->getFriendlyName(), 'EFFECTIVE_DATE' => date('M j, Y g:ia', $historyState->getEffectiveDate()), 'COMMITTED_BY' => $historyState->getCommittedBy());
         }
     }
     $tpl['history_rows'] = $stateRows;
     return PHPWS_Template::process($tpl, 'hms', 'admin/roomChangeParticipantView.tpl');
 }