HEX
Server: Apache
System: Linux clpupre 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64
User: undanet (1000)
PHP: 7.4.3
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/undanet/www/PortalEmpleo/src/Repository/DBImpugnacionRepository.php
<?php

namespace PortalEmpleo\Repository;

require __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../../bootstrap.php';

use Dotenv\Dotenv;
use PortalEmpleo\Entity\DboCandidato;
use PortalEmpleo\Entity\DboConvocatoria;
use PortalEmpleo\Entity\DboImpugnacion;
use PortalEmpleo\Entity\WpUsers;
use PortalEmpleo\Entity\WpUsermeta;
use Doctrine\Common\Collections\Criteria;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class DBImpugnacionRepository extends AbstractController
{
    private $dotenv;
    private $entityManager;
    
    public function __construct()
    {
    }

    private function loadEnv()
    {
        try{
            $dotenv = Dotenv::createImmutable(__DIR__ . "/../../");
            $dotenv->load();

            $em = getEntityManager();
            
            return $em;
        }
        catch (Exception $ex){
            echo $exception->getMessage();
            return null;
        }
    }

    private function loadEnvWP()
    {
        try{
            $dotenv = Dotenv::createImmutable(__DIR__ . "/../../");
            $dotenv->load();

            $em = getEntityManagerWP();
            
            return $em;
        }
        catch (Exception $ex){
            echo $exception->getMessage();
            return null;
        }
    }

    public function obtenerImpugnaciones($lang, $codigoconvocatoria)
    {
        try
        {
            $entityManager = $this->loadEnv();

                $ltrbvlc = $entityManager->getRepository(DboImpugnacion::class)
                ->createQueryBuilder('c')
                ->where('c.codigoconvocatoria = :cvt')
                    ->andwhere('c.baja = false')
                ->setParameter('cvt', $codigoconvocatoria)
                ->addOrderBy('c.idimpugnacion', 'ASC')
                ->getQuery()
                ->execute();

            if (!$ltrbvlc) {
                return ;
            }
			
			$entityManager->getConnection()->close();
			
            return $ltrbvlc;
        }
        catch (Exception $ex)
        {
            echo $exception->getMessage();
        }
    }

    public function insertarImpugnacion($impugnacion)
    {
        try
        {
            if(is_object($impugnacion))
            {
                $entityManager = $this->loadEnv();
                
                $trbVlc = new DboImpugnacion();
                
                $trbVlc = $trbVlc->setComentario($impugnacion->getComentario());                
                $trbVlc = $trbVlc->setFecha($impugnacion->getFecha());
                $trbVlc = $trbVlc->setEsRequisito($impugnacion->getEsRequisito());           
                $trbVlc = $trbVlc->setBaja($impugnacion->getBaja());
                
                if( $impugnacion->getIdImpugnacion() != 0 )
                     $trbVlc = $trbVlc->setIdImpugnacion( $impugnacion->getIdImpugnacion() );
                
                $cdt = $entityManager->getRepository(DboCandidato::class)->find(($impugnacion->getCodigocandidato())->getIdcandidato());
                $entityManager->clear();
                if (!$cdt) {
                    throw $this->createNotFoundException(
                        'No se encuentra el candidato con el id '. ($impugnacion->getCodigocandidato())->getIdcandidato()
                    );
                }
                $trbVlc = $trbVlc->setCodigocandidato2($cdt);

                $cvt = $entityManager->getRepository(DboConvocatoria::class)->find(($impugnacion->getCodigoconvocatoria())->getIdconvocatoria());
                $entityManager->clear();
                
                if (!$cvt) {
                    throw $this->createNotFoundException(
                        'No se encuentra la convocatoria con el id '. ($impugnacion->getCodigoconvocatoria())->getIdconvocatoria()
                    );
                }
                $trbVlc = $trbVlc->setCodigoconvocatoria2($cvt);


                $entityManager->merge($trbVlc);
                $entityManager->flush();
                $entityManager->clear();
				$entityManager->getConnection()->close();

                return $trbVlc;
            }
        }
        catch (Exception $ex)
        {
            echo $exception->getMessage();
        }
    }
}

?>