public function execute(CommandContext $context)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'banner_queue')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to enable/disable the Banner queue.');
     }
     if (is_null($this->term)) {
         $this->term = $context->get('term');
     }
     $term = $this->term;
     if (is_null($term)) {
         throw new InvalidArgumentException('No term was specified to DisableBannerQueue');
     }
     $term = new Term($term);
     if (!$term->getBannerQueue()) {
         NQ::Simple('hms', hms\NotificationView::ERROR, 'The Banner Queue is not enabled for ' . Term::toString($term->term) . '.');
     } else {
         if ($term->getQueueCount() < 1) {
             NQ::Simple('hms', hms\NotificationView::WARNING, 'The Banner Queue was already empty for ' . Term::toString($term->term) . '.');
             $term->setBannerQueue(FALSE);
             $term->save();
             NQ::Simple('hms', hms\NotificationView::SUCCESS, 'Banner Queue has been disabled for ' . Term::toString($term->term) . '.');
         } else {
             PHPWS_Core::initModClass('hms', 'BannerQueue.php');
             $result = BannerQueue::processAll($term->term);
             if ($result === TRUE) {
                 NQ::Simple('hms', hms\NotificationView::SUCCESS, 'Banner Queue has been processed for ' . Term::toString($term->term) . '.');
                 $term->setBannerQueue(FALSE);
                 $term->save();
                 NQ::Simple('hms', hms\NotificationView::SUCCESS, 'Banner Queue has been disabled for ' . Term::toString($term->term) . '.');
             } else {
                 // TODO: This is just awful.
                 $text = 'The following failures occurred reporting to Banner:<br /><br /><ul>';
                 foreach ($result as $error) {
                     $text .= "<li>{$error['username']}: ({$error['code']}) - {$error['message']}</li>";
                 }
                 $text .= '</ul>The queue was not disabled.';
                 NQ::Simple('hms', hms\NotificationView::ERROR, $text);
             }
         }
     }
     $cmd = CommandFactory::getCommand('ShowEditTerm');
     $cmd->redirect();
 }
Beispiel #2
0
 /**
  * Queues a Remove Assignment
  *
  * NOTE: If the queue contains a Create Assignment for the same
  * user to the same room, this will NOT queue a room assignment,
  * but rather will delete the original assignment, UNLESS the
  * $force_queue flag is set.  The $force_queue flag being true will
  * queue a removal no matter what.
  *
  * MORE NOTE: If this requires immediate processing because banner
  * commits are enabled, the it will be sent straight to Banner,
  * and so the force_queue flag will be ignored.
  */
 public static function queueRemoveAssignment(Student $student, $term, HMS_Residence_Hall $hall, HMS_Bed $bed, $refund)
 {
     $entry = new BannerQueueItem(0, BANNER_QUEUE_REMOVAL, $student, $term, $hall, $bed, null, null, $refund);
     if (BannerQueue::processImmediately($term)) {
         return $entry->process();
     }
     // Otherwise, look for an corresponding assignment
     $db = new PHPWS_DB('hms_banner_queue');
     $db->addWhere('type', BANNER_QUEUE_ASSIGNMENT);
     $db->addWhere('asu_username', $student->getUsername());
     $db->addWhere('building_code', $hall->getBannerBuildingCode());
     $db->addWhere('bed_code', $bed->getBannerId());
     $db->addWhere('term', $term);
     $result = $db->count();
     if (PHPWS_Error::logIfError($result)) {
         throw new DatabaseException($result->toString());
     }
     if ($result == 0) {
         return $entry->save();
     } else {
         return $db->delete();
     }
 }
Beispiel #3
0
 /**
  * Removes/unassignes a student
  *
  * Valid values for $reason are defined in defines.php.
  *
  * @param Student $student Student to un-assign.
  * @param String $term The term of the assignment to remove.
  * @param String $notes Additional notes for the ActivityLog.
  * @param String $reason Reason string, defined in defines.php
  * @param Integer $refund Percentage of original charges student should be refunded
  * @throws PermissionException
  * @throws InvalidArgumentException
  * @throws AssignmentException
  * @throws DatabaseException
  */
 public static function unassignStudent(Student $student, $term, $notes = "", $reason, $refund)
 {
     if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'assignment_maintenance')) {
         PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
         throw new PermissionException('You do not have permission to unassign students.');
     }
     PHPWS_Core::initModClass('hms', 'BannerQueue.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'AssignmentHistory.php');
     PHPWS_Core::initModClass('hms', 'exception/AssignmentException.php');
     $username = $student->getUsername();
     // Make sure a username was entered
     if (!isset($username) || $username == '') {
         throw new InvalidArgumentException('Bad username.');
     }
     $username = strtolower($username);
     // Check refund field, required field
     if (!isset($refund) || $refund == '') {
         throw new InvalidArgumentException('Please enter a refund percentage.');
     }
     // Refund must be numeric
     if (!is_numeric($refund) || $refund < 0 || $refund > 100) {
         throw new InvalidArgumentException('The refund percentage must be between 0 and 100 percent.');
     }
     // Must be whole number
     if (is_float($refund)) {
         throw new InvalidArgumentException('Only whole number refund percentages are supported, no decimal place is allowed.');
     }
     // Make sure the requested username is actually assigned
     if (!HMS_Assignment::checkForAssignment($username, $term)) {
         throw new AssignmentException('Student is not assigned.');
     }
     $assignment = HMS_Assignment::getAssignment($username, $term);
     if ($assignment == FALSE || $assignment == NULL) {
         throw new AssignmentException('Could not load assignment object.');
     }
     $bed = $assignment->get_parent();
     $room = $bed->get_parent();
     $floor = $room->get_parent();
     $building = $floor->get_parent();
     // Attempt to unassign the student in Banner though SOAP
     $banner_result = BannerQueue::queueRemoveAssignment($student, $term, $building, $bed, $refund);
     // Show an error and return if there was an error
     if ($banner_result !== TRUE) {
         throw new AssignmentException('Error while adding the assignment removal to the Banner queue.');
     }
     // Record this before we delete from the db
     $banner_bed_id = $bed->getBannerId();
     $banner_building_code = $building->getBannerBuildingCode();
     // Attempt to delete the assignment in HMS
     $result = $assignment->delete();
     if (!$result) {
         throw new DatabaseException($result->toString());
     }
     // Log in the activity log
     HMS_Activity_Log::log_activity($username, ACTIVITY_REMOVED, UserStatus::getUsername(), $term . ' ' . $banner_building_code . ' ' . $banner_bed_id . ' ' . $notes . 'Refund: ' . $refund);
     // Insert into history table
     AssignmentHistory::makeUnassignmentHistory($assignment, $reason);
     // Generate assignment notices for old roommates
     $assignees = $room->get_assignees();
     // get an array of student objects for those assigned to this room
     if (sizeof($assignees) > 1) {
         foreach ($assignees as $roommate) {
             // Skip this student
             if ($roommate->getUsername() == $username) {
                 continue;
             }
             $roommate_assign = HMS_Assignment::getAssignment($roommate->getUsername(), Term::getSelectedTerm());
             $roommate_assign->letter_printed = 0;
             $roommate_assign->email_sent = 0;
             $roommate_assign->save();
         }
     }
     // Show a success message
     return true;
 }
 public function assign($app, $bed, $term)
 {
     $bbc = $bed->get_banner_building_code();
     $bid = $bed->banner_id;
     $user = $app->username;
     $meal_plan = array();
     $meal_plan['plan'] = 'HOME';
     $meal_plan['meal'] = $app->meal_plan;
     $error = BannerQueue::queueAssignment($user, $term, $bbc, $bid, $meal_plan['plan'], $meal_plan['meal']);
     if ($error) {
         return "Skipped bed {$bbc} {$bid} username {$user} due to banner error code {$error}";
     }
     $assignment = new HMS_Assignment();
     $assignment->asu_username = $user;
     $assignment->bed_id = $bed->id;
     $assignment->term = $term;
     $assignment->meal_option = $app->meal_plan;
     $assignment->save();
     HMS_Activity_Log::log_activity($user, ACTIVITY_AUTO_ASSIGNED, Current_User::getUsername(), "{$term} {$bbc} {$bid}");
     return TRUE;
 }