src/project/OfficeBrain/CustomBundle/CareerBundle/Controller/CareerPageController.php line 118

Open in your IDE?
  1. <?php
  2. namespace App\project\OfficeBrain\CustomBundle\CareerBundle\Controller;
  3. // use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use App\project\OfficeBrain\CustomBundle\CareerBundle\Form\CareerUserApplicationType;
  10. use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerUserApplication;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerApplicationEducation;
  13. use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerApplicationExperience;
  14. use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerApplicationReferences;
  15. use App\project\OfficeBrain\CustomBundle\CareerBundle\Entity\CareerApplicationUserData;
  16. use App\project\OfficeBrain\CustomBundle\CareerBundle\Form\CareerApplicationFormType;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\DependencyInjection\ContainerInterface;
  19. use App\OfficeBrain\Bundle\CoreBundle\Manager\Service\CoreService;
  20. use App\project\OfficeBrain\CustomBundle\CareerBundle\Manager\Service\CareerPositionService;
  21. use App\OfficeBrain\Bundle\CmsBundle\Manager\Service\CmsMediaLibraryService;
  22. class CareerPageController extends AbstractController
  23. {
  24.     protected $request;
  25.     protected $session;
  26.     protected $translator;
  27.     protected $projectSetting;
  28.     protected $responseArray;
  29.     protected $careerPositionManager;
  30.     protected $locale;
  31.     protected $userId;
  32.     
  33.     /**
  34.      *
  35.      * @author Employee Id: 5836
  36.      * Description: set default value
  37.      *
  38.      * @return NULL
  39.      */
  40.     public function __construct(ContainerInterface $containerCoreService $coreServiceCareerPositionService $careerPositionServiceCmsMediaLibraryService $cmsMediaLibraryService)
  41.     {
  42.         $this->request null;
  43.         $this->userId null;
  44.         $this->locale null;
  45.         $this->session null;
  46.         $this->form null;
  47.         $this->careerPositionManager $careerPositionService->getCareerPositionExtended();
  48.         $this->translator null;
  49.         $this->serviceContainer $container;
  50.         $this->coreManager $coreService->getCoreExtended();
  51.         $this->cmsMediaLibrary $cmsMediaLibraryService->getCmsMediaLibraryExtended();
  52.     }
  53.     
  54.     public function __destruct()
  55.     {
  56.         unset($this->request);
  57.         unset($this->session);
  58.         unset($this->translator);
  59.         unset($this->projectSetting);
  60.         unset($this->coreManager);
  61.         unset($this->responseArray);
  62.         unset($this->careerPositionManager);
  63.         unset($this->locale);
  64.         unset($this->serviceContainer);
  65.     }
  66.     
  67.     public function initAction(Request $request)
  68.     {
  69.         $this->request $request;
  70.         $this->session $this->request->getSession();
  71.         $this->responseArray['status'] = 'error';
  72.         $this->translator $this->serviceContainer->get('translator');
  73.         $this->projectSetting $this->request->get('project_setting');
  74.         // $this->coreManager = $this->serviceContainer->get('office_brain_core_manager');
  75.         $this->coreManager $this->coreManager;
  76.         // $this->careerPositionManager = $this->serviceContainer->get('office_brain_custombundle_career_position_manager');
  77.         $this->careerPositionManager $this->careerPositionManager;
  78.         // $this->cmsMediaLibrary = $this->serviceContainer->get('office_brain_cms_media_library_manager');
  79.         $this->cmsMediaLibrary $this->cmsMediaLibrary;
  80.         $this->userId $this->projectSetting['user_id'];
  81.         $this->responseArray = array();
  82.         $this->page $this->request->get('page''1');
  83. //         $this->recordsPerPage = $this->request->get('records_per_page', '10');
  84.         $this->categoryId $this->request->get('categoryId',null);
  85.         $this->applicationUploadPath $this->serviceContainer->getParameter('career_application_upload');
  86.     }
  87.     
  88.     /**
  89.      * @author Employee Id: 5051
  90.      * @Route("/{_locale}/career" , name="office_brain_custombundle_careerbundle_careerpage")
  91.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerPage.html.twig")
  92.      */
  93.     public function careerPageAction(Request $request)
  94.     {
  95.         return array();
  96.     }
  97.     
  98.     /**
  99.      * @author Employee Id: 5051
  100.      * @Route("/{_locale}/career-benefits", name="office_brain_custombundle_careerbundle_careerbenefits")
  101.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerBenefits.html.twig")
  102.      */
  103.     public function careerBenefitsAction(Request $request)
  104.     {
  105.         return array();
  106.     }
  107.     
  108.     /**
  109.      * @author Employee Id: 5051
  110.      * @Route("/{_locale}/careers", name="office_brain_custombundle_careerbundle_careercenter",
  111.      * options={"expose"=true})
  112.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerCenter.html.twig")
  113.      */
  114.     public function careerCenterAction(Request $request)
  115.     {
  116.         $this->initAction($request);
  117. //         $this->responseArray['records_per_page'] = $this->recordsPerPage;
  118. //         $this->responseArray['page'] = $this->page;
  119. //         $this->responseArray['data'] = $this->careerPositionManager->viewPositions($this->page,$this->recordsPerPage);
  120.         $this->responseArray['data'] = $this->careerPositionManager->viewPositings();
  121.         return $this->responseArray;
  122.     }
  123.     
  124.     /**
  125.      * @author Employee Id: 5051
  126.      * @Route("/{_locale}/job-description/{categoryId}", name="office_brain_custombundle_careerbundle_jobdescription")
  127.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/jobDescription.html.twig")
  128.      */
  129.     public function jobDescriptionAction(Request $request)
  130.     {
  131.         $this->initAction($request);
  132.         $this->responseArray['data'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
  133. //         echo "<pre>";print_R(\Doctrine\Common\Util\Debug::dump($this->responseArray['data']));die();
  134.         return $this->responseArray;
  135.     }
  136.     
  137.     /**
  138.      * @author Employee Id: 5836
  139.      * @Route(
  140.      * "/{_locale}/job-apply/{categoryId}", name="office_brain_custombundle_careerbundle_job_apply",
  141.      * options={"expose"=true}, methods={"GET"}
  142.      * )
  143.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/jobApply.html.twig")
  144.      */
  145.     public function addJobApplyAction(Request $request)
  146.     {
  147.         $this->initAction($request);
  148.         $this->form $this->createFormCareerUserApplicationType::class, new CareerUserApplication(),[
  149.             'container' => $this->container,
  150.         ]);
  151.         $this->form->handleRequest($this->request);
  152.         $this->responseArray['form_career'] = $this->form->createView();
  153.         $this->responseArray['categoryId'] = $this->categoryId;
  154.         $this->responseArray['data'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
  155.         return $this->responseArray;
  156.     }
  157.     
  158.     /**
  159.      * @author Employee Id: 5836
  160.      * @Route(
  161.      * "/{_locale}/job-apply/{categoryId}", name="office_brain_custombundle_careerbundle_job_applypost",
  162.      * options={"expose"=true}, methods={"POST"}
  163.      * )
  164.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/jobApply.html.twig")
  165.      */
  166.     
  167. public function addJobApplyPostAction(Request $request){
  168.         $this->initAction($request);
  169. //         echo "<pre>";var_dump($_FILES);die;
  170.         $applicationData $this->request->request->all();
  171.         $this->responseArray['applicationId'] = $applicationData['form_career_application_id'];
  172.         $this->responseArray['applicationForm'] = $applicationData['form_career_application_pdf_name'];
  173.         $this->responseArray['categoryId'] = $this->categoryId;
  174.         $this->responseArray['data'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
  175.         $this->form $this->createFormCareerUserApplicationType::class, new CareerUserApplication(),[
  176.             'container' => $this->container,
  177.         ]);
  178.         $this->form->handleRequest($this->request);
  179.         if ($this->form->isValid()) {
  180.             $careerData $this->form->getData();
  181.             if($this->responseArray['applicationId'] == "" && $careerData->getUploadResume() == ""){
  182.                 $this->responseArray['form_career'] = $this->form->createView();
  183.                 $this->get('session')->getFlashBag()->set('error_message'$this->translator->trans('Please upload resume or fill Application Form.'));
  184.                 $response['status'] = "error";
  185.                 $response['message'] = 'Please upload resume or fill Application Form.';
  186.                 return new JsonResponse($response);
  187.                 //return $this->responseArray;
  188.             }else{
  189.                 $add $this->careerPositionManager->addJobApply($careerData,$this->categoryId,$this->responseArray['applicationId'],$this->responseArray['applicationForm']);
  190.                 if ($add['status'] == 'SUCCESS'){
  191.                     $response['status'] = "success";
  192.                     $response['message'] =  $this->translator->trans('career_apply.success_mesg');
  193.                     $response['page_url'] = $this->generateUrl('office_brain_custombundle_careerbundle_job_apply',array('categoryId'=>$this->categoryId));
  194.                     return new JsonResponse($response);
  195.                 }
  196.                 else{
  197.                     $response['status'] = "error";
  198.                     $response['message'] =  $this->translator->trans('career_apply.error_mesg');
  199.                     return new JsonResponse($response);
  200.                 }
  201.             }
  202.         }
  203.         
  204.         $this->responseArray['form_career'] = $this->form->createView();
  205.         $response['status'] = "error";
  206.         $response['message'] = 'invalid_form';
  207.         $response['data'] = $this->getErrorMessages($this->form);
  208. //                 echo "<pre>";print_R($response['data']);die;
  209.         return new JsonResponse($response);
  210.     }
  211.     
  212.     /**
  213.      * @author Employee Id: 5051
  214.      * @Route(
  215.      * "/{_locale}/job-application-form/{categoryId}", name="office_brain_custombundle_careerbundle_applicationform",
  216.      * options={"expose"=true}, methods={"GET"}
  217.      * )
  218.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerApplicationForm.html.twig")
  219.      */
  220.     
  221.     public function careerApplicationFormAction(Request $request)
  222.     {
  223.         $this->initAction($request);
  224.         
  225.         $entityArr = array();        
  226.         $careerApplicationUserData = new CareerApplicationUserData();
  227.         $careerApplicationExperience = new CareerApplicationExperience();
  228.         $careerApplicationReferences = new CareerApplicationReferences();
  229.         
  230.         $careerApplicationEducation = new CareerApplicationEducation();
  231.          //$entityArr['career_application_education'] = $careerApplicationEducation;
  232.         
  233.         $entityArr['career_application_experience'] = $careerApplicationExperience;
  234.         $entityArr['career_application_reference'] = $careerApplicationReferences;
  235.         $entityArr['career_application_user_data'] = $careerApplicationUserData;
  236.         $this->responseArray['careerPositionData'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
  237.         $this->form $this->createForm(CareerApplicationFormType::class,[
  238.             'serviceContainer' => $this->serviceContainer,
  239.             'coreManager' => $this->coreManager,
  240.             'entityArr' => $entityArr,
  241.             'careerPosition' => $this->responseArray['careerPositionData'],
  242.         ]);
  243.         $this->form->handleRequest($this->request);
  244.         $this->responseArray['form_career_application'] = $this->form->createView();
  245.         return $this->responseArray;
  246.     }
  247.     
  248.     /**
  249.      * @author Employee Id: 5051
  250.      * @Route(
  251.      * "/{_locale}/job-application-form/{categoryId}", name="office_brain_custombundle_careerbundle_postapplicationform",
  252.      * options={"expose"=true}, methods={"POST"}
  253.      * )
  254.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerApplicationForm.html.twig")
  255.      */
  256.     
  257.     public function postCareerApplicationFormAction(Request $request)
  258.     {
  259.         $this->initAction($request);
  260.         $entityArr = array();
  261.         $careerApplicationUserData = new CareerApplicationUserData();
  262.         $careerApplicationExperience = new CareerApplicationExperience();
  263.         $careerApplicationReferences = new CareerApplicationReferences();
  264.         $careerApplicationEducation = new CareerApplicationEducation();
  265.         $entityArr['career_application_education'] = $careerApplicationEducation;
  266.         $entityArr['career_application_experience'] = $careerApplicationExperience;
  267.         $entityArr['career_application_reference'] = $careerApplicationReferences;
  268.         $entityArr['career_application_user_data'] = $careerApplicationUserData;
  269.          
  270.         $this->responseArray['careerPositionData'] = $this->careerPositionManager->viewPositionsById($this->categoryId);
  271.         $this->form $this->createForm(CareerApplicationFormType::class,[
  272.             'serviceContainer' => $this->serviceContainer,
  273.             'coreManager' => $this->coreManager,
  274.             'entityArr' => $entityArr,
  275.             'careerPosition' => $this->responseArray['careerPositionData'],
  276.         ]);
  277.         $this->form->handleRequest($this->request);
  278.         if ($this->form->isValid()) {
  279.             $careerApplicationData $this->form->getData();
  280.             $careerCustomData $this->request->request->all();
  281.             //echo "<pre>";print_R($careerCustomData);die;
  282.             $status $this->careerPositionManager->addCareerApplicationForm($careerCustomData);
  283.             if($status['data']->getId() > 0){
  284.                 $html $this->renderView('project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/viewPdfApplication.html.twig',$careerCustomData);
  285.                 $currentTimetime() . '_application.pdf';
  286.                 // $this->get('knp_snappy.pdf')->getInternalGenerator()->setTimeout(1000);
  287.                 $this->serviceContainer->get('knp_snappy.pdf')->setTimeout(1000);
  288.                 // $this->get('knp_snappy.pdf')->generateFromHtml($html, $this->applicationUploadPath . $currentTime);               
  289.                 $this->serviceContainer->get('knp_snappy.pdf')->generateFromHtml($html$this->applicationUploadPath $currentTime,
  290.                     [
  291.                         'enable-local-file-access' => true,
  292.                     ]);
  293.                 $status['successed']['applicationName'] = $currentTime;
  294.                 $status['successed']['applicationId']= $status['data']->getId();
  295.                 $status['successed']['status']="success";
  296.                 $this->responseArray['status'] = $status;
  297.                 return new JsonResponse($status['successed']);    
  298.             }
  299.             else
  300.             {
  301.                 $this->responseArray['status'] = $status;
  302.             }
  303.         }
  304.         $this->responseArray['form_career_application'] = $this->form->createView();
  305.         
  306.         $response['status'] = "error";
  307.         $response['message'] = 'Invalid form';
  308.         $response['data'] = $this->getErrorMessages($this->form);
  309.         return new JsonResponse($response);
  310.     }
  311.     
  312.     protected function getErrorMessages(\Symfony\Component\Form\Form $form)
  313.     {
  314.         $errors = array();
  315.         foreach ($form->getErrors() as $key => $error) {
  316.             $errors[] = $error->getMessage();
  317.         }
  318.         
  319.         foreach ($form->all() as $child) {
  320.             if (!$child->isValid()) {
  321.                 $errors[$child->getName()] = $this->getErrorMessages($child);
  322.             }
  323.         }
  324.         return $errors;
  325.     }
  326.     
  327.     /**
  328.      * @Route("/{_locale}/career-thank-you",
  329.      *     name="office_brain_custombundle_careerbundle_thankyou",
  330.      * )
  331.      *
  332.      * @Template("project/OfficeBrain/CustomBundle/CareerBundle/CareerPage/careerThankYou.html.twig")
  333.      */
  334.     public function careerThankYouAction(Request $request)
  335.     {
  336.         return array();
  337.     }
  338. }