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());
 }
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'admin_approve_room_change')) {
         PHPWS_Core::initModClasS('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to approve room changes.');
     }
     PHPWS_Core::initModClass('hms', 'RoomChangeRequestFactory.php');
     PHPWS_Core::initModClass('hms', 'RoomChangeApprovalView.php');
     $term = Term::getSelectedTerm();
     // Get all requests in the FutureRDApproved state (i.e. waiting on housing assignments office)
     $needsApprovalChanges = RoomChangeRequestFactory::getAllRoomChangesNeedsAdminApproval($term);
     // Get all requests that are Approved (in-progress)
     $allApproved = RoomChangeRequestFactory::getAllRoomChangesByState($term, array('Approved'));
     // Get all requests that are pending/in-progress, but not waiting on Housing
     $allPending = RoomChangeRequestFactory::getAllRoomChangesByState($term, array('Pending', 'Hold'));
     // Get all complete requests
     $allComplete = RoomChangeRequestFactory::getAllRoomChangesByState($term, array('Complete'));
     // Get all requests that are inactive (cancelled, denied, complete)
     $allInactive = RoomChangeRequestFactory::getAllRoomChangesByState($term, array('Cancelled', 'Denied'));
     $view = new RoomChangeApprovalView($needsApprovalChanges, $allApproved, $allPending, $allComplete, $allInactive, array('All Halls'), $term);
     $context->setContent($view->show());
 }