public function execute() { PHPWS_Core::initModClass('hms', 'HMS_Util.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'SpringApplication.php'); PHPWS_Core::initModClass('hms', 'SummerApplication.php'); PHPWS_Core::initModClass('hms', 'FallApplication.php'); PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $term = $this->term; $sem = Term::getTermSem($term); // List of student 'application terms' which we'll consider as 'Freshmen' for term we're looking at // E.g. Students with an applicationt erm in Summer 1, Summer 2, and Fall all count as Freshmen for Fall. $applicationTerms = array(); $db = new PHPWS_DB('hms_new_application'); $db->addColumn('hms_new_application.banner_id'); $db->addColumn('hms_new_application.username'); $db->addColumn('hms_new_application.term'); $db->addColumn('hms_new_application.gender'); $db->addColumn('hms_new_application.application_term'); $db->addColumn('hms_new_application.student_type'); $db->addColumn('hms_new_application.cell_phone'); $db->addColumn('hms_new_application.meal_plan'); $db->addColumn('hms_new_application.physical_disability'); $db->addColumn('hms_new_application.psych_disability'); $db->addColumn('hms_new_application.medical_need'); $db->addColumn('hms_new_application.gender_need'); $db->addColumn('hms_new_application.international'); $db->addColumn('hms_new_application.created_on'); // Join for additional application data based on semester switch ($sem) { case TERM_SUMMER1: case TERM_SUMMER2: $db->addJoin('', 'hms_new_application', 'hms_summer_application', 'id', 'id'); $db->addColumn('hms_summer_application.*'); $applicationTerms[] = $term; $db->addWhere('application_type', 'summer'); break; case TERM_FALL: $db->addJoin('', 'hms_new_application', 'hms_fall_application', 'id', 'id'); $db->addColumn('hms_fall_application.*'); // Add the summer 1 and summe 2 application terms $summer2 = Term::getPrevTerm($term); $summer1 = Term::getPrevTerm($summer2); $applicationTerms[] = $summer1; $applicationTerms[] = $summer2; $applicationTerms[] = $term; $db->addWhere('application_type', 'fall'); break; case TERM_SPRING: $db->addJoin('', 'hms_new_application', 'hms_spring_application', 'id', 'id'); $db->addColumn('hms_spring_application.*'); $applicationTerms[] = $term; $db->addWhere('application_type', 'spring'); break; default: // error throw new InvalidArgumentException('Invalid term specified.'); } // Join for un-assigned students $db->addJoin('LEFT OUTER', 'hms_new_application', 'hms_assignment', 'banner_id', 'banner_id AND hms_new_application.term = hms_assignment.term'); $db->addWhere('hms_assignment.banner_id', 'NULL'); $db->addWhere('hms_new_application.term', $term); $db->addWhere('hms_new_application.student_type', 'F'); // Don't show students who have cancelled applications $db->addWhere('hms_new_application.cancelled', 0); // Limit by application term foreach ($applicationTerms as $t) { $db->addWhere('application_term', $t, '=', 'OR', 'app_term_group'); } // Sort by gender, then application date (earliest to latest) $db->addOrder(array('gender ASC', 'created_on ASC')); $results = $db->select(); if (PHPWS_Error::isError($results)) { throw new DatabaseException($results->toString()); } // Post-processing, cleanup, making it pretty foreach ($results as $row) { // Updates counts $this->total++; if ($row['gender'] == MALE) { $this->male++; } else { if ($row['gender'] == FEMALE) { $this->female++; } } $row['application_term'] = Term::toString($row['application_term']); $row['gender'] = HMS_Util::formatGender($row['gender']); $row['created_on'] = HMS_Util::get_short_date_time($row['created_on']); $row['meal_plan'] = HMS_Util::formatMealOption($row['meal_plan']); $row['lifestyle_option'] = HMS_Util::formatLifestyle($row['lifestyle_option']); $row['room_condition'] = HMS_Util::formatRoomCondition($row['room_condition']); $row['preferred_bedtime'] = HMS_Util::formatBedtime($row['preferred_bedtime']); // Roommates $roommie = HMS_Roommate::get_confirmed_roommate($row['username'], $this->term); if (!is_null($roommie)) { $row['roommate'] = $roommie->getUsername(); $row['roommate_banner_id'] = $roommie->getBannerId(); } // Copy the cleaned up row to the member var for data $this->data[] = $row; } }
public function show() { $tpl = array(); PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); PHPWS_Core::initModClass('hms', 'HMS_Util.php'); $roommate = HMS_Roommate::get_confirmed_roommate(UserStatus::getUsername(), $this->term); $requests = HMS_Roommate::countPendingRequests(UserStatus::getUsername(), $this->term); $tpl['DATES'] = HMS_Util::getPrettyDateRange($this->startDate, $this->endDate); $tpl['STATUS'] = ""; // Roommate has been selected and confirmed if (!is_null($roommate)) { $name = $roommate->getFullName(); $tpl['ROOMMATE_MSG'] = "<b>{$name}</b> has confirmed your roommate request. Roommate requests are subject to space availability."; $tpl['ICON'] = FEATURE_COMPLETED_ICON; if (time() < $this->editDate) { $cmd = CommandFactory::GetCommand('ShowRoommateBreak'); $rm = HMS_Roommate::getByUsernames(UserStatus::getUsername(), $roommate->getUsername(), $this->term); $cmd->setRoommateId($rm->id); $tpl['ROOMMATE_BREAK'] = $cmd->getLink('Remove roommate request'); } } else { if (time() < $this->startDate) { $tpl['ROOMMATE_MSG'] = '<b>It is too early to choose a roommate.</b> You can choose a roommate on ' . HMS_Util::getFriendlyDate($this->startDate) . '.'; $tpl['ICON'] = FEATURE_NOTYET_ICON; } else { if (time() > $this->endDate) { $tpl['ROOMMATE_MSG'] = '<b>It is too late to choose a roommate.</b> The deadline passed on ' . HMS_Util::getFriendlyDate($this->endDate) . '.'; // fade out header $tpl['STATUS'] = "locked"; $tpl['ICON'] = FEATURE_LOCKED_ICON; } else { if ($requests > 0) { $tpl['ROOMMATE_REQUESTS'] = HMS_Roommate::display_requests(UserStatus::getUsername(), $this->term); if ($requests == 1) { $tpl['ROOMMATE_REQUESTS_MSG'] = "<b style='color: #F00'>You have a roommate request.</b> Please click the name below to confirm or reject the request."; } else { $tpl['ROOMMATE_REQUESTS_MSG'] = "<b style='color: #F00'>You have roommate requests.</b> Please click a name below to confirm or reject a request."; } } else { if (HMS_Roommate::has_roommate_request(UserStatus::getUsername(), $this->term)) { $tpl['ICON'] = FEATURE_COMPLETED_ICON; $tpl['ROOMMATE_MSG'] = "<b>You have selected a roommate</b> and are awaiting their approval."; $requestee = HMS_Roommate::get_unconfirmed_roommate(UserStatus::getUsername(), $this->term); if (time() < $this->editDate) { $rm = HMS_Roommate::getByUsernames(UserStatus::getUsername(), $requestee, $this->term); $cmd = CommandFactory::getCommand('RoommateRequestCancel'); $cmd->setRoommateId($rm->id); $tpl['ROOMMATE_BREAK'] = $cmd->getLink('Cancel Request'); } } else { $tpl['ICON'] = FEATURE_OPEN_ICON; $tpl['ROOMMATE_MSG'] = 'If you know who you want your roommate to be, <b>you may select your roommate now</b>. You will need to know your roommate\'s ASU user name (their e-mail address). You have until ' . HMS_Util::getFriendlyDate($this->endDate) . ' to choose a roommate. Click the link below to select your roommate.'; $cmd = CommandFactory::getCommand('ShowRequestRoommate'); $cmd->setTerm($this->term); $tpl['ROOMMATE_LINK'] = $cmd->getLink('Select Your Roommate'); } } } } } Layout::addPageTitle("Roommate Selection"); return PHPWS_Template::process($tpl, 'hms', 'student/menuBlocks/roommateMenuBlock.tpl'); }
/** * $roommates is the focus of getProfileView(). It's structure is helpful in * StudentProfileView. It also makes it a little easier to recognize which roommmates * are requested ones so they can be emphasized in the template (admin/fancy-student-info.tpl) * Note that a student can only have a single pending/confirmed roommate request but multiple * assigned roommates! * */ public function getProfileView() { PHPWS_Core::initModClass('hms', 'StudentProfileView.php'); PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); PHPWS_Core::initModClass('hms', 'HousingApplication.php'); PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_Bed.php'); $studentUsername = $this->student->getUsername(); $assignment = HMS_Assignment::getAssignmentByBannerId($this->student->getBannerId(), $this->term); $pendingRoommate = HMS_Roommate::get_pending_roommate($studentUsername, $this->term); $confirmedRoommate = HMS_Roommate::get_confirmed_roommate($studentUsername, $this->term); if (!is_null($assignment)) { $assignedRoommates = $assignment->get_parent()->get_parent()->get_assignees(); } // // If student is assigned to room... // if (!is_null($assignment)) { foreach ($assignedRoommates as $roomie) { // make sure $roomie isn't the student being profiled or the requested roomies if ($roomie != FALSE && $roomie->getUsername() != $studentUsername) { $roomieUsername = $roomie->getUsername(); if (is_null($confirmedRoommate) || $roomieUsername != $confirmedRoommate->getUsername()) { if (is_null($pendingRoommate) || $roomieUsername != $pendingRoommate->getUsername()) { // Get student object and room link $roomLink = $this->getRoommateRoomLink($roomie->getUsername()); // if $roomie was assigned but not requested $this->roommates['ASSIGNED'][] = $roomie->getProfileLink() . " - {$roomLink}"; } } } } } // // Check status of requested roommates // if (!is_null($confirmedRoommate)) { if (!is_null($assignment)) { $confirmedRmAssignment = HMS_Assignment::getAssignment($confirmedRoommate->getUsername(), $this->term); if (!is_null($confirmedRmAssignment)) { // if confirmed roommate is assigned to different room than profile student if ($assignment->get_parent()->room_id != $confirmedRmAssignment->get_parent()->room_id) { $this->setRoommateVar($confirmedRoommate, "confirmed", "mismatched_rooms"); } else { $this->setRoommateVar($confirmedRoommate, "confirmed"); } } else { // if profile student's room is full if (!$assignment->get_parent()->get_parent()->has_vacancy()) { $this->setRoommateVar($confirmedRoommate, "confirmed", "no_bed_available"); } else { $this->setRoommateVar($confirmedRoommate, "confirmed"); } } } else { $this->setRoommateVar($confirmedRoommate, "confirmed"); } } else { if (!is_null($pendingRoommate)) { if (!is_null($assignment)) { $pendingRmAssignment = HMS_Assignment::getAssignment($pendingRoommate->getUsername(), $this->term); if (!is_null($pendingRmAssignment)) { // if pending roommate is assigned to different room than profile student if ($assignment->get_parent()->room_id != $pendingRmAssignment->get_parent()->room_id) { $this->setRoommateVar($pendingRoommate, "pending", "mismatched_rooms"); } else { $this->setRoommateVar($pendingRoommate, "pending"); } } else { // if profile student's room is full if (!$assignment->get_parent()->get_parent()->has_vacancy()) { $this->setRoommateVar($pendingRoommate, "pending", "no_bed_available"); } else { $this->setRoommateVar($pendingRoommate, "pending"); } } } else { $this->setRoommateVar($pendingRoommate, "pending"); } } } $applications = HousingApplication::getAllApplicationsForStudent($this->student); $subTypeApps = array(); // Convert each of the general HousingApplication objets to its specific sub type (e.g. FallApplication) foreach ($applications as $app) { $subTypeApps[] = HousingApplicationFactory::getApplicationById($app->id); } return new StudentProfileView($this->student, $subTypeApps, $assignment, $this->roommates); }
/** * Returns the fields for this HousingApplication parent class. Usually called by overriding methods in subclasses (e.g. SummerApplication). * * @return Array Array of fields for this HousingApplication. */ protected function unassignedStudentsFields() { $fields = array(); $fields['banner_id'] = $this->getBannerId(); $fields['username'] = $this->getUsername(); $fields['gender'] = HMS_Util::formatGender($this->getGender()); $fields['application_term'] = Term::toString($this->getApplicationTerm(), true); $fields['student_type'] = HMS_Util::formatType($this->getStudentType()); $fields['meal_plan'] = HMS_Util::formatMealOption($this->getMealPlan()); $fields['created_on'] = HMS_Util::get_long_date($this->getCreatedOn()); $roommate = HMS_Roommate::get_confirmed_roommate($this->getUsername(), $this->getTerm()); if (!is_null($roommate)) { $fields['roommate'] = $roommate->getFullName(); $fields['roommate_id'] = $roommate->getBannerId(); } else { $fields['roommate'] = ''; $fields['roommate_id'] = ''; } return $fields; }