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.
|
|
<?php
declare(strict_types=1);
namespace App\Controller\Admin;
use App\Controller\ChatController;use App\Entity\FinancialActor;use App\Entity\Bso;use App\Entity\GreenEntrepreneur;use App\Entity\Sala;use App\Entity\SalaLastAccess;use App\Entity\Tarea;use App\Entity\User;use Doctrine\Common\Collections\ArrayCollection;use phpDocumentor\Reflection\Types\Object_;use Sonata\AdminBundle\Controller\CRUDController;use Symfony\Component\HttpFoundation\JsonResponse;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;use Symfony\Component\HttpFoundation\RedirectResponse;
final class TrainerAdminController extends CRUDController{ private $chatController;
public function __construct(ChatController $chatController) { $this->chatController = $chatController; }
public function contactarAjaxAction($id){ $user = $this->getUser(); if(!($user instanceof FinancialActor) && !($user instanceof Bso)){ throw new AccessDeniedHttpException(); } $em = $this->getDoctrine()->getManager(); $ge = $em->getReference(User::class, $id); if(!($ge instanceof Trainer)){ throw new AccessDeniedHttpException(); } $sala = new Sala(); $sala->addUser($user); $sala->addUser($ge); $sala->setDenominacion('Contacto'); $lastAccess = new SalaLastAccess(); $lastAccess->setSala($sala); $lastAccess->setUser($ge); $lastAccess->setLastAccess(new \DateTime("1970-01-01")); $em->persist($lastAccess); $sala->addSalaLastAccess($lastAccess); $em->persist($sala); $ge->addContacto($user); $user->addContacto($ge); $em->persist($ge); $em->persist($user); $em->flush(); $route = $this->generateUrl('admin_app_trainer_giveAccessToFiles', ['id'=> $user->getId()]); $message = "A financial actor would like to talk to you.<br><a href=\"{$route}\">Give access to files</a>"; $message = "A financial actor would like to talk to you.<br><a href=\"{$route}\">Give access to files</a>"; $this->chatController->publishMessage($message, $user, $sala); return new RedirectResponse($this->generateUrl('sonata_admin_dashboard'));
return new JsonResponse("success", 200); } public function giveAccessToFilesAction($id){ if(!$this->isXmlHttpRequest()){ throw new AccessDeniedHttpException(); } $user = $this->getUser(); if(!($user instanceof GreenEntrepreneur)){ throw new AccessDeniedHttpException(); } $em = $this->getDoctrine()->getManager(); $fa = $em->getReference(User::class, $id); if(!($fa instanceof FinancialActor)){ throw new AccessDeniedHttpException(); } $user->addFinancial($fa); $em->persist($user); $em->flush(); $modalBody = "You have successfully shared your documents with ".$fa->getNombreCompleto(); $modalTitle = "Congratulations!!!"; return $this->renderWithExtraParams('listajaxactions/modal_content.html.twig', [ 'modalTitle' => $modalTitle, 'modalBody' => $modalBody, ], null); }
}
|