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.

144 lines
4.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Admin;
  4. use App\Controller\ChatController;
  5. use App\Entity\Contable;
  6. use App\Entity\Bso;
  7. use App\Entity\Licitador;
  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. use HttpInvalidParamException;
  20. use Symfony\Component\Intl\Countries;
  21. use Symfony\Component\Routing\Exception\InvalidParameterException;
  22. use Symfony\Component\HttpFoundation\Request;
  23. final class SupervisorAdminController extends CRUDController
  24. {
  25. private $chatController;
  26. public function __construct(ChatController $chatController)
  27. {
  28. $this->chatController = $chatController;
  29. }
  30. /**
  31. * Export data to specified format.
  32. *
  33. * @param Request $request
  34. *
  35. * @return Response
  36. *
  37. * @throws AccessDeniedException If access is not granted
  38. * @throws \RuntimeException If the export format is invalid
  39. */
  40. public function exportAction(Request $request = null)
  41. {
  42. //$request = $this->resolveRequest($request);
  43. $request = $this->getRequest();
  44. $this->admin->checkAccess('export');
  45. $format = $request->get('format');
  46. $allowedExportFormats = (array) $this->admin->getExportFormats();
  47. if (!in_array($format, $allowedExportFormats)) {
  48. throw new \RuntimeException(
  49. sprintf(
  50. 'Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`',
  51. $format,
  52. $this->admin->getClass(),
  53. implode(', ', $allowedExportFormats)
  54. )
  55. );
  56. }
  57. $filename = sprintf(
  58. 'export_%s_%s.%s',
  59. strtolower(substr($this->admin->getClass(), strripos($this->admin->getClass(), '\\') + 1)),
  60. date('Y_m_d_H_i_s', strtotime('now')),
  61. $format
  62. );
  63. return $this->get('sonata.admin.exporter')->getResponse(
  64. $format,
  65. $filename,
  66. $this->admin->getDataSourceIterator()
  67. );
  68. }
  69. public function contactarAjaxAction($id){
  70. $user = $this->getUser();
  71. if(!($user instanceof Contable) && !($user instanceof Bso)){
  72. die("not instance of Bso");
  73. throw new AccessDeniedHttpException();
  74. }
  75. $em = $this->getDoctrine()->getManager();
  76. $ge = $em->getReference(User::class, $id);
  77. if($ge->getType()!=='trainer'){
  78. die("not instance of Supervisor".$ge->getType());
  79. throw new AccessDeniedHttpException();
  80. }
  81. $sala = new Sala();
  82. $sala->addUser($user);
  83. $sala->addUser($ge);
  84. $sala->setDenominacion('Contacto');
  85. $lastAccess = new SalaLastAccess();
  86. $lastAccess->setSala($sala);
  87. $lastAccess->setUser($ge);
  88. $lastAccess->setLastAccess(new \DateTime("1970-01-01"));
  89. $em->persist($lastAccess);
  90. $sala->addSalaLastAccess($lastAccess);
  91. $em->persist($sala);
  92. $ge->addContacto($user);
  93. $user->addContacto($ge);
  94. $em->persist($ge);
  95. $em->persist($user);
  96. $em->flush();
  97. //$route = $this->generateUrl('admin_app_trainer_giveAccessToFiles', ['id'=> $user->getId()]);
  98. if($user instanceof Bso){
  99. $message = "A Bso would like to talk to you.<br>";//<a href=\"{$route}\">Give access to files</a>";
  100. }else{
  101. $message = "A financial actor would like to talk to you.<br>";//<a href=\"{$route}\">Give access to files</a>";
  102. }
  103. $this->chatController->publishMessage($message, $user, $sala);
  104. return new RedirectResponse($this->generateUrl('sonata_admin_dashboard'));
  105. return new JsonResponse("success", 200);
  106. }
  107. public function giveAccessToFilesAction($id){
  108. if(!$this->isXmlHttpRequest()){
  109. throw new AccessDeniedHttpException();
  110. }
  111. $user = $this->getUser();
  112. if(!($user instanceof Licitador)){
  113. throw new AccessDeniedHttpException();
  114. }
  115. $em = $this->getDoctrine()->getManager();
  116. $fa = $em->getReference(User::class, $id);
  117. if(!($fa instanceof Contable)){
  118. throw new AccessDeniedHttpException();
  119. }
  120. $user->addFinancial($fa);
  121. $em->persist($user);
  122. $em->flush();
  123. $modalBody = "You have successfully shared your documents with ".$fa->getNombreCompleto();
  124. $modalTitle = "Congratulations!!!";
  125. return $this->renderWithExtraParams('listajaxactions/modal_content.html.twig', [
  126. 'modalTitle' => $modalTitle,
  127. 'modalBody' => $modalBody,
  128. ], null);
  129. }
  130. }