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); } $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}"); } $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 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; }