src/Controller/DefaultController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Analytics;
  4. use App\Entity\CasoClinico;
  5. use App\Entity\CasoClinicoUser;
  6. use App\Entity\Curso;
  7. use App\Entity\CursoDoctor;
  8. use App\Entity\CursoParticular;
  9. use App\Entity\Doctor;
  10. use App\Entity\ImpModulos;
  11. use App\Entity\ImpModulosParticular;
  12. use App\Entity\ImpPildoras;
  13. use App\Entity\ImpPildorasParticular;
  14. use App\Entity\ImpRutaFormativa;
  15. use App\Entity\ImpRutasFormativasParticular;
  16. use App\Entity\Particular;
  17. use App\Entity\Quiz;
  18. use App\Entity\QuizResponse;
  19. use App\Entity\UserAnalytics;
  20. use App\Entity\UserAnalyticsCategory;
  21. use App\Entity\VademecumPresentation;
  22. use App\Utils\Utils;
  23. use Exception;
  24. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Session\Session;
  27. class DefaultController extends AbstractController
  28. {
  29.     public function index()
  30.     {
  31.         // Llevamos a la home page del administrador
  32.         return $this->redirectToRoute('admin_homepage');
  33.     }
  34.     public function admin_homepage_clicks(Request $request)
  35.     {
  36.         if (== $this->getUser()->getId() || 15 == $this->getUser()->getId() || 17 == $this->getUser()->getId()) {
  37.             return $this->redirectToRoute('ecommerce_vademecum_product_list');
  38.         }
  39.         if (== $this->getUser()->getId()) {
  40.             return $this->redirectToRoute('tecnico_vademecum_product_list');
  41.         }       
  42.         
  43.         if (18 == $this->getUser()->getId()) {
  44.             return $this->redirectToRoute('admin_imp_ruta_formativa_list');
  45.         }           
  46.         $session = new Session();
  47.         $repository $this->getDoctrine()->getRepository(UserAnalytics::class);
  48.         $categoryRepository $this->getDoctrine()->getRepository(UserAnalyticsCategory::class);
  49.         if ('POST' === $_SERVER['REQUEST_METHOD']) {
  50.             $datefrom $_POST['datepicker_from'].' 00:00:00';
  51.             $dateto $_POST['datepicker_to'].' 23:59:59';
  52.             $datepicker_from_value date('d/m/Y'strtotime($_POST['datepicker_from']));
  53.             $datepicker_to_value date('d/m/Y'strtotime($_POST['datepicker_to']));
  54.             $session->set('datepicker_from_value'$datefrom);
  55.             $session->set('datepicker_to_value'$dateto);
  56.         } elseif ($session->has('datepicker_from_value') && '' != $session->get('datepicker_from_value')
  57.                 && $session->has('datepicker_to_value') && '' != $session->get('datepicker_to_value')) {
  58.             $datefrom $session->get('datepicker_from_value');
  59.             $dateto $session->get('datepicker_to_value');
  60.             $datepicker_from_value date('d/m/Y'strtotime($session->get('datepicker_from_value')));
  61.             $datepicker_to_value date('d/m/Y'strtotime($session->get('datepicker_to_value')));
  62.         } else {
  63.             $datefrom = new \DateTime();
  64.             $datefrom->modify('-29 days');
  65.             $datepicker_from_value $datefrom->format('d/m/Y');
  66.             $datefrom $datefrom->format('Y-m-d').' 00:00:00';
  67.             $dateto = new \DateTime();
  68.             $datepicker_to_value $dateto->format('d/m/Y');
  69.             $dateto $dateto->format('Y-m-d').' 23:59:59';
  70.         }
  71.         $origin $request->query->has('origin') ? $request->query->get('origin') : null;
  72.         $category $request->query->has('c') ? $request->query->get('c') : null;
  73.         $subcategory $request->query->has('sc') ? $request->query->get('sc') : null;
  74.         $originTitle '';
  75.         switch ($origin) {
  76.             case 'aps':
  77.                 $originTitle 'Profesionales de la salud';
  78.             break;
  79.             case 'lfh':
  80.                 $originTitle 'La Farmacia Hoy';
  81.             break;
  82.             case 'advancedkit':
  83.                 $originTitle 'AdvancedKit';
  84.             break;
  85.             case 'faesclinic':
  86.                 $originTitle 'Faes Clinic';
  87.             break;
  88.             case 'farmaquiz':
  89.                 $originTitle 'Faes Farma Quiz';
  90.             break;
  91.             case 'arcenepoc':
  92.                 $originTitle 'ARC en EPOC';
  93.             break;
  94.         }
  95.         $pagesControl = [];
  96.         $pages = [];
  97.         $usersControl = [];
  98.         $users = [];
  99.         $tags = [];
  100.         $subtags = [];
  101.         if (null != $origin) {
  102.             $tags $categoryRepository->findBy([
  103.                 'origin' => $origin,
  104.                 'parent' => null,
  105.             ]);
  106.             if (null != $category) {
  107.                 $subtags $categoryRepository->findBy([
  108.                     'origin' => $origin,
  109.                     'parent' => $category,
  110.                 ]);
  111.             }
  112.             $_pages $repository->findClicksByOrigin($origin$category$subcategory$datefrom$dateto);
  113.             foreach ($_pages as $_page) {
  114.                 if (null != $_page->getDoctor() && (6908 == $_page->getDoctor()->getId() || 836 == $_page->getDoctor()->getId() || 8370 == $_page->getDoctor()->getId())) {
  115.                     continue;
  116.                 }
  117.                 if (null != $_page->getParticular() && (3359 == $_page->getParticular()->getId() || 526 == $_page->getParticular()->getId() || 9901 == $_page->getParticular()->getId() || 4034 == $_page->getParticular()->getId())) {
  118.                     continue;
  119.                 }
  120.                 if (!key_exists($_page->getPageId(), $pagesControl)) {
  121.                     $pagesControl[$_page->getPageId()] = [
  122.                         'doctors' => [],
  123.                         'particulars' => [],
  124.                     ];
  125.                     $pages[$_page->getPageId()] = [
  126.                         'title' => $_page->getPageTitle(),
  127.                         'url' => $_page->getPageUrl(),
  128.                         'button_text' => $_page->getButtonText(),
  129.                         'visits' => 1,
  130.                         'users' => 1,
  131.                     ];
  132.                 } else {
  133.                     if (null != $_page->getDoctor()) {
  134.                         $pagesControl[$_page->getPageId()]['doctors'][] = $_page->getDoctor()->getId();
  135.                     }
  136.                     if (null != $_page->getParticular()) {
  137.                         $pagesControl[$_page->getPageId()]['particulars'][] = $_page->getParticular()->getId();
  138.                     }
  139.                     $pages[$_page->getPageId()]['visits'] = count($pagesControl[$_page->getPageId()]['doctors']) + count($pagesControl[$_page->getPageId()]['particulars']);
  140.                     $pages[$_page->getPageId()]['users'] = count(array_unique($pagesControl[$_page->getPageId()]['doctors'])) + count(array_unique($pagesControl[$_page->getPageId()]['particulars']));
  141.                 }
  142.                 if (null != $_page->getDoctor()) {
  143.                     if (!key_exists($_page->getDoctor()->getId(), $users)) {
  144.                         $users[$_page->getDoctor()->getId()]['is_doctor'] = 1;
  145.                         $users[$_page->getDoctor()->getId()]['id'] = $_page->getDoctor()->getId();
  146.                         $users[$_page->getDoctor()->getId()]['visits'] = 1;
  147.                         $users[$_page->getDoctor()->getId()]['sessions'][] = $_page->getExtra();
  148.                         $users[$_page->getDoctor()->getId()]['sessions_number'] = 1;
  149.                         try {
  150.                             $users[$_page->getDoctor()->getId()]['name'] = $_page->getDoctor()->getUsername();
  151.                         } catch (Exception $e) {
  152.                             $users[$_page->getDoctor()->getId()]['name'] = $_page->getDoctor()->getId();
  153.                         }
  154.                     } else {
  155.                         $users[$_page->getDoctor()->getId()]['visits'] = $users[$_page->getDoctor()->getId()]['visits'] + 1;
  156.                         if (!in_array($_page->getExtra(), $users[$_page->getDoctor()->getId()]['sessions'])) {
  157.                             $users[$_page->getDoctor()->getId()]['sessions'][] = $_page->getExtra();
  158.                         }
  159.                         $users[$_page->getDoctor()->getId()]['sessions_number'] = count($users[$_page->getDoctor()->getId()]['sessions']);
  160.                     }
  161.                 }
  162.                 if (null != $_page->getParticular()) {
  163.                     if (!key_exists($_page->getParticular()->getId(), $users)) {
  164.                         $users[$_page->getParticular()->getId()]['is_doctor'] = 0;
  165.                         $users[$_page->getParticular()->getId()]['id'] = $_page->getParticular()->getId();
  166.                         $users[$_page->getParticular()->getId()]['visits'] = 1;
  167.                         $users[$_page->getParticular()->getId()]['sessions'][] = $_page->getExtra();
  168.                         $users[$_page->getParticular()->getId()]['sessions_number'] = 1;
  169.                         try {
  170.                             $users[$_page->getParticular()->getId()]['name'] = $_page->getParticular()->getUsername();
  171.                         } catch (Exception $e) {
  172.                             $users[$_page->getParticular()->getId()]['name'] = $_page->getParticular()->getId();
  173.                         }
  174.                     } else {
  175.                         $users[$_page->getParticular()->getId()]['visits'] = $users[$_page->getParticular()->getId()]['visits'] + 1;
  176.                         if (!in_array($_page->getExtra(), $users[$_page->getParticular()->getId()]['sessions'])) {
  177.                             $users[$_page->getParticular()->getId()]['sessions'][] = $_page->getExtra();
  178.                         }
  179.                         $users[$_page->getParticular()->getId()]['sessions_number'] = count($users[$_page->getParticular()->getId()]['sessions']);
  180.                     }
  181.                 }
  182.             }
  183.             $pages Utils::orderMultiDimensionalArray($pages'visits'true);
  184.             $users Utils::orderMultiDimensionalArray($users'visits'true);
  185.         }
  186.         return $this->render('backend/dashboard/clicks.html.twig', [
  187.             'menu_section' => 'dashboard',
  188.             'origin' => $origin,
  189.             'originTitle' => $originTitle,
  190.             'pages' => $pages,
  191.             'users' => $users,
  192.             'tags' => $tags,
  193.             'subtags' => $subtags,
  194.             'datepicker_from_value' => $datepicker_from_value,
  195.             'datepicker_to_value' => $datepicker_to_value,
  196.         ]);
  197.     }
  198.     public function admin_homepage_contenido(Request $request)
  199.     {
  200.         if (== $this->getUser()->getId() || 15 == $this->getUser()->getId() || 17 == $this->getUser()->getId()) {
  201.             return $this->redirectToRoute('ecommerce_vademecum_product_list');
  202.         }
  203.         if (== $this->getUser()->getId()) {
  204.             return $this->redirectToRoute('tecnico_vademecum_product_list');
  205.         }    
  206.         
  207.         if (18 == $this->getUser()->getId()) {
  208.             return $this->redirectToRoute('admin_imp_ruta_formativa_list');
  209.         }           
  210.         $session = new Session();
  211.         $repository $this->getDoctrine()->getRepository(UserAnalytics::class);
  212.         $categoryRepository $this->getDoctrine()->getRepository(UserAnalyticsCategory::class);
  213.         if ('POST' === $_SERVER['REQUEST_METHOD']) {
  214.             $datefrom $_POST['datepicker_from'].' 00:00:00';
  215.             $dateto $_POST['datepicker_to'].' 23:59:59';
  216.             $datepicker_from_value date('d/m/Y'strtotime($_POST['datepicker_from']));
  217.             $datepicker_to_value date('d/m/Y'strtotime($_POST['datepicker_to']));
  218.             $session->set('datepicker_from_value'$datefrom);
  219.             $session->set('datepicker_to_value'$dateto);
  220.         } elseif ($session->has('datepicker_from_value') && '' != $session->get('datepicker_from_value')
  221.                 && $session->has('datepicker_to_value') && '' != $session->get('datepicker_to_value')) {
  222.             $datefrom $session->get('datepicker_from_value');
  223.             $dateto $session->get('datepicker_to_value');
  224.             $datepicker_from_value date('d/m/Y'strtotime($session->get('datepicker_from_value')));
  225.             $datepicker_to_value date('d/m/Y'strtotime($session->get('datepicker_to_value')));
  226.         } else {
  227.             $datefrom = new \DateTime();
  228.             $datefrom->modify('-29 days');
  229.             $datepicker_from_value $datefrom->format('d/m/Y');
  230.             $datefrom $datefrom->format('Y-m-d').' 00:00:00';
  231.             $dateto = new \DateTime();
  232.             $datepicker_to_value $dateto->format('d/m/Y');
  233.             $dateto $dateto->format('Y-m-d').' 23:59:59';
  234.         }
  235.         $origin $request->query->has('origin') ? $request->query->get('origin') : null;
  236.         $category $request->query->has('c') ? $request->query->get('c') : null;
  237.         $subcategory $request->query->has('sc') ? $request->query->get('sc') : null;
  238.         $originTitle '';
  239.         switch ($origin) {
  240.             case 'aps':
  241.                 $originTitle 'Profesionales de la salud';
  242.             break;
  243.             case 'lfh':
  244.                 $originTitle 'La Farmacia Hoy';
  245.             break;
  246.             case 'advancedkit':
  247.                 $originTitle 'AdvancedKit';
  248.             break;
  249.             case 'faesclinic':
  250.                 $originTitle 'Faes Clinic';
  251.             break;
  252.             case 'farmaquiz':
  253.                 $originTitle 'Faes Farma Quiz';
  254.             break;
  255.             case 'arcenepoc':
  256.                 $originTitle 'ARC en EPOC';
  257.             break;
  258.         }
  259.         $pagesControl = [];
  260.         $pages = [];
  261.         $usersControl = [];
  262.         $users = [];
  263.         $tags = [];
  264.         $subtags = [];
  265.         if (null != $origin) {
  266.             $tags $categoryRepository->findBy([
  267.                 'origin' => $origin,
  268.                 'parent' => null,
  269.             ]);
  270.             if (null != $category) {
  271.                 $subtags $categoryRepository->findBy([
  272.                     'origin' => $origin,
  273.                     'parent' => $category,
  274.                 ]);
  275.             }
  276.             $_pages $repository->findPagesByOrigin($origin$category$subcategory$datefrom$dateto);
  277.             foreach ($_pages as $_page) {
  278.                 if (null != $_page->getDoctor() && (6908 == $_page->getDoctor()->getId() || 836 == $_page->getDoctor()->getId() || 8370 == $_page->getDoctor()->getId())) {
  279.                     continue;
  280.                 }
  281.                 if (null != $_page->getParticular() && (3359 == $_page->getParticular()->getId() || 526 == $_page->getParticular()->getId() || 9901 == $_page->getParticular()->getId() || 4034 == $_page->getParticular()->getId())) {
  282.                     continue;
  283.                 }
  284.                 if (!key_exists($_page->getPageId(), $pagesControl)) {
  285.                     $pagesControl[$_page->getPageId()] = [
  286.                         'doctors' => [],
  287.                         'particulars' => [],
  288.                     ];
  289.                     $pages[$_page->getPageId()] = [
  290.                         'title' => $_page->getPageTitle(),
  291.                         'url' => $_page->getPageUrl(),
  292.                         'visits' => 1,
  293.                         'users' => 1,
  294.                     ];
  295.                 } else {
  296.                     if (null != $_page->getDoctor()) {
  297.                         $pagesControl[$_page->getPageId()]['doctors'][] = $_page->getDoctor()->getId();
  298.                     }
  299.                     if (null != $_page->getParticular()) {
  300.                         $pagesControl[$_page->getPageId()]['particulars'][] = $_page->getParticular()->getId();
  301.                     }
  302.                     $pages[$_page->getPageId()]['visits'] = count($pagesControl[$_page->getPageId()]['doctors']) + count($pagesControl[$_page->getPageId()]['particulars']);
  303.                     $pages[$_page->getPageId()]['users'] = count(array_unique($pagesControl[$_page->getPageId()]['doctors'])) + count(array_unique($pagesControl[$_page->getPageId()]['particulars']));
  304.                 }
  305.                 if (null != $_page->getDoctor()) {
  306.                     if (!key_exists($_page->getDoctor()->getId(), $users)) {
  307.                         $users[$_page->getDoctor()->getId()]['is_doctor'] = 1;
  308.                         $users[$_page->getDoctor()->getId()]['id'] = $_page->getDoctor()->getId();
  309.                         $users[$_page->getDoctor()->getId()]['visits'] = 1;
  310.                         $users[$_page->getDoctor()->getId()]['sessions'][] = $_page->getExtra();
  311.                         $users[$_page->getDoctor()->getId()]['sessions_number'] = 1;
  312.                         try {
  313.                             $users[$_page->getDoctor()->getId()]['name'] = $_page->getDoctor()->getUsername();
  314.                         } catch (Exception $e) {
  315.                             $users[$_page->getDoctor()->getId()]['name'] = $_page->getDoctor()->getId();
  316.                         }
  317.                     } else {
  318.                         $users[$_page->getDoctor()->getId()]['visits'] = $users[$_page->getDoctor()->getId()]['visits'] + 1;
  319.                         if (!in_array($_page->getExtra(), $users[$_page->getDoctor()->getId()]['sessions'])) {
  320.                             $users[$_page->getDoctor()->getId()]['sessions'][] = $_page->getExtra();
  321.                         }
  322.                         $users[$_page->getDoctor()->getId()]['sessions_number'] = count($users[$_page->getDoctor()->getId()]['sessions']);
  323.                     }
  324.                 }
  325.                 if (null != $_page->getParticular()) {
  326.                     if (!key_exists($_page->getParticular()->getId(), $users)) {
  327.                         $users[$_page->getParticular()->getId()]['is_doctor'] = 0;
  328.                         $users[$_page->getParticular()->getId()]['id'] = $_page->getParticular()->getId();
  329.                         $users[$_page->getParticular()->getId()]['visits'] = 1;
  330.                         $users[$_page->getParticular()->getId()]['sessions'][] = $_page->getExtra();
  331.                         $users[$_page->getParticular()->getId()]['sessions_number'] = 1;
  332.                         try {
  333.                             $users[$_page->getParticular()->getId()]['name'] = $_page->getParticular()->getUsername();
  334.                         } catch (Exception $e) {
  335.                             $users[$_page->getParticular()->getId()]['name'] = $_page->getParticular()->getId();
  336.                         }
  337.                     } else {
  338.                         $users[$_page->getParticular()->getId()]['visits'] = $users[$_page->getParticular()->getId()]['visits'] + 1;
  339.                         if (!in_array($_page->getExtra(), $users[$_page->getParticular()->getId()]['sessions'])) {
  340.                             $users[$_page->getParticular()->getId()]['sessions'][] = $_page->getExtra();
  341.                         }
  342.                         $users[$_page->getParticular()->getId()]['sessions_number'] = count($users[$_page->getParticular()->getId()]['sessions']);
  343.                     }
  344.                 }
  345.             }
  346.             $pages Utils::orderMultiDimensionalArray($pages'visits'true);
  347.             $users Utils::orderMultiDimensionalArray($users'visits'true);
  348.         }
  349.         return $this->render('backend/dashboard/contenido.html.twig', [
  350.             'menu_section' => 'dashboard',
  351.             'origin' => $origin,
  352.             'originTitle' => $originTitle,
  353.             'pages' => $pages,
  354.             'users' => $users,
  355.             'tags' => $tags,
  356.             'subtags' => $subtags,
  357.             'datepicker_from_value' => $datepicker_from_value,
  358.             'datepicker_to_value' => $datepicker_to_value,
  359.         ]);
  360.     }
  361.     public function admin_homepage()
  362.     {
  363.         if (== $this->getUser()->getId() || 15 == $this->getUser()->getId() || 17 == $this->getUser()->getId()) {
  364.             return $this->redirectToRoute('ecommerce_vademecum_product_list');
  365.         }
  366.         if (== $this->getUser()->getId()) {
  367.             return $this->redirectToRoute('tecnico_vademecum_product_list');
  368.         }
  369.         
  370.         if (18 == $this->getUser()->getId()) {
  371.             return $this->redirectToRoute('admin_imp_ruta_formativa_list');
  372.         }           
  373.         if ('POST' === $_SERVER['REQUEST_METHOD']) {
  374.             $datefrom $_POST['datepicker_from'].' 00:00:00';
  375.             $dateto $_POST['datepicker_to'].' 23:59:59';
  376.             $datepicker_from_value date('d/m/Y'strtotime($_POST['datepicker_from']));
  377.             $datepicker_to_value date('d/m/Y'strtotime($_POST['datepicker_to']));
  378.         } else {
  379.             $datefrom = new \DateTime();
  380.             $datefrom->modify('-29 days');
  381.             $datepicker_from_value $datefrom->format('d/m/Y');
  382.             $datefrom $datefrom->format('Y-m-d').' 00:00:00';
  383.             $dateto = new \DateTime();
  384.             $datepicker_to_value $dateto->format('d/m/Y');
  385.             $dateto $dateto->format('Y-m-d').' 23:59:59';
  386.         }
  387.         $entityManager $this->getDoctrine()->getManager();
  388.         $repository $this->getDoctrine()->getRepository(Analytics::class);
  389.         $particularRepository $this->getDoctrine()->getRepository(Particular::class);
  390.         $doctorRepository $this->getDoctrine()->getRepository(Doctor::class);
  391.         $userAnalyticsRepository $this->getDoctrine()->getRepository(UserAnalytics::class);
  392.         $_logins $repository->findLoginUsers($datefrom$dateto);
  393.         $logins = [];
  394.         foreach ($_logins as $login) {
  395.             $logins[] = [
  396.                 'particular' => $particularRepository->find($login['id']),
  397.                 'counter' => $login['counter'],
  398.                 'views' => $userAnalyticsRepository->findPageCountByOriginAndUser(null$particularRepository->find($login['id'])),
  399.             ];
  400.         }
  401.         $logins Utils::orderMultiDimensionalArray($logins'counter'true);
  402.         $_doctorLogins $repository->findLoginDoctors($datefrom$dateto);
  403.         $doctorLogins = [];
  404.         foreach ($_doctorLogins as $_doctorLogin) {
  405.             $doctorLogins[] = [
  406.                 'doctor' => $doctorRepository->find($_doctorLogin['id']),
  407.                 'counter' => $_doctorLogin['counter'],
  408.                 'views' => $userAnalyticsRepository->findPageCountByOriginAndUser($doctorRepository->find($_doctorLogin['id']), null),
  409.             ];
  410.         }
  411.         $doctorLogins Utils::orderMultiDimensionalArray($doctorLogins'counter'true);
  412.         return $this->render('backend/index.html.twig', [
  413.             'menu_section' => 'dashboard',
  414.             'logins' => $logins,
  415.             'doctorLogins' => $doctorLogins,
  416.             'particular_total' => $particularRepository->getTotal(),
  417.             'doctor_total' => $doctorRepository->getTotal(),
  418.             'datepicker_from_value' => $datepicker_from_value,
  419.             'datepicker_to_value' => $datepicker_to_value,
  420.         ]);
  421.     }
  422.     public function admin_homepage_cursos()
  423.     {
  424.         if ('POST' === $_SERVER['REQUEST_METHOD']) {
  425.             $datefrom $_POST['datepicker_from'].' 00:00:00';
  426.             $dateto $_POST['datepicker_to'].' 23:59:59';
  427.             $datepicker_from_value date('d/m/Y'strtotime($_POST['datepicker_from']));
  428.             $datepicker_to_value date('d/m/Y'strtotime($_POST['datepicker_to']));
  429.         } else {
  430.             $datefrom = new \DateTime();
  431.             $datefrom->modify('-29 days');
  432.             $datepicker_from_value $datefrom->format('d/m/Y');
  433.             $datefrom $datefrom->format('Y-m-d').' 00:00:00';
  434.             $dateto = new \DateTime();
  435.             $datepicker_to_value $dateto->format('d/m/Y');
  436.             $dateto $dateto->format('Y-m-d').' 23:59:59';
  437.         }
  438.         $entityManager $this->getDoctrine()->getManager();
  439.         $repository $this->getDoctrine()->getRepository(Analytics::class);
  440.         $particularRepository $this->getDoctrine()->getRepository(Particular::class);
  441.         $doctorRespository $this->getDoctrine()->getRepository(Doctor::class);
  442.         $cursoParticularRepository $this->getDoctrine()->getRepository(CursoParticular::class);
  443.         $cursoDoctorRepository $this->getDoctrine()->getRepository(CursoDoctor::class);
  444.         $cursoRepository $this->getDoctrine()->getRepository(Curso::class);
  445.         $_cursos $cursoRepository->findAll();
  446.         $cursos = [];
  447.         foreach ($_cursos as $curso) {
  448.             $countParticulars count($cursoParticularRepository->findParticipants($curso->getId(), $datefrom$dateto));
  449.             $countDoctors count($cursoDoctorRepository->findParticipants($curso->getId(), $datefrom$dateto));
  450.             if ($countParticulars 0) {
  451.                 $cursos[] = [
  452.                     'id' => $curso->getId(),
  453.                     'title' => $curso->getTitle(),
  454.                     'count' => $countParticulars,
  455.                     'type' => 'Farmacias',
  456.                 ];
  457.             } elseif ($countDoctors 0) {
  458.                 $cursos[] = [
  459.                     'id' => $curso->getId(),
  460.                     'title' => $curso->getTitle(),
  461.                     'count' => $countDoctors,
  462.                     'type' => 'Médicos',
  463.                 ];
  464.             }
  465.         }
  466.         $cursos Utils::orderMultiDimensionalArray($cursos'count'true);
  467.         $_particularsWithCursos $cursoParticularRepository->findOrderedByCount($datefrom$dateto);
  468.         $particularsWithCursos = [];
  469.         foreach ($_particularsWithCursos as $_particularsWithCurso) {
  470.             $particularsWithCursos[] = [
  471.                 'doctor' => null,
  472.                 'particular' => $particularRepository->find($_particularsWithCurso['id']),
  473.                 'counter' => $_particularsWithCurso['counter'],
  474.             ];
  475.         }
  476.         $_doctorsWithCursos $cursoParticularRepository->findOrderedByCount($datefrom$dateto);
  477.         foreach ($_doctorsWithCursos as $_doctorsWithCurso) {
  478.             $particularsWithCursos[] = [
  479.                 'doctor' => $doctorRespository->find($_doctorsWithCurso['id']),
  480.                 'particular' => null,
  481.                 'counter' => $_doctorsWithCurso['counter'],
  482.             ];
  483.         }
  484.         $particularsWithCursos Utils::orderMultiDimensionalArray($particularsWithCursos'counter'true);
  485.         return $this->render('backend/dashboard/cursos.html.twig', [
  486.             'menu_section' => 'dashboard',
  487.             'cursos' => $cursos,
  488.             'particularsWithCursos' => $particularsWithCursos,
  489.             'datepicker_from_value' => $datepicker_from_value,
  490.             'datepicker_to_value' => $datepicker_to_value,
  491.         ]);
  492.     }
  493.     public function admin_homepage_casos()
  494.     {
  495.         if ('POST' === $_SERVER['REQUEST_METHOD']) {
  496.             $datefrom $_POST['datepicker_from'].' 00:00:00';
  497.             $dateto $_POST['datepicker_to'].' 23:59:59';
  498.             $datepicker_from_value date('d/m/Y'strtotime($_POST['datepicker_from']));
  499.             $datepicker_to_value date('d/m/Y'strtotime($_POST['datepicker_to']));
  500.         } else {
  501.             $datefrom = new \DateTime();
  502.             $datefrom->modify('-29 days');
  503.             $datepicker_from_value $datefrom->format('d/m/Y');
  504.             $datefrom $datefrom->format('Y-m-d').' 00:00:00';
  505.             $dateto = new \DateTime();
  506.             $datepicker_to_value $dateto->format('d/m/Y');
  507.             $dateto $dateto->format('Y-m-d').' 23:59:59';
  508.         }
  509.         $entityManager $this->getDoctrine()->getManager();
  510.         $repository $this->getDoctrine()->getRepository(Analytics::class);
  511.         $particularRepository $this->getDoctrine()->getRepository(Particular::class);
  512.         $doctorRepository $this->getDoctrine()->getRepository(Doctor::class);
  513.         $cursoParticularRepository $this->getDoctrine()->getRepository(CursoParticular::class);
  514.         $cursoRepository $this->getDoctrine()->getRepository(Curso::class);
  515.         $casoClinicoUserRepository $this->getDoctrine()->getRepository(CasoClinicoUser::class);
  516.         $casoClinicoRepository $this->getDoctrine()->getRepository(CasoClinico::class);
  517.         $_casosclinicos $casoClinicoRepository->findAll();
  518.         $casosclinicos = [];
  519.         foreach ($_casosclinicos as $_casosclinico) {
  520.             $participants = [];
  521.             $userResponses $casoClinicoUserRepository->getUserResponsesByDate($_casosclinico->getId(), $datefrom$dateto);
  522.             foreach ($userResponses as $userResponse) {
  523.                 if (!in_array($userResponse->getUserId(), $participants)) {
  524.                     $participants[] = $userResponse->getUserId();
  525.                 }
  526.             }
  527.             $casosclinicos[] = [
  528.                 'id' => $_casosclinico->getId(),
  529.                 'title' => $_casosclinico->getTitle(),
  530.                 'counter' => count($participants),
  531.             ];
  532.         }
  533.         $casosclinicos Utils::orderMultiDimensionalArray($casosclinicos'counter'true);
  534.         $usersWithCasosClinicos $casoClinicoUserRepository->findOrderedByCount($datefrom$dateto);
  535.         foreach ($usersWithCasosClinicos as $key => $usersWithCasosClinico) {
  536.             $doctor $doctorRepository->find($usersWithCasosClinico['user_id']);
  537.             if ($doctor) {
  538.                 $usersWithCasosClinicos[$key]['doctor'] = $doctor;
  539.             } else {
  540.                 unset($usersWithCasosClinicos[$key]);
  541.             }
  542.         }
  543.         return $this->render('backend/dashboard/casos.html.twig', [
  544.             'menu_section' => 'dashboard',
  545.             'casosclinicos' => $casosclinicos,
  546.             'usersWithCasosClinicos' => $usersWithCasosClinicos,
  547.             'datepicker_from_value' => $datepicker_from_value,
  548.             'datepicker_to_value' => $datepicker_to_value,
  549.         ]);
  550.     }
  551.     public function admin_homepage_quiz()
  552.     {
  553.         if ('POST' === $_SERVER['REQUEST_METHOD']) {
  554.             $datefrom $_POST['datepicker_from'].' 00:00:00';
  555.             $dateto $_POST['datepicker_to'].' 23:59:59';
  556.             $datepicker_from_value date('d/m/Y'strtotime($_POST['datepicker_from']));
  557.             $datepicker_to_value date('d/m/Y'strtotime($_POST['datepicker_to']));
  558.         } else {
  559.             $datefrom = new \DateTime();
  560.             $datefrom->modify('-29 days');
  561.             $datepicker_from_value $datefrom->format('d/m/Y');
  562.             $datefrom $datefrom->format('Y-m-d').' 00:00:00';
  563.             $dateto = new \DateTime();
  564.             $datepicker_to_value $dateto->format('d/m/Y');
  565.             $dateto $dateto->format('Y-m-d').' 23:59:59';
  566.         }
  567.         $entityManager $this->getDoctrine()->getManager();
  568.         $repository $this->getDoctrine()->getRepository(Analytics::class);
  569.         $particularRepository $this->getDoctrine()->getRepository(Particular::class);
  570.         $doctorRepository $this->getDoctrine()->getRepository(Doctor::class);
  571.         $cursoParticularRepository $this->getDoctrine()->getRepository(CursoParticular::class);
  572.         $cursoRepository $this->getDoctrine()->getRepository(Curso::class);
  573.         $casoClinicoUserRepository $this->getDoctrine()->getRepository(CasoClinicoUser::class);
  574.         $casoClinicoRepository $this->getDoctrine()->getRepository(CasoClinico::class);
  575.         $quizRepository $this->getDoctrine()->getRepository(Quiz::class);
  576.         $quizResponseRepository $this->getDoctrine()->getRepository(QuizResponse::class);
  577.         $_quizes $quizRepository->findAll();
  578.         $quizes = [];
  579.         foreach ($_quizes as $_quiz) {
  580.             $participants = [];
  581.             $userResponses $quizResponseRepository->getUserResponsesByDate($_quiz->getId(), $datefrom$dateto);
  582.             foreach ($userResponses as $userResponse) {
  583.                 if (!in_array($userResponse->getParticular()->getId(), $participants)) {
  584.                     $participants[] = $userResponse->getParticular()->getId();
  585.                 }
  586.             }
  587.             $quizes[] = [
  588.                 'id' => $_quiz->getId(),
  589.                 'title' => $_quiz->getTitle(),
  590.                 'quiztype' => $_quiz->getQuiztype(),
  591.                 'counter' => count($participants),
  592.             ];
  593.         }
  594.         $quizes Utils::orderMultiDimensionalArray($quizes'counter'true);
  595.         $_usersWithQuizes $quizResponseRepository->findOrderedByCount($datefrom$dateto);
  596.         $usersWithQuizes = [];
  597.         foreach ($_usersWithQuizes as $key => $usersWithQuiz) {
  598.             if (!array_key_exists($usersWithQuiz['id'], $usersWithQuizes)) {
  599.                 $usersWithQuizes[$usersWithQuiz['id']][] = $usersWithQuiz['quiz_id'];
  600.             } else {
  601.                 if (!in_array($usersWithQuiz['quiz_id'], $usersWithQuizes[$usersWithQuiz['id']])) {
  602.                     $usersWithQuizes[$usersWithQuiz['id']][] = $usersWithQuiz['quiz_id'];
  603.                 }
  604.             }
  605.         }
  606.         $finalUsersWithQuizes = [];
  607.         foreach ($usersWithQuizes as $key => $usersWithQuiz) {
  608.             $finalUsersWithQuizes[] = [
  609.                 'particular' => $particularRepository->find($key),
  610.                 'counter' => count($usersWithQuiz),
  611.             ];
  612.         }
  613.         $finalUsersWithQuizes Utils::orderMultiDimensionalArray($finalUsersWithQuizes'counter'true);
  614.         return $this->render('backend/dashboard/quiz.html.twig', [
  615.             'menu_section' => 'dashboard',
  616.             'quizes' => $quizes,
  617.             'usersWithQuizes' => $finalUsersWithQuizes,
  618.             'datepicker_from_value' => $datepicker_from_value,
  619.             'datepicker_to_value' => $datepicker_to_value,
  620.         ]);
  621.     }
  622.     public function admin_homepage_vademecum()
  623.     {
  624.         if ('POST' === $_SERVER['REQUEST_METHOD']) {
  625.             $datefrom $_POST['datepicker_from'].' 00:00:00';
  626.             $dateto $_POST['datepicker_to'].' 23:59:59';
  627.             $datepicker_from_value date('d/m/Y'strtotime($_POST['datepicker_from']));
  628.             $datepicker_to_value date('d/m/Y'strtotime($_POST['datepicker_to']));
  629.         } else {
  630.             $datefrom = new \DateTime();
  631.             $datefrom->modify('-29 days');
  632.             $datepicker_from_value $datefrom->format('d/m/Y');
  633.             $datefrom $datefrom->format('Y-m-d').' 00:00:00';
  634.             $dateto = new \DateTime();
  635.             $datepicker_to_value $dateto->format('d/m/Y');
  636.             $dateto $dateto->format('Y-m-d').' 23:59:59';
  637.         }
  638.         $vademecumRepository $this->getDoctrine()->getRepository(VademecumPresentation::class);
  639.         $repository $this->getDoctrine()->getRepository(Analytics::class);
  640.         $_vademecumProducts $repository->getByItemTypeForDashboard('vademecum'$datefrom$dateto);
  641.         $vademecumProducts = [];
  642.         $particularVisitsTotal = [];
  643.         $doctorVisitsTotal = [];
  644.         $userVisits = [
  645.             'particulares' => [],
  646.             'doctores' => [],
  647.         ];
  648.         foreach ($_vademecumProducts as $_vademecumProduct) {
  649.             if (null != $_vademecumProduct->getDoctor() && (6908 == $_vademecumProduct->getDoctor()->getId() || 836 == $_vademecumProduct->getDoctor()->getId() || 8370 == $_vademecumProduct->getDoctor()->getId())) {
  650.                 continue;
  651.             }
  652.             if (null != $_vademecumProduct->getParticular() && (3359 == $_vademecumProduct->getParticular()->getId() || 526 == $_vademecumProduct->getParticular()->getId() || 9901 == $_vademecumProduct->getParticular()->getId() || 4034 == $_vademecumProduct->getParticular()->getId())) {
  653.                 continue;
  654.             }
  655.             if (array_key_exists($_vademecumProduct->getItemId(), $vademecumProducts)) {
  656.                 $vademecumProducts[$_vademecumProduct->getItemId()]['users'][] = [
  657.                     'particular' => $_vademecumProduct->getParticular(),
  658.                     'doctor' => $_vademecumProduct->getDoctor(),
  659.                     'date' => $_vademecumProduct->getCreatedAt(),
  660.                     'origin' => $_vademecumProduct->getOrigin(),
  661.                 ];
  662.             } else {
  663.                 $vademecumProducts[$_vademecumProduct->getItemId()] = [
  664.                     'users' => [
  665.                         [
  666.                             'particular' => $_vademecumProduct->getParticular(),
  667.                             'doctor' => $_vademecumProduct->getDoctor(),
  668.                             'date' => $_vademecumProduct->getCreatedAt(),
  669.                             'origin' => $_vademecumProduct->getOrigin(),
  670.                         ],
  671.                     ],
  672.                     'product' => $vademecumRepository->find($_vademecumProduct->getItemId()),
  673.                 ];
  674.             }
  675.             if (null != $_vademecumProduct->getParticular()) {
  676.                 if (!in_array($_vademecumProduct->getParticular()->getId(), $particularVisitsTotal)) {
  677.                     $particularVisitsTotal[] = $_vademecumProduct->getParticular()->getId();
  678.                     $userVisits['particulares'][$_vademecumProduct->getParticular()->getId()] = [
  679.                         'entity' => $_vademecumProduct->getParticular(),
  680.                         'type' => 'particular',
  681.                         'count' => 1,
  682.                     ];
  683.                 } else {
  684.                     ++$userVisits['particulares'][$_vademecumProduct->getParticular()->getId()]['count'];
  685.                 }
  686.             } elseif (null != $_vademecumProduct->getDoctor()) {
  687.                 if (!in_array($_vademecumProduct->getDoctor()->getId(), $doctorVisitsTotal)) {
  688.                     $doctorVisitsTotal[] = $_vademecumProduct->getDoctor()->getId();
  689.                     $userVisits['doctores'][$_vademecumProduct->getDoctor()->getId()] = [
  690.                         'entity' => $_vademecumProduct->getDoctor(),
  691.                         'type' => 'doctor',
  692.                         'count' => 1,
  693.                     ];
  694.                 } else {
  695.                     ++$userVisits['doctores'][$_vademecumProduct->getDoctor()->getId()]['count'];
  696.                 }
  697.             }
  698.             $vademecumProducts[$_vademecumProduct->getItemId()]['totalusers'] = count($vademecumProducts[$_vademecumProduct->getItemId()]['users']);
  699.         }
  700.         foreach ($vademecumProducts as $key => $vademecumProduct) {
  701.             $vademecumProducts[$key]['totalusers'] = count($vademecumProduct['users']);
  702.         }
  703.         $vademecumProducts Utils::orderMultiDimensionalArray($vademecumProducts'totalusers'true);
  704.         $finalVisits = [];
  705.         foreach ($userVisits['particulares'] as $userVisitParticular) {
  706.             $finalVisits[] = $userVisitParticular;
  707.         }
  708.         foreach ($userVisits['doctores'] as $userVisitDoctor) {
  709.             $finalVisits[] = $userVisitDoctor;
  710.         }
  711.         $finalVisits Utils::orderMultiDimensionalArray($finalVisits'count'true);
  712.         return $this->render('backend/dashboard/vademecum.html.twig', [
  713.             'menu_section' => 'dashboard',
  714.             'vademecumProducts' => $vademecumProducts,
  715.             'finalVisits' => $finalVisits,
  716.             'datepicker_from_value' => $datepicker_from_value,
  717.             'datepicker_to_value' => $datepicker_to_value,
  718.         ]);
  719.     }
  720.     public function admin_homepage_impactafaes()
  721.     {
  722.         if ('POST' === $_SERVER['REQUEST_METHOD']) {
  723.             $datefrom $_POST['datepicker_from'].' 00:00:00';
  724.             $dateto $_POST['datepicker_to'].' 23:59:59';
  725.             $datepicker_from_value date('d/m/Y'strtotime($_POST['datepicker_from']));
  726.             $datepicker_to_value date('d/m/Y'strtotime($_POST['datepicker_to']));
  727.         } else {
  728.             $datefrom = new \DateTime();
  729.             $datefrom->modify('-29 days');
  730.             $datepicker_from_value $datefrom->format('d/m/Y');
  731.             $datefrom $datefrom->format('Y-m-d').' 00:00:00';
  732.             $dateto = new \DateTime();
  733.             $datepicker_to_value $dateto->format('d/m/Y');
  734.             $dateto $dateto->format('Y-m-d').' 23:59:59';
  735.         }
  736.         $entityManager $this->getDoctrine()->getManager();
  737.         $repository $this->getDoctrine()->getRepository(Analytics::class);
  738.         $particularRepository $this->getDoctrine()->getRepository(Particular::class);
  739.         $impRutaFormativaRepository $this->getDoctrine()->getRepository(ImpRutaFormativa::class);
  740.         $impModuloRepository $this->getDoctrine()->getRepository(ImpModulos::class);
  741.         $impPildoraRepository $this->getDoctrine()->getRepository(ImpPildoras::class);
  742.         $impRutaFormativaParticularRepository $this->getDoctrine()->getRepository(ImpRutasFormativasParticular::class);
  743.         $impModulosParticularRepository $this->getDoctrine()->getRepository(ImpModulosParticular::class);
  744.         $impPildorasParticularRepository $this->getDoctrine()->getRepository(ImpPildorasParticular::class);
  745.         // usuarios con acceso a impactafaes
  746.         $usersWithAccessToImpactafaes $particularRepository->findBy(["impactafaes" => 1]);
  747.         // usuarios que se han registrado desde impactafaes
  748.         $usersRegisteredInImpactafaes $particularRepository->findBy(["origin" => "impactafaes"]);
  749.         // Cursos
  750.         $_cursos $impRutaFormativaRepository->findAll();
  751.         $cursos = [];
  752.         $cursos_finalizados = [];
  753.         foreach ($_cursos as $curso) {
  754.             $all_finished $impRutaFormativaParticularRepository->findAllCompletedByRuta($curso,$datefrom$dateto);
  755.             $all_unfinished $impRutaFormativaParticularRepository->findAllNotCompletedByRuta($curso,$datefrom$dateto);
  756.             $total_finished count($all_finished);
  757.             $total_unfinished count($all_unfinished);
  758.             $participants = [];
  759.             $userParticipations $impRutaFormativaParticularRepository->getUserResponsesByDate($curso->getId(), $datefrom$dateto);
  760.             foreach ($userParticipations as $userParticipation) {
  761.                 if (!in_array($userParticipation->getParticular()->getId(), $participants)) {
  762.                     $participants[] = $userParticipation->getParticular()->getId();
  763.                 }
  764.             }
  765.             $cursos[] = [
  766.                 'id' => $curso->getId(),
  767.                 'title' => $curso->getTitle(),
  768.                 'counter' => count($participants),
  769.                 'all_finished' => $all_finished,
  770.                 'total_unfinished' => $total_unfinished,
  771.                 'total_finished' => $total_finished,
  772.             ];
  773.         }
  774.         $finalCursos Utils::orderMultiDimensionalArray($cursos'counter'true);
  775.         // Módulos
  776.         $_modulos $impModuloRepository->findAll();
  777.         $modulos = [];
  778.         foreach ($_modulos as $modulo) {
  779.             $all_finished $impModulosParticularRepository->findByModulosfinished($modulo,$datefrom$dateto);
  780.             $participants = [];
  781.             $userParticipations $impModulosParticularRepository->getUserResponsesByDate($modulo->getId(), $datefrom$dateto);
  782.             foreach ($userParticipations as $userParticipation) {
  783.                 if (!in_array($userParticipation->getParticular()->getId(), $participants)) {
  784.                     $participants[] = $userParticipation->getParticular()->getId();
  785.                 }
  786.             }
  787.             $modulos[] = [
  788.                 'id' => $modulo->getId(),
  789.                 'title' => $modulo->getName(),
  790.                 'counter' => count($participants),
  791.                 'all_finished' => $all_finished,
  792.                 'ruta_formativa_id' => $modulo->getRutaFormativa()->getId(),
  793.                 'ruta_formativa_title' => $modulo->getRutaFormativa()->getTitle(),
  794.             ];
  795.         }        
  796.         $finalModulos Utils::orderMultiDimensionalArray($modulos'counter'true);
  797.         // Píldoras
  798.         $_pildoras $impPildoraRepository->findAll();
  799.         $pildoras = [];
  800.         foreach ($_pildoras as $pildora) {
  801.             $participants = [];
  802.             $userParticipations $impPildorasParticularRepository->getUserResponsesByDate($pildora->getId(), $datefrom$dateto);
  803.             foreach ($userParticipations as $userParticipation) {
  804.                 if (!in_array($userParticipation->getParticular()->getId(), $participants)) {
  805.                     $participants[] = $userParticipation->getParticular()->getId();
  806.                 }
  807.             }
  808.             $pildoras[] = [
  809.                 'id' => $pildora->getId(),
  810.                 'title' => $pildora->getName(),
  811.                 'counter' => count($participants),
  812.                 'modulo_id' => $pildora->getImpTema()->getImpModulo()->getId(),
  813.                 'modulo_title' => $pildora->getImpTema()->getImpModulo()->getName(),
  814.                 'ruta_formativa_id' => $pildora->getImpTema()->getImpModulo()->getRutaFormativa()->getId(),
  815.                 'ruta_formativa_title' => $pildora->getImpTema()->getImpModulo()->getRutaFormativa()->getTitle(),
  816.             ];
  817.         }        
  818.         $finalPildoras Utils::orderMultiDimensionalArray($pildoras'counter'true);
  819.         return $this->render('backend/dashboard/impactafaes.html.twig', [
  820.             'menu_section' => 'dashboard',
  821.             'usersWithAccessToImpactafaes' => $usersWithAccessToImpactafaes,
  822.             'usersRegisteredInImpactafaes' => $usersRegisteredInImpactafaes,
  823.             'cursos' => $finalCursos,
  824.             'modulos' => $finalModulos,
  825.             'pildoras' => $finalPildoras,
  826.             'datepicker_from_value' => $datepicker_from_value,
  827.             'datepicker_to_value' => $datepicker_to_value,
  828.         ]);
  829.     }
  830. }