<?php
namespace App\FHI360\Access\Exchange\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use App\FHI360\Access\Suite\Service\APISuiteCRM;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
class DashboardController extends Controller
{
/**
* @Route("/", name="exchange-index")
*/
public function indexAction()
{
return $this->redirectToRoute("exchangedashboard");
}
/**
* @Route("dashboard", name="exchangedashboard")
*/
public function dashboardAction()
{
// App\FHI360\Access\Suite\Service\ExchangeUtils
$exchangeUtils = $this->container->get('exchange_utils');
$suiteUtils = $this->container->get('suite_utils');
$user_id = $this->getUser()->getId();
$participant_id = $exchangeUtils->getParticipantId($user_id);
//Pass in the status individual instead of putting logic in twig
$exchange = $exchangeUtils->getExchangeInfo($participant_id);
$passport_upload_status = $exchangeUtils->getPassportFilesStatus($participant_id);
$photo_upload_status = $exchangeUtils->getPhotoFileStatus($participant_id);
$medical_form_upload_status = $exchangeUtils->getMedicalFilesStatus($participant_id);
$tesol_form_upload_status = $exchangeUtils->getTESOLFilesStatus($participant_id);
$passport_info_status = $exchangeUtils->getPassportFormStatus($participant_id);
$participant_info_status = $exchangeUtils->getParticipantInfoFormStatus($participant_id);
//This status are saved in the exchange_participant_action_status table
$confirm_nominee_status = $exchangeUtils->getParticipantActionStatus($participant_id, 'confirm-nominee');
$privacy_status = $exchangeUtils->getParticipantActionStatus($participant_id,'privacy');
$release_status = $exchangeUtils->getParticipantActionStatus($participant_id,'release');
$terms_status = $exchangeUtils->getParticipantActionStatus($participant_id,'terms');
$resume_upload_status = $exchangeUtils->getParticipantActionStatus($participant_id,'resume', 'Not Required');
//Overall Participant Status
$participant_status = $exchangeUtils->getParticipantStatus($participant_id);
//load the country list from the language file on crm side
$portal_dir = $this->container->get('kernel')->getProjectDir();
$crm_lanuge_dir = $portal_dir . "/../crm/custom/include/language/";
include_once($crm_lanuge_dir . "en_us.lang.php");
$participant_status_list = $GLOBALS['app_list_strings']['exchange_participant_status_list'];
$form_status_list = $GLOBALS['app_list_strings']['participant_information_form_status_list'];
$document_status_list = $GLOBALS['app_list_strings']['exchanges_passport_file_status_list'];
$tesol_form_status_list = $GLOBALS['app_list_strings']['tesol_membership_status_list'];
/*
*Get the browser check information
*/
$participant_email = $this->getUser()->getEmail();
$browserDetails = $suiteUtils->getBrowserDetails();
$browserCheckInfo = $suiteUtils->getBrowserCheckInfo($participant_email.' - Exchange Participant',$browserDetails);
$save_browser_info = (isset($browserCheckInfo) && sizeof($browserCheckInfo)>0)?'no':'yes';
$templateParams = array(
'exchanges' => $exchange,
'confirm_nominee_status' => $confirm_nominee_status,
'passport_info_status' => $passport_info_status,
'participant_info_status' => $participant_info_status,
'privacy_status' => $privacy_status,
'release_status' => $release_status,
'terms_status' => $terms_status,
'passport_upload_status' => $passport_upload_status,
'photo_upload_status' => $photo_upload_status,
'medical_form_upload_status' => $medical_form_upload_status,
'tesol_form_upload_status' => $tesol_form_upload_status,
'resume_upload_status' => $resume_upload_status,
'participant_status' => $participant_status,
'participant_status_list' => $participant_status_list,
'form_status_list' => $form_status_list,
'document_status_list' => $document_status_list,
'tesol_form_status_list' => $tesol_form_status_list,
'save_browser_info' => $save_browser_info,
'browserDetails' => $browserDetails,
'ip_address' => $suiteUtils->getUserIP()
);
$exchange_id = $exchange[0]['id'];
if($exchange[0]['frontend_template_c']=='custom' && file_exists("{$portal_dir}/src/FHI360/Access/Exchange/Resources/views/Dashboard/{$exchange_id}/dashboard.html.twig")){
return $this->render("Exchange/Dashboard/{$exchange_id}/dashboard.html.twig", $templateParams);
}else{
return $this->render('Exchange/Dashboard/dashboard.html.twig', $templateParams);
}
}
/**
* @Route("update-to-in-progress", name="update-to-in-progress")
*/
public function updateToInProgress(Request $request)
{
// App\FHI360\Access\Suite\Service\ExchangeUtils
$exchangeUtils = $this->container->get('exchange_utils');
$user_id = $this->getUser()->getId();
$participant_id = $exchangeUtils->getParticipantId($user_id);
$action_type = $request->query->get('action_type');
if($exchangeUtils->getParticipantActionStatus($participant_id, $action_type) == 'Awaiting Action'){
$exchangeUtils->updateParticipantActionStatus($participant_id, $action_type, 'In Progress');
}
return new Response('successful');
}
/**
* @Route("update-to-in-progress-crm", name="update-to-in-progress-crm")
*/
public function updateFilesToInProgressInCRM(Request $request)
{
// App\FHI360\Access\Suite\Service\ExchangeUtils
$exchangeUtils = $this->container->get('exchange_utils');
$user_id = $this->getUser()->getId();
$participant_id = $exchangeUtils->getParticipantId($user_id);
$status_field_name = $request->query->get('field_name');
if($exchangeUtils->getParticipantActionStatusCRM($participant_id, $status_field_name) == 'awaiting_action'){
$exchangeUtils->updateParticipantActionStatusCRM($participant_id, $status_field_name, 'in_progress');
}
return new Response('successful');
}
/**
* @Route("download-blank-medical-form", name="download-blank-medical-form")
*/
public function downloadBlankMedicalForm(){
return $this->redirectToRoute("exchangedashboard");
}
/**
* @Route("download-blank-tesol-form", name="download-blank-tesol-form")
*/
public function downloadBlankTESOLForm(){
return $this->redirectToRoute("exchangedashboard");
}
}