class/Command/LotteryShowConfirmRoommateRequestCommand.php
<?php
namespace Homestead\Command;
use \Homestead\StudentFactory;
use \Homestead\UserStatus;
use \Homestead\ContractFactory;
use \Homestead\CommandFactory;
use \Homestead\HMS_Activity_Log;
use \Homestead\HMS_Lottery;
use \Homestead\LotteryConfirmRoommateRequestView;
class LotteryShowConfirmRoommateRequestCommand extends Command {
private $requestId;
private $mealPlan;
// TODO: check for this function being used elsewhere and rename it
public function setRoommateRequestId($id){
$this->requestId = $id;
}
public function setMealPlan($plan){
$this->mealPlan = $plan;
}
public function getRequestVars(){
$vars = array('action'=>'LotteryShowConfirmRoommateRequest');
$vars['roommateRequestId'] = $this->requestId;
$vars['mealPlan'] = $this->mealPlan;
return $vars;
}
public function execute(CommandContext $context)
{
$term = \PHPWS_Settings::get('hms', 'lottery_term');
$student = StudentFactory::getStudentByUsername(UserStatus::getUsername(), $term);
$contract = ContractFactory::getContractByStudentTerm($student, $term);
/**
if($contract !== false){
$contract->updateEnvelope();
}
*/
$mealPlanCode = $context->get('mealPlan');
if(empty($mealPlanCode) && !empty($context->get('meal_plan'))){
$mealPlanCode = $context->get('meal_plan');
}else{
$mealPlanCode = '1';
}
/**
if($contract === false || $contract->getEnvelopeStatus() !== 'completed'){
// If they haven't agreed, redirect to the agreement
$event = $context->get('event');
if(is_null($event) || !isset($event) || ($event != 'signing_complete' && $event != 'viewing_complete'))
{
$returnCmd = CommandFactory::getCommand('LotteryShowConfirmRoommateRequest');
$returnCmd->setRoommateRequestId($context->get('roommateRequestId'));
$returnCmd->setMealPlan($mealPlanCode);
$agreementCmd = CommandFactory::getCommand('ShowTermsAgreement');
$agreementCmd->setTerm($term);
$agreementCmd->setAgreedCommand($returnCmd);
$agreementCmd->redirect();
}else if($event === 'signing_complete'){
HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_CONTRACT_STUDENT_SIGN_EMBEDDED, UserStatus::getUsername(), "Student signed contract for $term through the embedded signing process");
}
}
*/
$request = HMS_Lottery::get_lottery_roommate_invite_by_id($context->get('roommateRequestId'));
$mealPlan = $mealPlanCode;
$view = new LotteryConfirmRoommateRequestView($request, $term, $mealPlan);
$context->setContent($view->show());
}
public function setTerm($term)
{
// Dummy method so that ShowTermsAgreementCommand can redirect here. This is a hack.
}
}