src/Controller/mainController.php line 258

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Ubel
  5.  * Date: 8/2/2019
  6.  * Time: 18:26
  7.  */
  8. namespace App\Controller;
  9. use App\Datatable\emailsDatatable;
  10. use App\Entity\Anouncement;
  11. use App\Entity\ContactMessage;
  12. use App\Entity\Job;
  13. use App\Entity\Metadata;
  14. use App\Entity\Notification;
  15. use App\Entity\Payment;
  16. use App\Entity\PaymentForJobs;
  17. use App\Entity\PaymentForServices;
  18. use App\Entity\PaymentForServicesMetadata;
  19. use App\Entity\Policy;
  20. use App\Entity\Resume;
  21. use App\Entity\StaticPage;
  22. use App\Entity\User;
  23. use App\Entity\UserJobMeta;
  24. use App\Form\ContactMessageFormType;
  25. use App\Form\ResumeFilesType;
  26. use App\Form\ResumeType;
  27. use App\Form\UserFullyEmployerType;
  28. use App\Form\UserFullyType;
  29. use App\Service\Mailer;
  30. use App\Repository\CompanyRepository;
  31. use App\Repository\ContactMessageRepository;
  32. use App\Repository\UserJobMetaRepository;
  33. use App\Repository\UserRepository;
  34. use App\Service\CategoryService;
  35. use App\Service\CompanyService;
  36. use App\Service\JobService;
  37. use Doctrine\ORM\NonUniqueResultException;
  38. use Exception;
  39. use Sg\DatatablesBundle\Datatable\DatatableFactory;
  40. use Sg\DatatablesBundle\Response\DatatableResponse;
  41. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  42. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  43. use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
  44. use Symfony\Component\HttpFoundation\JsonResponse;
  45. use Symfony\Component\HttpFoundation\RedirectResponse;
  46. use Symfony\Component\HttpFoundation\Request;
  47. use Symfony\Component\HttpFoundation\Response;
  48. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  49. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  50. use Symfony\Component\Routing\Annotation\Route;
  51. use App\constants;
  52. use App\Entity\ClientTransaction;
  53. use App\Entity\Slide;
  54. use DateTime;
  55. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  56. use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
  57. use Symfony\Component\Filesystem\Filesystem;
  58. use Symfony\Component\Filesystem\Exception\IOExceptionInterface;
  59. /**
  60.  * Class mainController
  61.  * @package App\Controller
  62.  */
  63. class mainController extends Controller
  64. {
  65.     /** @var CategoryService */
  66.     private $categoryService;
  67.     /** @var JobService */
  68.     private $jobService;
  69.     /** @var CompanyService */
  70.     private $companyService;
  71.     /** @var Mailer */
  72.     protected $mailer;
  73.     /** @var SessionInterface */
  74.     private $session;
  75.     /** @var DatatableFactory */
  76.     private $datatableFactory;
  77.     /** @var DatatableResponse */
  78.     private $datatableResponse;
  79.     /**
  80.      * mainController constructor.
  81.      * @param CategoryService $categoryService
  82.      * @param JobService $jobService
  83.      * @param CompanyService $companyService
  84.      * @param Mailer $mailer
  85.      * @param SessionInterface $session
  86.      * @param DatatableFactory $datatableFactory
  87.      * @param DatatableResponse $datatableResponse
  88.      */
  89.     public function __construct(
  90.         CategoryService $categoryService,
  91.         JobService $jobService,
  92.         CompanyService $companyService,
  93.         Mailer $mailer,
  94.         SessionInterface $session,
  95.         DatatableFactory $datatableFactory,
  96.         DatatableResponse $datatableResponse
  97.     ) {
  98.         $this->categoryService $categoryService;
  99.         $this->jobService $jobService;
  100.         $this->companyService $companyService;
  101.         $this->mailer $mailer;
  102.         $this->session $session;
  103.         $this->datatableFactory $datatableFactory;
  104.         $this->datatableResponse $datatableResponse;
  105.     }
  106.     /**
  107.      * @Route("/mail",name="mail")
  108.      */
  109.     public function mailView()
  110.     {
  111.         return $this->render('mail/contrata.html.twig');
  112.     }
  113.     public function verificateUser(AuthorizationCheckerInterface $authChecker)
  114.     {
  115.         if ($authChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
  116.             $fileSystem = new Filesystem();
  117.             try {
  118.                 $base $this->getParameter('kernel.project_dir') . '/public';
  119.                 $path $this->getParameter('app.path.user_images');
  120.                 $user $this->get('security.token_storage')->getToken()->getUser();
  121.                 $dir $base $path '/_files_' $user->getUsername();
  122.                 if (!$fileSystem->exists($dir)) {
  123.                     $fileSystem->mkdir($dir);
  124.                     if ($fileSystem->exists($base $path '/' $user->getImage())) {
  125.                         $fileSystem->copy($base $path '/' $user->getImage(), $dir '/' $user->getImage());
  126.                         $fileSystem->remove($base $path '/' $user->getImage());
  127.                     }
  128.                 }
  129.             } catch (IOExceptionInterface $exception) {
  130.             }
  131.             if (!$this->container->get('app.service.checker')->isUserValid()) {
  132.                 return true;
  133.             }
  134.         }
  135.         return false;
  136.     }
  137.     /**
  138.      * @param Request $request
  139.      * @return Response
  140.      * @Route("/pricing",name="pricing_page")
  141.      */
  142.     public function pricing(Request $request)
  143.     {
  144.         $em $this->getDoctrine()->getManager();
  145.         $packagesJobs $this->jobService->findAviableJobsPacks($this->getUser());
  146.         $packagesServices $em->getRepository(PaymentForServices::class)->findAll();
  147.         $type $request->query->get('type');
  148.         if (!isset($type)) {
  149.             if ($this->isGranted('ROLE_ADMIN')) {
  150.                 $type 'job';
  151.             } else {
  152.                 $type 'service';
  153.             }
  154.         }
  155.         $_error $this->session->get('_error');
  156.         $_error_ $this->session->get('_error_');
  157.         if ($_error) {
  158.             $this->session->remove('_error');
  159.         }
  160.         if ($_error_) {
  161.             $this->session->remove('_error_');
  162.         }
  163.         return $this->render(
  164.             'site/pricing.html.twig',
  165.             [
  166.                 'notifications' => $this->loadNotifications(),
  167.                 'packagesJobs' => $packagesJobs,
  168.                 'packagesServices' => $packagesServices,
  169.                 'type' => $type,
  170.                 '_error' => $_error,
  171.                 '_error_' => $_error_
  172.             ]
  173.         );
  174.     }
  175.     /**
  176.      * @Route("/checkout/{packId}/{type}",name="checkout")
  177.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  178.      */
  179.     public function checkout($packId$type)
  180.     {
  181.         $em $this->getDoctrine()->getManager();
  182.         $transaction = new ClientTransaction();
  183.         $transaction
  184.             ->setCreatedAt(new DateTime('now'))
  185.             ->setConfirmed(false)
  186.             ->setUser($this->getUser())
  187.             ->setCode(md5(uniqid(rand(), true)));
  188.         if ($type == 'job') {
  189.             /** @var PaymentForJobs $package */
  190.             $package $em->getRepository(PaymentForJobs::class)->find($packId);
  191.         } else {
  192.             /** @var PaymentForServices $package */
  193.             $package $em->getRepository(PaymentForServices::class)->find($packId);
  194.         }
  195.         $em->persist($transaction);
  196.         $em->flush();
  197.         return $this->render(
  198.             'site/checkout.html.twig',
  199.             [
  200.                 'notifications' => $this->loadNotifications(),
  201.                 'package' => $package,
  202.                 'type' => $type,
  203.                 'transaction' => $transaction
  204.             ]
  205.         );
  206.     }
  207.     public function updateJobsFiles()
  208.     {
  209.         $em $this->getDoctrine()->getManager();
  210.         $jobs $em->getRepository(Job::class)->findAll();
  211.         $base $this->getParameter('kernel.project_dir') . '/public';
  212.         $path $this->getParameter('app.path.company_images');
  213.         $fileSystem = new Filesystem();
  214.         foreach ($jobs as $job) {
  215.             $dir $base $path '/_user_' $job->getUser()->getId();
  216.             try {
  217.                 $fileSystem->mkdir($dir);
  218.                 if ($fileSystem->exists($base $path '/' $job->getImage())) {
  219.                     $fileSystem->copy($base $path '/' $job->getImage(), $dir '/' $job->getImage());
  220.                     $fileSystem->remove($base $path '/' $job->getImage());
  221.                 }
  222.             } catch (IOExceptionInterface $exception) {
  223.                 echo $exception->getMessage();
  224.                 die;
  225.             }
  226.         }
  227.     }
  228.     /**
  229.      * @Route("/",name="homepage")
  230.      * @param AuthorizationCheckerInterface $authChecker
  231.      * @return Response
  232.      */
  233.     public function index(AuthorizationCheckerInterface $authChecker): Response
  234.     {
  235.         $verified $this->verificateUser($authChecker);
  236.         $em $this->getDoctrine()->getManager();
  237.         $this->container->get('app.service.checker')->checkJobs();
  238.         $slides $em->getRepository(Slide::class)->findAll();
  239.         return $this->render(
  240.             'site/job/index.html.twig',
  241.             [
  242.                 'verificated_acount' => $verified,
  243.                 'notifications' => $this->loadNotifications(),
  244.                 'jobs' => $em->getRepository(Job::class)->findBy(
  245.                     array('status' => constants::JOB_STATUS_ACTIVE),
  246.                     array('dateCreated' => 'desc'),
  247.                     10
  248.                 ),
  249.                 'services' => $em->getRepository(Anouncement::class)->findBy([
  250.                     'status' => constants::JOB_STATUS_ACTIVE,
  251.                 ], [
  252.                     'date' => 'desc'
  253.                 ], 10),
  254.                 'locations' => $this->container->get('app.service.helper')->loadLocations(),
  255.                 'categorys' => $this->jobService->findByAllCategory(),
  256.                 'citys' => $this->container->get('app.service.helper')->loadCityes(),
  257.                 'company' => $this->companyService->findActives(),
  258.                 'entity' => count($em->getRepository(User::class)->findByRole('ROLE_ADMIN')),
  259.                 'slides' => $slides
  260.             ]
  261.         );
  262.     }
  263.     /**
  264.      * @param CompanyRepository $repository
  265.      * @return Response
  266.      *
  267.      * @Route("/companies", name="listado_companias")
  268.      */
  269.     public function companies(CompanyRepository $repository)
  270.     {
  271.         return $this->render('site/job/companies.html.twig', [
  272.             'companies' => $repository->findActives(),
  273.             'notifications' => $this->loadNotifications(),
  274.             'locations' => $this->container->get('app.service.helper')->loadLocations(),
  275.             'categorys' => $this->jobService->findByAllCategory(),
  276.             'citys' => $this->container->get('app.service.helper')->loadCityes(),
  277.             'company' => $this->companyService->findActives(),
  278.         ]);
  279.     }
  280.     /**
  281.      * @return Response
  282.      *
  283.      * @Route ("/servicces", name="load_services_request")
  284.      */
  285.     public function serviciosSolicidatos()
  286.     {
  287.         /** @var User $user */
  288.         $user $this->getUser();
  289.         $ids $user->getServicesRequest();
  290.         $em $this->getDoctrine()->getManager();
  291.         $services = [];
  292.         foreach ($ids as $id) {
  293.             $services[] = $em->getRepository(Anouncement::class)->find($id);
  294.         }
  295.         return $this->render('site/job/services.html.twig', [
  296.             'services' => $services,
  297.             'notifications' => $this->loadNotifications(),
  298.         ]);
  299.     }
  300.     /**
  301.      * @return object[]|null
  302.      */
  303.     public function loadNotifications()
  304.     {
  305.         $user $this->get('security.token_storage')->getToken()->getUser();
  306.         if (null != $user) {
  307.             $em $this->getDoctrine()->getManager();
  308.             $notifications $em->getRepository(Notification::class)->findBy(
  309.                 array(
  310.                     'user' => $user,
  311.                     'active' => true,
  312.                 ),
  313.                 array(
  314.                     'date' => 'DESC',
  315.                 ),
  316.                 10
  317.             );
  318.             return $notifications;
  319.         }
  320.         return null;
  321.     }
  322.     /**
  323.      * @Route("/terms", name="site_policy")
  324.      * @param AuthorizationCheckerInterface $authChecker
  325.      * @return RedirectResponse|Response
  326.      * @throws NonUniqueResultException
  327.      */
  328.     public function policy(AuthorizationCheckerInterface $authChecker)
  329.     {
  330.         $em $this->getDoctrine()->getManager();
  331.         $verificated $this->verificateUser($authChecker);
  332.         $terms $em->getRepository(Policy::class)->load();
  333.         if (null == $terms) {
  334.             return $this->redirectToRoute('homepage');
  335.         }
  336.         return $this->render(
  337.             'site/policy.html.twig',
  338.             array(
  339.                 'verificated_acount' => $verificated,
  340.                 'notifications' => $this->loadNotifications(),
  341.                 'terms' => $terms,
  342.             )
  343.         );
  344.     }
  345.     /**
  346.      * @Route("/dashboard", name="dashboard")
  347.      * Require IS_AUTHENTICATED_FULLY for *every* controller method in this class.
  348.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  349.      * @param AuthorizationCheckerInterface $authChecker
  350.      * @return Response
  351.      */
  352.     public function dashboard(AuthorizationCheckerInterface $authChecker)
  353.     {
  354.         /** @var User $user */
  355.         $user $this->getUser();
  356.         $verificated $this->verificateUser($authChecker);
  357.         $paymentMetadata = [
  358.             'jobs' => $this->jobService->getCurrentJobPackage($user),
  359.             'services' => $this->jobService->getCurrentServicesPackage($user)
  360.         ];
  361.         if (in_array('ROLE_ADMIN'$user->getRoles())) {
  362.             $em $this->getDoctrine()->getManager();
  363.             $public $em->getRepository(Job::class)->countJob($user);
  364.             return $this->render(
  365.                 'user/employer/dashboard.html.twig',
  366.                 array(
  367.                     'notifications' => $this->loadNotifications(),
  368.                     'public' => $public,
  369.                     'requests' => $em->getRepository(Job::class)->requests($user),
  370.                     'paymentMetadata' => $paymentMetadata
  371.                 )
  372.             );
  373.         } else {
  374.             return $this->render(
  375.                 'user/dashboard.html.twig',
  376.                 array(
  377.                     'verificated_acount' => $verificated,
  378.                     'notifications' => $this->loadNotifications(),
  379.                     'paymentMetadata' => $paymentMetadata
  380.                 )
  381.             );
  382.         }
  383.     }
  384.     /**
  385.      * @param Request $request
  386.      * @param AuthorizationCheckerInterface $authChecker
  387.      * @return RedirectResponse|Response
  388.      * @throws Exception
  389.      * @Route("/profile/edit", name="dashboard_edit")
  390.      */
  391.     public function edit_profile(Request $requestAuthorizationCheckerInterface $authChecker)
  392.     {
  393.         $verified $this->verificateUser($authChecker);
  394.         $user $this->get('security.token_storage')->getToken()->getUser();
  395.         $is_admin in_array('ROLE_ADMIN'$user->getRoles());
  396.         $entityManager $this->getDoctrine()->getManager();
  397.         if ($is_admin) {
  398.             $form $this->createForm(UserFullyEmployerType::class, $user);
  399.             $form->handleRequest($request);
  400.             if ($form->isSubmitted() && $form->isValid()) {
  401.                 $entityManager->flush();
  402.                 $notification = new Notification();
  403.                 $notification->setDate(new \DateTime());
  404.                 $notification->setType(constants::NOTIFICATION_PROFILE_UPDATE);
  405.                 $notification->setContext("Su perfil se ha actualizado correctamente");
  406.                 $notification->setUser($user);
  407.                 $notification->setActive(true);
  408.                 $entityManager->persist($notification);
  409.                 $entityManager->flush();
  410.                 return $this->redirectToRoute('dashboard');
  411.             }
  412.         } else {
  413.             $form $this->createForm(UserFullyType::class, $user);
  414.             $form->handleRequest($request);
  415.             if ($form->isSubmitted() && $form->isValid()) {
  416.                 $entityManager->flush();
  417.                 $notification = new Notification();
  418.                 $notification->setDate(new \DateTime());
  419.                 $notification->setType(constants::NOTIFICATION_PROFILE_UPDATE);
  420.                 $notification->setContext("Su perfil se ha actualizado correctamente");
  421.                 $notification->setUser($user);
  422.                 $notification->setActive(true);
  423.                 $entityManager->persist($notification);
  424.                 $entityManager->flush();
  425.                 return $this->redirectToRoute('dashboard_resume_edit');
  426.             }
  427.         }
  428.         $paymentMetadata = [
  429.             'jobs' => $this->jobService->getCurrentJobPackage($user),
  430.             'services' => $this->jobService->getCurrentServicesPackage($user)
  431.         ];
  432.         if ($is_admin) {
  433.             return $this->render(
  434.                 'user/employer/edit_profile.html.twig',
  435.                 array(
  436.                     'verificated_acount' => $verified,
  437.                     'form' => $form->createView(),
  438.                     'notifications' => $this->loadNotifications(),
  439.                     'paymentMetadata' => $paymentMetadata
  440.                 )
  441.             );
  442.         } else {
  443.             $active $this->getDoctrine()->getRepository(PaymentForServicesMetadata::class)->checkUser($this->getUser());
  444.             return $this->render(
  445.                 'user/edit_profile.html.twig',
  446.                 array(
  447.                     'form' => $form->createView(),
  448.                     'notifications' => $this->loadNotifications(),
  449.                     'paymentMetadata' => $paymentMetadata,
  450.                     'activePack' => $active != null,
  451.                 )
  452.             );
  453.         }
  454.     }
  455.     /**
  456.      * @Route("/ajax", name="ajax")
  457.      */
  458.     public function deleteNotification($id)
  459.     {
  460.         //echo json_encode($id);
  461.     }
  462.     /**
  463.      * @Route("/dashboard/resume", name="dashboard_resume")
  464.      * Require IS_AUTHENTICATED_FULLY for *every* controller method in this class.
  465.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  466.      * @param AuthorizationCheckerInterface $authChecker
  467.      * @return Response
  468.      */
  469.     public function resume(AuthorizationCheckerInterface $authChecker)
  470.     {
  471.         $verificated $this->verificateUser($authChecker);
  472.         $user $this->get('security.token_storage')->getToken()->getUser();
  473.         $em $this->getDoctrine()->getManager();
  474.         $metas $em->getRepository(Metadata::class)->findBy(array("resume" => $user->getResume()));
  475.         $cv $user->getResume()->getCv();
  476.         $cart $user->getResume()->getCart();
  477.         return $this->render(
  478.             'user/resume.html.twig',
  479.             array(
  480.                 'verificated_acount' => $verificated,
  481.                 'resume' => $user->getResume(),
  482.                 'notifications' => $this->loadNotifications(),
  483.                 'cv' => $cv,
  484.                 'cart' => $cart,
  485.                 'metas' => $metas,
  486.                 'user' => $this->getUser()
  487.             )
  488.         );
  489.     }
  490.     /**
  491.      * @Route("/dashboard/resume/edit", name="dashboard_resume_edit")
  492.      * Require IS_AUTHENTICATED_FULLY for *every* controller method in this class.
  493.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  494.      * @param Request $request
  495.      * @param AuthorizationCheckerInterface $authChecker
  496.      * @return Response
  497.      */
  498.     public function resumeEdit(Request $requestAuthorizationCheckerInterface $authChecker)
  499.     {
  500.         $verificated $this->verificateUser($authChecker);
  501.         $user $this->get('security.token_storage')->getToken()->getUser();
  502.         $entityManager $this->getDoctrine()->getManager();
  503.         if ($user->getResume() == null) {
  504.             $resume = new Resume();
  505.             $resume->setUser($user);
  506.             $em $this->getDoctrine()->getManager();
  507.             $em->persist($resume);
  508.             $em->flush();
  509.         }
  510.         /** @var Resume $resume */
  511.         $resume $entityManager->getRepository(Resume::class)->findOneBy(array('user' => $user,));
  512.         $metas $entityManager->getRepository(Metadata::class)->findBy(array("resume" => $resume));
  513.         $form $this->createForm(ResumeType::class, $resume);
  514.         $haveCv false;
  515.         $haveCart false;
  516.         if ($resume->getCvFile()) {
  517.             $haveCv true;
  518.         }
  519.         if ($resume->getCartFile()) {
  520.             $haveCart false;
  521.         }
  522.         $formFiles $this->createForm(ResumeFilesType::class, $resume, [
  523.             'cv' => $haveCv,
  524.             'cart' => $haveCart
  525.         ]);
  526.         $formFiles->handleRequest($request);
  527.         if ($formFiles->isSubmitted() && $formFiles->isValid()) {
  528.             $resume->setUpdatedAt(new \DateTime("now"));
  529.             $entityManager->flush();
  530.             $notification = new Notification();
  531.             $notification->setDate(new \DateTime());
  532.             $notification->setType(constants::METADATA_RESUME_EDIT);
  533.             $notification->setContext("Su curriculum se ha actualizado correctamente");
  534.             $notification->setUser($user);
  535.             $notification->setActive(true);
  536.             $entityManager->persist($notification);
  537.             $entityManager->flush();
  538.         }
  539.         return $this->render(
  540.             'user/resume_edit.html.twig',
  541.             array(
  542.                 'verificated_acount' => $verificated,
  543.                 'resume' => $resume,
  544.                 'notifications' => $this->loadNotifications(),
  545.                 'form_resume' => $form->createView(),
  546.                 'form_files' => $formFiles->createView(),
  547.                 'metas' => $metas,
  548.             )
  549.         );
  550.     }
  551.     /**
  552.      * @Route("/dashboard/bookmarked", name="dashboard_bookmarked")
  553.      * Require IS_AUTHENTICATED_FULLY for *every* controller method in this class.
  554.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  555.      * @param AuthorizationCheckerInterface $authChecker
  556.      * @return Response
  557.      */
  558.     public function bookMarked(AuthorizationCheckerInterface $authChecker)
  559.     {
  560.         $verificated $this->verificateUser($authChecker);
  561.         $user $this->get('security.token_storage')->getToken()->getUser();
  562.         $marked $user->getBookmarked();
  563.         $jobs = array();
  564.         $entityManager $this->getDoctrine()->getManager();
  565.         foreach ($marked as $id) {
  566.             $jobs[] = $entityManager->getRepository(Job::class)->find($id);
  567.         }
  568.         return $this->render(
  569.             'user/mark.html.twig',
  570.             array(
  571.                 'verificated_acount' => $verificated,
  572.                 'jobs' => $jobs,
  573.                 'notifications' => $this->loadNotifications(),
  574.             )
  575.         );
  576.     }
  577.     /**
  578.      * @Route("/dashboard/applied", name="dashboard_applied")
  579.      * Require IS_AUTHENTICATED_FULLY for *every* controller method in this class.
  580.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  581.      * @param AuthorizationCheckerInterface $authChecker
  582.      * @return Response
  583.      */
  584.     public function applied(AuthorizationCheckerInterface $authChecker)
  585.     {
  586.         $verificated $this->verificateUser($authChecker);
  587.         /** @var User $user */
  588.         $user $this->get('security.token_storage')->getToken()->getUser();
  589.         $jobs $user->getJobAppiled();
  590.         //        $jobs = array();
  591.         //        $entityManager = $this->getDoctrine()->getManager();
  592.         //        foreach ($marked as $id) {
  593.         //            $jobs[] = $entityManager->getRepository(Job::class)->find($id);
  594.         //        }
  595.         return $this->render(
  596.             'user/applied.html.twig',
  597.             array(
  598.                 'verificated_acount' => $verificated,
  599.                 'jobs' => $jobs,
  600.                 'notifications' => $this->loadNotifications(),
  601.             )
  602.         );
  603.     }
  604.     /**
  605.      * @Route("/candidates", name="candidates")
  606.      * Require IS_AUTHENTICATED_FULLY for *every* controller method in this class.
  607.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  608.      * @param AuthorizationCheckerInterface $authChecker
  609.      * @return Response
  610.      */
  611.     public function candidates(AuthorizationCheckerInterface $authChecker)
  612.     {
  613.         $verificated $this->verificateUser($authChecker);
  614.         $user $this->get('security.token_storage')->getToken()->getUser();
  615.         $canditatesID $user->getCandidates();
  616.         $users = array();
  617.         $entityManager $this->getDoctrine()->getManager();
  618.         foreach ($canditatesID as $item) {
  619.             if ($user->getId() != $item) {
  620.                 array_push($users$entityManager->getRepository(User::class)->find($item));
  621.             }
  622.         }
  623.         return $this->render(
  624.             'site/candidate.html.twig',
  625.             array(
  626.                 'verificated_acount' => $verificated,
  627.                 'candidates' => $users,
  628.                 'notifications' => $this->loadNotifications(),
  629.             )
  630.         );
  631.     }
  632.     /**
  633.      * @Route("/manage/candidates", name="manage_candidates")
  634.      * Require IS_AUTHENTICATED_FULLY for *every* controller method in this class.
  635.      * @IsGranted("IS_AUTHENTICATED_FULLY")
  636.      * @param Request $request
  637.      * @param AuthorizationCheckerInterface $authChecker
  638.      * @param UserRepository $userRepository
  639.      * @return Response
  640.      */
  641.     public function manageCandidates(Request $requestAuthorizationCheckerInterface $authCheckerUserRepository $userRepository)
  642.     {
  643.         $verificated $this->verificateUser($authChecker);
  644.         $em $this->getDoctrine()->getManager();
  645.         $myJobs $em->getRepository(Job::class)->findBy([
  646.             'user' => $this->getUser()
  647.         ]);
  648.         $users $em->getRepository(User::class)->findUsersByJobsAppiled($myJobs);
  649.         $i 0;
  650.         foreach ($users as $user) {
  651.             if (!$user->getCandidate()) {
  652.                 unset($users[$i]);
  653.             }
  654.             $i++;
  655.         }
  656.         $pagination $this->get('knp_paginator')->paginate(
  657.             $users,
  658.             $request->query->getInt('page'1),
  659.             10
  660.         );
  661.         $pagination->setTemplate('site/pagination.html.twig');
  662.         $path $this->getParameter('app.path.user_cv') . '/';
  663.         $paymentMetadata = [
  664.             'jobs' => $this->jobService->getCurrentJobPackage($this->getUser()),
  665.             'services' => $this->jobService->getCurrentServicesPackage($this->getUser())
  666.         ];
  667.         return $this->render(
  668.             'user/employer/candidate.html.twig',
  669.             array(
  670.                 'verificated_acount' => $verificated,
  671.                 'candidates' => $pagination,
  672.                 'notifications' => $this->loadNotifications(),
  673.                 'url' => $path,
  674.                 'paymentMetadata' => $paymentMetadata
  675.             )
  676.         );
  677.     }
  678.     /**
  679.      * @param User $candidate
  680.      * @param Request $request
  681.      * @return JsonResponse|Response
  682.      *
  683.      * @Route ("/send_message/{id}", name="enviar_mensaje_de_correo" )
  684.      */
  685.     public function sendEmail(User $candidateRequest $request)
  686.     {
  687.         $message = new ContactMessage();
  688.         $message->setDestinatario($candidate);
  689.         $form $this->createForm(ContactMessageFormType::class, $message, [
  690.             'action' => $this->generateUrl('enviar_mensaje_de_correo', ['id' => $candidate->getId()])
  691.         ]);
  692.         $form->handleRequest($request);
  693.         if ($form->isSubmitted() && $form->isValid()) {
  694.             $em $this->getDoctrine()->getManager();
  695.             $message->setDate(new \DateTime('now'));
  696.             $message->setCreator($this->getUser());
  697.             $message->setDestinatario($candidate);
  698.             $em->persist($message);
  699.             $em->flush();
  700.             $this->mailer->sendEmailCandidate($message);
  701.             return new JsonResponse([
  702.                 'type' => 'success',
  703.                 'message' => 'Mensaje enviado'
  704.             ]);
  705.         }
  706.         return $this->render('user/senMessage.html.twig', [
  707.             'form' => $form->createView()
  708.         ]);
  709.     }
  710.     /**
  711.      * @param User $candidate
  712.      * @param ContactMessageRepository $messageRepository
  713.      * @return Response
  714.      *
  715.      * @Route ("/find_messages/{id}", name="buscar_mensajes", options={"expose" = true})
  716.      */
  717.     public function getEmails(User $candidateContactMessageRepository $messageRepository)
  718.     {
  719.         $employer $this->getUser();
  720.         return $this->render('user/employer/conversaciones.html.twig', [
  721.             'conversaciones' => $messageRepository->findByCandidate($candidate$employer),
  722.             'candidato' => $candidate
  723.         ]);
  724.     }
  725.     /**
  726.      * @param Job $job
  727.      * @param Request $request
  728.      * @return Response
  729.      * @Route("/candidates/job/{id}/detail", name="canditate_detail_by_job")
  730.      */
  731.     public function showCandidates(Job $jobRequest $request)
  732.     {
  733.         $candidates = [];
  734.         foreach ($job->getUserJobMetadata() as $metadata) {
  735.             if ($metadata->getStatus() == UserJobMeta::STATUS_APPLIED) {
  736.                 $candidates[] = $metadata->getUser();
  737.             }
  738.         }
  739.         $pagination $this->get('knp_paginator')->paginate(
  740.             $candidates,
  741.             $request->query->getInt('page'1),
  742.             10
  743.         );
  744.         $pagination->setTemplate('site/pagination.html.twig');
  745.         return $this->render('user/employer/show_candidates.html.twig', [
  746.             'candidates' => $pagination,
  747.             'notifications' => $this->loadNotifications(),
  748.             'job' => $job
  749.         ]);
  750.     }
  751.     /**
  752.      * @param User $canditate
  753.      * @param AuthorizationCheckerInterface $authChecker
  754.      * @return Response
  755.      *
  756.      * @Route("/candidate/{id}/detail", name="canditate_detail")
  757.      */
  758.     public function candidateDetails(User $canditateAuthorizationCheckerInterface $authChecker)
  759.     {
  760.         $verificated $this->verificateUser($authChecker);
  761.         return $this->render(
  762.             'user/employer/candidate_detail.html.twig',
  763.             array(
  764.                 'verificated_acount' => $verificated,
  765.                 'notifications' => $this->loadNotifications(),
  766.                 'candidate' => $canditate,
  767.             )
  768.         );
  769.     }
  770.     /**
  771.      * @param User $destinanario
  772.      * @param Request $request
  773.      * @return Response
  774.      * @throws Exception
  775.      * @Route("/sendContactMessage/{id}", name="sendContactMessage", options={"expose" = true})
  776.      */
  777.     public function sendMessage(User $destinanarioRequest $request)
  778.     {
  779.         $user $this->getUser();
  780.         $message = new ContactMessage();
  781.         $message
  782.             ->setDate(new \DateTime('now'))
  783.             ->setCreator($user)
  784.             ->setDestinatario($destinanario);
  785.         $form $this->createForm(ContactMessageFormType::class, $message, [
  786.             'action' => $this->generateUrl('sendContactMessage', ['id' => $destinanario->getId()])
  787.         ]);
  788.         $form->handleRequest($request);
  789.         if ($form->isSubmitted() && $form->isValid()) {
  790.             $message
  791.                 ->setDate(new \DateTime('now'))
  792.                 ->setCreator($user)
  793.                 ->setDestinatario($destinanario);
  794.             $em $this->getDoctrine()->getManager();
  795.             $em->persist($message);
  796.             $em->flush();
  797.             $mailerThemplate $this->renderView('mail/service_contact.html.twig', [
  798.                 'remit' => $message->getCreator(),
  799.                 'body' => $message->getContext(),
  800.             ]);
  801.             $this->mailer->sendEmailMessage(
  802.                 'Notificación de Benditotrabajo.com',
  803.                 $mailerThemplate,
  804.                 'benditotrabajoecuador@gmail.com',
  805.                 $destinanario->getEmail(),
  806.                 'ubelamgelfonseca@gmail.com'
  807.             );
  808.             return new JsonResponse([
  809.                 'type' => 'success',
  810.                 'message' => 'Mensaje enviado'
  811.             ]);
  812.         }
  813.         return $this->render('user/employer/contactForm.html.twig', [
  814.             'form' => $form->createView()
  815.         ]);
  816.     }
  817.     /**
  818.      * @Route("/resume/view/{id}", name="resume_view")
  819.      */
  820.     public function resumeView($id)
  821.     {
  822.         $em $this->getDoctrine()->getManager();
  823.         $user $em->getRepository(User::class)->find($id);
  824.         return $this->render(
  825.             'user/resumeView.html.twig',
  826.             array(
  827.                 'user' => $user,
  828.                 'notifications' => $this->loadNotifications(),
  829.             )
  830.         );
  831.     }
  832.     /**
  833.      * @Route("/dowload/cv/{name}/{username}", name="dowload_cv")
  834.      */
  835.     public function dowloadCv($name$username)
  836.     {
  837.         try {
  838.             $base $this->getParameter('kernel.project_dir') . '/public/';
  839.             $path $this->getParameter('app.path.user_cv') . '/';
  840.             $response = new BinaryFileResponse($base $path $name);
  841.             $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT$username '_' $name);
  842.             return $response;
  843.         } catch (FileNotFoundException $exception) {
  844.             return new Response('File not found');
  845.         }
  846.     }
  847.     /**
  848.      * @Route("acount/verificate", name="acount_verificate")
  849.      *
  850.      */
  851.     public function verificateAcount(Request $request)
  852.     {
  853.         if (null !== $request->get('code')) {
  854.             $currentUser $this->get('security.token_storage')->getToken()->getUser();
  855.             if ($currentUser->getSecret() == $request->get('code')) {
  856.                 $em $this->getDoctrine()->getManager();
  857.                 $currentUser->setVerificated(true);
  858.                 $em->flush();
  859.                 return $this->redirectToRoute('homepage');
  860.             } else {
  861.                 $this->addFlash('error''Código de verificación incorrecto');
  862.                 return $this->redirectToRoute('homepage');
  863.             }
  864.         }
  865.         return $this->render('site/acount_verificate.html.twig');
  866.     }
  867.     /**
  868.      * @Route("send/code", name="send_code")
  869.      */
  870.     public function sendCode(\Swift_Mailer $mailer)
  871.     {
  872.         /** @var User $currentUser */
  873.         $currentUser $this->get('security.token_storage')->getToken()->getUser();
  874.         if (empty($currentUser->getSecret())) {
  875.             $currentUser->setSecret(rand(1000099999));
  876.         }
  877.         $message = (new \Swift_Message('Código de verificación'))
  878.             ->setFrom('benditotrabajoecuador@gmail.com')
  879.             ->setBody(
  880.                 $this->renderView(
  881.                     'mail/code.html.twig',
  882.                     [
  883.                         'code' => $currentUser->getSecret(),
  884.                     ]
  885.                 ),
  886.                 'text/html'
  887.             )
  888.             ->setTo($currentUser->getEmail());
  889.         $mailer->send($message);
  890.         $this->addFlash('success''Se ha enviado el código a ' $currentUser->getEmail());
  891.         return $this->redirectToRoute('homepage');
  892.     }
  893.     /**
  894.      * @Route("admin/package", name="admin_package")
  895.      */
  896.     public function packageIndex()
  897.     {
  898.         $em $this->getDoctrine()->getManager();
  899.         $packages $em->getRepository(Payment::class)->findAll();
  900.         return $this->render(
  901.             'admin/dashboard.html.twig',
  902.             array(
  903.                 'notifications' => $this->container->get('app.service.helper')->loadNotifications(),
  904.                 'packages' => $packages,
  905.             )
  906.         );
  907.     }
  908.     /**
  909.      * @Route("/ajax/abaut", name="ajax_about")
  910.      */
  911.     public function aboutAjax(Request $request)
  912.     {
  913.         $entityManager $this->getDoctrine()->getManager();
  914.         $resume $entityManager->getRepository(Resume::class)->findOneBy(
  915.             array('id' => $request->request->get('resume_id'))
  916.         );
  917.         $info $request->request->get('about');
  918.         if ($info != null) {
  919.             $resume->setAboutMe($request->request->get('about'));
  920.         }
  921.         $entityManager->flush();
  922.         $response = new JsonResponse();
  923.         $response->setStatusCode(200);
  924.         $response->setData(
  925.             array(
  926.                 'response' => 'success',
  927.                 'data' => $info,
  928.             )
  929.         );
  930.         return $response;
  931.     }
  932.     /**
  933.      * @Route("/ajax/skill", name="ajax_skill")
  934.      */
  935.     public function skillAjax(Request $request)
  936.     {
  937.         $count $request->request->get('count');
  938.         $info = array();
  939.         for ($i 1$i <= $count$i++) {
  940.             $val $request->request->get('skill-' $i);
  941.             if ($val != null) {
  942.                 $info[] = $val;
  943.             }
  944.         }
  945.         /** @var User $user */
  946.         $user $this->get('security.token_storage')->getToken()->getUser();
  947.         $user->setSkillArray($info);
  948.         $entityManager $this->getDoctrine()->getManager();
  949.         $entityManager->flush();
  950.         $response = new JsonResponse();
  951.         $response->setStatusCode(200);
  952.         $response->setData(
  953.             array(
  954.                 'response' => 'success',
  955.                 'data' => $info,
  956.             )
  957.         );
  958.         return $response;
  959.     }
  960.     /**
  961.      * @Route("/ajax/skill/remove", name="ajax_skill_remove")
  962.      */
  963.     public function removeSkil(Request $request)
  964.     {
  965.         $entityManager $this->getDoctrine()->getManager();
  966.         /** @var User $user */
  967.         $user $this->get('security.token_storage')->getToken()->getUser();
  968.         $item $request->request->get('item');
  969.         $user->remove_skill($item);
  970.         $entityManager->flush();
  971.         $response = new JsonResponse();
  972.         $response->setStatusCode(200);
  973.         $response->setData(
  974.             array(
  975.                 'response' => 'success',
  976.                 'data' => $item,
  977.             )
  978.         );
  979.         return $response;
  980.     }
  981.     /**
  982.      * @return Response
  983.      * @Route("/carousel_company", name="carousel_company", options={"expose" = true})
  984.      */
  985.     public function loadCompanies()
  986.     {
  987.         return $this->render('site/includes/carousel_company.html.twig', [
  988.             'companies' => $this->companyService->findActives()
  989.         ]);
  990.     }
  991.     /**
  992.      * @param Request $request
  993.      * @return RedirectResponse|Response
  994.      * @Route("/page", name="static_page_view", options={"expose" = true})
  995.      */
  996.     public function showStaticPage(Request $request)
  997.     {
  998.         $type urldecode($request->query->get('type'));
  999.         /** @var StaticPage $page */
  1000.         $page $this->getDoctrine()->getRepository(StaticPage::class)->findOneBy(['type' => $type]);
  1001.         if (null === $page) {
  1002.             return $this->redirectToRoute('homepage');
  1003.         }
  1004.         return $this->render('site/static_page.html.twig', [
  1005.             'page' => $page,
  1006.             'notifications' => $this->container->get('app.service.helper')->loadNotifications(),
  1007.         ]);
  1008.     }
  1009.     /**
  1010.      * @param Request $request
  1011.      * @return JsonResponse
  1012.      *
  1013.      * @Route ("/check_email", name="check_email", options={"expose" = true})
  1014.      */
  1015.     public function checkEmail(Request $request)
  1016.     {
  1017.         $email $request->query->get('email');
  1018.         $em $this->getDoctrine()->getManager();
  1019.         $user $em->getRepository(User::class)->findOneBy([
  1020.             'email' => $email
  1021.         ]);
  1022.         return new JsonResponse([
  1023.             'valid' => $user false true
  1024.         ]);
  1025.     }
  1026.     /**
  1027.      * @param Request $request
  1028.      * @return Response
  1029.      *
  1030.      * @throws Exception
  1031.      * @Route ("/view_emails", name="emails_view", options={"expose" = true})
  1032.      */
  1033.     public function loadEmails(Request $request)
  1034.     {
  1035.         $datatable $this->datatableFactory->create(emailsDatatable::class);
  1036.         $datatable->buildDatatable([
  1037.             'url' => $this->generateUrl('emails_view')
  1038.         ]);
  1039.         if ($request->isXmlHttpRequest() && $request->isMethod('POST')) {
  1040.             $this->datatableResponse->setDatatable($datatable);
  1041.             $builder $this->datatableResponse->getDatatableQueryBuilder();
  1042.             if ($this->isGranted('ROLE_ADMIN')) {
  1043.                 $builder->getQb()
  1044.                     ->where('contactmessage.creator=:user')
  1045.                     ->setParameter('user'$this->getUser());
  1046.             } else {
  1047.                 $builder->getQb()
  1048.                     ->where('contactmessage.destinatario=:user')
  1049.                     ->setParameter('user'$this->getUser());
  1050.             }
  1051.             return $this->datatableResponse->getResponse();
  1052.         }
  1053.         return $this->render('mail/emails_list.html.twig', [
  1054.             'datatable' => $datatable
  1055.         ]);
  1056.     }
  1057. }