public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id == 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } $username = UserStatus::getUsername(); if ($username != $roommate->requestor) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}"); } $roommate->delete(); $other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term); HMS_Activity_Log::log_activity($other->getUsername(), ACTIVITY_STUDENT_CANCELLED_ROOMMATE_REQUEST, $username, "{$username} cancelled roommate request"); HMS_Activity_Log::log_activity($username, ACTIVITY_STUDENT_CANCELLED_ROOMMATE_REQUEST, $other->getUsername(), "{$username} cancelled roommate request"); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_cancel_emails($roommate); $name = $other->getFullName(); NQ::Simple('hms', hms\NotificationView::SUCCESS, "You have cancelled your roommate request for {$name}."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id = 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } $username = UserStatus::getUsername(); if ($username != $roommate->requestor && $username != $roommate->requestee) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}"); } PHPWS_Core::initCoreClass('Captcha.php'); // get other roommate $other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term); $form = new PHPWS_Form(); $cmd = CommandFactory::getCommand('RoommateBreak'); $cmd->setRoommateId($id); $cmd->initForm($form); $form->addTplTag('CAPTCHA_IMAGE', Captcha::get()); $form->addTplTag('NAME', $other->getFullName()); $form->addSubmit('Confirm'); $form->addCssClass('submit', 'btn btn-danger'); $context->setContent(PHPWS_Template::process($form->getTemplate(), 'hms', 'student/roommate_break_confirm.tpl')); }
public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id == 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } if (UserStatus::getUsername() != $roommate->requestee) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to reject roommate pairing {$roommate->id}"); } $requestor = StudentFactory::getStudentByUsername($roommate->requestor, $roommate->term); $name = $requestor->getFullName(); $username = $requestor->getUsername(); $roommate->delete(); HMS_Activity_Log::log_activity($roommate->requestor, ACTIVITY_REJECTED_AS_ROOMMATE, $roommate->requestee, "{$roommate->requestee} rejected {$roommate->requestor}'s request"); HMS_Activity_Log::log_activity($roommate->requestee, ACTIVITY_REJECTED_AS_ROOMMATE, $roommate->requestor, "{$roommate->requestee} rejected {$roommate->requestor}'s request"); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_reject_emails($roommate); NQ::Simple('hms', hms\NotificationView::SUCCESS, "<b>You rejected the roommate request from {$name}.</b> If this was an error, you may re-request using their username, <b>{$username}</b>."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { if (!UserStatus::isUser()) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to request a roommate.'); } $term = $context->get('term'); $requestee = $context->get('username'); $requestor = UserStatus::getUsername(); if (empty($term)) { throw new InvalidArgumentException('Term was not specified.'); } $err = CommandFactory::getCommand('ShowRequestRoommate'); $err->setTerm($term); if (empty($requestee)) { NQ::simple('hms', hms\NotificationView::WARNING, 'You did not enter a username.'); $err->redirect(); } if (!PHPWS_Text::isValidInput($requestee)) { NQ::simple('hms', hms\NotificationView::WARNING, 'You entered an invalid username. Please use letters and numbers only.'); $err->redirect(); } // Attempt to Create Roommate Request PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $request = new HMS_Roommate(); try { $request->request($requestor, $requestee, $term); } catch (RoommateCompatibilityException $rre) { NQ::simple('hms', hms\NotificationView::WARNING, $rre->getMessage()); $err->redirect(); } $request->save(); $endTime = $request->calc_req_expiration_date(); $expirationMsg = " expires on " . date('m/d/Y h:i:s a', $endTime); HMS_Activity_Log::log_activity($requestee, ACTIVITY_REQUESTED_AS_ROOMMATE, $requestor, "{$requestor} requested {$requestee}" . $expirationMsg); HMS_Activity_Log::log_activity($requestor, ACTIVITY_REQUESTED_AS_ROOMMATE, $requestee, "{$requestor} requested {$requestee}" . $expirationMsg); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_request_emails($request); // Notify PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $student = StudentFactory::getStudentByUsername($requestee, $term); $name = $student->getName(); $fname = $student->getFirstName(); NQ::simple('hms', hms\NotificationView::SUCCESS, "You have requested {$name} to be your roommate. {$fname} has been emailed, and will need to log into HMS and approve your roommate request."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'roommate_maintenance')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to create/edit roommate groups.'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $id = $context->get('id'); if (is_null($id)) { throw new InvalidArgumentException('Missing roommate group id.'); } $viewCmd = CommandFactory::getCommand('EditRoommateGroupsView'); try { $roommate = new HMS_Roommate($id); $roommate->delete(); } catch (Exception $e) { NQ::simple('hms', hms\NotificationView::SUCCESS, 'Error deleting roommate group: ' . $e->getMessage()); $viewCmd->redirect(); } // Log the success $notes = "{$roommate->getRequestor()} requested {$roommate->getRequestee()}"; HMS_Activity_Log::log_activity($roommate->getRequestor(), ACTIVITY_ADMIN_REMOVED_ROOMMATE, UserStatus::getUsername(), $notes); HMS_Activity_Log::log_activity($roommate->getRequestee(), ACTIVITY_ADMIN_REMOVED_ROOMMATE, UserStatus::getUsername(), $notes); NQ::simple('hms', hms\NotificationView::SUCCESS, 'Roommate group successfully deleted.'); $viewCmd->redirect(); }
public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id == 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } $username = UserStatus::getUsername(); if ($username != $roommate->requestor && $username != $roommate->requestee) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}"); } $err = CommandFactory::getCommand('ShowRoommateBreak'); $err->setRoommateId($id); PHPWS_Core::initCoreClass('Captcha.php'); $verified = Captcha::verify(TRUE); if ($verified === FALSE || is_null($verified)) { NQ::Simple('hms', hms\NotificationView::ERROR, 'Sorry, please try again.'); $err->redirect(); } $roommate->delete(); $other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term); HMS_Activity_Log::log_activity($other->getUsername(), ACTIVITY_STUDENT_BROKE_ROOMMATE, $username, "{$username} broke pairing, CAPTCHA: {$verified}"); HMS_Activity_Log::log_activity($username, ACTIVITY_STUDENT_BROKE_ROOMMATE, $other->getUsername(), "{$username} broke pairing, CAPTCHA: {$verified}"); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_break_emails($roommate, $username); $name = $other->getFullName(); NQ::Simple('hms', hms\NotificationView::SUCCESS, "You have removed your roommate request for {$name}."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { $id = $context->get('roommateId'); if (is_null($id)) { throw new InvalidArgumentException('Must set roommateId'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roommate = new HMS_Roommate($id); if ($roommate->id == 0) { throw new InvalidArgumentException('Invalid roommateId ' . $id); } $username = UserStatus::getUsername(); if ($username != $roommate->requestee) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException("{$username} tried to confirm roommate pairing {$roommate->id}"); } $err = CommandFactory::getCommand('ShowRoommateConfirmAccept'); $err->setRoommateId($id); PHPWS_Core::initCoreClass('Captcha.php'); $verified = Captcha::verify(TRUE); if ($verified === FALSE || is_null($verified)) { NQ::Simple('hms', hms\NotificationView::ERROR, 'Sorry, please try again.'); $err->redirect(); } try { $roommate->confirm(); } catch (RoommateCompatibilityException $rce) { NQ::simple('hms', hms\NotificationView::WARNING, $rce->getMessage()); $err->redirect(); } $roommate->save(); HMS_Activity_Log::log_activity($roommate->requestor, ACTIVITY_ACCEPTED_AS_ROOMMATE, $roommate->requestee, "{$roommate->requestee} accepted request, CAPTCHA: {$verified}"); HMS_Activity_Log::log_activity($roommate->requestee, ACTIVITY_ACCEPTED_AS_ROOMMATE, $roommate->requestor, "{$roommate->requestee} accepted request, CAPTCHA: {$verified}"); // Email both parties PHPWS_Core::initModClass('hms', 'HMS_Email.php'); HMS_Email::send_confirm_emails($roommate); // Remove any other requests for the requestor HMS_Roommate::removeOutstandingRequests($roommate->requestor, $roommate->term); // Remove any other requests for the requestee HMS_Roommate::removeOutstandingRequests($roommate->requestee, $roommate->term); $requestor = StudentFactory::getStudentByUsername($roommate->requestor, $roommate->term); $name = $requestor->getFullName(); NQ::Simple('hms', hms\NotificationView::SUCCESS, "You and {$name} are confirmed as roommates."); $cmd = CommandFactory::getCommand('ShowStudentMenu'); $cmd->redirect(); }
public function execute(CommandContext $context) { if (!UserStatus::isUser()) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to request a roommate.'); } $term = $context->get('term'); if (is_null($term)) { throw new InvalidArgumentException('Must specify a term.'); } PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $username = UserStatus::getUsername(); $err = CommandFactory::getCommand('ShowStudentMenu'); // Make sure the user doesn't already have a request pending $result = HMS_Roommate::has_roommate_request($username, $term); if ($result === TRUE) { NQ::simple('hms', hms\NotificationView::WARNING, 'You have a pending roommate request. You can not request another roommate request until your current request is either denied or expires.'); $err->redirect(); } // Make sure the user doesn't already have a confirmed roommate $result = HMS_Roommate::has_confirmed_roommate($username, $term); if ($result === TRUE) { NQ::simple('hms', hms\NotificationView::WARNING, 'You already have a confirmed roommate.'); $err->redirect(); } $form = new PHPWS_Form(); $cmd = CommandFactory::getCommand('RequestRoommate'); $cmd->setTerm($term); $cmd->initForm($form); $form->addText('username'); $form->addCssClass('username', 'form-control'); $form->setExtra('username', 'autofocus'); $form->addSubmit('submit', 'Request Roommate'); $form->addButton('cancel', 'Cancel'); $form->setExtra('cancel', 'onClick="document.location=\'index.php\'"'); $tpl = $form->getTemplate(); $context->setContent(PHPWS_Template::process($tpl, 'hms', 'student/select_roommate.tpl')); }
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'); }
public static function send_break_emails(HMS_Roommate $request, $breaker) { PHPWS_Core::initModClass('hms', 'HMS_Email.php'); $breakee = $request->get_other_guy($breaker); $breakerStudent = StudentFactory::getStudentByUsername($breaker, $request->term); $breakeeStudent = Studentfactory::getStudentByUsername($breakee, $request->term); $tags = array(); $tags['BREAKER'] = $breakerStudent->getFullName(); $tags['BREAKER_FIRST'] = $breakerStudent->getFirstName(); $tags['BREAKEE'] = $breakeeStudent->getFullName(); // to the breaker HMS_Email::send_template_message($breaker . TO_DOMAIN, 'HMS Roommate Pairing Broken', 'email/roommate_break_breaker.tpl', $tags); // to the breakee HMS_Email::send_template_message($breakee . TO_DOMAIN, 'HMS Roommate Pairing Broken', 'email/roommate_break_breakee.tpl', $tags); return TRUE; }
/** * $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 this rlc application (and assignment) as array of fields for CSV export * * @return Array */ public function viewByRLCExportFields() { PHPWS_Core::initModClass('hms', 'HMS_Assignment.php'); PHPWS_Core::initModClass('hms', 'StudentFactory.php'); $row = array(); // Get the Student object try { $student = StudentFactory::getStudentByUsername($this->username, Term::getSelectedTerm()); } catch (StudentNotFoundException $e) { // Catch the StudentNotFound exception in the odd case that someone doesn't exist. // Show a warning message and skip the rest of the method NQ::simple('hms', hms\NotificationView::WARNING, "No student found with username: {$this->username}."); $row['username'] = $this->username; $row['name'] = 'UNKNOWN - INVALID'; return $tags; } $row['name'] = $student->getFullName(); $row['gender'] = $student->getPrintableGender(); $row['student_type'] = $student->getPrintableType(); $row['username'] = $student->getUsername(); $row['banner_id'] = $student->getBannerId(); /*** Assignment Status/State ***/ // Lookup the assignmnet (used later as well) $assign = HMS_RLC_Assignment::getAssignmentByUsername($this->username, $this->term); $state = $assign->getStateName(); if ($state == 'confirmed') { $row['state'] = 'confirmed'; } else { if ($state == 'declined') { $row['state'] = 'declined'; } else { if ($state == 'new') { $row['state'] = 'not invited'; } else { if ($state == 'invited') { $row['state'] = 'pending'; } else { $row['state'] = ''; } } } } // Check for/display room assignment $roomAssign = HMS_Assignment::getAssignmentByBannerId($student->getBannerId(), Term::getSelectedTerm()); if (isset($roomAssign)) { $row['room_assignment'] = $roomAssign->where_am_i(); } else { $row['room_assignment'] = 'n/a'; } /*** Roommates ***/ // Show all possible roommates for this application PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $allRoommates = HMS_Roommate::get_all_roommates($this->username, $this->term); $row['roommates'] = 'N/A'; // Default text if (sizeof($allRoommates) > 1) { // Don't show all the roommates $row['roommates'] = "Multiple Requests"; } elseif (sizeof($allRoommates) == 1) { // Get other roommate $otherGuy = StudentFactory::getStudentByUsername($allRoommates[0]->get_other_guy($this->username), $this->term); $row['roommates'] = $otherGuy->getFullName(); // If roommate is pending then show little status message if (!$allRoommates[0]->confirmed) { $row['roommates'] .= " (Pending)"; } } return $row; }
/** * Handles removing roommate requests * @param Student $student */ private function handleRoommate(Student $student) { # check for and delete any roommate requests, perhaps let the other roommate know? $roommates = HMS_Roommate::get_all_roommates($student->getUsername(), $this->term); if (sizeof($roommates) > 0) { # Delete each roommate request foreach ($roommates as $rm) { try { $rm->delete(); } catch (Exception $e) { //TODO } $this->actions[$student->getUsername()][] = "Roommate request removed. {$rm->requestor} -> {$rm->requestee}"; HMS_Activity_Log::log_activity($rm->requestor, ACTIVITY_WITHDRAWN_ROOMMATE_DELETED, UserStatus::getUsername(), "Withdarwn search; {$rm->requestor}->{$rm->requestee}"); HMS_Activity_Log::log_activity($rm->requestee, ACTIVITY_WITHDRAWN_ROOMMATE_DELETED, UserStatus::getUsername(), "withdrawn search; {$rm->requestor}->{$rm->requestee}"); # TODO: notify the other roommate, perhaps? } } }
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 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) { if (!Current_User::allow('hms', 'view_rlc_applications')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to view rlc applications'); } $term = Term::getSelectedTerm(); $db = new PHPWS_DB('hms_learning_communities'); $db->addColumn('community_name'); $db->addWhere('id', $_REQUEST['rlc_list']); $title = $db->select('one'); $filename = $title . '-applications-' . date('Ymd') . ".csv"; // setup the title and headings $buffer = $title . "\n"; $buffer .= '"last_name","first_name","middle_name","gender","roommate","email","second_choice","third_choice","major","application_date","denied"' . "\n"; // get the userlist $db = new PHPWS_DB('hms_learning_community_applications'); $db->addColumn('username'); $db->addColumn('rlc_second_choice_id'); $db->addColumn('rlc_third_choice_id'); $db->addColumn('date_submitted'); $db->addWhere('rlc_first_choice_id', $_REQUEST['rlc_list']); $db->addWhere('term', Term::getSelectedTerm()); $db->addOrder('denied asc'); //$db->addWhere('denied', 0); // Only show non-denied applications $users = $db->select(); foreach ($users as $user) { PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $roomie = NULL; $roomie = HMS_Roommate::has_confirmed_roommate($user['username'], $term) ? HMS_Roommate::get_Confirmed_roommate($user['username'], $term) : NULL; if ($roomie == NULL) { $roomie = HMS_Roommate::has_roommate_request($user['username'], $term) ? HMS_Roommate::get_unconfirmed_roommate($user['username'], $term) . ' *pending* ' : NULL; } $student = StudentFactory::getStudentByUsername($user['username'], Term::getSelectedTerm()); $buffer .= '"' . $student->getLastName() . '",'; $buffer .= '"' . $student->getFirstName() . '",'; $buffer .= '"' . $student->getMiddleName() . '",'; $buffer .= '"' . $student->getPrintableGender() . '",'; if ($roomie != NULL) { $buffer .= '"' . $roomie->getFullName() . '",'; } else { $buffer .= '"",'; } $buffer .= '"' . $student->getUsername() . '@appstate.edu' . '",'; if (isset($user['rlc_second_choice_id'])) { $db = new PHPWS_DB('hms_learning_communities'); $db->addColumn('community_name'); $db->addWhere('id', $user['rlc_second_choice_id']); $result = $db->select('one'); if (!PHPWS_Error::logIfError($result)) { $buffer .= '"' . $result . '",'; } } else { $buffer .= '"",'; } if (isset($user['rlc_third_choice_id'])) { $db = new PHPWS_DB('hms_learning_communities'); $db->addColumn('community_name'); $db->addWhere('id', $user['rlc_third_choice_id']); $result = $db->select('one'); if (!PHPWS_Error::logIfError($result)) { $buffer .= '"' . $result . '",'; } } else { $buffer .= '"",'; } //Major for this user, N/A for now $buffer .= '"N/A",'; //Application Date if (isset($user['date_submitted'])) { PHPWS_Core::initModClass('hms', 'HMS_Util.php'); $buffer .= '"' . HMS_Util::get_long_date($user['date_submitted']) . '",'; } else { $buffer .= '"Error with the submission Date",'; } //Denied $buffer .= isset($user['denied']) && $user['denied'] == 1 ? '"yes"' : '"no"'; $buffer .= "\n"; } //HERES THE QUERY: //select hms_learning_community_applications.user_id, date_submitted, rlc_first_choice.abbreviation as first_choice, rlc_second_choice.abbreviation as second_choice, rlc_third_choice.abbreviation as third_choice FROM (SELECT hms_learning_community_applications.user_id, hms_learning_communities.abbreviation FROM hms_learning_communities,hms_learning_community_applications WHERE hms_learning_communities.id = hms_learning_community_applications.rlc_first_choice_id) as rlc_first_choice, (SELECT hms_learning_community_applications.user_id, hms_learning_communities.abbreviation FROM hms_learning_communities,hms_learning_community_applications WHERE hms_learning_communities.id = hms_learning_community_applications.rlc_second_choice_id) as rlc_second_choice, (SELECT hms_learning_community_applications.user_id, hms_learning_communities.abbreviation FROM hms_learning_communities,hms_learning_community_applications WHERE hms_learning_communities.id = hms_learning_community_applications.rlc_third_choice_id) as rlc_third_choice, hms_learning_community_applications WHERE rlc_first_choice.user_id = hms_learning_community_applications.user_id AND rlc_second_choice.user_id = hms_learning_community_applications.user_id AND rlc_third_choice.user_id = hms_learning_community_applications.user_id; //Download file if (ob_get_contents()) { print 'Some data has already been output, can\'t send file'; } if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')) { header('Content-Type: application/force-download'); } else { header('Content-Type: application/octet-stream'); } if (headers_sent()) { print 'Some data has already been output to browser, can\'t send file'; } header('Content-Length: ' . strlen($buffer)); header('Content-disposition: attachment; filename="' . $filename . '"'); echo $buffer; die; }
public function execute(CommandContext $context) { if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'roommate_maintenance')) { PHPWS_Core::initModClass('hms', 'exception/PermissionException.php'); throw new PermissionException('You do not have permission to create/edit roommate groups.'); } PHPWS_Core::initModClass('hms', 'StudentFactory.php'); PHPWS_Core::initModClass('hms', 'HMS_Roommate.php'); $term = Term::getSelectedTerm(); # Check for reasonable input $roommate1 = trim($context->get('roommate1')); $roommate2 = trim($context->get('roommate2')); $viewCmd = CommandFactory::getCommand('CreateRoommateGroupView'); $viewCmd->setRoommate1($roommate1); $viewCmd->setRoommate2($roommate2); if (is_null($roommate1) || empty($roommate1) || is_null($roommate2) || empty($roommate2)) { NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid user names.'); $viewCmd->redirect(); } try { $student1 = StudentFactory::getStudentByUsername($roommate1, $term); $student2 = StudentFactory::getStudentByUsername($roommate2, $term); } catch (StudentNotFoundException $e) { NQ::simple('hms', hms\NotificationView::ERROR, $e->getMessage()); $viewCmd->redirect(); } try { # Check if these two can live together HMS_Roommate::canLiveTogetherAdmin($student1, $student2, $term); } catch (Exception $e) { NQ::simple('hms', hms\NotificationView::ERROR, 'Could not create roommate group: ' . $e->getMessage()); $viewCmd->redirect(); } # Check for pending requests for either roommate and break them if (HMS_Roommate::countPendingRequests($roommate1, $term) > 0) { NQ::simple('hms', hms\NotificationView::WARNING, "Warning: Pending roommate requests for {$roommate1} were deleted."); } $result = HMS_Roommate::removeOutstandingRequests($roommate1, $term); if (!$result) { NQ::simple('hms', hms\NotificationView::ERROR, "Error removing pending requests for {$roommate1}, roommate group was not created."); $viewCmd->redirect(); } if (HMS_Roommate::countPendingRequests($roommate2, $term) > 0) { NQ::simple('hms', hms\NotificationView::WARNING, "Warning: Pending roommate requests for {$roommate2} were deleted."); } $result = HMS_Roommate::removeOutstandingRequests($roommate2, $term); if (!$result) { NQ::simple('hms', hms\NotificationView::ERROR, "Error removing pending requests for {$roommate2}, roommate group was not created."); $viewCmd->redirect(); } # Create the roommate group and save it $roommate_group = new HMS_Roommate(); $roommate_group->term = $term; $roommate_group->requestor = $roommate1; $roommate_group->requestee = $roommate2; $roommate_group->confirmed = 1; $roommate_group->requested_on = time(); $roommate_group->confirmed_on = time(); $result = $roommate_group->save(); if (!$result) { NQ::simple('hms', hms\NotificationView::ERROR, 'Error saving roommate group.'); $viewCmd->redirect(); } else { PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php'); HMS_Activity_Log::log_activity($roommate1, ACTIVITY_ADMIN_ASSIGNED_ROOMMATE, UserStatus::getUsername(), $roommate2); HMS_Activity_Log::log_activity($roommate2, ACTIVITY_ADMIN_ASSIGNED_ROOMMATE, UserStatus::getUsername(), $roommate1); NQ::simple('hms', hms\NotificationView::SUCCESS, 'Roommate group created successfully.'); $viewCmd->redirect(); } }
public function canLiveTogetherAdmin(Student $roommate1, Student $roommate2, $term) { // Sanity Checking if (is_null($roommate1)) { throw new RoommateException('Null student object for roommate 1.'); } if (is_null($roommate2)) { throw new RoommateException('Null student object for roommate 1.'); } // Check that the two user names aren't the same if ($roommate1->getUsername() == $roommate2->getUsername()) { throw new RoommateException('Roommate user names must be unique.'); } // Use SOAP for the following checks // Make that both roommate have some sort of soap info $name = $roommate1->getLastName(); if (empty($name)) { throw new RoommateException('No banner information for first roommate.'); } $name = $roommate2->getLastName(); if (empty($name)) { throw new RoommateException('No banner information for second roommate.'); } // Make sure the genders match if ($roommate1->getGender() != $roommate2->getGender()) { throw new RoommateException('Roommate genders do not match.'); } // Check if either has a confirmed roommate if (HMS_Roommate::has_confirmed_roommate($roommate1->getUsername(), $term)) { throw new RoommateException('The first roommate already has a confirmed roommate.'); } if (HMS_Roommate::has_confirmed_roommate($roommate2->getUsername(), $term)) { throw new RoommateException('The second roommate already has a confirmed roommate.'); } true; }
/** * 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; }