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 __construct(HMS_Room $room) { if ($room->getId() == 0) { throw new Exception('Ivalid room object.'); } $this->room = $room; }
/** * Constructor * * @param HMS_Room $room * @param integer $damageType * @param string $note */ public function __construct(HMS_Room $room, $term, $damageType, $side, $note) { $this->id = null; $this->room_persistent_id = $room->getPersistentId(); $this->term = $term; $this->damage_type = $damageType; $this->side = $side; $this->repaired = false; $this->note = $note; $this->reported_by = Current_User::getUsername(); $this->reported_on = time(); }
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()); }
/** * Returns the set of RoomDamage objects that were created before * the give timestmap. * * @param HMS_Room $room * @param unknown $timestamp * @throws DatabaseException * @throws InvalidArgumentException * @return Array<RoomDamage> null */ public static function getDamagesBefore(HMS_Room $room, $timestamp) { if (!isset($timestamp)) { throw new InvalidArgumentException('Missing timestamp.'); } $db = new PHPWS_DB('hms_room_damage'); $db->addWhere('room_persistent_id', $room->getPersistentId()); $db->addWhere('repaired', 0); $db->addWhere('reported_on', $timestamp, '<='); $result = $db->getObjects('RoomDamageDb'); if (PHPWS_Error::logIfError($result)) { throw new DatabaseException($result->toString()); } return $result; }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'HMS_Util.php'); //TODO check for a hallId $room = new HMS_Room($context->get('roomId')); $beds = $room->get_beds(); $json_beds = array(); $json_beds[0] = 'Select...'; foreach ($beds as $bed) { if ($bed->room_change_reserved != 0) { //Cannot assign to reserved rooms continue; } $json_beds[$bed->id] = $bed->bed_letter; } $context->setContent(json_encode($json_beds)); }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'HMS_Util.php'); //TODO check for a floorId $room = new HMS_Room($context->get('roomId')); $beds = $room->getBedsWithVacancies(); $json_beds = array(); $json_beds[0] = 'Select ...'; foreach ($beds as $bed) { unset($text); $text = strtoupper($bed->bedroom_label) . $bed->bed_letter; /* if($bed->ra_bed == 1){ $text .= ' (RA)'; }*/ $json_beds[$bed->id] = $text; } $context->setContent(json_encode($json_beds)); }
public function execute(CommandContext $context) { if (!Current_User::allow('hms', 'room_structure')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to add a room.'); } $floor_id = $context->get('floor'); $room = new HMS_Room(); $room->floor_id = $floor_id; $room->room_number = $context->get('room_number'); $room->gender_type = $context->get('gender_type'); $room->default_gender = $context->get('default_gender'); $room->ra = !is_null($context->get('ra')) ? 1 : 0; $room->private = !is_null($context->get('private')) ? 1 : 0; $room->overflow = !is_null($context->get('overflow')) ? 1 : 0; $room->reserved = !is_null($context->get('reserved')) ? 1 : 0; $room->offline = !is_null($context->get('offline')) ? 1 : 0; $room->parlor = !is_null($context->get('parlor')) ? 1 : 0; $room->ada = !is_null($context->get('ada')) ? 1 : 0; $room->hearing_impaired = !is_null($context->get('hearing_impaired')) ? 1 : 0; $room->bath_en_suite = !is_null($context->get('bath_en_suite')) ? 1 : 0; $rlcId = $context->get('rlc_reserved'); $room->reserved_rlc_id = !is_null($rlcId) ? $rlcId : null; $room->term = Term::getSelectedTerm(); // Get the building code $floor = new HMS_Floor($floor_id); $hall = $floor->get_parent(); // and set the rooms building code to the same as the hall it is in $room->banner_building_code = $hall->banner_building_code; // creates a persistent_id for the new room $room->persistent_id = uniqid(); $room->save(); $cmd = CommandFactory::getCommand('EditRoomView'); $cmd->setRoomId($room->getId()); $cmd->redirect(); }
/** * @see View::show() */ public function show() { $jsParams = array('LINK_SELECT' => '#addDamageLink'); javascript('addRoomDamage', $jsParams, 'mod/hms/'); // Drop down enhancements for room damage dialog javascript('chosen', null, 'mod/hms/'); /*** Header Info ***/ $tpl = array(); $tpl['TERM'] = Term::getPrintableSelectedTerm(); $tpl['HALL_NAME'] = $this->hall->getLink(); $tpl['FLOOR_NUMBER'] = $this->floor->getLink('Floor'); /*** Page Title ***/ $tpl['ROOM'] = $this->room->getRoomNumber(); /*** Room Attributes Labels ***/ if ($this->room->isOffline()) { $tpl['OFFLINE_ATTRIB'] = 'Offline'; } if ($this->room->isReserved()) { $tpl['RESERVED_ATTRIB'] = 'Reserved'; } if ($this->room->isRa()) { $tpl['RA_ATTRIB'] = 'RA'; } if ($this->room->isPrivate()) { $tpl['PRIVATE_ATTRIB'] = 'Private'; } if ($this->room->isOverflow()) { $tpl['OVERFLOW_ATTRIB'] = 'Overflow'; } if ($this->room->isParlor()) { $tpl['PARLOR_ATTRIB'] = 'Parlor'; } if ($this->room->isADA()) { $tpl['ADA_ATTRIB'] = 'ADA'; } if ($this->room->isHearingImpaired()) { $tpl['HEARING_ATTRIB'] = 'Hearing Impaired'; } if ($this->room->bathEnSuite()) { $tpl['BATHENSUITE_ATTRIB'] = 'Bath en Suite'; } $number_of_assignees = $this->room->get_number_of_assignees(); $tpl['NUMBER_OF_BEDS'] = $this->room->get_number_of_beds(); $tpl['NUMBER_OF_ASSIGNEES'] = $number_of_assignees; $form = new PHPWS_Form(); $submitCmd = CommandFactory::getCommand('EditRoom'); $submitCmd->setRoomId($this->room->id); $submitCmd->initForm($form); $form->addText('room_number', $this->room->getRoomNumber()); $form->setLabel('room_number', 'Room Number'); $form->addCssClass('room_number', 'form-control'); /*** Room Gender ***/ if ($number_of_assignees == 0) { // Room is empty, show the drop down so the user can change the gender $roomGenders = array(FEMALE => FEMALE_DESC, MALE => MALE_DESC, AUTO => AUTO_DESC); // Check if the user is allowed to set rooms to co-ed, if so add Co-ed to the drop down if (Current_User::allow('hms', 'coed_rooms')) { $roomGenders[COED] = COED_DESC; } $form->addDropBox('gender_type', $roomGenders); $form->setMatch('gender_type', $this->room->gender_type); $form->addCssClass('gender_type', 'form-control'); } else { // Room is not empty so just show the gender (no drop down) $tpl['GENDER_MESSAGE'] = HMS_Util::formatGender($this->room->getGender()); // Add a hidden variable for 'gender_type' so it will be defined upon submission $form->addHidden('gender_type', $this->room->gender_type); // Show the reason the gender could not be changed. if ($number_of_assignees != 0) { $tpl['GENDER_REASON'] = 'Remove occupants to change room gender.'; } } //Always show the option to set the default gender $form->addDropBox('default_gender', array(FEMALE => FEMALE_DESC, MALE => MALE_DESC, AUTO => AUTO_DESC)); $form->setLabel('default_gender', 'Default Gender'); $form->setMatch('default_gender', $this->room->default_gender); $form->addCssClass('default_gender', 'form-control'); $form->addDropBox('rlc_reserved', array("0" => "Choose RLC") + RlcFactory::getRlcList($this->room->getTerm())); $form->setLabel('rlc_reserved', 'Reserved for RLC'); $form->setMatch('rlc_reserved', $this->room->getReservedRlcId()); $form->addCssClass('rlc_reserved', 'form-control'); $form->addCheck('offline', 1); $form->setLabel('offline', 'Offline'); $form->setMatch('offline', $this->room->isOffline()); $form->addCheck('reserved', 1); $form->setLabel('reserved', 'Reserved'); $form->setMatch('reserved', $this->room->isReserved()); $form->addCheck('ra', 1); $form->setLabel('ra', 'Reserved for RA'); $form->setMatch('ra', $this->room->isRa()); $form->addCheck('private', 1); $form->setLabel('private', 'Private'); $form->setMatch('private', $this->room->isPrivate()); $form->addCheck('overflow', 1); $form->setLabel('overflow', 'Overflow'); $form->setMatch('overflow', $this->room->isOverflow()); $form->addCheck('parlor', 1); $form->setLabel('parlor', 'Parlor'); $form->setMatch('parlor', $this->room->isParlor()); $form->addCheck('ada', 1); $form->setLabel('ada', 'ADA'); $form->setMatch('ada', $this->room->isAda()); $form->addCheck('hearing_impaired', 1); $form->setLabel('hearing_impaired', 'Hearing Impaired'); $form->setMatch('hearing_impaired', $this->room->isHearingImpaired()); $form->addCheck('bath_en_suite', 1); $form->setLabel('bath_en_suite', 'Bath en Suite'); $form->setMatch('bath_en_suite', $this->room->bathEnSuite()); $form->addSubmit('submit', 'Submit'); // Assignment pagers $tpl['BED_PAGER'] = HMS_Bed::bed_pager_by_room($this->room->id); // if the user has permission to view the form but not edit it then // disable it if (Current_User::allow('hms', 'room_view') && !Current_User::allow('hms', 'room_attributes') && !Current_User::allow('hms', 'room_structure')) { $form_vars = get_object_vars($form); $elements = $form_vars['_elements']; foreach ($elements as $element => $value) { $form->setDisabled($element); } } $form->mergeTemplate($tpl); $tpl = $form->getTemplate(); $reasonsList = HMS_Room::listReserveReasons(); $tpl['ATHLETICS_OPTIONS'] = $reasonsList['Athletics']; $tpl['SPECIAL_NEEDS_OPTIONS'] = $reasonsList['SpecialNeeds']; $tpl['SCHOLARS_OPTIONS'] = $reasonsList['ScholarsOrganizations']; $tpl['MISC_OPTIONS'] = $reasonsList['Miscellaneous']; if ($this->room->getReservedReason() == "") { $tpl['CURRENT_REASON'] = 'none'; } else { $tpl['CURRENT_REASON'] = $this->room->getReservedReason(); } $tpl['RESERVED_NOTES'] = $this->room->getReservedNotes(); Layout::addPageTitle("Edit Room"); $tpl['ROOM_DAMAGE_LIST'] = $this->roomDamagePager(); if (Current_User::allow('hms', 'add_room_dmg')) { $dmgCmd = CommandFactory::getCommand('ShowAddRoomDamage'); $dmgCmd->setRoom($this->room); $tpl['ADD_DAMAGE_URI'] = $dmgCmd->getURI(); } return PHPWS_Template::process($tpl, 'hms', 'admin/edit_room.tpl'); }
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 show() { PHPWS_Core::initModClass('hms', 'HMS_Util.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $tpl = array(); $submitCmd = CommandFactory::getCommand('LotteryConfirm'); $submitCmd->setRoomId($this->roomId); $submitCmd->setMealPlan($this->mealPlan); $form = new PHPWS_Form(); $submitCmd->initForm($form); # Add the beds and user names back to the form so they end up in the request in a pretty way foreach ($this->roommates as $key => $value) { if (isset($value) && $value != '') { $form->addHidden("roommates[{$key}]", $value); } } # List the student's room PHPWS_Core::initModClass('hms', 'HMS_Room.php'); $room = new HMS_Room($this->roomId); $tpl['ROOM'] = $room->where_am_i(); # List all the students which will be assigned and their beds $beds = $room->get_beds(); foreach ($beds as $bed) { $bed_row = array(); # Check for an assignment $bed->loadAssignment(); # Check for a reservation $reservation = $bed->get_lottery_reservation_info(); $bedLabel = $room->getRoomNumber(); if ($room->get_number_of_beds() == 4) { $bedLabel = $bedLabel . $bed->getBedroomLabel(); } $bedLabel = $bedLabel . $bed->getLetter(); $bed_row['BED_LABEL'] = $bedLabel; $roommate = null; if ($bed->_curr_assignment != NULL) { # Bed is assigned $roommate = StudentFactory::getStudentByUsername($bed->_curr_assignment->asu_username, $this->term); $bed_row['TEXT'] = $roommate->getName(); } else { if ($reservation != NULL) { # Bed is reserved $roommate = StudentFactory::getStudentByUsername($reservation['asu_username'], $this->term); $bed_row['TEXT'] = $roommate->getName() . ' (reserved)'; } else { # Get the new roommate name out of the request if (!isset($this->roommates[$bed->id]) || $this->roommates[$bed->id] == '') { $bed_row['TEXT'] = 'Empty'; } else { $roommate = StudentFactory::getStudentByUsername($this->roommates[$bed->id], $this->term); $bed_row['TEXT'] = $roommate->getName() . ' ' . $this->roommates[$bed->id]; } } } $tpl['beds'][] = $bed_row; } # Show the meal plan $tpl['MEAL_PLAN'] = HMS_Util::formatMealOption($this->mealPlan); $form->addHidden('meal_plan', $this->mealPlan); PHPWS_Core::initCoreClass('Captcha.php'); $form->addTplTag('CAPTCHA_IMAGE', Captcha::get()); $form->addSubmit('submit_form', 'Confirm room & roommates'); $form->mergeTemplate($tpl); Layout::addPageTitle("Confirm Re-Application"); return PHPWS_Template::process($form->getTemplate(), 'hms', 'student/lottery_confirm.tpl'); }
public static function deleteRoom($roomId) { if (!Current_User::allow('hms', 'room_structure')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to delete a room.'); } // check that we're not about to do something stupid if (!isset($roomId)) { throw new InvalidArgumentException('Invalid room id.'); } $room = new HMS_Room($roomId); // make sure there isn't an assignment if ($room->get_number_of_assignees() != 0) { PHPWS_Core::initModClass('hms', 'exception/HallStructureException.php'); throw new HallStructureException('One or more students are currently assigned to that room and therefore it cannot deleted.'); } // delete any beds try { if ($room->loadBeds()) { if (!empty($room->_beds)) { foreach ($room->_beds as $bed) { HMS_Bed::deleteBed($bed->id); } } } $room->delete(); } catch (Exception $e) { throw $e; } return true; }
public function show() { if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'floor_view')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You are not allowed to edit or view floors.'); } javascript('jquery_ui'); $floor_num = $this->floor->getFloorNumber(); // Setup the title and color of the title bar $tpl = array(); $tpl['FLOOR_NUMBER'] = HMS_Util::ordinal($floor_num); $tpl['TERM'] = Term::getPrintableSelectedTerm(); $submitCmd = CommandFactory::getCommand('EditFloor'); $submitCmd->setFloorId($this->floor->getId()); $form = new PHPWS_Form(); $submitCmd->initForm($form); $tpl['HALL_NAME'] = $this->hall->getLink(); $tpl['NUMBER_OF_ROOMS'] = $this->floor->get_number_of_rooms(); $tpl['NUMBER_OF_BEDS'] = $this->floor->get_number_of_beds(); $tpl['NOMINAL_BEDS'] = $this->floor->countNominalBeds(); $tpl['NUMBER_OF_ASSIGNEES'] = $this->floor->get_number_of_assignees(); if (!$this->floor->isOnline()) { $tpl['OFFLINE_ATTRIB'] = 'Offline'; } $form->addDropBox('gender_type', array(FEMALE => FEMALE_DESC, MALE => MALE_DESC, COED => COED_DESC)); $form->setMatch('gender_type', $this->floor->gender_type); $form->addCssClass('gender_type', 'form-control'); $form->addCheck('is_online', 1); $form->setMatch('is_online', $this->floor->is_online); $movein_times = HMS_Movein_Time::get_movein_times_array(); $form->addDropBox('f_movein_time', $movein_times); $form->addCssClass('f_movein_time', 'form-control'); if (!isset($this->floor->f_movein_time_id)) { $form->setMatch('f_movein_time', 0); } else { $form->setMatch('f_movein_time', $this->floor->f_movein_time_id); } $form->addDropBox('t_movein_time', $movein_times); $form->addCssClass('t_movein_time', 'form-control'); if (!isset($this->floor->t_movein_time_id)) { $form->setMatch('t_movein_time', 0); } else { $form->setMatch('t_movein_time', $this->floor->t_movein_time_id); } $form->addDropBox('rt_movein_time', $movein_times); $form->addCssClass('rt_movein_time', 'form-control'); if (!isset($this->floor->rt_movein_time_id)) { $form->setMatch('rt_movein_time', 0); } else { $form->setMatch('rt_movein_time', $this->floor->rt_movein_time_id); } // Get a list of the RLCs indexed by id PHPWS_Core::initModClass('hms', 'HMS_Learning_Community.php'); $learning_communities = RlcFactory::getRlcList($this->floor->getTerm()); $learning_communities[0] = 'None'; $form->addDropBox('floor_rlc_id', $learning_communities); $form->addCssClass('floor_rlc_id', 'form-control'); if (isset($this->floor->rlc_id)) { $tpl['RLC_NAME'] = $learning_communities[$this->floor->rlc_id]; $form->setMatch('floor_rlc_id', $this->floor->rlc_id); } else { $form->setMatch('floor_rlc_id', 0); } PHPWS_Core::initModClass('filecabinet', 'Cabinet.php'); if (isset($this->floor->floor_plan_image_id)) { $manager = Cabinet::fileManager('floor_plan_image_id', $this->floor->floor_plan_image_id); } else { $manager = Cabinet::fileManager('floor_plan_image_id'); } $manager->maxImageWidth(300); $manager->maxImageHeight(300); $manager->imageOnly(false, false); $form->addTplTag('FILE_MANAGER', $manager->get()); $form->addHidden('type', 'floor'); $form->addHidden('op', 'edit_floor'); $tpl['STATIC_ROOM_PAGER'] = HMS_Room::room_pager_by_floor($this->floor->id); $tpl['DYNAMIC_ROOM_PAGER'] = HMS_Room::room_pager_by_floor($this->floor->id, true); // if the user has permission to view the form but not edit it then // disable it if (Current_User::allow('hms', 'floor_view') && !Current_User::allow('hms', 'floor_attributes') && !Current_User::allow('hms', 'floor_structure')) { $form_vars = get_object_vars($form); $elements = $form_vars['_elements']; foreach ($elements as $element => $value) { $form->setDisabled($element); } } $form->mergeTemplate($tpl); $tpl = $form->getTemplate(); if (Current_User::allow('hms', 'edit_role_members')) { javascript('modules/hms/role_editor'); $tpl['ROLE_EDITOR'] = PHPWS_Template::process(array('CLASS_NAME' => "'HMS_Floor'", 'ID' => $this->floor->id), 'hms', 'admin/role_editor.tpl'); } Layout::addPageTitle("Edit Floor"); return PHPWS_Template::process($tpl, 'hms', 'admin/edit_floor.tpl'); }
/** * Creates the rooms and beds for a new floor */ public function create_child_objects($rooms_per_floor, $beds_per_room) { for ($i = 0; $i < $rooms_per_floor; $i++) { $room = new HMS_Room(); $room->floor_id = $this->id; $room->term = $this->term; $room->gender_type = $this->gender_type; if ($room->save()) { $room->create_child_objects($beds_per_room); } else { // Decide on bad Result. } } }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'HMS_Room.php'); if (!Current_User::allow('hms', 'room_attributes')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to edit rooms.'); } $roomId = $context->get('roomId'); $viewCmd = CommandFactory::getCommand('EditRoomView'); $viewCmd->setRoomId($roomId); // Create the room object given the room_id $room = new HMS_Room($roomId); if (!$room) { NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid room.'); $viewCmd->redirect(); } // Check if the user is trying to change a room's gender to co-ed. // If so, make sure the user has the permission to do so. if ($room->getGender() != $context->get('gender_type') && $context->get('gender_type') == COED) { if (!Current_User::allow('hms', 'coed_rooms')) { NQ::simple('hms', hms\NotificationView::ERROR, 'Error: You do not have permission to change the room gender to co-ed. No changes were made.'); $viewCmd->redirect(); } } // Compare the room's gender and the gender the user selected // If they're not equal, call 'can_change_gender' public function if ($room->gender_type != $context->get('gender_type')) { if (!$room->can_change_gender($context->get('gender_type'))) { NQ::simple('hms', hms\NotificationView::ERROR, 'Error: Incompatible genders detected. No changes were made.'); $viewCmd->redirect(); } } // Check the default gender in the same way if ($room->default_gender != $context->get('default_gender')) { if (!$room->can_change_gender($context->get('default_gender'))) { NQ::simple('hms', hms\NotificationView::ERROR, 'Error: Default gender incompatable. No changes were made.'); $viewCmd->redirect(); } } if ($room->get_number_of_assignees() > 0 && $context->get('offline') == 1) { NQ::simple('hms', hms\NotificationView::ERROR, 'Error: Cannot take room offline while students are assigned to the room. No changes were made.'); $viewCmd->redirect(); } // Grab all the input from the form and save the room //Changed from radio buttons to checkboxes, ternary //prevents null since only 1 is defined as a return value //test($_REQUEST['room_number']); $room->room_number = $context->get('room_number'); $room->gender_type = $context->get('gender_type'); $room->default_gender = $context->get('default_gender'); $rlcReserved = $context->get('rlc_reserved'); if ($rlcReserved != 0) { $room->setReservedRlcId($rlcReserved); } else { $room->setReservedRlcId(null); } $room->offline = $context->get('offline') == 1 ? 1 : 0; $room->reserved = $context->get('reserved') == 1 ? 1 : 0; $room->ra = $context->get('ra') == 1 ? 1 : 0; $room->private = $context->get('private') == 1 ? 1 : 0; $room->overflow = $context->get('overflow') == 1 ? 1 : 0; $room->parlor = $context->get('parlor') == 1 ? 1 : 0; $room->ada = $context->get('ada') == 1 ? 1 : 0; $room->hearing_impaired = $context->get('hearing_impaired') == 1 ? 1 : 0; $room->bath_en_suite = $context->get('bath_en_suite') == 1 ? 1 : 0; $reservedReason = $context->get('reserved_reason'); if ($reservedReason == 'none') { $room->setReserved(0); } else { $room->setReserved(1); } $room->setReservedReason($reservedReason); $room->setReservedNotes($context->get('reserved_notes')); $result = $room->save(); if (!$result || PHPWS_Error::logIfError($result)) { NQ::simple('hms', hms\NotificationView::ERROR, 'There was a problem saving the room data. No changes were made.'); $viewCmd->redirect(); } NQ::simple('hms', hms\NotificationView::SUCCESS, 'The room was updated successfully.'); $viewCmd->redirect(); }
public function auto_assign($test = 0) { PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); // TODO update this to use HousignAssignment PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php'); PHPWS_Core::initModClass('hms', 'BannerQueue.php'); $term = Term::get_selected_term(); // In both cases: Random, and include Banner info $f_rooms = HMS_Room::get_all_free_rooms($term, FEMALE, TRUE); $m_rooms = HMS_Room::get_all_free_rooms($term, MALE, TRUE); $roommates = HMS_Roommate::get_all_confirmed_roommates($term, TRUE); $applicants = HousingApplication::getAllFreshmenApplications($term, 'gender', 'hms_fall_application.lifestyle_option', 'hms_fall_application.preferred_bedtime', 'hms_fall_application.room_condition', 'random'); $problems = array(); $rlcs = array(); $assigns = array(); $notices = array(); $successes = array(); $assigned = array(); reset($f_rooms); reset($m_rooms); $i_f_count = count($f_rooms); $i_m_count = count($m_rooms); // Assign Roommates reset($roommates); foreach ($roommates as $pair) { $a = HousingApplication::getApplicationByUser($pair['requestor'], $term); if (in_array($a->username, $assigned)) { $notices[] = "<strong>{$a->username}</strong> already scheduled for assignment."; continue; } $rlc = HMS_RLC_Assignment::checkForAssignment($a->username, $term); if ($rlc !== FALSE) { $rlcs[] = "Skipping <strong>{$a->username}</strong>; assigned to an RLC."; continue; } $b = HousingApplication::getApplicationByUser($pair['requestee'], $term); if (in_array($b->username, $assigned)) { $notices[] = "<strong>{$b->username}</strong> already scheduled for assignment."; continue; } $rlc = HMS_RLC_Assignment::checkForAssignment($b->username, $term); if ($rlc !== FALSE) { $rlcs[] = "Skipping <strong>{$b->username}</strong>; assigned to an RLC."; continue; } if (is_null($a->id)) { $problems[] = "Could not assign <strong>{$a->username}</strong> with roommate <strong>{$b->username}</strong>; {$a->username} does not have an application."; continue; } if (is_null($b->id)) { $problems[] = "Could not assign <strong>{$a->username}</strong> with roommate <strong>{$b->username}</strong>; {$b->username} does not have an application."; continue; } if ($a->gender != $b->gender) { $problems[] = "Epic FAIL... <strong>{$a->username}</strong> and <strong>{$b->username}</strong> are not the same gender."; continue; } $ass = HMS_Assignment::get_assignment($a->username, $term); if (is_a($ass, 'HMS_Assignment')) { $bbc = $ass->get_banner_building_code(); $bed = $ass->get_banner_bed_id(); $assigns[] = "Could not assign <strong>{$a->username}</strong>; already assigned to <strong>{$bbc} {$bed}</strong>"; continue; } $ass = HMS_Assignment::get_assignment($b->username, $term); if (is_a($ass, 'HMS_Assignment')) { $bbc = $ass->get_banner_building_code(); $bed = $ass->get_banner_bed_id(); $assigns[] = "Could not assign <strong>{$b->username}</strong>; already assigned to <strong>{$bbc} {$bed}</strong>"; continue; } $room = $a->gender == FEMALE ? array_shift($f_rooms) : ($a->gender == MALE ? array_shift($m_rooms) : 'badgender'); if (is_null($room)) { $problems[] = "Could not assign <strong>{$a->username}</strong>; out of empty " . ($a->gender ? 'male' : 'female') . ' rooms.'; $problems[] = "Could not assign <strong>{$b->username}</strong>; out of empty " . ($b->gender ? 'male' : 'female') . ' rooms.'; continue; } else { if ($room === 'badgender') { $problems[] = "Could not assign <strong>{$a->username}</strong>; {$a->gender} is not a valid gender."; continue; } } // Prepare for assignment $room =& new HMS_Room($room); $room->loadBeds(); $bed_a_text = $room->_beds[0]->get_banner_building_code() . ' ' . $room->_beds[0]->banner_id; $bed_b_text = $room->_beds[1]->get_banner_building_code() . ' ' . $room->_beds[1]->banner_id; if ($test) { $successes[] = HMS_Autoassigner::record_success('TEST Requested', $a, $b, $bed_a_text); $successes[] = HMS_Autoassigner::record_success('TEST Requested', $b, $a, $bed_b_text); } else { $result = HMS_Autoassigner::assign($a, $room->_beds[0], $term); if ($result === TRUE) { $successes[] = HMS_Autoassigner::record_success('Requested', $a, $b, $bed_a_text); $assigned[] = $a->username; } else { $problems[] = $result; } if (!is_null($b->id)) { $result = HMS_Autoassigner::assign($b, $room->_beds[1], $term); if ($result === TRUE) { $successes[] = HMS_Autoassigner::record_success('Requested', $b, $a, $bed_b_text); $assigned[] = $b->username; } else { $problems[] = $result; } } } } reset($applicants); while (count($applicants) > 0) { $a = array_shift($applicants); if ($a === FALSE) { continue; } if (!isset($a)) { continue; } if (in_array($a->username, $assigned)) { $notices[] = "<strong>{$a->username}</strong> already scheduled for assignment."; continue; } $rlc = HMS_RLC_Assignment::checkForAssignment($a->username, $term); if ($rlc !== FALSE) { $rlcs[] = "Skipping <strong>{$a->username}</strong>; assigned to an RLC."; continue; } $b = array_shift($applicants); if (in_array($b->username, $assigned)) { $notices[] = "<strong>{$b->username}</strong> already scheduled for assignment."; array_unshift($applicants, $a); continue; } $rlc = HMS_RLC_Assignment::checkForAssignment($b->username, $term); if ($rlc !== FALSE) { $rlcs[] = "Skipping <strong>{$b->username}</strong>; assigned to an RLC."; array_unshift($applicants, $a); continue; } if ($a->gender != $b->gender) { array_unshift($applicants, $b); $b = NULL; continue; } $ass = HMS_Assignment::get_assignment($a->username, $term); if (is_a($ass, 'HMS_Assignment')) { $bbc = $ass->get_banner_building_code(); $bed = $ass->get_banner_bed_id(); $assigns[] = "Could not assign <strong>{$a->username}</strong>; already assigned to <strong>{$bbc} {$bed}</strong>"; array_unshift($applicants, $b); continue; } $ass = HMS_Assignment::get_assignment($b->username, $term); if (is_a($ass, 'HMS_Assignment')) { $bbc = $ass->get_banner_building_code(); $bed = $ass->get_banner_bed_id(); $assigns[] = "Could not assign <strong>{$b->username}</strong>; already assigned to <strong>{$bbc} {$bed}</strong>"; array_unshift($applicants, $a); continue; } // Determine Room Gender $room = $a->gender == FEMALE ? array_shift($f_rooms) : ($a->gender == MALE ? array_shift($m_rooms) : 'badgender'); // We could be out of rooms or have database corruption if (is_null($room)) { $problems[] = "Could not assign <strong>{$a->username}</strong>; out of " . ($a->gender ? 'male' : 'female') . ' rooms.'; $problems[] = "Could not assign <strong>{$b->username}</strong>; out of " . ($b->gender ? 'male' : 'female') . ' rooms.'; continue; } else { if ($room === 'badgender') { $problems[] = "Could not assign <strong>{$a->username}</strong>; {$a->gender} is not a valid gender."; continue; } } // Prepare for assignment $room =& new HMS_Room($room); $room->loadBeds(); $bed_a_text = $room->_beds[0]->get_banner_building_code() . ' ' . $room->_beds[0]->banner_id; $bed_b_text = $room->_beds[1]->get_banner_building_code() . ' ' . $room->_beds[1]->banner_id; if ($test) { $successes[] = HMS_Autoassigner::record_success('TEST Auto', $a, $b, $bed_a_text); $successes[] = HMS_Autoassigner::record_success('TEST Auto', $b, $a, $bed_b_text); } else { $result = HMS_Autoassigner::assign($a, $room->_beds[0], $term); if ($result === TRUE) { $successes[] = HMS_Autoassigner::record_success('Auto', $a, $b, $bed_a_text); $assigned[] = $a->username; } else { $problems[] = $result; } if (!is_null($b->id)) { $result = HMS_Autoassigner::assign($b, $room->_beds[1], $term); if ($result === TRUE) { $successes[] = HMS_Autoassigner::record_success('Auto', $b, $a, $bed_b_text); $assigned[] = $b->username; } else { $problems[] = $result; } } } } $f_f_count = count($f_rooms); $f_m_count = count($m_rooms); usort($successes, array('HMS_Autoassigner', 'sort_successes')); $content = '<h1>Autoassigner Results - ' . date('Y-m-d') . '</h1>'; $content .= '<h2>Total Assignments: ' . count($assigned) . '</h2>'; $content .= "<p>Began with {$i_f_count} female rooms and {$i_m_count} male rooms</p>"; $content .= "<p>Ended with {$f_f_count} female rooms and {$f_m_count} male rooms</p>"; $content .= '<h2>Assignment Report (' . count($successes) . ')</h2>'; $content .= '<table><tr>'; $content .= '<th>Type</th><th>Bed A</th><th>Code A</th><th>Bed B</th><th>Code B</th><th>Room</th>'; $content .= '</tr>'; foreach ($successes as $success) { $content .= '<tr>'; $content .= '<td>' . $success['type'] . '</td>'; $content .= '<td>' . $success['a'] . '</td>'; $content .= '<td>' . $success['a_code'] . '</td>'; $content .= '<td>' . $success['room'] . '</td>'; $content .= '<td>' . $success['b'] . '</td>'; $content .= '<td>' . $success['b_code'] . '</td>'; $content .= "</tr>\n"; } $content .= '</tr></table>'; sort($problems); $content .= '<h2>Problems (' . count($problems) . ')</h2>'; $content .= implode("<br />\n", $problems); sort($rlcs); $content .= '<h2>Skipped for RLC (' . count($rlcs) . ')</h2>'; $content .= implode("<br />\n", $rlcs); sort($assigns); $content .= '<h2>Skipped, already assigned (' . count($assigns) . ')</h2>'; $content .= implode("<br />\n", $assigns); sort($notices); $content .= '<h2>Notices (' . count($notices) . ')</h2>'; $content .= implode("<br />\n", $notices); Layout::nakedDisplay($content, NULL, TRUE); }
public function execute(CommandContext $context) { // Make sure the user has permission to change room attributes if (!Current_User::allow('hms', 'room_attributes')) { echo json_encode(false); die; } // Get the values from the request $id = $context->get('id'); $element = $context->get('field'); $value = $context->get('value'); // Make sure the required values were passed in on the request if (is_null($id) || is_null($element) || is_null($value)) { echo json_encode(false); die; } // Instantiate the room object try { $room = new HMS_Room($id); } catch (Exception $e) { echo json_encode(false); die; } /********** * Gender * */ // If the user is trying to change the gender, make sure no one is assigned if ($element == 'gender_type') { if ($room->get_number_of_assignees() > 0) { echo json_encode(false); die; } } // Check if the user is trying to change a room's gender to co-ed. // If so, make sure the user has the permission to do so. if ($element == 'gender_type' && $room->getGender() != $value && $value == COED) { if (!Current_User::allow('hms', 'coed_rooms')) { echo json_encode(false); die; } } // If the gender field was changed if ($element == 'gender_type' && $room->getGender() != $value) { // Make sure the requested gender is compatiable with the hall/floor if ($room->can_change_gender($value)) { $room->setGender($value); } else { echo json_encode(false); die; } } /****************** * Default Gender * */ // If default gender was changed if ($element == 'default_gender' && $room->getDefaultGender() != $value) { // Make sure the requested default gender is compatiable with the hall/floor if ($room->can_change_gender($value)) { $room->setDefaultGender($value); } else { echo json_encode(false); die; } } /* RLC Reservation */ if ($element == 'rlc_reserved') { if ($value <= 0) { $room->setReservedRlcId(null); } else { $room->setReservedRlcId($value); } } // A switch statement for all the check boxes switch ($element) { case 'ra': $room->setRa($value); break; case 'private': $room->setPrivate($value); break; case 'overflow': $room->setOverflow($value); break; case 'ada': $room->setADA($value); break; case 'reserved': $room->setReserved($value); break; case 'offline': $room->setOffline($value); break; } try { $room->save(); } catch (Exception $e) { echo json_encode(false); die; } echo json_encode($room); die; }
public function execute(CommandContext $context) { PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $roomId = $context->get('roomId'); $roommates = $context->get('roommates'); $mealPlan = $context->get('mealPlan'); $term = PHPWS_Settings::get('hms', 'lottery_term'); $student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term); $errorCmd = CommandFactory::getCommand('LotteryShowConfirm'); $errorCmd->setRoomId($roomId); $errorCmd->setRoommates($roommates); $errorCmd->setMealPlan($mealPlan); $successCmd = CommandFactory::getCommand('LotteryShowConfirmed'); $successCmd->setRoomId($roomId); PHPWS_Core::initCoreClass('Captcha.php'); $captcha = Captcha::verify(TRUE); // returns the words entered if correct, FALSE otherwise //$captcha = TRUE; if ($captcha === FALSE) { NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, the words you eneted were incorrect. Please try again.'); $errorCmd->redirect(); } PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'HMS_Room.php'); PHPWS_Core::initModClass('hms', 'HMS_Bed.php'); PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_Lottery.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_Email.php'); PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); PHPWS_Core::initModClass('hms', 'HMS_Util.php'); PHPWS_Core::initModClass('hms', 'RlcMembershipFactory.php'); PHPWS_Core::initModClass('hms', 'RlcAssignmentSelfAssignedState.php'); $room = new HMS_Room($roomId); // Check for an RLC assignment in the self-select status $rlcAssignment = RlcMembershipFactory::getMembership($student, $term); // Check roommates for validity foreach ($roommates as $bed_id => $username) { // Double check the student is valid try { $roommate = StudentFactory::getStudentByUsername($username, $term); } catch (StudentNotFoundException $e) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is not a valid student. Please choose a different roommate."); $errorCmd->redirect(); } // Make sure the bed is still empty $bed = new HMS_Bed($bed_id); if ($bed->has_vacancy() != TRUE) { NQ::simple('hms', hms\NotificationView::ERROR, 'One or more of the beds in the room you selected is no longer available. Please try again.'); $errorCmd->redirect(); } // Make sure none of the needed beds are reserved if ($bed->is_lottery_reserved()) { NQ::simple('hms', hms\NotificationView::ERROR, 'One or more of the beds in the room you selected is no longer available. Please try again.'); $errorCmd->redirect(); } // Double check the genders are all the same as the person logged in if ($student->getGender() != $roommate->getGender()) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is a different gender. Please choose a roommate of the same gender."); $errorCmd->redirect(); } // Double check the genders are the same as the room (as long as the room isn't AUTO) if ($room->gender_type != AUTO && $roommate->getGender() != $room->gender_type) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is a different gender. Please choose a roommate of the same gender."); $errorCmd->redirect(); } // If this student is an RLC-self-selection, then each roommate must be in the same RLC and in the selfselect-invite state too if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') { // This student is an RLC-self-select, so check the roommate's RLC status $roommateRlcAssign = RlcMembershipFactory::getMembership($roommate, $term); // Make sure the roommate is a member of the same RLC and is eligible for self-selection if ($roommateRlcAssign == null || $roommateRlcAssign->getStateName() != 'selfselect-invite' || $rlcAssignment->getRlc()->getId() != $roommateRlcAssign->getRlc()->getId()) { NQ::simple('hms', hms\NotificationView::ERROR, "{$roommate} must be a member of the same learning community as you, and must also be eligible for self-selction."); $errorCmd->redirect(); } // Otherwise (if not RLC members), make sure each roommate is eligible } else { if (HMS_Lottery::determineEligibility($username) !== TRUE) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} is not eligible for assignment."); $errorCmd->redirect(); } } // If this student is a self-select RLC member, then this student must also be a self-select RLC member of the same RLC if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') { $roommateRlcAssign = RlcMembershipFactory::getMembership($roommate, $term); if ($roommateRlcAssign == null || $roommateRlcAssign->getStateName() != 'selfselect-invite' || $rlcAssignment->getRlc()->getId() != $roommateRlcAssign->getRlc()->getId()) { NQ::simple('hms', hms\NotificationView::ERROR, "{$username} must be a member of the same learning community as you, and must also be eligible for self-selction."); $errorCmd->redirect(); } } } // If the room's gender is 'AUTO' and no one is assigned to it yet, switch it to the student's gender if ($room->gender_type == AUTO && $room->get_number_of_assignees() == 0) { $room->gender_type = $student->getGender(); $room->save(); } // Assign the student to the requested bed $bed_id = array_search(UserStatus::getUsername(), $roommates); // Find the bed id of the student who's logged in try { $result = HMS_Assignment::assignStudent($student, PHPWS_Settings::get('hms', 'lottery_term'), NULL, $bed_id, $mealPlan, 'Confirmed lottery invite', TRUE, ASSIGN_LOTTERY); } catch (Exception $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'Sorry, there was an error creating your room assignment. Please try again or contact University Housing.'); $errorCmd->redirect(); } // Log the assignment HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ROOM_CHOSEN, UserStatus::getUsername(), 'Captcha: ' . $captcha); // Update the student's meal plan in the housing application, just for future reference $app = HousingApplication::getApplicationByUser($student->getUsername(), $term); $app->setMealPlan($mealPlan); $app->save(); // If this student was an RLC self-select, update the RLC memberhsip state if ($rlcAssignment != null && $rlcAssignment->getStateName() == 'selfselect-invite') { $rlcAssignment->changeState(new RlcAssignmentSelfAssignedState($rlcAssignment)); } foreach ($roommates as $bed_id => $username) { // Skip the current user if ($username == $student->getUsername()) { continue; } # Reserve the bed for the roommate $expires_on = time() + INVITE_TTL_HRS * 3600; $bed = new HMS_Bed($bed_id); if (!$bed->lottery_reserve($username, $student->getUsername(), $expires_on)) { NQ::smiple('hms', hms\NotificationView::WARNING, "You were assigned, but there was a problem reserving space for your roommates. Please contact University Housing."); $successCmd->redirect(); } HMS_Activity_Log::log_activity($username, ACTIVITY_LOTTERY_REQUESTED_AS_ROOMMATE, $student->getUsername(), 'Expires: ' . HMS_Util::get_long_date_time($expires_on)); # Invite the selected roommates $roomie = StudentFactory::getStudentByUsername($username, $term); $term = PHPWS_Settings::get('hms', 'lottery_term'); $year = Term::toString($term) . ' - ' . Term::toString(Term::getNextTerm($term)); HMS_Email::send_lottery_roommate_invite($roomie, $student, $expires_on, $room->where_am_i(), $year); } HMS_Email::send_lottery_assignment_confirmation($student, $room->where_am_i(), $term); $successCmd->redirect(); }
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(); }