示例#1
0
 public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_structure')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to remove a bed.');
     }
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $viewCmd = CommandFactory::getCommand('EditRoomView');
     $viewCmd->setRoomId($context->get('roomId'));
     $bedId = $context->get('bedId');
     $roomId = $context->get('roomId');
     if (!isset($roomId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing room ID.');
         $viewCmd->redirect();
     }
     if (!isset($bedId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing bed ID.');
         $viewCmd->redirect();
     }
     # Try to delete the bed
     try {
         HMS_Bed::deleteBed($bedId);
     } catch (Exception $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error deleting the bed: ' . $e->getMessage());
         $viewCmd->redirect();
     }
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Bed successfully deleted.');
     $viewCmd->redirect();
 }
示例#2
0
 public static function deleteRoom($roomId)
 {
     if (!Current_User::allow('hms', 'room_structure')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to delete a room.');
     }
     // check that we're not about to do something stupid
     if (!isset($roomId)) {
         throw new InvalidArgumentException('Invalid room id.');
     }
     $room = new HMS_Room($roomId);
     // make sure there isn't an assignment
     if ($room->get_number_of_assignees() != 0) {
         PHPWS_Core::initModClass('hms', 'exception/HallStructureException.php');
         throw new HallStructureException('One or more students are currently assigned to that room and therefore it cannot deleted.');
     }
     // delete any beds
     try {
         if ($room->loadBeds()) {
             if (!empty($room->_beds)) {
                 foreach ($room->_beds as $bed) {
                     HMS_Bed::deleteBed($bed->id);
                 }
             }
         }
         $room->delete();
     } catch (Exception $e) {
         throw $e;
     }
     return true;
 }