public function execute(CommandContext $context)
 {
     $term = Term::getCurrentTerm();
     // Get the list of role memberships this user has
     // NB: This gets memberships for all terms.. must filter later
     $hms_perm = new HMS_Permission();
     $memberships = $hms_perm->getMembership('room_change_approve', NULL, UserStatus::getUsername());
     // Use the roles to instantiate a list of floors this user has access to
     $floors = array();
     foreach ($memberships as $member) {
         if ($member['class'] == 'hms_residence_hall') {
             $hall = new HMS_Residence_Hall($member['instance']);
             // Filter out halls that aren't in the current term
             if ($hall->getTerm() != $term) {
                 continue;
             }
             $floors = array_merge($floors, $hall->getFloors());
         } else {
             if ($member['class'] == 'hms_floor') {
                 $f = new HMS_Floor($member['instance']);
                 // Filter out floors that aren't in the current term
                 if ($f->getTerm() != $term) {
                     continue;
                 }
                 $floors[] = $f;
             } else {
                 throw new Exception('Unknown object type.');
             }
         }
     }
     if (empty($floors)) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         NQ::simple('hms', hms\NotificationView::ERROR, "You do not have the 'RD' role on any residence halls or floors.");
         $cmd = CommandFactory::getCommand('ShowAdminMaintenanceMenu');
         $cmd->redirect();
     }
     // Remove duplicate floors
     $uniqueFloors = array();
     foreach ($floors as $floor) {
         $uniqueFloors[$floor->getId()] = $floor;
     }
     // Use the list of floors to get a unique list of hall names
     $hallNames = array();
     foreach ($uniqueFloors as $floor) {
         $hall = $floor->get_parent();
         $hallNames[$hall->getId()] = $hall->getHallName();
     }
     // Get the set of room changes which are not complete based on the floor list
     $needsApprovalChanges = RoomChangeRequestFactory::getRoomChangesNeedsApproval($term, $uniqueFloors);
     $approvedChanges = RoomChangeRequestFactory::getRoomChangesByFloor($term, $uniqueFloors, array('Approved'));
     $allPendingChanges = RoomChangeRequestFactory::getRoomChangesByFloor($term, $uniqueFloors, array('Pending', 'Hold'));
     $completedChanges = RoomChangeRequestFactory::getRoomChangesByFloor($term, $uniqueFloors, array('Complete'));
     $inactiveChanges = RoomChangeRequestFactory::getRoomChangesByFloor($term, $uniqueFloors, array('Cancelled', 'Denied'));
     $view = new RoomChangeApprovalView($needsApprovalChanges, $approvedChanges, $allPendingChanges, $completedChanges, $inactiveChanges, $hallNames, $term);
     $context->setContent($view->show());
 }
Esempio n. 2
0
 /**
  * Returns the earliest check-in for the given student, in the given hall, which the student
  * has not checked out of yet.
  * //TODO update for persistent ID
  */
 public static function getPendingCheckoutForStudentByHall(Student $student, HMS_Residence_Hall $hall)
 {
     $db = new PHPWS_DB('hms_checkin');
     // Join the hall structure
     $db->addJoin('', 'hms_checkin', 'hms_hall_structure', 'bed_id', 'bedid');
     $db->addWhere('banner_id', $student->getBannerId());
     // Smarter term logic: If it's Spring or Summer 2 then we can also look in the previous term
     $term = $hall->getTerm();
     $sem = Term::getTermSem($term);
     if ($sem == TERM_SPRING || $sem == TERM_SUMMER2) {
         $db->addWhere('term', $term, '=', 'OR', 'term_group');
         $db->addWhere('term', Term::getPrevTerm($term), '=', 'OR', 'term_group');
     } else {
         $db->addWhere('term', $term);
     }
     // Checkin bed ID must be in the request hall
     //$db->addWhere('hms_hall_structure.hallid', $hall->getId());
     $db->addWhere('checkout_date', null, 'IS NULL');
     $db->addOrder(array('hms_checkin.checkin_date ASC'));
     // Earliest checkin first
     $checkin = new RestoredCheckin();
     $result = $db->loadObject($checkin);
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     if ($checkin->getId() == null) {
         return null;
     }
     return $checkin;
 }