src/Controller/BaseController.php line 221

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Idempiere\AdWindowAccess;
  4. use App\Repository\Idempiere\AdRoleRepository;
  5. use App\Repository\Idempiere\AdWindowAccessRepository;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\Security\Core\Security;
  13. use Twig\Environment;
  14. use Twig\Extra\Intl\IntlExtension;
  15. use Twig\Loader\FilesystemLoader;
  16. class BaseController extends AbstractController
  17. {
  18.     /**
  19.      * Accion de Documento
  20.      * 
  21.      * @var array Estatus
  22.      */
  23.     protected $docaction = [
  24.         'CO' => [
  25.             'code'  => 'CO',
  26.             'name'  => 'ToComplete',
  27.             'flag'  => 'success'
  28.         ],
  29.         'VO' => [
  30.             'code'  => 'VO',
  31.             'name'  => 'Cancel',
  32.             'flag'  => 'danger'
  33.         ],
  34.         'CL' => [
  35.             'code'  => 'CL',
  36.             'name'  => 'Close',
  37.             'flag'  => 'warning',
  38.         ]
  39.     ];
  40.     /**
  41.      * Estatus de Documento
  42.      * 
  43.      * @var array Estatus
  44.      */
  45.     protected $docstatus = [
  46.         'DR' => [
  47.             'code'  => 'DR',
  48.             'name'  => 'Draft',
  49.             'flag'  => 'info'
  50.         ],
  51.         'IP' => [
  52.             'code'  => 'IP',
  53.             'name'  => 'In Progress',
  54.             'flag'  => 'warning'
  55.         ],
  56.         'AP' => [
  57.             'code'  => 'AP',
  58.             'name'  => 'Approved',
  59.             'flag'  => 'warning'
  60.         ],
  61.         'NA' => [
  62.             'code'  => 'NA',
  63.             'name'  => 'Not Approved',
  64.             'flag'  => 'danger'
  65.         ],
  66.         'CO' => [
  67.             'code'  => 'CO',
  68.             'name'  => 'Complete',
  69.             'flag'  => 'success'
  70.         ],
  71.         'VO' => [
  72.             'code'  => 'VO',
  73.             'name'  => 'Voided',
  74.             'flag'  => 'danger'
  75.         ],
  76.         'RE' => [
  77.             'code'  => 'RE',
  78.             'name'  => 'Reversed',
  79.             'flag'  => 'danger'
  80.         ],
  81.         'IN' => [
  82.             'code'  => 'IN',
  83.             'name'  => 'Invalid',
  84.             'flag'  => 'danger'
  85.         ],
  86.         'CL' => [
  87.             'code'  => 'CL',
  88.             'name'  => 'Closed',
  89.             'flag'  => 'dark',
  90.         ],
  91.         'LS' => [
  92.             'code'  => 'LS',
  93.             'name'  => 'Loss of Sales',
  94.             'flag'  => 'danger',
  95.         ],
  96.         'PD' => [
  97.             'code'  => 'PD',
  98.             'name'  => 'Pendiente por despachar',
  99.             'flag'  => 'info',
  100.         ],
  101.         '??' => [
  102.             'code'  => '??',
  103.             'name'  => '??',
  104.             'flag'  => 'info',
  105.         ],
  106.         'PC' => [
  107.             'code'  => 'PC',
  108.             'name'  => 'Pendiente por cerrar',
  109.             'flag'  => 'info',
  110.         ]
  111.     ];
  112.     /**
  113.      * Prioridad de Documento
  114.      * 
  115.      * @var array Niveles de Prioridad
  116.      */
  117.     protected $priorityrule = [
  118.         => 'Priority.Urgent',
  119.         => 'Priority.High',
  120.         => 'Priority.Medium',
  121.         => 'Priority.Low',
  122.         => 'Priority.Minor'
  123.     ];
  124.     /**
  125.      * Templates Handler
  126.      * @var FilesystemLoader
  127.      */
  128.     protected $loader;
  129.     protected $pdf;
  130.     /** 
  131.      * Public Directory 
  132.      * @var String
  133.      */
  134.     protected $publicDir;
  135.     /**
  136.      * Request Stack
  137.      * @var RequestStack
  138.      */
  139.     protected $requestStack;
  140.     /**
  141.      * Security Manager
  142.      * @var Security
  143.      */
  144.     protected $security;
  145.     /** 
  146.      * Session Interface 
  147.      * @var SessionInterface
  148.      */
  149.     protected $session;
  150.     protected $status = [
  151.         'VO' => [
  152.             'flag' => 'danger',
  153.             'name' => 'anulado'
  154.         ],
  155.         'IN' => [
  156.             'flag' => 'danger',
  157.             'name' => 'invalido'
  158.         ],
  159.         'CL' => [
  160.             'flag' => 'dark',
  161.             'name' => 'cerrado'
  162.         ],
  163.         'CO' => [
  164.             'flag' => 'success',
  165.             'name' => 'completo'
  166.         ],
  167.         'NA' => [
  168.             'flag' => 'danger',
  169.             'name' => 'no aprobado'
  170.         ],
  171.         'AP' => [
  172.             'flag' => 'warning',
  173.             'name' => 'aprobado'
  174.         ],
  175.         'IP' => [
  176.             'flag' => 'warning',
  177.             'name' => 'en progreso'
  178.         ],
  179.         'DR' => [
  180.             'flag' => 'info',
  181.             'name' => 'borrador'
  182.         ]
  183.     ];
  184.     /** 
  185.      * Twig Engine 
  186.      *  @var Enviroment 
  187.      */
  188.     protected $twig;
  189.     public function __construct(RequestStack $requestStackSecurity $security)
  190.     {
  191.         $this->requestStack $requestStack;
  192.         $this->session $requestStack->getSession();
  193.         
  194.         $this->security $security;
  195.         $this->publicDir dirname(__FILE__) . '/../../public/';
  196.     }
  197.     /**
  198.      * Ruta raiz - corroborar la sesion del usuario
  199.      * @Route("/", name="app_index")
  200.      * 
  201.      * @return RedirectResponse Vista
  202.      */
  203.     public function index(): RedirectResponse
  204.     
  205.         return is_null($this->security->getUser()) ? $this->redirectToRoute('app_login') : $this->redirectToRoute('app_dashboard'); 
  206.     }
  207.     /**
  208.      * Funcion para enrutar la salida del sistema
  209.      * @Route("/salir", name="app_logout")
  210.      * 
  211.      * @return RedirectResponse Vista
  212.      */
  213.     public function logout(): RedirectResponse { return $this->redirectToRoute('app_login'); }
  214.     /** 
  215.      * Verifica los accesos del rol a la ventana
  216.      * 
  217.      * @param ManagerRegistry $manager Administrador de conexiones a la BD
  218.      * @param int $windowID Identificador de la ventana
  219.      * @param int $roleID Identificador del rol
  220.      * 
  221.      * @return boolean Permiso de lectura
  222.      * 
  223.      */
  224.     public function VerifyWindow(ManagerRegistry $managerInt $windowID 0Int $roleID 0): bool
  225.     {
  226.         $window $this->WindowAccess($manager$windowID$roleID);
  227.         if ( !is_null($window) )
  228.             return $window->isActive();
  229.        
  230.         return false;
  231.     }
  232.     /** 
  233.      * Accesos del rol a la ventana
  234.      * 
  235.      * @param ManagerRegistry $manager Administrador de conexiones a la BD
  236.      * @param int $windowID Identificador de la ventana
  237.      * @param int $roleID Identificador del rol
  238.      * 
  239.      * @return null|AdWindowAccess Permiso
  240.      */
  241.     public function WindowAccess(ManagerRegistry $managerInt $windowID 0Int $roleID 0):? AdWindowAccess
  242.     {
  243.         $RWindowAccess = new AdWindowAccessRepository($manager);
  244.         $window $RWindowAccess->findOneBy(['ad_window_id'  => $windowID'ad_role_id'    => $roleID]);
  245.         if ( !is_null($window) ) 
  246.             return $window;
  247.         $RRole = new AdRoleRepository($manager);
  248.         $role $RRole->find($roleID);
  249.         $roleIncludes $role->getAdRoleIncludeds();
  250.         foreach ($roleIncludes as $role) {
  251.             $window $this->WindowAccess($manager$windowID$role->getIncludedRoleId());
  252.             if ( !is_null($window) ) 
  253.                 return $window;
  254.         }
  255.        
  256.         return null;
  257.     }
  258.     /**
  259.      * Create a directory
  260.      * 
  261.      * @param string $targetDir Ruta de la carpeta destino
  262.      * @param string $folder Nombre de carpeta a crear
  263.      * @return string Nombre de carpeta
  264.      */
  265.     public function createDir($targetDir$folder)
  266.     {
  267.         if (!is_dir($this->publicDir $targetDir $folder)) {
  268.             mkdir($this->publicDir $targetDir $folder);
  269.         }
  270.         return $targetDir $folder;
  271.     }
  272.     public function replaceUrl(String $relativePath): String
  273.     {
  274.         return str_replace($this->getParameter('app.url'), $this->publicDir$relativePath);
  275.     }
  276. }
  277. ?>