public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'RoomDamageFactory.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'CheckinFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $term = Term::getSelectedTerm();
     // Get the total damages assessed for each student
     $damages = RoomDamageFactory::getAssessedDamagesStudentTotals($term);
     foreach ($damages as $dmg) {
         $student = StudentFactory::getStudentByBannerId($dmg['banner_id'], $term);
         // Get the student's last checkout
         // (NB: the damages may be for multiple check-outs,
         // but we'll just take the last one)
         $checkout = CheckinFactory::getLastCheckoutForStudent($student);
         $bed = new HMS_Bed($checkout->getBedId());
         $room = $bed->get_parent();
         $floor = $room->get_parent();
         $hall = $floor->get_parent();
         $coordinators = $hall->getCoordinators();
         if ($coordinators != null) {
             $coordinatorName = $coordinators[0]->getDisplayName();
             $coordinatorEmail = $coordinators[0]->getEmail();
         } else {
             $coordinatorName = '(No coordinator set for this hall.)';
             $coordinatorEmail = '(No coordinator set for this hall.)';
         }
         HMS_Email::sendDamageNotification($student, $term, $dmg['sum'], $coordinatorName, $coordinatorEmail);
     }
     // Show a success message and redirect back to the main admin menu
     NQ::simple('hms', hms\NotificationView::SUCCESS, 'Room damage noties sent.');
     $cmd = CommandFactory::getCommand('ShowAdminMaintenanceMenu');
     $cmd->redirect();
 }
Ejemplo n.º 2
0
 /**
  * Constructor.
  * Requires a Checkin object to get started.
  *
  * @param Checkin $checkin
  */
 public function __construct(Checkin $checkin)
 {
     $this->checkin = $checkin;
     $this->bannerId = $this->checkin->getBannerId();
     $this->term = $this->checkin->getTerm();
     $this->student = StudentFactory::getStudentByBannerId($this->bannerId, $this->term);
     // Lookup the student's housing application
     $this->application = HousingApplicationFactory::getAppByStudent($this->student, $this->term);
     // Create a dummy application if a real one doesn't exist
     if (!isset($this->application)) {
         $this->application = new HousingApplication();
     }
     // Get the hall, floor, and room from the checkin's bed
     $this->bed = new HMS_Bed($this->checkin->getBedId());
     $this->room = $this->bed->get_parent();
     $this->floor = $this->room->get_parent();
     $this->hall = $this->floor->get_parent();
     // Get the damages at check-in time
     $this->checkinDamages = RoomDamageFactory::getDamagesBefore($this->room, $this->checkin->getCheckinDate() + Checkin::CHECKIN_TIMEOUT);
     if (sizeof($this->checkinDamages) <= 0) {
         $this->checkinDamages = array();
     }
     // Get the damages at check-out time
     $this->checkoutDamages = RoomDamageFactory::getDamagesByRoom($this->room);
     if (sizeof($this->checkoutDamages) <= 0) {
         $this->checkoutDamages = array();
     }
 }
Ejemplo n.º 3
0
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'CheckinFactory.php');
     PHPWS_Core::initModClass('hms', 'RoomDamageFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'BedFactory.php');
     $term = Term::getCurrentTerm();
     $bannerId = $context->get('bannerId');
     $hallId = $context->get('hallId');
     $errorCmd = CommandFactory::getCommand('ShowCheckoutStart');
     if (!isset($bannerId) || is_null($bannerId) || $bannerId == '') {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing student ID.');
         $errorCmd->redirect();
     }
     if (!isset($hallId)) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Missing residence hall ID.');
         $errorCmd->redirect();
     }
     // If search string is all numeric, make sure it looks like a valid Banner ID
     if (is_numeric($bannerId) && preg_match("/[\\d]{9}/", $bannerId) == false) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Imporperly formatted Banner ID.');
         $errorCmd->redirect();
     }
     // Try to lookup the student in Banner
     try {
         // If it's all numeric assume it's a student ID, otherwise assume it's a username
         if (is_numeric($bannerId) && strlen((string) $bannerId) == 9) {
             $student = StudentFactory::getStudentByBannerId($bannerId, $term);
         } else {
             $student = StudentFactory::getStudentByUsername($bannerId, $term);
         }
     } catch (StudentNotFoundException $e) {
         NQ::simple('hms', hms\NotificationView::ERROR, 'Could not locate a student with that Banner ID.');
         $errorCmd->redirect();
     }
     // Find the earliest checkin that matches hall the user selected
     $hall = new HMS_Residence_Hall($hallId);
     $checkin = CheckinFactory::getPendingCheckoutForStudentByHall($student, $hall);
     if (!isset($checkin)) {
         NQ::simple('hms', hms\NotificationView::ERROR, "Sorry, we couldn't find a matching check-in at {$hall->getHallName()} for this student to check-out of.");
         $errorCmd->redirect();
     }
     $bed = BedFactory::getBedByPersistentId($checkin->getBedPersistentId(), $term);
     $room = $bed->get_parent();
     // Get the damages for this student's room
     $damages = RoomDamageFactory::getDamagesByRoom($room);
     PHPWS_Core::initModClass('hms', 'CheckoutFormView.php');
     $view = new CheckoutFormView($student, $hall, $room, $bed, $damages, $checkin);
     $context->setContent($view->show());
 }
Ejemplo n.º 4
0
 public function execute(CommandContext $context)
 {
     PHPWS_Core::initModClass('hms', 'RoomDamageFactory.php');
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     $bedId = $context->get('bed_id');
     $bed = new HMS_Bed($bedId);
     $room = $bed->get_parent();
     // Get the damages for this student's room
     $damages = RoomDamageFactory::getDamagesByRoom($room);
     if ($damages == null) {
         $context->setContent(json_encode(array()));
         return;
     }
     $context->setContent(json_encode($damages));
 }
 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));
 }
 private function addDamage(array $dmg, HMS_Room $room)
 {
     $damage = new RoomDamage($room, $this->term, $dmg['damage_type'], $dmg['side'], $dmg['note']);
     // Save the damage
     RoomDamageFactory::save($damage);
     // Determine the residents which were responsible
     // For each resident submitted
     foreach ($dmg['residents'] as $resident) {
         // If the resident was selected as being responsible for this damage
         if (isset($resident['selected']) && $resident['selected']) {
             // Create the student
             $student = StudentFactory::getStudentByBannerId($resident['studentId'], $this->term);
             // Create the responsibility
             $resp = new RoomDamageResponsibility($student, $damage);
             RoomDamageResponsibilityFactory::save($resp);
         }
     }
 }