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
144 lines
4.9 KiB
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Admin;
|
|
|
|
use App\Controller\ChatController;
|
|
use App\Entity\Contable;
|
|
use App\Entity\Bso;
|
|
use App\Entity\Licitador;
|
|
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;
|
|
use HttpInvalidParamException;
|
|
use Symfony\Component\Intl\Countries;
|
|
use Symfony\Component\Routing\Exception\InvalidParameterException;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
final class SupervisorAdminController extends CRUDController
|
|
{
|
|
private $chatController;
|
|
|
|
public function __construct(ChatController $chatController)
|
|
{
|
|
$this->chatController = $chatController;
|
|
}
|
|
|
|
/**
|
|
* Export data to specified format.
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return Response
|
|
*
|
|
* @throws AccessDeniedException If access is not granted
|
|
* @throws \RuntimeException If the export format is invalid
|
|
*/
|
|
public function exportAction(Request $request = null)
|
|
{
|
|
//$request = $this->resolveRequest($request);
|
|
$request = $this->getRequest();
|
|
$this->admin->checkAccess('export');
|
|
|
|
$format = $request->get('format');
|
|
|
|
$allowedExportFormats = (array) $this->admin->getExportFormats();
|
|
|
|
if (!in_array($format, $allowedExportFormats)) {
|
|
throw new \RuntimeException(
|
|
sprintf(
|
|
'Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`',
|
|
$format,
|
|
$this->admin->getClass(),
|
|
implode(', ', $allowedExportFormats)
|
|
)
|
|
);
|
|
}
|
|
|
|
$filename = sprintf(
|
|
'export_%s_%s.%s',
|
|
strtolower(substr($this->admin->getClass(), strripos($this->admin->getClass(), '\\') + 1)),
|
|
date('Y_m_d_H_i_s', strtotime('now')),
|
|
$format
|
|
);
|
|
|
|
return $this->get('sonata.admin.exporter')->getResponse(
|
|
$format,
|
|
$filename,
|
|
$this->admin->getDataSourceIterator()
|
|
);
|
|
}
|
|
public function contactarAjaxAction($id){
|
|
$user = $this->getUser();
|
|
if(!($user instanceof Contable) && !($user instanceof Bso)){
|
|
die("not instance of Bso");
|
|
throw new AccessDeniedHttpException();
|
|
}
|
|
$em = $this->getDoctrine()->getManager();
|
|
$ge = $em->getReference(User::class, $id);
|
|
if($ge->getType()!=='trainer'){
|
|
die("not instance of Supervisor".$ge->getType());
|
|
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()]);
|
|
if($user instanceof Bso){
|
|
$message = "A Bso would like to talk to you.<br>";//<a href=\"{$route}\">Give access to files</a>";
|
|
}else{
|
|
$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 Licitador)){
|
|
throw new AccessDeniedHttpException();
|
|
}
|
|
$em = $this->getDoctrine()->getManager();
|
|
$fa = $em->getReference(User::class, $id);
|
|
if(!($fa instanceof Contable)){
|
|
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);
|
|
}
|
|
|
|
}
|