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());
 }
示例#2
0
 public function __construct()
 {
     parent::__construct();
     if (UserStatus::isAdmin()) {
         if (Current_User::allow('hms', 'assignment_maintenance')) {
             $this->addCommandByName('Assign student', 'ShowAssignStudent');
             $this->addCommandByName('Unassign student', 'ShowUnassignStudent');
             $this->addCommandByName('Set move-in times', 'ShowMoveinTimesView');
         }
         if (Current_User::allow('hms', 'run_hall_overview')) {
             $hallOverviewCmd = CommandFactory::getCommand('SelectResidenceHall');
             $hallOverviewCmd->setTitle('Hall Overview');
             $hallOverviewCmd->setOnSelectCmd(CommandFactory::getCommand('HallOverview'));
             $this->addCommand('Hall Overview', $hallOverviewCmd);
         }
         if (Current_User::allow('hms', 'assign_by_floor')) {
             $floorAssignCmd = CommandFactory::getCommand('AssignByFloor');
             $floorAssignCmd->setOnSelectCmd(CommandFactory::getCommand('ShowFloorAssignmentView'));
             $floorAssignCmd->setTitle('Assign Students to Floor');
             $this->addCommand('Assign students by floor', $floorAssignCmd);
         }
         if (UserStatus::isAdmin() && Current_User::allow('hms', 'roommate_maintenance')) {
             $this->addCommandByName('Edit freshmen roommate requests', 'EditRoommateGroupsView');
         }
         if (Current_User::allow('hms', 'autoassign')) {
             $autoAssignCmd = CommandFactory::getCommand('JSConfirm');
             $autoAssignCmd->setLink('Auto-assign');
             $autoAssignCmd->setTitle('Auto-assign');
             $autoAssignCmd->setQuestion('Start auto-assign process for the selected term?');
             $autoAssignCmd->setOnConfirmCommand(CommandFactory::getCommand('ScheduleAutoassign'));
             $this->addCommand('Start Autoassigner', $autoAssignCmd);
         }
         if (Current_User::allow('hms', 'withdrawn_search')) {
             $withdrawnSearchCmd = CommandFactory::getCommand('JSConfirm');
             $withdrawnSearchCmd->setLink('Withdrawn search');
             $withdrawnSearchCmd->setTitle('Withdrawn search');
             $withdrawnSearchCmd->setQuestion('Start search for withdrawn students for the selected term?');
             $withdrawnSearchCmd->setOnConfirmCommand(CommandFactory::getCommand('WithdrawnSearch'));
             $this->addCommand('Withdrawn search', $withdrawnSearchCmd);
         }
         $hms_perm = new HMS_Permission();
         $memberships = $hms_perm->getMembership('room_change_approve', NULL, UserStatus::getUsername());
         if (!empty($memberships)) {
             $RDRoomChangeCmd = CommandFactory::getCommand('ShowRDRoomChangeList');
             $this->addCommand('Room Change Approval (RD)', $RDRoomChangeCmd);
         }
         if (Current_User::allow('hms', 'admin_approve_room_change')) {
             $adminRoomChangeCmd = CommandFactory::getCommand('ShowAdminRoomChangeList');
             $this->addCommand('Room Change Approval (Admin)', $adminRoomChangeCmd);
         }
     }
 }
 public function execute(CommandContext $context)
 {
     if (!Current_User::allow('hms', 'view_role_members')) {
         //PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         //throw new PermissionException('You do not have permission to view role members.');
         // Can't throw an exception here, since there's nothing to catch it and this is called
         // even when the user doesn't have permissions to do it
         // TODO: fix the interface so this isn't called unless the user has permissions
         // See Trac #664
         echo '';
         exit;
     }
     $class = $context->get('type');
     $instance = $context->get('instance');
     $class = new $class();
     $class->id = $instance;
     $hms_perm = new HMS_Permission();
     $members = $hms_perm->getMembership('email', $class, null, true);
     echo json_encode($members);
     exit;
 }
 public function execute(CommandContext $context)
 {
     $term = $context->get('term');
     if (!isset($term)) {
         throw new InvalidArgumentException('Missing term.');
     }
     // Get the list of floors which the current user has permission to assess
     // Get the list of role memberships this user has
     $hms_perm = new HMS_Permission();
     $memberships = $hms_perm->getMembership('assess_damage', NULL, UserStatus::getUsername());
     if (empty($memberships)) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException("You do not have permission to assess damages on any residence halls or floors.");
     }
     // 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']);
             if (!is_array($floors)) {
                 $floors = array();
             }
             $hallFloors = $hall->getFloors();
             if (!is_array($hallFloors)) {
                 $hallFloors = array();
             }
             $floors = array_merge($floors, $hallFloors);
         } else {
             if ($member['class'] == 'hms_floor') {
                 $floors[] = new HMS_Floor($member['instance']);
             } else {
                 throw new Exception('Unknown object type.');
             }
         }
     }
     // Remove duplicate floors
     $uniqueFloors = array();
     foreach ($floors as $floor) {
         $uniqueFloors[$floor->getId()] = $floor;
     }
     // Filter the list of floors for just the term we're interested in
     foreach ($uniqueFloors as $k => $f) {
         if ($f->getTerm() != $term) {
             unset($uniqueFloors[$k]);
         }
     }
     // Get the list of damages with pending assessments on those floors
     $damages = RoomDamageFactory::getDamagesToAssessByFloor($uniqueFloors, $term);
     $roomList = array();
     // For each damage, get the list of responsible students
     foreach ($damages as &$dmg) {
         $pId = $dmg->getRoomPersistentId();
         $dmg->responsibilities = RoomDamageResponsibilityFactory::getResponsibilitiesByDmg($dmg);
         foreach ($dmg->responsibilities as &$resp) {
             $student = StudentFactory::getStudentByBannerId($resp->getBannerId(), $term);
             $resp->studentName = $student->getName();
         }
         $roomList[$dmg->getRoomPersistentId()][] = $dmg;
     }
     $rooms = array();
     foreach ($roomList as $pId => $dmgList) {
         $roomObj = RoomFactory::getRoomByPersistentId($pId, $term);
         $roomObj->hallName = $roomObj->get_parent()->get_parent()->getHallName();
         $roomObj->damages = $dmgList;
         $rooms[] = $roomObj;
     }
     // JSON enocde it all and send it to Angular
     $context->setContent(json_encode($rooms));
 }
 /**
  * Returns an array of users names who have access to approve room changes for the
  * given bed id.
  *
  * @param int $bedId
  * @return multitype:array
  */
 private function getApproverList($bedId)
 {
     $bed = new HMS_Bed($bedId);
     $room = $bed->get_parent();
     $floor = $room->get_parent();
     $hall = $floor->get_parent();
     $hms_perm = new HMS_Permission();
     $hallMembers = $hms_perm->getMembership('room_change_approve', $hall);
     $floorMembers = $hms_perm->getMembership('room_change_approve', $floor);
     $hallMembers = array_merge($hallMembers, $floorMembers);
     $users = array();
     if (sizeof($hallMembers) <= 0) {
         return $users;
     }
     foreach ($hallMembers as $member) {
         $users[] = $member['username'];
     }
     return array_unique($users);
 }