Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
3.2 KiB

5 years ago
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Admin;
  4. use App\Controller\ChatController;
  5. use App\Entity\FinancialActor;
  6. use App\Entity\Bso;
  7. use App\Entity\GreenEntrepreneur;
  8. use App\Entity\Sala;
  9. use App\Entity\SalaLastAccess;
  10. use App\Entity\Tarea;
  11. use App\Entity\User;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use phpDocumentor\Reflection\Types\Object_;
  14. use Sonata\AdminBundle\Controller\CRUDController;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  18. use Symfony\Component\HttpFoundation\RedirectResponse;
  19. final class TrainerAdminController extends CRUDController
  20. {
  21. private $chatController;
  22. public function __construct(ChatController $chatController)
  23. {
  24. $this->chatController = $chatController;
  25. }
  26. public function contactarAjaxAction($id){
  27. $user = $this->getUser();
  28. if(!($user instanceof FinancialActor) && !($user instanceof Bso)){
  29. throw new AccessDeniedHttpException();
  30. }
  31. $em = $this->getDoctrine()->getManager();
  32. $ge = $em->getReference(User::class, $id);
  33. if(!($ge instanceof Trainer)){
  34. throw new AccessDeniedHttpException();
  35. }
  36. $sala = new Sala();
  37. $sala->addUser($user);
  38. $sala->addUser($ge);
  39. $sala->setDenominacion('Contacto');
  40. $lastAccess = new SalaLastAccess();
  41. $lastAccess->setSala($sala);
  42. $lastAccess->setUser($ge);
  43. $lastAccess->setLastAccess(new \DateTime("1970-01-01"));
  44. $em->persist($lastAccess);
  45. $sala->addSalaLastAccess($lastAccess);
  46. $em->persist($sala);
  47. $ge->addContacto($user);
  48. $user->addContacto($ge);
  49. $em->persist($ge);
  50. $em->persist($user);
  51. $em->flush();
  52. $route = $this->generateUrl('admin_app_trainer_giveAccessToFiles', ['id'=> $user->getId()]);
  53. $message = "A financial actor would like to talk to you.<br><a href=\"{$route}\">Give access to files</a>";
  54. $message = "A financial actor would like to talk to you.<br><a href=\"{$route}\">Give access to files</a>";
  55. $this->chatController->publishMessage($message, $user, $sala);
  56. return new RedirectResponse($this->generateUrl('sonata_admin_dashboard'));
  57. return new JsonResponse("success", 200);
  58. }
  59. public function giveAccessToFilesAction($id){
  60. if(!$this->isXmlHttpRequest()){
  61. throw new AccessDeniedHttpException();
  62. }
  63. $user = $this->getUser();
  64. if(!($user instanceof GreenEntrepreneur)){
  65. throw new AccessDeniedHttpException();
  66. }
  67. $em = $this->getDoctrine()->getManager();
  68. $fa = $em->getReference(User::class, $id);
  69. if(!($fa instanceof FinancialActor)){
  70. throw new AccessDeniedHttpException();
  71. }
  72. $user->addFinancial($fa);
  73. $em->persist($user);
  74. $em->flush();
  75. $modalBody = "You have successfully shared your documents with ".$fa->getNombreCompleto();
  76. $modalTitle = "Congratulations!!!";
  77. return $this->renderWithExtraParams('listajaxactions/modal_content.html.twig', [
  78. 'modalTitle' => $modalTitle,
  79. 'modalBody' => $modalBody,
  80. ], null);
  81. }
  82. }