public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'room_view')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to view rooms.'); } // Check for a hall ID $roomId = $context->get('room'); if (!isset($roomId)) { throw new InvalidArgumentException('Missing room ID.'); } // Load the room $room = new HMS_Room($roomId); if ($room->term != Term::getSelectedTerm()) { $roomCmd = CommandFactory::getCommand('SelectRoom'); $roomCmd->setTitle('Edit a Room'); $roomCmd->setOnSelectCmd(CommandFactory::getCommand('EditRoomView')); $roomCmd->redirect(); } // Load the floor/hall $floor = $room->get_parent(); $hall = $floor->get_parent(); // Load the room damages and damage types $damageTypes = DamageTypeFactory::getDamageTypeAssoc(); $roomView = new RoomView($hall, $floor, $room, $damageTypes); $context->setContent($roomView->show()); }
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 create a bed.'); } PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'AddBedView.php'); $roomId = $context->get('roomId'); $room = new HMS_Room($roomId); $floor = $room->get_parent(); $hall = $floor->get_parent(); $addBedView = new AddBedView($hall, $floor, $room, $context->get('bedLetter'), $context->get('bedroomLabel'), $context->get('phoneNumber'), $context->get('bannerId')); $context->setContent($addBedView->show()); }
public function show() { PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'LotteryApplication.php'); PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_Room.php'); javascript('jquery'); $tpl = array(); #TODO: place a temporary reservation on the entire room # Grab all of their preferred roommates $lotteryApplication = HousingApplication::getApplicationByUser($this->student->getUsername(), $this->term); # List each bed in the room and if it's available, assigned, or reserved $room = new HMS_Room($this->roomId); $beds = $room->get_beds(); $tpl['ROOM'] = $room->where_am_i(); $form = new PHPWS_Form(); $submitCmd = CommandFactory::getCommand('LotteryChooseRoommates'); $submitCmd->setRoomId($this->roomId); $submitCmd->initForm($form); $assigned_self = FALSE; // Whether or not we've placed *this* student in a bed yet // Search the request to see if the student has already assigned themselves previously (this is only used if the user is being // set back from a subsequent page after an error). if (isset($_REQUEST['roommates']) && !(array_search($this->student->getUsername(), $_REQUEST['roommates']) === FALSE)) { $assigned_self = TRUE; } $bedCount = count($beds); for ($i = 0; $i < $bedCount; $i++) { $bed = $beds[$i]; $bed_row = array(); $bedLabel = $room->getRoomNumber(); if ($room->get_number_of_beds() == 4) { $bedLabel = $bedLabel . $bed->getBedroomLabel(); } $bedLabel = $bedLabel . $bed->getLetter(); $bed_row['BED_LABEL'] = $bedLabel; # Check for an assignment $bed->loadAssignment(); # Check for a reservation $reservation = $bed->get_lottery_reservation_info(); if ($bed->_curr_assignment != NULL) { # Bed is assigned, so show who's in it $assignedStudent = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, $this->term); $bed_row['TEXT'] = $assignedStudent->getName() . ' (assigned)'; } else { if ($reservation != NULL) { # Bed is reserved $reservedStudent = StudentFactory::getStudentByUsername($reservation['asu_username'], $this->term); $bed_row['TEXT'] = $reservedStudent->getName() . ' (unconfirmed invitation)'; } else { if ($bed->isInternationalReserved() || $bed->isRaRoommateReserved() || $bed->isRa()) { $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" value=\"Reserved\" disabled>"; } else { # Bed is empty, so decide what we should do with it if (isset($_REQUEST['roommates'][$bed->id])) { # The user already submitted the form once, put the value in the request in the text box by default $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\" value=\"{$_REQUEST['roommates'][$bed->id]}\">"; } else { if (!$assigned_self) { # No value in the request, this bed is empty, and this user hasn't been assigned anywhere yet # So put their user name in this field by default $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\" value=\"{$this->student->getUsername()}\">"; $assigned_self = TRUE; } else { $bed_row['TEXT'] = "<input type=\"text\" class=\"form-control\" name=\"roommates[{$bed->id}]\" class=\"roommate_entry\">"; } } } } } $tpl['beds'][] = $bed_row; } # Decide which meal plan drop box to show based on whether or not the chosen room # is in a hall which requires a meal plan $floor = $room->get_parent(); $hall = $floor->get_parent(); if ($hall->meal_plan_required == 0) { $form->addDropBox('meal_plan', array(BANNER_MEAL_NONE => _('None'), BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super'))); $form->addCssClass('meal_plan', 'form-control'); } else { $form->addDropBox('meal_plan', array(BANNER_MEAL_LOW => _('Low'), BANNER_MEAL_STD => _('Standard'), BANNER_MEAL_HIGH => _('High'), BANNER_MEAL_SUPER => _('Super'))); $form->addCssClass('meal_plan', 'form-control'); } $form->setMatch('meal_plan', $lotteryApplication->getMealPlan()); $form->addSubmit('submit_form', 'Review Roommate & Room Selection'); $form->mergeTemplate($tpl); $tpl = $form->getTemplate(); Layout::addPageTitle("Lottery Choose Roommate"); return PHPWS_Template::process($tpl, 'hms', 'student/lottery_select_roommate.tpl'); }
/** * Does all the checks necessary to assign a student and makes the assignment * * The $room_id and $bed_id fields are optional, but one or the other must be specificed * * @param Student $student * @param Integer $term * @param Integer $room_id * @param Integer $bed_id * @param Integer $meal_plan * @param String $notes * @param boolean $lottery * @param string $reason * @throws InvalidArgumentException * @throws AssignmentException * @throws DatabaseException * @throws Exception */ public static function assignStudent(Student $student, $term, $room_id = NULL, $bed_id = NULL, $meal_plan, $notes = "", $lottery = FALSE, $reason) { /** * Can't check permissions here because there are some student-facing commands that needs to make assignments (e.g. * the lottery/re-application code) * * if(!UserStatus::isAdmin() || !Current_User::allow('hms', 'assignment_maintenance')) { * PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); * throw new PermissionException('You are not allowed to edit student assignments.'); * } */ PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php'); PHPWS_Core::initModClass('hms', 'HMS_Floor.php'); PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'HMS_Bed.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'BannerQueue.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); if ($student->getType() == TYPE_WITHDRAWN) { throw new AssignmentException('Invalid student type. Student is withdrawn.'); } if (HMS_Assignment::checkForAssignment($username, $term)) { throw new AssignmentException('The student is already assigned.'); } if (isset($bed_id)) { // A bed_id was given, so create that bed object $vacant_bed = new HMS_Bed($bed_id); if (!$vacant_bed) { throw new AssignmentException('Null bed object.'); } // Get the room that this bed is in $room = $vacant_bed->get_parent(); } else { if (isset($room_id)) { // A room_id was given, so create that room object $room = new HMS_Room($room_id); // And find a vacant bed in that room $beds = $room->getBedsWithVacancies(); $vacant_bed = $beds[0]; } else { // Both the bed and room IDs were null, so return an error throw new AssignmentException('No room nor bed specified.'); } } if (!$room) { throw new AssignmentException('Null room object.'); } // Make sure the room has a vacancy if (!$room->has_vacancy()) { throw new AssignmentException('The room is full.'); } // Make sure the room is not offline if ($room->offline) { throw new AssignmentException('The room is offline'); } // Double check that the bed is in the same term as we're being requested to assign for if ($vacant_bed->getTerm() != $term) { throw new AssignmentException('The bed\'s term and the assignment term do not match.'); } // Double check that the resulting bed is empty if ($vacant_bed->get_number_of_assignees() > 0) { throw new AssignmentException('The bed is not empty.'); } // Issue a warning if the bed was reserved for room change //TODO Move this to the room change view /* if ($vacant_bed->room_change_reserved != 0) { NQ::simple('hms', hms\NotificationView::WARNING, 'Room was reserved for room change'); } */ // Check that the room's gender and the student's gender match $student_gender = $student->getGender(); if (is_null($student_gender)) { throw new AssignmentException('Student gender is null.'); } // Genders must match unless the room is COED if ($room->getGender() != $student_gender && $room->getGender() != COED) { throw new AssignmentException('Room gender does not match the student\'s gender.'); } // We probably shouldn't check permissions inside this method, since sometimes this can be // called from student-facing interfaces.. But, since I want to be really careful with co-ed rooms, // I'm going to take the extra step of making sure no students are putting themselves in co-ed rooms. if ($room->getGender() == COED && !Current_User::allow('hms', 'coed_assignment')) { throw new AssignmentException('You do not have permission to make assignments for Co-ed rooms.'); } // Create the floor object $floor = $room->get_parent(); if (!$floor) { throw new AssignmentException('Null floor object.'); } // Create the hall object $hall = $floor->get_parent(); if (!$hall) { throw new AssignmentException('Null hall object.'); } if ($meal_plan == BANNER_MEAL_NONE) { $meal_plan = NULL; } // Determine which meal plan to use // If this is a freshmen student and they've somehow selected none or low, give them standard if ($student->getType() == TYPE_FRESHMEN && ($meal_plan == BANNER_MEAL_NONE || $meal_plan == BANNER_MEAL_LOW)) { $meal_plan = BANNER_MEAL_STD; // If a student is living in a dorm which requires a meal plan and they've selected none, give them low } else { if ($hall->meal_plan_required == 1 && $meal_plan == BANNER_MEAL_NONE) { $meal_plan = BANNER_MEAL_LOW; } } /** * *************************** * Temporary Assignment HACK * * *************************** */ // Check for an assignment in the temp assignment table $db = new PHPWS_DB('hms_temp_assignment'); $db->addWhere('banner_id', $student->getBannerId()); $result = $db->select(); if (PHPWS_Error::logIfError($result)) { throw new DatabaseException($result->toString()); } if (sizeof($result) > 0) { // Queue an unassign for this student $soap = SOAP::getInstance(UserStatus::getUsername(), UserStatus::isAdmin() ? SOAP::ADMIN_USER : SOAP::STUDENT_USER); try { $soap->removeRoomAssignment($student->getBannerId(), $term, 'TMPR', $result[0]['room_number'], 100); // Hard-code to 100% refund } catch (Exception $e) { throw $e; } $db = new PHPWS_DB('hms_temp_assignment'); $db->addValue('banner_id', null); $db->addWhere('room_number', $result[0]['room_number']); $db->update(); if (PHPWS_Error::logIfError($result)) { throw new DatabaseException($result->toString()); } NQ::simple('hms', hms\NotificationView::WARNING, 'Temporary assignment was removed.'); } // Send this off to the queue for assignment in banner $banner_success = BannerQueue::queueAssignment($student, $term, $hall, $vacant_bed, 'HOME', $meal_plan); if ($banner_success !== TRUE) { throw new AssignmentException('Error while adding the assignment to the Banner queue.'); } // Make the assignment in HMS $assignment = new HMS_Assignment(); $assignment->setBannerId($student->getBannerId()); $assignment->asu_username = $username; $assignment->bed_id = $vacant_bed->id; $assignment->term = $term; $assignment->letter_printed = 0; $assignment->email_sent = 0; $assignment->meal_option = $meal_plan; $assignment->reason = $reason; $assignment->application_term = $student->getApplicationTerm(); $assignment->class = $student->getComputedClass($term); // If this was a lottery assignment, flag it as such if ($lottery) { $assignment->lottery = 1; if (!isset($reason)) { // Automatically tag reason as lottery $assignment->reason = ASSIGN_LOTTERY; } } else { $assignment->lottery = 0; } $result = $assignment->save(); if (!$result || PHPWS_Error::logIfError($result)) { throw new DatabaseException($result->toString()); } // Log the assignment HMS_Activity_Log::log_activity($username, ACTIVITY_ASSIGNED, UserStatus::getUsername(), $term . ' ' . $hall->hall_name . ' ' . $room->room_number . ' ' . $notes); // Insert assignment into History table AssignmentHistory::makeAssignmentHistory($assignment); // Look for roommates and flag their assignments as needing a new letter $room_id = $assignment->get_room_id(); $room = new HMS_Room($room_id); // Go to the room level to get all the 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); $roommate_assign->letter_printed = 0; $roommate_assign->email_sent = 0; $roommate_assign->save(); } } // Return Sucess return true; }
public function execute(CommandContext $context) { 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 assign students.'); } PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'FallApplication.php'); PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'BannerQueue.php'); // NB: Username must be all lowercase $username = strtolower(trim($context->get('username'))); $term = Term::getSelectedTerm(); // Setup command to redirect to in case of error $errorCmd = CommandFactory::getCommand('ShowAssignStudent'); $errorCmd->setUsername($username); /*** * Input Sanity Checking */ // Must supply a user name if (is_null($username)) { NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid or missing username.'); $errorCmd->redirect(); } // Must supply at least a room ID $roomId = $context->get('room'); if (is_null($roomId) || $roomId == 0) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must select a room.'); $errorCmd->redirect(); } // Must choose an assignment type $assignmentType = $context->get('assignment_type'); if (!isset($assignmentType) || is_null($assignmentType) || $assignmentType < 0) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must choose an assignment type.'); $errorCmd->redirect(); } // Check to make sure the student has an application on file $applicationStatus = HousingApplication::checkForApplication($username, $term); if ($applicationStatus == FALSE) { NQ::simple('hms', hms\NotificationView::WARNING, 'Warning: No housing application found for this student in this term.'); } // If the student is already assigned, redirect to the confirmation screen. If the student is already assigned // and the confirmation flag is true, then set a flag and proceed. $moveNeeded = FALSE; if (HMS_Assignment::checkForAssignment($username, $term)) { if ($context->get('moveConfirmed') == 'true') { // Move has been confirmed $moveNeeded = true; } else { // Redirect to the move confirmation interface $moveConfirmCmd = CommandFactory::getCommand('ShowAssignmentMoveConfirmation'); $moveConfirmCmd->setUsername($username); $moveConfirmCmd->setRoom($context->get('room')); $moveConfirmCmd->setBed($context->get('bed')); $moveConfirmCmd->setMealPlan($context->get('meal_plan')); $moveConfirmCmd->setAssignmentType($assignmentType); $moveConfirmCmd->setNotes($context->get('note')); $moveConfirmCmd->redirect(); } } try { $student = StudentFactory::getStudentByUsername($username, $term); } catch (StudentNotFoundException $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid user name, no such student found.'); $errorCmd->redirect(); } // Check age, issue a warning for over 25 if (strtotime($student->getDOB()) < strtotime("-25 years")) { NQ::simple('hms', hms\NotificationView::WARNING, 'Student is 25 years old or older!'); } $gender = $student->getGender(); if (!isset($gender) || is_null($gender)) { throw new InvalidArgumentException('Missing student gender.'); } // Create the room object so we can check gender $room = new HMS_Room($roomId); if (!$room) { NQ::simple('hms', hms\NotificationView::ERROR, 'Error creating the room object.'); $errorCmd->redirect(); } // Create the hall object for later $floor = $room->get_parent(); $hall = $floor->get_parent(); // If the room is Co-ed, make sure the user has permission to assign to co-ed rooms if ($room->getGender() == COED && !Current_User::allow('hms', 'coed_assignment')) { NQ::simple('hms', hms\NotificationView::ERROR, 'Error: You do not have permission to assign students to co-ed rooms.'); $errorCmd->redirect(); } // Make sure the student's gender matches the gender of the room, unless the room is co-ed. if ($room->getGender() != $gender && $room->getGender() != COED) { // Room gender does not match student's gender, so check if we can change it if ($room->can_change_gender($gender) && Current_User::allow('hms', 'room_attributes')) { $room->setGender($gender); $room->save(); NQ::simple('hms', hms\NotificationView::WARNING, 'Warning: Changing room gender.'); } else { NQ::simple('hms', hms\NotificationView::ERROR, 'Error: The student\'s gender and the room\'s gender do not match and the room could not be changed.'); $errorCmd->redirect(); } } // If the user is attempting to re-assign and has confirmed the move, // then unassign the student first. if ($moveNeeded) { try { //TODO don't hard-code refund percentage to 100% HMS_Assignment::unassignStudent($student, $term, '(re-assign)', UNASSIGN_REASSIGN, 100); } catch (Exception $e) { NQ::simple('hms', hms\NotificationView::ERROR, "Error deleting current assignment. {$username} was not removed."); $errorCmd->redirect(); } } // Actually try to make the assignment, decide whether to use the room id or the bed id $bed = $context->get('bed'); try { if (isset($bed) && $bed != 0) { HMS_Assignment::assignStudent($student, $term, NULL, $bed, $context->get('meal_plan'), $context->get('note'), false, $context->get('assignment_type')); } else { HMS_Assignment::assignStudent($student, $term, $context->get('room'), NULL, $context->get('meal_plan'), $context->get('note'), false, $context->get('assignment_type')); } } catch (AssignmentException $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'Assignment error: ' . $e->getMessage()); $errorCmd->redirect(); } // Show a success message if ($context->get('moveConfirmed') == 'true') { NQ::simple('hms', hms\NotificationView::SUCCESS, 'Successfully moved ' . $username . ' to ' . $hall->hall_name . ' room ' . $room->room_number); } else { NQ::simple('hms', hms\NotificationView::SUCCESS, 'Successfully assigned ' . $username . ' to ' . $hall->hall_name . ' room ' . $room->room_number); } $successCmd = CommandFactory::getCommand('ShowAssignStudent'); $successCmd->redirect(); }