/**
  * removes an assignment from this object's array
  *
  * @param AssignmentHistory $assignmentHistory an assignment history object
  * @return boolean|AssignmentHistory false if failed or the removed assignment object if success
  */
 public function remove(AssignmentHistory $assignmentHistory)
 {
     $id = $assignmentHistory->getID();
     if (isset($this->theArray[$id])) {
         $rObject = $this->theArray[$id];
         unset($this->theArray[$id]);
         return $rObject;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * static method to enable an AssignmentHistory to be created by means of passing an
  * assignment and reason only
  *
  * @param HMS_Assignment $assignment HMS_Assignment object from which to pull data
  * @param String $reason A defined reason for assignment if not wishing to use one in assignment (see definitions)
  * @return boolean true if success, false if failure
  */
 public static function makeAssignmentHistory(HMS_Assignment $assignment, $reason = null)
 {
     if (is_null($assignment)) {
         throw new InvalidArgumentException('Missing HMS_Assignment object.');
     }
     if (is_null($reason)) {
         $reason = $assignment->reason;
     }
     // check if an open-ended assignment exists for the term sent.  If so, unassign with reason "AUTO"
     if (AssignmentHistory::historyExists($assignment)) {
         AssignmentHistory::makeUnassignmentHistory($assignment, UNASSIGN_REASSIGN);
     }
     $ah = new AssignmentHistory();
     $ah->setBanner($assignment->banner_id);
     $ah->setBedId($assignment->bed_id);
     $ah->setTerm($assignment->term);
     $ah->setAssign($reason);
     // set all the assignment data
     $ah->setApplicationTerm($assignment->application_term);
     $ah->setClass($assignment->class);
     $ah->save();
     return true;
 }
Ejemplo n.º 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;
 }