public function execute() { PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php'); PHPWS_Core::initModClass('hms', 'HMS_Util.php'); $halls = HMS_Residence_Hall::get_halls($this->term); $rows = array(); foreach ($halls as $hall) { if ($hall->count_avail_lottery_rooms('1') || $hall->count_avail_lottery_rooms('0')) { $row = array(); $row['HALL_NAME'] = $hall->getHallName(); $row['MALE_FREE'] = $hall->count_avail_lottery_rooms('1'); $row['FEMALE_FREE'] = $hall->count_avail_lottery_rooms('0'); $rooms = $hall->get_rooms(); $roomRows = ""; foreach ($rooms as $room) { if ($room->count_avail_lottery_beds() > 0) { $roomRow = "<tr><td>"; $roomRow = $roomRow . $room->getRoomNumber(); $roomRow = $roomRow . "</td><td>"; $roomRow = $roomRow . HMS_Util::formatGender($room->getGender()); $roomRow = $roomRow . "</td><td>"; $roomRow = $roomRow . $room->count_avail_lottery_beds(); $roomRow = $roomRow . "</td></tr>"; $roomRows = $roomRows . $roomRow; } } $row['ROOMS'] = $roomRows; $rows[] = $row; } } $this->data = $rows; }
public function execute() { PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php'); if (!isset($this->term) || is_null($this->term)) { throw new InvalidArgumentException('Missing term.'); } // Get all of the residence halls for this term $halls = HMS_Residence_Hall::get_halls($this->term); $hallRow = array(); foreach ($halls as $hall) { $hallName = $hall->hall_name; $maxOccupancy = $hall->get_number_of_online_nonoverflow_beds(); $currOccupancy = $hall->get_number_of_assignees(); $offline = ""; // If the hall is offline, make a note of that if ($hall->is_online == 0) { $offline = '(Offline)'; } $query = "select * from hms_room JOIN (SELECT hms_room.id, count(*) as c FROM hms_residence_hall JOIN hms_floor ON hms_residence_hall.id = hms_floor.residence_hall_id JOIN hms_room ON hms_floor.id = hms_room.floor_id JOIN hms_bed ON hms_room.id = hms_bed.room_id LEFT OUTER JOIN hms_assignment ON hms_bed.id = hms_assignment.bed_id WHERE ( hms_assignment.id IS NULL AND hms_residence_hall.id = '{$hall->id}' AND hms_room.offline = 0 AND hms_room.overflow = 0 AND hms_room.reserved = 0 AND hms_room.private = 0 AND hms_room.parlor = 0 AND hms_room.ra = 0 AND hms_bed.room_change_reserved = 0 AND hms_bed.ra_roommate = 0 AND hms_bed.international_reserved = 0) GROUP BY hms_room.id) as foo ON foo.id = hms_room.id ORDER BY hms_room.room_number"; $results = PHPWS_DB::getAll($query); $maleRoomList = array(); $femaleRoomList = array(); $coedRoomList = array(); // each room on this hall foreach ($results as $room) { $this->totalRooms++; $roomNum = $room['room_number']; // If the room has more than one avaialble bed, note that in the room number if ($room['c'] > 1) { $roomNum .= '(x' . $room['c'] . ')'; } // catagorize it by gender if ($room['gender_type'] == MALE) { $maleRoomList[] = $roomNum; $this->male += $room['c']; $this->totalBeds += $room['c']; } else { if ($room['gender_type'] == FEMALE) { $femaleRoomList[] = $roomNum; $this->female += $room['c']; $this->totalBeds += $room['c']; } else { if ($room['gender_type'] == COED || $room['gender_type'] == AUTO) { $coedRoomList[] = $roomNum; $this->coed += $room['c']; $this->totalBeds += $room['c']; } else { throw new InvalidArgumentException('Bad room gender. Room id: ' . $room['id']); } } } } $hallRow[] = array('hallName' => $hallName . $offline, 'maxOccupancy' => $maxOccupancy, 'currOccupancy' => $currOccupancy, 'maleRooms' => implode(", ", $maleRoomList), 'femaleRooms' => implode(", ", $femaleRoomList), 'coedRooms' => implode(", ", $coedRoomList)); } $this->data = $hallRow; }
/** * Checks each hall, floor, and room for the given term and returns * an associative array containing all of the invalid items. **/ public function check($term = null) { $results = array(); if (!isset($term)) { $term = Term::getCurrentTerm(); } $halls = HMS_Residence_Hall::get_halls($term); foreach ($halls as $hall) { $floors = $hall->get_floors(); if (!isset($floors)) { $results[$hall->hall_name] = "No Floors in Hall!"; } else { foreach ($floors as $floor) { if ($hall->gender_type != COED && $floor->gender_type != $hall->gender_type) { $results[$hall->hall_name][$floor->floor_number] = "Gender Mismatch With Hall"; continue; } $rooms = $floor->get_rooms(); if (!isset($rooms)) { $results[$hall->hall_name][$floor->floor_number] = "No rooms in Floor!"; } else { foreach ($rooms as $room) { if ($floor->gender_type != COED && $room->gender_type != $floor->gender_type) { $results[$hall->hall_name][$floor->floor_number][$room->room_number] = "Gender Mismatch with Floor " . "(Floor: " . $floor->gender_type . ") (Room: " . $room->gender_type . ")"; } } } $suites = $floor->get_suites(); if (isset($suites)) { foreach ($suites as $suite) { $rooms = $suite->get_rooms(); $suite_gender = null; foreach ($rooms as $room) { if (!isset($suite_gender)) { $suite_gender = $room->gender_type; continue; } if ($room->gender_type != $suite_gender) { $results[$hall->hall_name][$floor->floor_number][$room->room_number] = "Suite Gender Mismatch"; } } } } } } } return $results; }
public function show_select_hall() { /* if(!Current_User::allow('hms', 'email_hall')){ return PHPWS_Template::process($tpl, 'hms', 'admin/permission_denied.tpl'); } */ PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php'); $tpl = array(); if (Current_User::allow('hms', 'email_all')) { $halls = HMS_Residence_Hall::get_halls(HMS_Term::get_selected_term()); $form = new PHPWS_Form('select_halls_to_email'); foreach ($halls as $hall) { if ($hall->is_online != 1) { continue; } else { $form->addCheck('hall[' . $hall->id . ']', $hall->id); $form->setLabel('hall[' . $hall->id . ']', $hall->hall_name); } } $form->addHidden('type', 'notification'); $form->addHidden('op', 'edit'); $form->addSubmit('Continue'); $i = 0; $elements = $form->getTemplate(); foreach ($elements as $row) { //put the first and last elements directly into the template, not the row repeat because they are form tags if ($i == 0) { $tpl['START_FORM'] = $row; $i++; continue; } elseif ($i == sizeof($elements) - 1) { $tpl['END_FORM'] = $row; break; } //even numbered rows are checkboxes, odd are labels if ($i % 2 == 1) { $tpl['halls_list'][$i + 1]['LABEL'] = $row; } else { $tpl['halls_list'][$i]['SELECT'] = $row; } $i++; } } else { $tpl['SELECT'] = HMS_Residence_Hall::show_select_residence_hall('Select recipient Hall', 'notification', 'edit'); } return PHPWS_Template::process($tpl, 'hms', 'admin/messages.tpl'); }
public function execute(CommandContext $context) { if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'edit_terms')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to edit terms.'); } $successCmd = CommandFactory::getCommand('ShowEditTerm'); $errorCmd = CommandFactory::getCommand('ShowCreateTerm'); $year = $context->get('year_drop'); $sem = $context->get('term_drop'); if (!isset($year) || is_null($year) || empty($year)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a year.'); $errorCmd->redirect(); } if (!isset($sem) || is_null($sem) || empty($sem)) { NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a semester.'); $errorCmd->redirect(); } // Check to see if the specified term already exists if (!Term::isValidTerm($year . $sem)) { $term = new Term(NULL); $term->setTerm($year . $sem); $term->setBannerQueue(1); try { $term->save(); } catch (DatabaseException $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error saving the term. Please try again or contact ESS.'); $errorCmd->redirect(); } } else { $term = new Term($year . $sem); // The term already exists, make sure there are no halls for this term $db = new PHPWS_DB('hms_residence_hall'); $db->addWhere('term', $term->getTerm()); $num = $db->count(); if (!is_null($num) && $num > 0) { NQ::simple('hms', hms\NotificationView::ERROR, 'One or more halls already exist for this term, so nothing can be copied.'); $errorCmd->redirect(); } } $text = Term::toString($term->getTerm()); $copy = $context->get('copy_pick'); $copyAssignments = false; $copyRoles = false; // If you want to copy roles and/or assignments // you must also copy the hall structure. if (isset($copy['struct'])) { // Copy hall structure if (isset($copy['assign'])) { // Copy assignments. $copyAssignments = true; } if (isset($copy['role'])) { // Copy roles. $copyRoles = true; } } else { // either $copy == 'nothing', or the view didn't specify... either way, we're done NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully."); $successCmd->redirect(); } # Figure out which term we're copying from, if there isn't one then use the "current" term. $fromTerm = $context->get('from_term'); if (is_null($fromTerm)) { $fromTerm = Term::getCurrentTerm(); } PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); $db = new PHPWS_DB(); try { $db->query('BEGIN'); # Get the halls from the current term $halls = HMS_Residence_Hall::get_halls($fromTerm); set_time_limit(36000); foreach ($halls as $hall) { $hall->copy($term->getTerm(), $copyAssignments, $copyRoles); } $db->query('COMMIT'); } catch (Exception $e) { $db->query('ROLLBACK'); PHPWS_Error::log(print_r($e, true), 'hms'); NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error copying the hall structure and/or assignments. The term was created, but nothing was copied.'); $errorCmd->redirect(); } if ($copyAssignments) { NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully. The hall structure and assignments were copied successfully."); } else { NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully and hall structure copied successfully."); } Term::setSelectedTerm($term->getTerm()); $successCmd->redirect(); }
/** * Returns an associate array (key = hall id, value = hall name) of halls * which have an available lottery bed (based on the term, gender, the number * of lottery rooms allotted in the hall, the number of used lottery rooms, and * any pending lottery bed reservations. */ public static function get_lottery_avail_hall_list($term) { $halls = HMS_Residence_Hall::get_halls($term); $output_list = array(); foreach ($halls as $hall) { // Make sure we have a room of the specified gender available in the hall (or a co-ed room) if ($hall->count_avail_lottery_rooms($gender) <= 0 && $hall->count_avail_lottery_rooms(COED) <= 0) { continue; } $output_list[] = $hall; } return $output_list; }