Пример #1
0
 public static function confirm_roommate_request($username, $requestId, $meal_plan)
 {
     PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
     PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
     PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
     PHPWS_Core::initModClass('hms', 'HMS_Email.php');
     PHPWS_Core::initModClass('hms', 'StudentFactory.php');
     $term = PHPWS_Settings::get('hms', 'lottery_term');
     // Get the roommate invite
     $invite = HMS_Lottery::get_lottery_roommate_invite_by_id($requestId);
     // If the invite wasn't found, show an error
     if ($invite === false) {
         return E_LOTTERY_ROOMMATE_INVITE_NOT_FOUND;
     }
     // Check that the reserved bed is still empty
     $bed = new HMS_Bed($invite['bed_id']);
     if (!$bed->has_vacancy()) {
         return E_ASSIGN_BED_NOT_EMPTY;
     }
     // Make sure the student isn't assigned anywhere else
     if (HMS_Assignment::checkForAssignment($username, $term)) {
         return E_ASSIGN_ALREADY_ASSIGNED;
     }
     $student = StudentFactory::getStudentByUsername($username, $term);
     $requestor = StudentFactory::getStudentByUsername($invite['requestor'], $term);
     // Actually make the assignment
     HMS_Assignment::assignStudent($student, $term, null, $invite['bed_id'], $meal_plan, 'Confirmed roommate invite', true, ASSIGN_LOTTERY);
     // return successfully
     HMS_Email::send_roommate_confirmation($student, $requestor);
     return E_SUCCESS;
 }