<?php
namespace App\project\OfficeBrain\CustomBundle\CareerBundle\Controller;
// use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\project\OfficeBrain\CustomBundle\CareerBundle\Form\CareerUserApplicationType;
use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerUserApplication;
use Symfony\Component\HttpFoundation\Response;
use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerApplicationEducation;
use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerApplicationExperience;
use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerApplicationReferences;
use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerApplicationUserData;
use App\project\OfficeBrain\CustomBundle\CareerBundle\Form\CareerApplicationFormType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerInterface;
use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
use App\project\OfficeBrain\CustomBundle\CareerBundle\Manager\Service\CareerPositionService;
use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsMediaLibraryService;
class CareerPageController extends AbstractController
{
protected $request;
protected $session;
protected $translator;
protected $projectSetting;
protected $responseArray;
protected $careerPositionManager;
protected $locale;
protected $userId;
/**
*
* @author Employee Id: 5836
* Description: set default value
*
* @return NULL
*/
public function __construct(ContainerInterface $container, CoreService $coreService, CareerPositionService $careerPositionService, CmsMediaLibraryService $cmsMediaLibraryService)
{
$this->request = null;
$this->userId = null;
$this->locale = null;
$this->session = null;
$this->form = null;
$this->careerPositionManager = $careerPositionService->getCareerPositionExtended();
$this->translator = null;
$this->serviceContainer = $container;
$this->coreManager = $coreService->getCoreExtended();
$this->cmsMediaLibrary = $cmsMediaLibraryService->getCmsMediaLibraryExtended();
}
public function __destruct()
{
unset($this->request);
unset($this->session);
unset($this->translator);
unset($this->projectSetting);
unset($this->coreManager);
unset($this->responseArray);
unset($this->careerPositionManager);
unset($this->locale);
unset($this->serviceContainer);
}
public function initAction(Request $request)
{
$this->request = $request;
$this->session = $this->request->getSession();
$this->responseArray['status'] = 'error';
$this->translator = $this->serviceContainer->get('translator');
$this->projectSetting = $this->request->get('project_setting');
// $this->coreManager = $this->serviceContainer->get('office_brain_core_manager');
$this->coreManager = $this->coreManager;
// $this->careerPositionManager = $this->serviceContainer->get('office_brain_custombundle_career_position_manager');
$this->careerPositionManager = $this->careerPositionManager;
// $this->cmsMediaLibrary = $this->serviceContainer->get('office_brain_cms_media_library_manager');
$this->cmsMediaLibrary = $this->cmsMediaLibrary;
$this->userId = $this->projectSetting['user_id'];
$this->responseArray = array();
$this->page = $this->request->get('page', '1');
// $this->recordsPerPage = $this->request->get('records_per_page', '10');
$this->categoryId = $this->request->get('categoryId',null);
$this->applicationUploadPath = $this->serviceContainer->getParameter('career_application_upload');
}
/**
* @author Employee Id: 5051
* @Route("/{_locale}/career" , name="office_brain_custombundle_careerbundle_careerpage")
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerPage.html.twig")
*/
public function careerPageAction(Request $request)
{
return array();
}
/**
* @author Employee Id: 5051
* @Route("/{_locale}/career-benefits", name="office_brain_custombundle_careerbundle_careerbenefits")
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerBenefits.html.twig")
*/
public function careerBenefitsAction(Request $request)
{
return array();
}
/**
* @author Employee Id: 5051
* @Route("/{_locale}/careers", name="office_brain_custombundle_careerbundle_careercenter",
* options={"expose"=true})
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerCenter.html.twig")
*/
public function careerCenterAction(Request $request)
{
$this->initAction($request);
// $this->responseArray['records_per_page'] = $this->recordsPerPage;
// $this->responseArray['page'] = $this->page;
// $this->responseArray['data'] = $this->careerPositionManager->viewPositions($this->page,$this->recordsPerPage);
$this->responseArray['data'] = $this->careerPositionManager->viewPositings();
return $this->responseArray;
}
/**
* @author Employee Id: 5051
* @Route("/{_locale}/job-description/{categoryId}", name="office_brain_custombundle_careerbundle_jobdescription")
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/jobDescription.html.twig")
*/
public function jobDescriptionAction(Request $request)
{
$this->initAction($request);
$this->responseArray['data'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
// echo "<pre>";print_R(\Doctrine\Common\Util\Debug::dump($this->responseArray['data']));die();
return $this->responseArray;
}
/**
* @author Employee Id: 5836
* @Route(
* "/{_locale}/job-apply/{categoryId}", name="office_brain_custombundle_careerbundle_job_apply",
* options={"expose"=true}, methods={"GET"}
* )
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/jobApply.html.twig")
*/
public function addJobApplyAction(Request $request)
{
$this->initAction($request);
$this->form = $this->createForm( CareerUserApplicationType::class, new CareerUserApplication(),[
'container' => $this->container,
]);
$this->form->handleRequest($this->request);
$this->responseArray['form_career'] = $this->form->createView();
$this->responseArray['categoryId'] = $this->categoryId;
$this->responseArray['data'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
return $this->responseArray;
}
/**
* @author Employee Id: 5836
* @Route(
* "/{_locale}/job-apply/{categoryId}", name="office_brain_custombundle_careerbundle_job_applypost",
* options={"expose"=true}, methods={"POST"}
* )
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/jobApply.html.twig")
*/
public function addJobApplyPostAction(Request $request){
$this->initAction($request);
// echo "<pre>";var_dump($_FILES);die;
$applicationData = $this->request->request->all();
$this->responseArray['applicationId'] = $applicationData['form_career_application_id'];
$this->responseArray['applicationForm'] = $applicationData['form_career_application_pdf_name'];
$this->responseArray['categoryId'] = $this->categoryId;
$this->responseArray['data'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
$this->form = $this->createForm( CareerUserApplicationType::class, new CareerUserApplication(),[
'container' => $this->container,
]);
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
$careerData = $this->form->getData();
if($this->responseArray['applicationId'] == "" && $careerData->getUploadResume() == ""){
$this->responseArray['form_career'] = $this->form->createView();
$this->get('session')->getFlashBag()->set('error_message', $this->translator->trans('Please upload resume or fill Application Form.'));
$response['status'] = "error";
$response['message'] = 'Please upload resume or fill Application Form.';
return new JsonResponse($response);
//return $this->responseArray;
}else{
$add = $this->careerPositionManager->addJobApply($careerData,$this->categoryId,$this->responseArray['applicationId'],$this->responseArray['applicationForm']);
if ($add['status'] == 'SUCCESS'){
$response['status'] = "success";
$response['message'] = $this->translator->trans('career_apply.success_mesg');
$response['page_url'] = $this->generateUrl('office_brain_custombundle_careerbundle_job_apply',array('categoryId'=>$this->categoryId));
return new JsonResponse($response);
}
else{
$response['status'] = "error";
$response['message'] = $this->translator->trans('career_apply.error_mesg');
return new JsonResponse($response);
}
}
}
$this->responseArray['form_career'] = $this->form->createView();
$response['status'] = "error";
$response['message'] = 'invalid_form';
$response['data'] = $this->getErrorMessages($this->form);
// echo "<pre>";print_R($response['data']);die;
return new JsonResponse($response);
}
/**
* @author Employee Id: 5051
* @Route(
* "/{_locale}/job-application-form/{categoryId}", name="office_brain_custombundle_careerbundle_applicationform",
* options={"expose"=true}, methods={"GET"}
* )
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerApplicationForm.html.twig")
*/
public function careerApplicationFormAction(Request $request)
{
$this->initAction($request);
$entityArr = array();
$careerApplicationUserData = new CareerApplicationUserData();
$careerApplicationExperience = new CareerApplicationExperience();
$careerApplicationReferences = new CareerApplicationReferences();
$careerApplicationEducation = new CareerApplicationEducation();
//$entityArr['career_application_education'] = $careerApplicationEducation;
$entityArr['career_application_experience'] = $careerApplicationExperience;
$entityArr['career_application_reference'] = $careerApplicationReferences;
$entityArr['career_application_user_data'] = $careerApplicationUserData;
$this->responseArray['careerPositionData'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
$this->form = $this->createForm(CareerApplicationFormType::class,[
'serviceContainer' => $this->serviceContainer,
'coreManager' => $this->coreManager,
'entityArr' => $entityArr,
'careerPosition' => $this->responseArray['careerPositionData'],
]);
$this->form->handleRequest($this->request);
$this->responseArray['form_career_application'] = $this->form->createView();
return $this->responseArray;
}
/**
* @author Employee Id: 5051
* @Route(
* "/{_locale}/job-application-form/{categoryId}", name="office_brain_custombundle_careerbundle_postapplicationform",
* options={"expose"=true}, methods={"POST"}
* )
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerApplicationForm.html.twig")
*/
public function postCareerApplicationFormAction(Request $request)
{
$this->initAction($request);
$entityArr = array();
$careerApplicationUserData = new CareerApplicationUserData();
$careerApplicationExperience = new CareerApplicationExperience();
$careerApplicationReferences = new CareerApplicationReferences();
$careerApplicationEducation = new CareerApplicationEducation();
$entityArr['career_application_education'] = $careerApplicationEducation;
$entityArr['career_application_experience'] = $careerApplicationExperience;
$entityArr['career_application_reference'] = $careerApplicationReferences;
$entityArr['career_application_user_data'] = $careerApplicationUserData;
$this->responseArray['careerPositionData'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
$this->form = $this->createForm(CareerApplicationFormType::class,[
'serviceContainer' => $this->serviceContainer,
'coreManager' => $this->coreManager,
'entityArr' => $entityArr,
'careerPosition' => $this->responseArray['careerPositionData'],
]);
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
$careerApplicationData = $this->form->getData();
$careerCustomData = $this->request->request->all();
//echo "<pre>";print_R($careerCustomData);die;
$status = $this->careerPositionManager->addCareerApplicationForm($careerCustomData);
if($status['data']->getId() > 0){
$html = $this->renderView('project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/viewPdfApplication.html.twig',$careerCustomData);
$currentTime= time() . '_application.pdf';
// $this->get('knp_snappy.pdf')->getInternalGenerator()->setTimeout(1000);
$this->serviceContainer->get('knp_snappy.pdf')->setTimeout(1000);
// $this->get('knp_snappy.pdf')->generateFromHtml($html, $this->applicationUploadPath . $currentTime);
$this->serviceContainer->get('knp_snappy.pdf')->generateFromHtml($html, $this->applicationUploadPath . $currentTime,
[
'enable-local-file-access' => true,
]);
$status['successed']['applicationName'] = $currentTime;
$status['successed']['applicationId']= $status['data']->getId();
$status['successed']['status']="success";
$this->responseArray['status'] = $status;
return new JsonResponse($status['successed']);
}
else
{
$this->responseArray['status'] = $status;
}
}
$this->responseArray['form_career_application'] = $this->form->createView();
$response['status'] = "error";
$response['message'] = 'Invalid form';
$response['data'] = $this->getErrorMessages($this->form);
return new JsonResponse($response);
}
protected function getErrorMessages(\Symfony\Component\Form\Form $form)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
return $errors;
}
/**
* @Route("/{_locale}/career-thank-you",
* name="office_brain_custombundle_careerbundle_thankyou",
* )
*
* @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerThankYou.html.twig")
*/
public function careerThankYouAction(Request $request)
{
return array();
}
}