/** * 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(); } }
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()); }
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)); }