src/Controller/OutOfOfficeController.php line 561

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions
  4.  * Date: 19/09/2019
  5.  */
  6. namespace App\Controller;
  7. use App\Entity\Client;
  8. use App\Entity\OutOfOffice;
  9. use App\Entity\User;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\HttpFoundation\JsonResponse;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use App\Form\OutOfOfficeType;
  16. use App\MDS\EventsBundle\Entity\Proposal;
  17. use Swift_Mailer;
  18. use Swift_Message;
  19. use Swift_SmtpTransport;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. class OutOfOfficeController extends AbstractController
  22. {
  23.     private $translator;
  24.     public function __construct(TranslatorInterface $translator) {
  25.         $this->translator $translator;
  26.     }
  27.     
  28.     /**
  29.      * @Route("/outofoffice", name="outofoffice_home")
  30.      */
  31.     public function indexOutOfOfficeAction(Request $request) {
  32.         return $this->redirectToRoute('outofoffice_index');
  33.     }
  34.     /**
  35.      * @Route("/outofoffice/list", name="outofoffice_index")
  36.      */
  37.     public function listAction(Request $request) {
  38.         $em $this->getDoctrine()->getManager();
  39.         // No se realizará la busqueda de todos los OOO, solo se listarán los que tengan fecha de hoy en adelante
  40.         $today = new \DateTime("now"NULL);
  41.         $yesterday $today->modify("-1 day");
  42.         $parameters = array(
  43.             'yesterday' => $yesterday,
  44.         );
  45.         $dql 'SELECT p
  46.                         FROM App:OutOfOffice p
  47.                         WHERE p.dateAt > :yesterday 
  48.                         ORDER BY p.dateAt DESC ';
  49.         $query $em->createQuery($dql)->setParameters($parameters);
  50.         $ooo $query->getResult();
  51.         $data = array();
  52.         foreach($ooo as $item) {
  53.             if (!empty($item->getProposalId())) {
  54.                 $proposal $em->getRepository(Proposal::class)->findOneById($item->getProposalId());
  55.                 $proposalInfo '#'.$proposal->getId().' - '.$proposal->getTitle();
  56.             } else {
  57.                 $proposal null;
  58.                 $proposalInfo null;
  59.             }
  60.             $arrayAgents = array();
  61.             $arrayAgentsNames = array();
  62.             $arrayAgentsIds explode(","$item->getAgentsIds());
  63.             foreach ($arrayAgentsIds as $agentId){
  64.                 $agent $em->getRepository(User::class)->findOneById($agentId);
  65.                 if(!is_null($agent)){
  66.                     $arrayAgents[] = $agent;
  67.                     $arrayAgentsNames[] = $agent->getName().' '.$agent->getLastName();
  68.                 }
  69.             }
  70.             $agentsNames implode(", "$arrayAgentsNames);
  71.             if (!empty($item->getClientId())) {
  72.                 $client $em->getRepository(Client::class)->findOneById($item->getClientId());
  73.             } else {
  74.                 $client null;
  75.             }
  76.             $ref = ($item->getDateAt())->format('Ymd');
  77.             // Se eliminan las 2 primeras cifras del año 2000 para reducir la longitud del string
  78.             $ref '#'.substr($ref,2);
  79.             if ($item->getDateAt() == $item->getDateFinalAt()){
  80.                 $dateAt = ($item->getDateAt())->format('d-m-Y');
  81.             } else {
  82.                 $dateAt = ($item->getDateAt())->format('d-m-Y').' al '.($item->getDateFinalAt())->format('d-m-Y');
  83.             }
  84.             $data[] = array(
  85.                 'id' => $item->getId(),
  86.                 'ref' => $ref,
  87.                 'status' => $item->getStatus(),
  88.                 'dateAt' => $dateAt,
  89.                 'hourStart' => ($item->getHourStart())->format('H:i'),
  90.                 'hourEnd' => ($item->getHourEnd())->format('H:i'),
  91.                 'proposal' => $proposal,
  92.                 'proposalInfo' => $proposalInfo,
  93.                 'client' => $client,
  94.                 'text' => $item->getText(),
  95.                 'arrayAgents' => $arrayAgents,
  96.                 'agentsNames' => $agentsNames
  97.             );
  98.         }
  99. //d($data);exit();
  100.         //Usuario Loggeado
  101.         $loggedUser $this->get('security.token_storage')->getToken()->getUser();
  102.         return $this->render('outofoffice/outofoffice/list-outofoffice.html.twig', array(
  103.             'outofoffice' => $data,
  104.             'historic' => false,
  105.             'user' => $loggedUser
  106.         ));
  107.     }
  108.     /**
  109.      * @Route("/outofoffice/add",  name="outofoffice_add")
  110.      */
  111.     public function addOutOfOfficeAction(Request $request)
  112.     {
  113.         $ooo = new OutOfOffice();
  114.         $form $this->createOutOfOfficeCreateForm($ooo);
  115.         return $this->render('outofoffice/outofoffice/add-outofoffice.html.twig',
  116.             array(
  117. //                'description' => '',
  118.                 'form' => $form->createView()
  119.             )
  120.         );
  121.     }
  122.     private function createOutOfOfficeCreateForm(OutOfOffice $entity)
  123.     {
  124.         $form $this->createForm(OutOfOfficeType::class, $entity, array(
  125.             'action' => $this->generateUrl('outofoffice_create'),
  126.             'method' => 'POST'
  127.         ));
  128.         return $form;
  129.     }
  130.     /**
  131.      * @Route("/outofoffice/create", name="outofoffice_create")
  132.      */
  133.     public function createOutOfOfficeAction(Request $request)
  134.     {
  135.         $ooo = new OutOfOffice();
  136.         $form $this->createOutOfOfficeCreateForm($ooo);
  137.         $form->handleRequest($request);
  138.         if($form->isValid())
  139.         {
  140.             $em $this->getDoctrine()->getManager();
  141.             /* Obtengo usuario logueado */
  142.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  143.             $user_id $user_logueado->getId();
  144.             $today = new \DateTime("now");
  145.             $ooo->setCreatedId($user_id);
  146.             $ooo->setUpdatedId($user_id);
  147.             $ooo->setCreatedAt($today);
  148.             $ooo->setUpdatedAt($today);
  149.             $ooo->setStatus(null);
  150.             if (!empty($ooo->getClientId())) {
  151.                 $ooo->setClientId($ooo->getClientId()->getId());
  152.             }
  153.             if (!empty($ooo->getProposalId())) {
  154.                 $ooo->setProposalId($ooo->getProposalId()->getId());
  155.             }
  156.             // Se genera la lista de los agentes
  157.             $listAgents '';
  158.             /**
  159.              * @var ArrayCollection $ooo->getAgentsIds()
  160.              */
  161.             foreach ($ooo->getAgentsIds() as $item){
  162.                 if (!empty($listAgents)){
  163.                     $listAgents $listAgents.','.$item->getId();
  164.                 } else {
  165.                     $listAgents $item->getId();
  166.                 }
  167.             }
  168.             $ooo->setAgentsIds($listAgents);
  169.             //Verificación de fechas
  170.             if (empty($ooo->getDateFinalAt())){
  171.                 $ooo->setDateFinalAt($ooo->getDateAt());
  172.             }
  173.             try{
  174.                 $em->persist($ooo);
  175.                 $em->flush();
  176.                 // INICIO: Envio de Correo a administradores por FDO
  177.                 // Nombre de los agentes involucrados en la FDO
  178.                 $textoAgentes ='';
  179.                 // Se genera el arreglo de agentes a partir del agentsIds
  180.                 $arraysIds explode(',',$ooo->getAgentsIds());
  181.                 foreach ($arraysIds as $item){
  182.                     $agent $em->getRepository(User::class)->findOneById($item);
  183.                     if(!empty($textoAgentes)){
  184.                         $textoAgentes $textoAgentes', '$agent->getName().' '.$agent->getLastName();
  185.                     } else {
  186.                         $textoAgentes $agent->getName().' '.$agent->getLastName();
  187.                     }
  188.                 }
  189.                 if (!empty($ooo->getProposalId())){
  190.                     $proposal $em->getRepository(Proposal::class)->findOneById($ooo->getProposalId());
  191.                     $textoProposal ' '$proposal->getTitle();
  192.                 } else {
  193.                     $textoProposal '';
  194.                 }
  195.                 $loggedUser $em->getRepository(User::class)->findOneById($user_id);
  196.                 $allAdmins $em->getRepository(User::class)->findBy(
  197.                     array(
  198.                         'role' => 'ROLE_ADMIN'
  199.                     ));
  200.                 $mailAgentSent = array();
  201.                 foreach ($allAdmins as $item){
  202.                     $mailAgentSent[$item->getEmail()] = $item->getName().' '.$item->getLastName();
  203.                 }
  204.                 if ($ooo->getDateAt() == $ooo->getDateFinalAt()){
  205.                     // Es un solo dia de actividad
  206.                     $textoDias 'El día de la actividad es: '.($ooo->getDateAt())->format('d/m/Y');
  207.                 } else {
  208.                     // Son varios dias de actividad
  209.                     $textoDias 'Los días de la actividad son: del '.($ooo->getDateAt())->format('d/m/Y').' al '.($ooo->getDateFinalAt())->format('d/m/Y');
  210.                 }
  211.                 $textoHoras 'La actividad comienza a las '.($ooo->getHourStart())->format('H:i');
  212.                 if (!((($ooo->getHourEnd())->format('H')=='00') and (($ooo->getHourEnd())->format('i')=='00'))) {
  213.                     $textoHoras $textoHoras ' y finaliza a las ' . ($ooo->getHourEnd())->format('H:i');
  214.                 }
  215.                 $data = array(
  216.                     'body' => '' '<p>Estimado administrador, ha sido creada la actividad fuera de oficina. &nbsp;</p>                        
  217.                     <p><h2>' $textoProposal '</h2></p>
  218.                     <p>Los agentes de esta actividad son: <strong>' $textoAgentes '</strong></p>                                               
  219.                     <p>'.$textoDias.'</p>   
  220.                     <p>'.$textoHoras.'</p>
  221.                     <br>   
  222.                     <br>                       
  223.                     <a href="https://'.$_SERVER['HTTP_HOST'].'/outofoffice/status/1/' $ooo->getId() .'"
  224.                     style="background-color:#0048ff;border:1px solid #3870ff;border-radius:3px;color:#ffffff;display:inline-block;
  225.                     font-family:sans-serif;font-size:16px;line-height:44px;text-align:center;text-decoration:none;width:150px"
  226.                     target="_blank">Aprobar</a>
  227.                     <a href="https://'.$_SERVER['HTTP_HOST'].'/outofoffice/edit/' $ooo->getId() .'"
  228.                     style="background-color:#5cb85c;border:1px solid #5cb85c;border-radius:3px;color:#ffffff;display:inline-block;
  229.                     font-family:sans-serif;font-size:16px;line-height:44px;text-align:center;text-decoration:none;width:150px"
  230.                     target="_blank">Editar</a>
  231.                     <a href="https://'.$_SERVER['HTTP_HOST'].'/outofoffice/status/0/' $ooo->getId() .'"
  232.                     style="background-color:#ff0700;border:1px solid #d9534f;border-radius:3px;color:#ffffff;display:inline-block;
  233.                     font-family:sans-serif;font-size:16px;line-height:44px;text-align:center;text-decoration:none;width:150px"
  234.                     target="_blank">Rechazar</a>
  235.                     
  236.                     <br>
  237.                     <p>El usuario que hizo esta solicitud fue: ' $loggedUser->getName() .' '$loggedUser->getLastName() . '</p>'
  238.                 ,
  239. //                        'firm' => '' . '<div dir="ltr" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px;"><table border="0" cellpadding="0" style="font-size: 13.3333px; font-family: Verdana, Arial, Helvetica, sans-serif;"><tbody><tr><td width="35%" style="font-family: arial, sans-serif; margin: 0px;"><img src="https://ci4.googleusercontent.com/proxy/xTPcHPPSpFqSf8EjRTvJIv21y6LHuzwbsDqBA4oxRzrrUZQWNYERW7oMbgXjw6CzSDsE9QqPHEk9PiNylx5UaAuSJykk6eA3WiyMGmZmQYc=s0-d-e1-ft#http://www.inout-travel.com/inout-travel/img/logo/logo.jpg" alt="Logo InOut Travel" class="CToWUd"></td><td width="65%" style="font-family: arial, sans-serif; margin: 0px;"><p style="margin-bottom: 0px;"></p><span style="font-size: small; color: rgb(0, 121, 186);"><b>M.I.C.E Dept.</b>&nbsp;<br></span><span style="font-size: x-small; color: rgb(0, 121, 186);">Phone :&nbsp;<a href="tel:+34%20911%2087%2083%2093" value="+34911878393" target="_blank" style="color: rgb(17, 85, 204);">+34 91 187 83 93</a>&nbsp;/&nbsp;<a href="tel:+34%20917%2058%2007%2020" value="+34917580720" target="_blank" style="color: rgb(17, 85, 204);">+34 91 758 07 20</a>&nbsp;</span><span style="font-size: x-small; color: rgb(0, 121, 186);">Fax :&nbsp;<a href="tel:+34%20911%2087%2083%2090" value="+34911878390" target="_blank" style="color: rgb(17, 85, 204);">+34 91 187 83&nbsp;90</a>&nbsp;<br></span><span style="font-size: x-small; color: rgb(0, 121, 186);"><u></u><a href="mailto:eventos@inout-travel.com" target="_blank" style="color: rgb(17, 85, 204);">eventos@inout-travel.com&nbsp;</a><br></span><span style="font-size: small; color: rgb(0, 128, 128);"><a href="http://s.wisestamp.com/links?url=http%3A%2F%2Fs.wisestamp.com%2Flinks%3Furl%3Dhttps%253A%252F%252Furldefense.proofpoint.com%252Fv1%252Furl%253Fu%253Dhttp%253A%252F%252Fs.wisestamp.com%252Flinks%253Furl%25253Dhttp%2525253A%2525252F%2525252Fs.wisestamp.com%2525252Flinks%2525253Furl%2525253Dhttp%252525253A%252525252F%252525252Fwww.inout-travel.com%25252526amp%2525253Bsn%2525253D%252526sn%25253D%2526amp%253Bk%253D2BjihEEf49EEnl2c9cXhDQ%25253D%25253D%25250A%2526amp%253Br%253DoVBgYJTSgqKobIhrxHXwWFa1hslDOFZMhTZjQm3slhE%25253D%25250A%2526amp%253Bm%253DiRaDYfk0sXIZzunVdLJPLTs52u8wk7HMfjdCh290Q5I%25253D%25250A%2526amp%253Bs%253D1a9ff7d8f4f1fb953d74200f6537f77ca64418a966d39f4786e9aed71833d44c%26amp%3Bsn%3D&amp;sn=" target="_blank" data-saferedirecturl="https://www.google.com/url?hl=es&amp;q=http://s.wisestamp.com/links?url%3Dhttp%253A%252F%252Fs.wisestamp.com%252Flinks%253Furl%253Dhttps%25253A%25252F%25252Furldefense.proofpoint.com%25252Fv1%25252Furl%25253Fu%25253Dhttp%25253A%25252F%25252Fs.wisestamp.com%25252Flinks%25253Furl%2525253Dhttp%252525253A%252525252F%252525252Fs.wisestamp.com%252525252Flinks%252525253Furl%252525253Dhttp%25252525253A%25252525252F%25252525252Fwww.inout-travel.com%2525252526amp%252525253Bsn%252525253D%25252526sn%2525253D%252526amp%25253Bk%25253D2BjihEEf49EEnl2c9cXhDQ%2525253D%2525253D%2525250A%252526amp%25253Br%25253DoVBgYJTSgqKobIhrxHXwWFa1hslDOFZMhTZjQm3slhE%2525253D%2525250A%252526amp%25253Bm%25253DiRaDYfk0sXIZzunVdLJPLTs52u8wk7HMfjdCh290Q5I%2525253D%2525250A%252526amp%25253Bs%25253D1a9ff7d8f4f1fb953d74200f6537f77ca64418a966d39f4786e9aed71833d44c%2526amp%253Bsn%253D%26sn%3D&amp;source=gmail&amp;ust=1516881697636000&amp;usg=AFQjCNGFDs4JRUVibUfVQaFSuQ0u9PVwzQ" style="color: rgb(17, 85, 204); font-size: x-small;">http://www.inout-travel.com</a></span><p></p><span style="font-size: small; color: rgb(51, 102, 255);"><a href="https://www.facebook.com/InOutTravel/" target="_blank" data-saferedirecturl="https://www.google.com/url?hl=es&amp;q=https://www.facebook.com/InOutTravel/&amp;source=gmail&amp;ust=1516881697636000&amp;usg=AFQjCNH3zSTpYN6Jn0ibd4io116DlxPPNg" style="color: rgb(17, 85, 204);"><span style="color: rgb(51, 102, 255);"><img src="https://ci5.googleusercontent.com/proxy/8luozs3Ef6tofaP9YvpFMJfUFEqz1QLUJ4pmjmbiZBmIbtfxbFDGS7mVrEd2y32b_P4vDTb14QmA1gowrSAKvtWxet9R3_02VVFOV4S3mKU=s0-d-e1-ft#https://s3.amazonaws.com/images.wisestamp.com/facebook.png" alt="Facebook" width="16" height="16" border="0" class="CToWUd"></span></a><span lang="ES">&nbsp;</span><a href="https://twitter.com/inout_travel?lang=es" target="_blank" data-saferedirecturl="https://www.google.com/url?hl=es&amp;q=https://twitter.com/inout_travel?lang%3Des&amp;source=gmail&amp;ust=1516881697636000&amp;usg=AFQjCNEe-ltzYrhEmNPcORkqhPnlInLutw" style="color: rgb(17, 85, 204);"><span style="color: rgb(51, 102, 255);"><img src="https://ci5.googleusercontent.com/proxy/6sqL0BxRRr4QwfAOhK_hNNAXIpUHZNg-gl3CPQKITbX2dpT2jMTzf3zlwMmhB9BgxZehJzFQT_AJzsskN1uQR-SqppTRLIbJIILDeDNjlA=s0-d-e1-ft#https://s3.amazonaws.com/images.wisestamp.com/twitter.png" alt="Twitter" width="16" height="16" border="0" class="CToWUd"></span></a><span lang="ES">&nbsp; &nbsp;</span><span style="color: rgb(255, 102, 0);"><strong><span lang="ES">Visítanos en las redes sociales!!</span></strong></span></span></td></tr></tbody></table><img src="https://ci4.googleusercontent.com/proxy/rDdypMfZKWPkRRuCB3bp8PSQXo0k5aswGQRjFzy71EB2XEQkr4_rbaroShG2FEJbnrmwoEfE3-Z6r_hNFlfRMNPC1X8yjwJ2eOmZ1DagWHkl8sh7Y60=s0-d-e1-ft#http://www.inout-travel.com/inout-travel/img/logo/firma_MICE.png" class="CToWUd"><br><div></div></div><div dir="ltr" style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: 12.8px;"><p style="text-align: justify; text-indent: 7.1pt; line-height: 14.72px;"><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">De conformidad con lo dispuesto en la Ley Orgánica 15/1999 de Protección de Datos de carácter Personal VIAJES IN OUT TRAVEL, S.L., domiciliado en&nbsp;</span><a href="https://maps.google.com/?q=C/+CRISTOBAL+BORDIU,+53+-+28003+MADRID&amp;entry=gmail&amp;source=g" target="_blank" data-saferedirecturl="https://www.google.com/url?hl=es&amp;q=https://maps.google.com/?q%3DC/%2BCRISTOBAL%2BBORDIU,%2B53%2B-%2B28003%2BMADRID%26entry%3Dgmail%26source%3Dg&amp;source=gmail&amp;ust=1516881697636000&amp;usg=AFQjCNFHPMBadB0TD0U63EsqPiOZ7TPldg" style="color: rgb(17, 85, 204);"><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">C/ CRISTOBAL BORDIU, 53 - 28003 MADRID</span></a><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">, le informa que los datos que nos ha proporcionado formarán parte de un fichero de datos de carácter personal, responsabilidad de dicha entidad, con la finalidad de gestionar las comunicaciones que pudiera mantener con el personal de la misma.</span></p><p style="text-align: justify; text-indent: 7.1pt; line-height: 14.72px;"><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">En el supuesto de que desee ejercitar los derechos que le asisten de acceso, rectificación, cancelación y oposición dirija una comunicación por escrito a VIAJES IN OUT TRAVEL, S.L. a la dirección&nbsp;</span><a href="https://maps.google.com/?q=C/+CRISTOBAL+BORDIU,+53+-+28003+MADRID&amp;entry=gmail&amp;source=g" target="_blank" data-saferedirecturl="https://www.google.com/url?hl=es&amp;q=https://maps.google.com/?q%3DC/%2BCRISTOBAL%2BBORDIU,%2B53%2B-%2B28003%2BMADRID%26entry%3Dgmail%26source%3Dg&amp;source=gmail&amp;ust=1516881697636000&amp;usg=AFQjCNFHPMBadB0TD0U63EsqPiOZ7TPldg" style="color: rgb(17, 85, 204);"><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">C/ CRISTOBAL BORDIU, 53 - 28003 MADRID</span></a><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">&nbsp;&nbsp;incluyendo copia de su Documento Nacional de Identidad o documento identificativo equivalente, ó a través de un mensaje de correo electrónico a la dirección&nbsp;</span><a href="mailto:info@inout-travel.com" target="_blank" style="color: rgb(17, 85, 204);"><b><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">info@inout-travel.com</span></b></a><b><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">.</span></b></p><p style="text-align: justify; text-indent: 7.1pt; line-height: 14.72px;"><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">La información contenida en el presente mensaje de correo electrónico es confidencial y su acceso únicamente está autorizado al destinatario original del mismo, quedando prohibida cualquier comunicación, divulgación, o reenvío, tanto del mensaje como de su contenido. En el supuesto de que usted no sea el destinatario autorizado, le rogamos borre el contenido del mensaje y nos comunique dicha circunstancia a través de un mensaje de correo electrónico a la dirección&nbsp;</span><a href="mailto:info@inout-travel.com" target="_blank" style="color: rgb(17, 85, 204);"><b><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">info@inout-travel.com</span></b></a><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">&nbsp;o al teléfono<b>&nbsp;</b></span><a href="tel:911%2087%2083%2091" target="_blank" style="color: rgb(17, 85, 204);"><b><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">+34&nbsp;</span></b></a><b><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">&nbsp;</span></b><a href="tel:917%2058%2007%2085" target="_blank" style="color: rgb(17, 85, 204);"><b><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">917580785</span></b></a><span style="font-size: 10pt; line-height: 15.3333px; font-family: Arial, sans-serif;">.</span></p></div>',
  240.                     'firm' => '',
  241.                 );
  242.                 // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  243.                 $transporter = new Swift_SmtpTransport();
  244.                 $transporter->setHost('smtp.gmail.com')
  245.                     ->setEncryption('ssl')//ssl / tls
  246.                     ->setPort(465)// 465 / 587
  247.                     ->setUsername('desarrollo@develup.solutions')
  248.                     ->setPassword('MeDITeRRANeAN_Develup30102023#');
  249.                 $mailer = new Swift_Mailer($transporter);
  250.                 $message = new Swift_Message();
  251.                 $message->setSubject('#' $ooo->getId() . ', Nueva Actividad Fuera de Oficina')
  252.                     ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  253.                     ->setTo($mailAgentSent)
  254.                     //->setTo('eduardo.pagola@develup.solutions')
  255.                     ->setBody(
  256.                         $this->renderView(
  257.                             'mail/structure-mail.html.twig',
  258.                             array('data' => $data)
  259.                         ),
  260.                         'text/html'
  261.                     );
  262.                 $mailer->send($message);
  263.                 // FIN: Envio de Correo a administradores por FDO
  264.                 $event 'The Activities has been created..';
  265.                 $successMessage $this->translator->trans($event);
  266.                 $this->addFlash('mensajesupplier'$successMessage);
  267.             } catch (\Exception $e){
  268.                 $event 'An error occurred: '.$e->getMessage();
  269.                 /* Para el usuario */
  270.                 $errorMessage $this->translator->trans($event);
  271.                 $this->addFlash('mensajeactivitieserror'$errorMessage);
  272.             }
  273.             return $this->redirectToRoute('outofoffice_index');
  274.         }else{
  275.             $errorMessage $this->translator->trans('Error, some fields are empty');
  276.             $this->addFlash('mensajeactivitieserror'$errorMessage);
  277.         }
  278.         return $this->render('activities/activities/add-outofoffice.html.twig', array(
  279. //                'description' => $description_form,
  280.                 'form' => $form->createView())
  281.         );
  282.     }
  283.     /**
  284.      * @Route("/outofoffice/edit/{id}", name="outofoffice_edit")
  285.      */
  286.     public function editOutOfOfficeAction($id)
  287.     {
  288.         $em $this->getDoctrine()->getManager();
  289.         $ooo $em->getRepository(OutOfOffice::class)->findOneById($id);
  290.         // Se genera el arreglo de agentes a partir del agentsIds
  291.         $arraysIds explode(',',$ooo->getAgentsIds());
  292.         $agents = array();
  293.         foreach ($arraysIds as $item){
  294.             $agent $em->getRepository(User::class)->findOneById($item);
  295.             $agents[] = $agent;
  296.         }
  297.         $ooo->setAgentsIds($agents);
  298.         // Se genera el cliente a partir del clientId
  299.         if(!empty($ooo->getClientId())){
  300.             $ooo->setClientId($em->getRepository(Client::class)->findOneById($ooo->getClientId()));
  301.         }
  302.         // Se genera el proposal a partir del proposalId
  303.         if(!empty($ooo->getProposalId())){
  304.             $ooo->setProposalId($em->getRepository(Proposal::class)->findOneById($ooo->getProposalId()));
  305.         }
  306.         $form $this->createEditOutOfOfficeForm($ooo$id);
  307.         return $this->render('outofoffice/outofoffice/edit-outofoffice.html.twig',
  308.             array(
  309.                 'id' =>$id,
  310.                 'ooo' => $ooo,
  311.                 'form' => $form->createView(),
  312.             )
  313.         );
  314.     }
  315.     private function createEditOutOfOfficeForm(OutOfOffice $entity$id)
  316.     {
  317. //        d($entity, $id);exit();
  318.         $form $this->createForm(OutOfOfficeType::class, $entity,
  319.             array(
  320.                 'action' => $this->generateUrl('outofoffice_update',
  321.                     array(
  322.                         'id' => $id
  323.                     )
  324.                 ), 'method' => 'PUT'));
  325.         return $form;
  326.     }
  327.     /**
  328.      * @Route("/outofoffice/update/{id}", name="outofoffice_update", methods={"POST"})
  329.      */
  330.     public function updateOutOfOfficeAction($idRequest $request)
  331.     {
  332.         $em $this->getDoctrine()->getManager();
  333.         $ooo $em->getRepository(OutOfOffice::class)->findOneById($id);
  334.         $agentsID $ooo->getAgentsIds();
  335.         $agentsID explode(',',$agentsID);
  336.         //Se convierte en arreglo de objetos lo Ids para que este acorde con el formulario
  337.         $arrayObj = array();
  338.         foreach ($agentsID as $item){
  339.             $arrayObj[] =  $em->getRepository(User::class)->findOneById($item);
  340.         }
  341.         $ooo->setAgentsIds($arrayObj);
  342.         //Se convierte en objeto el ProposalId para que este acorde con el formulario
  343.         if(!empty($ooo->getProposalId())) {
  344.             $ooo->setProposalId($em->getRepository(Proposal::class)->findOneById($ooo->getProposalId()));
  345.         }
  346.         //Se convierte en objeto el ClientId para que este acorde con el formulario
  347.         if(!empty($ooo->getClientId())) {
  348.             $ooo->setClientId($em->getRepository(Client::class)->findOneById($ooo->getClientId()));
  349.         }
  350.         $form $this->createEditOutOfOfficeForm($ooo$id);
  351.         $form->handleRequest($request);
  352.         if($form->isSubmitted() && $form->isValid())
  353.         {
  354.             //Se genera el string de AgentsIds a partir del objeto
  355.             $arrayObj $ooo->getAgentsIds();
  356.             $txtAgentsIds ='';
  357.             foreach ($arrayObj as $item){
  358.                 if (!empty($txtAgentsIds)){
  359.                     $txtAgentsIds $txtAgentsIds.','.$item->getId();
  360.                 } else {
  361.                     $txtAgentsIds $item->getId();
  362.                 }
  363.             }
  364.             $ooo->setAgentsIds($txtAgentsIds);
  365.             if (!empty($ooo->getClientId())){
  366.                 $ooo->setClientId(($ooo->getClientId()->getId()));
  367.             }
  368.             if (!empty($ooo->getProposalId())){
  369.                 $ooo->setProposalId(($ooo->getProposalId()->getId()));
  370.             }
  371.             //Verificación de fechas
  372.             if (empty($ooo->getDateFinalAt())){
  373.                 $ooo->setDateFinalAt($ooo->getDateAt());
  374.             }
  375.             /* Obtengo usuario logueado */
  376.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  377.             $user_id $user_logueado->getId();
  378.             $today = new \DateTime("now");
  379.             $ooo->setUpdatedId($user_id);
  380.             $ooo->setUpdatedAt($today);
  381.             $em $this->getDoctrine()->getManager();
  382.             try{
  383.                 $em->persist($ooo);
  384.                 $em->flush();
  385.                 $event 'The Activities has been modified.';
  386.                 $successMessage $this->translator->trans($event);
  387.                 $this->addFlash('mensajeactivities'$successMessage);
  388.             } catch (\Exception $e){
  389.                 $event 'An error occurred: '.$e->getMessage().' | transport';
  390.                 /* Para el usuario */
  391.                 $errorMessage $this->translator->trans($event);
  392.                 $this->addFlash('mensajeactivitieserror'$errorMessage);
  393.             }
  394.             /* Fin Gestión de eventos en Log */
  395.             $successMessage $this->translator->trans('The Activities has been modified.');
  396.             $this->addFlash('mensajeactivities'$successMessage);
  397.             return $this->redirectToRoute('outofoffice_index');
  398.         }
  399.         return $this->render('/outofoffice/outofoffice/edit-outofoffice.html.twig', array(
  400.             'id'=> $id,
  401.             'ooo' => $ooo,
  402.             'form' => $form->createView()));
  403.     }
  404.     /**
  405.      * @Route("/outofoffice/delete/{id}", name="outofoffice_delete")
  406.      */
  407.     public function deleteOutOfOfficeAction($idRequest $request)
  408.     {
  409.         $em $this->getDoctrine()->getManager();
  410.         $ooo $em->getRepository(OutOfOffice::class)->findOneById($id);
  411.         try{
  412.             $em->remove($ooo);
  413.             $em->flush();
  414.             $event 'The '.$ooo->getId().' segment has been Deleted.';
  415.             $successMessage $this->translator->trans($event);
  416.             $this->addFlash('mensaje'$successMessage);
  417.         } catch (\Exception $e){
  418.             $event 'An error occurred: '.$e->getMessage().' | Activities';
  419.             /* Para el usuario */
  420.             $errorMessage $this->translator->trans($event);
  421.             $this->addFlash('mensajeerror'$errorMessage);
  422.         }
  423.         return $this->redirectToRoute('outofoffice_index');
  424.     }
  425.     /**
  426.      * @Route("/outofoffice/status/{idst}/{id}", name="outofoffice_status")
  427.      */
  428.     public function statusOutOfOfficeAction($idst,$idRequest $request)
  429.     {
  430.         $em $this->getDoctrine()->getManager();
  431.         $ooo $em->getRepository(OutOfOffice::class)->findOneById($id);
  432.         if ($idst ==1){
  433.             $ooo->setStatus(1);
  434.         } else {
  435.             $ooo->setStatus(0);
  436.         }
  437.         try{
  438.             $em->persist($ooo);
  439.             $em->flush();
  440.             $event 'The Activities has been modified.';
  441.             $successMessage $this->translator->trans($event);
  442.             $this->addFlash('mensaje'$successMessage);
  443.         } catch (\Exception $e){
  444.             $event 'An error occurred: '.$e->getMessage().' | transport';
  445.             /* Para el usuario */
  446.             $errorMessage $this->translator->trans($event);
  447.             $this->addFlash('mensajeactivitieserror'$errorMessage);
  448.         }
  449.         return $this->redirectToRoute('outofoffice_index');
  450.     }
  451.     /**
  452.      * @Route("/outofoffice/events", name="get_outofoffice")
  453.      */
  454.     public function outofofficeSelectAction(Request $request) {
  455.         $em $this->getDoctrine()->getManager();
  456.         $parameters = array(
  457.             'status' => true,
  458.         );
  459.         $dql 'SELECT p
  460.                         FROM App\Entity\OutOfOffice p
  461.                         WHERE p.status = :status 
  462.                         ORDER BY p.dateAt ASC ';
  463.         $query $em->createQuery($dql)->setParameters($parameters);
  464.         $ooo $query->getResult();
  465.         //Usuario Loggeado
  466.         $loggedUser $this->get('security.token_storage')->getToken()->getUser();
  467.         $datos = array();
  468.         if (!empty($ooo)){
  469.             foreach($ooo as $item) {
  470.                 $arrayAgents = array();
  471.                 $arrayAgentsNames = array();
  472.                 $arrayAgentsIds explode(","$item->getAgentsIds());
  473.                 foreach ($arrayAgentsIds as $agentId){
  474.                     $agent $em->getRepository(User::class)->findOneById($agentId);
  475.                     if(!is_null($agent)){
  476.                         $arrayAgents[] = $agent;
  477.                         $arrayAgentsNames[] = $agent->getName().' '.$agent->getLastName();
  478.                     }
  479.                 }
  480.                 $agentsNames implode("<br> "$arrayAgentsNames);
  481.                 $tooltip $item->getText();
  482.                 $title '(FDO.)<br>'.($item->getHourStart())->format('H:i').'<br>'.$agentsNames;
  483.                 $color "#ff0000";
  484.                 $desde = ($item->getDateAt())->format('Y-m-d') .' '.($item->getHourStart())->format('H:i');
  485.                 $hasta = ($item->getDateFinalAt())->format('Y-m-d') .' '.($item->getHourEnd())->format('H:i');
  486.                 if ($loggedUser->getRole() == 'ROLE_ADMIN'){
  487.                     $url "/outofoffice/edit/" $item->getId();
  488.                 } else {
  489.                     $url "/outofoffice/view/" $item->getId();
  490.                 }
  491.                 if (!empty($item)){
  492.                     $datos[] = array(
  493.                         "id" => $item->getId(),
  494.                         "title" => $title,
  495.                         "tooltip" => $tooltip,
  496.                         "start" => $desde,
  497.                         "end" => $hasta,
  498.                         "color" => $color,
  499.                         "url" => $url,
  500.                     );
  501.                 } else {
  502.                     $datos = [];
  503.                 }
  504.             }
  505.         }
  506.         $return = array(
  507.             'outofoffice' => $datos,
  508.         );
  509.         $response = new JsonResponse($return);
  510.         return $response;
  511.     }
  512.     /**
  513.      * @Route("/outofoffice/listhistoric", name="outofoffice_listhistoric")
  514.      */
  515.     public function listHistoricAction(Request $request) {
  516.         $em $this->getDoctrine()->getManager();
  517.         $today = new \DateTime("now"NULL);
  518.         $parameters = array(
  519.             'today' => $today,
  520.         );
  521.         $dql 'SELECT p
  522.                         FROM App:OutOfOffice p
  523.                         WHERE p.dateAt < :today 
  524.                         ORDER BY p.dateAt DESC ';
  525.         $query $em->createQuery($dql)->setParameters($parameters);
  526.         $ooo $query->getResult();
  527.         $data = array();
  528.         foreach($ooo as $item) {
  529.             if (!empty($item->getProposalId())) {
  530.                 $proposal $em->getRepository(Proposal::class)->findOneById($item->getProposalId());
  531.                 $proposalInfo '#'.$proposal->getId().' - '.$proposal->getTitle();
  532.             } else {
  533.                 $proposal null;
  534.                 $proposalInfo null;
  535.             }
  536.             $arrayAgents = array();
  537.             $arrayAgentsNames = array();
  538.             $arrayAgentsIds explode(","$item->getAgentsIds());
  539.             foreach ($arrayAgentsIds as $agentId){
  540.                 $agent $em->getRepository(User::class)->findOneById($agentId);
  541.                 if(!is_null($agent)){
  542.                     $arrayAgents[] = $agent;
  543.                     $arrayAgentsNames[] = $agent->getName().' '.$agent->getLastName();
  544.                 }
  545.             }
  546.             $agentsNames implode(", "$arrayAgentsNames);
  547.             if (!empty($item->getClientId())) {
  548.                 $client $em->getRepository(Client::class)->findOneById($item->getClientId());
  549.             } else {
  550.                 $client null;
  551.             }
  552.             $data[] = array(
  553.                 'id' => $item->getId(),
  554.                 'status' => $item->getStatus(),
  555.                 'dateAt' => ($item->getDateAt())->format('Y-m-d'),
  556.                 'hourStart' => ($item->getHourStart())->format('H:i'),
  557.                 'hourEnd' => ($item->getHourEnd())->format('H:i'),
  558.                 'proposal' => $proposal,
  559.                 'proposalInfo' => $proposalInfo,
  560.                 'client' => $client,
  561.                 'text' => $item->getText(),
  562.                 'arrayAgents' => $arrayAgents,
  563.                 'agentsNames' => $agentsNames
  564.             );
  565.         }
  566.         //Usuario Loggeado
  567.         $loggedUser $this->get('security.token_storage')->getToken()->getUser();
  568.         return $this->render('outofoffice/outofoffice/list-outofoffice.html.twig', array(
  569.             'outofoffice' => $data,
  570.             'historic' => true,
  571.             'user' => $loggedUser
  572.         ));
  573.     }
  574.     /**
  575.      * @Route("/outofoffice/view/{id}", name="outofoffice_view")
  576.      */
  577.     public function viewOutOfOfficeAction($id)
  578.     {
  579.         $em $this->getDoctrine()->getManager();
  580.         $ooo $em->getRepository(OutOfOffice::class)->findOneById($id);
  581.         // Se genera el arreglo de agentes a partir del agentsIds
  582.         $arraysIds explode(',',$ooo->getAgentsIds());
  583.         $agents = array();
  584.         foreach ($arraysIds as $item){
  585.             $agent $em->getRepository(User::class)->findOneById($item);
  586.             $agents[] = $agent;
  587.         }
  588.         $ooo->setAgentsIds($agents);
  589.         // Se genera el cliente a partir del clientId
  590.         if(!empty($ooo->getClientId())){
  591.             $ooo->setClientId($em->getRepository(Client::class)->findOneById($ooo->getClientId()));
  592.         }
  593.         // Se genera el proposal a partir del proposalId
  594.         if(!empty($ooo->getProposalId())){
  595.             $ooo->setProposalId($em->getRepository(Proposal::class)->findOneById($ooo->getProposalId()));
  596.         }
  597.         $form $this->createViewOutOfOfficeForm($ooo$id);
  598.         return $this->render('outofoffice/outofoffice/view-outofoffice.html.twig',
  599.             array(
  600.                 'id' =>$id,
  601.                 'ooo' => $ooo,
  602.                 'form' => $form->createView(),
  603.             )
  604.         );
  605.     }
  606.     private function createViewOutOfOfficeForm(OutOfOffice $entity$id)
  607.     {
  608. //        d($entity, $id);exit();
  609.         $form $this->createForm(OutOfOfficeType::class, $entity,
  610.             array(
  611.                 'action' => $this->generateUrl('outofoffice_watch',
  612.                     array(
  613.                         'id' => $id
  614.                     )
  615.                 ), 'method' => 'PUT'));
  616.         return $form;
  617.     }
  618.     /**
  619.      * @Route("/outofoffice/watch/{id}", name="outofoffice_watch", methods={"POST"})
  620.      */
  621.     public function watchOutOfOfficeAction($idRequest $request)
  622.     {
  623.         $em $this->getDoctrine()->getManager();
  624.         $ooo $em->getRepository(OutOfOffice::class)->findOneById($id);
  625.         $agentsID $ooo->getAgentsIds();
  626.         $agentsID explode(',',$agentsID);
  627.         //Se convierte en arreglo de objetos lo Ids para que este acorde con el formulario
  628.         $arrayObj = array();
  629.         foreach ($agentsID as $item){
  630.             $arrayObj[] =  $em->getRepository(User::class)->findOneById($item);
  631.         }
  632.         $ooo->setAgentsIds($arrayObj);
  633.         //Se convierte en objeto el ProposalId para que este acorde con el formulario
  634.         if(!empty($ooo->getProposalId())) {
  635.             $ooo->setProposalId($em->getRepository(Proposal::class)->findOneById($ooo->getProposalId()));
  636.         }
  637.         //Se convierte en objeto el ClientId para que este acorde con el formulario
  638.         if(!empty($ooo->getClientId())) {
  639.             $ooo->setClientId($em->getRepository(Client::class)->findOneById($ooo->getClientId()));
  640.         }
  641.         $form $this->createEditOutOfOfficeForm($ooo$id);
  642.         $form->handleRequest($request);
  643.         if($form->isSubmitted() && $form->isValid())
  644.         {
  645.             //Se genera el string de AgentsIds a partir del objeto
  646.             $arrayObj $ooo->getAgentsIds();
  647.             $txtAgentsIds ='';
  648.             foreach ($arrayObj as $item){
  649.                 if (!empty($txtAgentsIds)){
  650.                     $txtAgentsIds $txtAgentsIds.','.$item->getId();
  651.                 } else {
  652.                     $txtAgentsIds $item->getId();
  653.                 }
  654.             }
  655.             $ooo->setAgentsIds($txtAgentsIds);
  656.             if (!empty($ooo->getClientId())){
  657.                 $ooo->setClientId(($ooo->getClientId()->getId()));
  658.             }
  659.             if (!empty($ooo->getProposalId())){
  660.                 $ooo->setProposalId(($ooo->getProposalId()->getId()));
  661.             }
  662.             //Verificación de fechas
  663.             if (empty($ooo->getDateFinalAt())){
  664.                 $ooo->setDateFinalAt($ooo->getDateAt());
  665.             }
  666.             /* Obtengo usuario logueado */
  667.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  668.             $user_id $user_logueado->getId();
  669.             $today = new \DateTime("now");
  670.             $ooo->setUpdatedId($user_id);
  671.             $ooo->setUpdatedAt($today);
  672.             $em $this->getDoctrine()->getManager();
  673.             try{
  674.                 if ($user_logueado->getRole()=='ROLE_ADMIN') {
  675.                     // En modo vista solo puede modificar un administrador
  676.                     $em->persist($ooo);
  677.                     $em->flush();
  678.                     $event 'The Activities has been modified.';
  679.                     $successMessage $this->translator->trans($event);
  680.                     $this->addFlash('mensajeactivities'$successMessage);
  681.                 }
  682.             } catch (\Exception $e){
  683.                 $event 'An error occurred: '.$e->getMessage().' | transport';
  684.                 /* Para el usuario */
  685.                 $errorMessage $this->translator->trans($event);
  686.                 $this->addFlash('mensajeactivitieserror'$errorMessage);
  687.             }
  688.             /* Fin Gestión de eventos en Log */
  689.             $successMessage $this->translator->trans('The Activities has been modified.');
  690.             $this->addFlash('mensajeactivities'$successMessage);
  691.             return $this->redirectToRoute('outofoffice_index');
  692.         }
  693.         return $this->render('/outofoffice/outofoffice/view-outofoffice.html.twig', array(
  694.             'id'=> $id,
  695.             'ooo' => $ooo,
  696.             'form' => $form->createView()));
  697.     }
  698.     /**
  699.      * @Route("/outofoffice/getProposalsOfClient", name="get_proposals_of_client")
  700.      */
  701.     public function getProposalsOfClientAction(Request $request) {
  702.         $clientId $_POST['clientId'];
  703.         $em $this->getDoctrine()->getManager();
  704.         if ($clientId == 0){
  705.             $proposals $em->getRepository(Proposal::class)->findAll();
  706.         } else {
  707.             $proposals $em->getRepository(Proposal::class)->findBy(
  708.                 array(
  709.                     'clientId' => $clientId
  710.                 )
  711.             );
  712.         }
  713.         $datos = array();
  714.         if (!empty($proposals)){
  715.             foreach($proposals as $item){
  716.                 $datos[] = array(
  717.                     "id" => $item->getId(),
  718.                     "title" => $item->getId() . ' - ' $item->getTitle(),
  719.                 );
  720.             }
  721.         }
  722.         $return = array(
  723.             'proposals' => $datos,
  724.             'id' => $clientId,
  725.         );
  726.         $response = new JsonResponse($return);
  727.         return $response;
  728.     }
  729. }