<?php
namespace App\Controller;
use App\Entity\Analytics;
use App\Entity\CasoClinico;
use App\Entity\CasoClinicoUser;
use App\Entity\Curso;
use App\Entity\CursoDoctor;
use App\Entity\CursoParticular;
use App\Entity\Doctor;
use App\Entity\ImpModulos;
use App\Entity\ImpModulosParticular;
use App\Entity\ImpPildoras;
use App\Entity\ImpPildorasParticular;
use App\Entity\ImpRutaFormativa;
use App\Entity\ImpRutasFormativasParticular;
use App\Entity\Particular;
use App\Entity\Quiz;
use App\Entity\QuizResponse;
use App\Entity\UserAnalytics;
use App\Entity\UserAnalyticsCategory;
use App\Entity\VademecumPresentation;
use App\Utils\Utils;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
class DefaultController extends AbstractController
{
public function index()
{
// Llevamos a la home page del administrador
return $this->redirectToRoute('admin_homepage');
}
public function admin_homepage_clicks(Request $request)
{
if (5 == $this->getUser()->getId() || 15 == $this->getUser()->getId() || 17 == $this->getUser()->getId()) {
return $this->redirectToRoute('ecommerce_vademecum_product_list');
}
if (7 == $this->getUser()->getId()) {
return $this->redirectToRoute('tecnico_vademecum_product_list');
}
if (18 == $this->getUser()->getId()) {
return $this->redirectToRoute('admin_imp_ruta_formativa_list');
}
$session = new Session();
$repository = $this->getDoctrine()->getRepository(UserAnalytics::class);
$categoryRepository = $this->getDoctrine()->getRepository(UserAnalyticsCategory::class);
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$datefrom = $_POST['datepicker_from'].' 00:00:00';
$dateto = $_POST['datepicker_to'].' 23:59:59';
$datepicker_from_value = date('d/m/Y', strtotime($_POST['datepicker_from']));
$datepicker_to_value = date('d/m/Y', strtotime($_POST['datepicker_to']));
$session->set('datepicker_from_value', $datefrom);
$session->set('datepicker_to_value', $dateto);
} elseif ($session->has('datepicker_from_value') && '' != $session->get('datepicker_from_value')
&& $session->has('datepicker_to_value') && '' != $session->get('datepicker_to_value')) {
$datefrom = $session->get('datepicker_from_value');
$dateto = $session->get('datepicker_to_value');
$datepicker_from_value = date('d/m/Y', strtotime($session->get('datepicker_from_value')));
$datepicker_to_value = date('d/m/Y', strtotime($session->get('datepicker_to_value')));
} else {
$datefrom = new \DateTime();
$datefrom->modify('-29 days');
$datepicker_from_value = $datefrom->format('d/m/Y');
$datefrom = $datefrom->format('Y-m-d').' 00:00:00';
$dateto = new \DateTime();
$datepicker_to_value = $dateto->format('d/m/Y');
$dateto = $dateto->format('Y-m-d').' 23:59:59';
}
$origin = $request->query->has('origin') ? $request->query->get('origin') : null;
$category = $request->query->has('c') ? $request->query->get('c') : null;
$subcategory = $request->query->has('sc') ? $request->query->get('sc') : null;
$originTitle = '';
switch ($origin) {
case 'aps':
$originTitle = 'Profesionales de la salud';
break;
case 'lfh':
$originTitle = 'La Farmacia Hoy';
break;
case 'advancedkit':
$originTitle = 'AdvancedKit';
break;
case 'faesclinic':
$originTitle = 'Faes Clinic';
break;
case 'farmaquiz':
$originTitle = 'Faes Farma Quiz';
break;
case 'arcenepoc':
$originTitle = 'ARC en EPOC';
break;
}
$pagesControl = [];
$pages = [];
$usersControl = [];
$users = [];
$tags = [];
$subtags = [];
if (null != $origin) {
$tags = $categoryRepository->findBy([
'origin' => $origin,
'parent' => null,
]);
if (null != $category) {
$subtags = $categoryRepository->findBy([
'origin' => $origin,
'parent' => $category,
]);
}
$_pages = $repository->findClicksByOrigin($origin, $category, $subcategory, $datefrom, $dateto);
foreach ($_pages as $_page) {
if (null != $_page->getDoctor() && (6908 == $_page->getDoctor()->getId() || 836 == $_page->getDoctor()->getId() || 8370 == $_page->getDoctor()->getId())) {
continue;
}
if (null != $_page->getParticular() && (3359 == $_page->getParticular()->getId() || 526 == $_page->getParticular()->getId() || 9901 == $_page->getParticular()->getId() || 4034 == $_page->getParticular()->getId())) {
continue;
}
if (!key_exists($_page->getPageId(), $pagesControl)) {
$pagesControl[$_page->getPageId()] = [
'doctors' => [],
'particulars' => [],
];
$pages[$_page->getPageId()] = [
'title' => $_page->getPageTitle(),
'url' => $_page->getPageUrl(),
'button_text' => $_page->getButtonText(),
'visits' => 1,
'users' => 1,
];
} else {
if (null != $_page->getDoctor()) {
$pagesControl[$_page->getPageId()]['doctors'][] = $_page->getDoctor()->getId();
}
if (null != $_page->getParticular()) {
$pagesControl[$_page->getPageId()]['particulars'][] = $_page->getParticular()->getId();
}
$pages[$_page->getPageId()]['visits'] = count($pagesControl[$_page->getPageId()]['doctors']) + count($pagesControl[$_page->getPageId()]['particulars']);
$pages[$_page->getPageId()]['users'] = count(array_unique($pagesControl[$_page->getPageId()]['doctors'])) + count(array_unique($pagesControl[$_page->getPageId()]['particulars']));
}
if (null != $_page->getDoctor()) {
if (!key_exists($_page->getDoctor()->getId(), $users)) {
$users[$_page->getDoctor()->getId()]['is_doctor'] = 1;
$users[$_page->getDoctor()->getId()]['id'] = $_page->getDoctor()->getId();
$users[$_page->getDoctor()->getId()]['visits'] = 1;
$users[$_page->getDoctor()->getId()]['sessions'][] = $_page->getExtra();
$users[$_page->getDoctor()->getId()]['sessions_number'] = 1;
try {
$users[$_page->getDoctor()->getId()]['name'] = $_page->getDoctor()->getUsername();
} catch (Exception $e) {
$users[$_page->getDoctor()->getId()]['name'] = $_page->getDoctor()->getId();
}
} else {
$users[$_page->getDoctor()->getId()]['visits'] = $users[$_page->getDoctor()->getId()]['visits'] + 1;
if (!in_array($_page->getExtra(), $users[$_page->getDoctor()->getId()]['sessions'])) {
$users[$_page->getDoctor()->getId()]['sessions'][] = $_page->getExtra();
}
$users[$_page->getDoctor()->getId()]['sessions_number'] = count($users[$_page->getDoctor()->getId()]['sessions']);
}
}
if (null != $_page->getParticular()) {
if (!key_exists($_page->getParticular()->getId(), $users)) {
$users[$_page->getParticular()->getId()]['is_doctor'] = 0;
$users[$_page->getParticular()->getId()]['id'] = $_page->getParticular()->getId();
$users[$_page->getParticular()->getId()]['visits'] = 1;
$users[$_page->getParticular()->getId()]['sessions'][] = $_page->getExtra();
$users[$_page->getParticular()->getId()]['sessions_number'] = 1;
try {
$users[$_page->getParticular()->getId()]['name'] = $_page->getParticular()->getUsername();
} catch (Exception $e) {
$users[$_page->getParticular()->getId()]['name'] = $_page->getParticular()->getId();
}
} else {
$users[$_page->getParticular()->getId()]['visits'] = $users[$_page->getParticular()->getId()]['visits'] + 1;
if (!in_array($_page->getExtra(), $users[$_page->getParticular()->getId()]['sessions'])) {
$users[$_page->getParticular()->getId()]['sessions'][] = $_page->getExtra();
}
$users[$_page->getParticular()->getId()]['sessions_number'] = count($users[$_page->getParticular()->getId()]['sessions']);
}
}
}
$pages = Utils::orderMultiDimensionalArray($pages, 'visits', true);
$users = Utils::orderMultiDimensionalArray($users, 'visits', true);
}
return $this->render('backend/dashboard/clicks.html.twig', [
'menu_section' => 'dashboard',
'origin' => $origin,
'originTitle' => $originTitle,
'pages' => $pages,
'users' => $users,
'tags' => $tags,
'subtags' => $subtags,
'datepicker_from_value' => $datepicker_from_value,
'datepicker_to_value' => $datepicker_to_value,
]);
}
public function admin_homepage_contenido(Request $request)
{
if (5 == $this->getUser()->getId() || 15 == $this->getUser()->getId() || 17 == $this->getUser()->getId()) {
return $this->redirectToRoute('ecommerce_vademecum_product_list');
}
if (7 == $this->getUser()->getId()) {
return $this->redirectToRoute('tecnico_vademecum_product_list');
}
if (18 == $this->getUser()->getId()) {
return $this->redirectToRoute('admin_imp_ruta_formativa_list');
}
$session = new Session();
$repository = $this->getDoctrine()->getRepository(UserAnalytics::class);
$categoryRepository = $this->getDoctrine()->getRepository(UserAnalyticsCategory::class);
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$datefrom = $_POST['datepicker_from'].' 00:00:00';
$dateto = $_POST['datepicker_to'].' 23:59:59';
$datepicker_from_value = date('d/m/Y', strtotime($_POST['datepicker_from']));
$datepicker_to_value = date('d/m/Y', strtotime($_POST['datepicker_to']));
$session->set('datepicker_from_value', $datefrom);
$session->set('datepicker_to_value', $dateto);
} elseif ($session->has('datepicker_from_value') && '' != $session->get('datepicker_from_value')
&& $session->has('datepicker_to_value') && '' != $session->get('datepicker_to_value')) {
$datefrom = $session->get('datepicker_from_value');
$dateto = $session->get('datepicker_to_value');
$datepicker_from_value = date('d/m/Y', strtotime($session->get('datepicker_from_value')));
$datepicker_to_value = date('d/m/Y', strtotime($session->get('datepicker_to_value')));
} else {
$datefrom = new \DateTime();
$datefrom->modify('-29 days');
$datepicker_from_value = $datefrom->format('d/m/Y');
$datefrom = $datefrom->format('Y-m-d').' 00:00:00';
$dateto = new \DateTime();
$datepicker_to_value = $dateto->format('d/m/Y');
$dateto = $dateto->format('Y-m-d').' 23:59:59';
}
$origin = $request->query->has('origin') ? $request->query->get('origin') : null;
$category = $request->query->has('c') ? $request->query->get('c') : null;
$subcategory = $request->query->has('sc') ? $request->query->get('sc') : null;
$originTitle = '';
switch ($origin) {
case 'aps':
$originTitle = 'Profesionales de la salud';
break;
case 'lfh':
$originTitle = 'La Farmacia Hoy';
break;
case 'advancedkit':
$originTitle = 'AdvancedKit';
break;
case 'faesclinic':
$originTitle = 'Faes Clinic';
break;
case 'farmaquiz':
$originTitle = 'Faes Farma Quiz';
break;
case 'arcenepoc':
$originTitle = 'ARC en EPOC';
break;
}
$pagesControl = [];
$pages = [];
$usersControl = [];
$users = [];
$tags = [];
$subtags = [];
if (null != $origin) {
$tags = $categoryRepository->findBy([
'origin' => $origin,
'parent' => null,
]);
if (null != $category) {
$subtags = $categoryRepository->findBy([
'origin' => $origin,
'parent' => $category,
]);
}
$_pages = $repository->findPagesByOrigin($origin, $category, $subcategory, $datefrom, $dateto);
foreach ($_pages as $_page) {
if (null != $_page->getDoctor() && (6908 == $_page->getDoctor()->getId() || 836 == $_page->getDoctor()->getId() || 8370 == $_page->getDoctor()->getId())) {
continue;
}
if (null != $_page->getParticular() && (3359 == $_page->getParticular()->getId() || 526 == $_page->getParticular()->getId() || 9901 == $_page->getParticular()->getId() || 4034 == $_page->getParticular()->getId())) {
continue;
}
if (!key_exists($_page->getPageId(), $pagesControl)) {
$pagesControl[$_page->getPageId()] = [
'doctors' => [],
'particulars' => [],
];
$pages[$_page->getPageId()] = [
'title' => $_page->getPageTitle(),
'url' => $_page->getPageUrl(),
'visits' => 1,
'users' => 1,
];
} else {
if (null != $_page->getDoctor()) {
$pagesControl[$_page->getPageId()]['doctors'][] = $_page->getDoctor()->getId();
}
if (null != $_page->getParticular()) {
$pagesControl[$_page->getPageId()]['particulars'][] = $_page->getParticular()->getId();
}
$pages[$_page->getPageId()]['visits'] = count($pagesControl[$_page->getPageId()]['doctors']) + count($pagesControl[$_page->getPageId()]['particulars']);
$pages[$_page->getPageId()]['users'] = count(array_unique($pagesControl[$_page->getPageId()]['doctors'])) + count(array_unique($pagesControl[$_page->getPageId()]['particulars']));
}
if (null != $_page->getDoctor()) {
if (!key_exists($_page->getDoctor()->getId(), $users)) {
$users[$_page->getDoctor()->getId()]['is_doctor'] = 1;
$users[$_page->getDoctor()->getId()]['id'] = $_page->getDoctor()->getId();
$users[$_page->getDoctor()->getId()]['visits'] = 1;
$users[$_page->getDoctor()->getId()]['sessions'][] = $_page->getExtra();
$users[$_page->getDoctor()->getId()]['sessions_number'] = 1;
try {
$users[$_page->getDoctor()->getId()]['name'] = $_page->getDoctor()->getUsername();
} catch (Exception $e) {
$users[$_page->getDoctor()->getId()]['name'] = $_page->getDoctor()->getId();
}
} else {
$users[$_page->getDoctor()->getId()]['visits'] = $users[$_page->getDoctor()->getId()]['visits'] + 1;
if (!in_array($_page->getExtra(), $users[$_page->getDoctor()->getId()]['sessions'])) {
$users[$_page->getDoctor()->getId()]['sessions'][] = $_page->getExtra();
}
$users[$_page->getDoctor()->getId()]['sessions_number'] = count($users[$_page->getDoctor()->getId()]['sessions']);
}
}
if (null != $_page->getParticular()) {
if (!key_exists($_page->getParticular()->getId(), $users)) {
$users[$_page->getParticular()->getId()]['is_doctor'] = 0;
$users[$_page->getParticular()->getId()]['id'] = $_page->getParticular()->getId();
$users[$_page->getParticular()->getId()]['visits'] = 1;
$users[$_page->getParticular()->getId()]['sessions'][] = $_page->getExtra();
$users[$_page->getParticular()->getId()]['sessions_number'] = 1;
try {
$users[$_page->getParticular()->getId()]['name'] = $_page->getParticular()->getUsername();
} catch (Exception $e) {
$users[$_page->getParticular()->getId()]['name'] = $_page->getParticular()->getId();
}
} else {
$users[$_page->getParticular()->getId()]['visits'] = $users[$_page->getParticular()->getId()]['visits'] + 1;
if (!in_array($_page->getExtra(), $users[$_page->getParticular()->getId()]['sessions'])) {
$users[$_page->getParticular()->getId()]['sessions'][] = $_page->getExtra();
}
$users[$_page->getParticular()->getId()]['sessions_number'] = count($users[$_page->getParticular()->getId()]['sessions']);
}
}
}
$pages = Utils::orderMultiDimensionalArray($pages, 'visits', true);
$users = Utils::orderMultiDimensionalArray($users, 'visits', true);
}
return $this->render('backend/dashboard/contenido.html.twig', [
'menu_section' => 'dashboard',
'origin' => $origin,
'originTitle' => $originTitle,
'pages' => $pages,
'users' => $users,
'tags' => $tags,
'subtags' => $subtags,
'datepicker_from_value' => $datepicker_from_value,
'datepicker_to_value' => $datepicker_to_value,
]);
}
public function admin_homepage()
{
if (5 == $this->getUser()->getId() || 15 == $this->getUser()->getId() || 17 == $this->getUser()->getId()) {
return $this->redirectToRoute('ecommerce_vademecum_product_list');
}
if (7 == $this->getUser()->getId()) {
return $this->redirectToRoute('tecnico_vademecum_product_list');
}
if (18 == $this->getUser()->getId()) {
return $this->redirectToRoute('admin_imp_ruta_formativa_list');
}
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$datefrom = $_POST['datepicker_from'].' 00:00:00';
$dateto = $_POST['datepicker_to'].' 23:59:59';
$datepicker_from_value = date('d/m/Y', strtotime($_POST['datepicker_from']));
$datepicker_to_value = date('d/m/Y', strtotime($_POST['datepicker_to']));
} else {
$datefrom = new \DateTime();
$datefrom->modify('-29 days');
$datepicker_from_value = $datefrom->format('d/m/Y');
$datefrom = $datefrom->format('Y-m-d').' 00:00:00';
$dateto = new \DateTime();
$datepicker_to_value = $dateto->format('d/m/Y');
$dateto = $dateto->format('Y-m-d').' 23:59:59';
}
$entityManager = $this->getDoctrine()->getManager();
$repository = $this->getDoctrine()->getRepository(Analytics::class);
$particularRepository = $this->getDoctrine()->getRepository(Particular::class);
$doctorRepository = $this->getDoctrine()->getRepository(Doctor::class);
$userAnalyticsRepository = $this->getDoctrine()->getRepository(UserAnalytics::class);
$_logins = $repository->findLoginUsers($datefrom, $dateto);
$logins = [];
foreach ($_logins as $login) {
$logins[] = [
'particular' => $particularRepository->find($login['id']),
'counter' => $login['counter'],
'views' => $userAnalyticsRepository->findPageCountByOriginAndUser(null, $particularRepository->find($login['id'])),
];
}
$logins = Utils::orderMultiDimensionalArray($logins, 'counter', true);
$_doctorLogins = $repository->findLoginDoctors($datefrom, $dateto);
$doctorLogins = [];
foreach ($_doctorLogins as $_doctorLogin) {
$doctorLogins[] = [
'doctor' => $doctorRepository->find($_doctorLogin['id']),
'counter' => $_doctorLogin['counter'],
'views' => $userAnalyticsRepository->findPageCountByOriginAndUser($doctorRepository->find($_doctorLogin['id']), null),
];
}
$doctorLogins = Utils::orderMultiDimensionalArray($doctorLogins, 'counter', true);
return $this->render('backend/index.html.twig', [
'menu_section' => 'dashboard',
'logins' => $logins,
'doctorLogins' => $doctorLogins,
'particular_total' => $particularRepository->getTotal(),
'doctor_total' => $doctorRepository->getTotal(),
'datepicker_from_value' => $datepicker_from_value,
'datepicker_to_value' => $datepicker_to_value,
]);
}
public function admin_homepage_cursos()
{
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$datefrom = $_POST['datepicker_from'].' 00:00:00';
$dateto = $_POST['datepicker_to'].' 23:59:59';
$datepicker_from_value = date('d/m/Y', strtotime($_POST['datepicker_from']));
$datepicker_to_value = date('d/m/Y', strtotime($_POST['datepicker_to']));
} else {
$datefrom = new \DateTime();
$datefrom->modify('-29 days');
$datepicker_from_value = $datefrom->format('d/m/Y');
$datefrom = $datefrom->format('Y-m-d').' 00:00:00';
$dateto = new \DateTime();
$datepicker_to_value = $dateto->format('d/m/Y');
$dateto = $dateto->format('Y-m-d').' 23:59:59';
}
$entityManager = $this->getDoctrine()->getManager();
$repository = $this->getDoctrine()->getRepository(Analytics::class);
$particularRepository = $this->getDoctrine()->getRepository(Particular::class);
$doctorRespository = $this->getDoctrine()->getRepository(Doctor::class);
$cursoParticularRepository = $this->getDoctrine()->getRepository(CursoParticular::class);
$cursoDoctorRepository = $this->getDoctrine()->getRepository(CursoDoctor::class);
$cursoRepository = $this->getDoctrine()->getRepository(Curso::class);
$_cursos = $cursoRepository->findAll();
$cursos = [];
foreach ($_cursos as $curso) {
$countParticulars = count($cursoParticularRepository->findParticipants($curso->getId(), $datefrom, $dateto));
$countDoctors = count($cursoDoctorRepository->findParticipants($curso->getId(), $datefrom, $dateto));
if ($countParticulars > 0) {
$cursos[] = [
'id' => $curso->getId(),
'title' => $curso->getTitle(),
'count' => $countParticulars,
'type' => 'Farmacias',
];
} elseif ($countDoctors > 0) {
$cursos[] = [
'id' => $curso->getId(),
'title' => $curso->getTitle(),
'count' => $countDoctors,
'type' => 'Médicos',
];
}
}
$cursos = Utils::orderMultiDimensionalArray($cursos, 'count', true);
$_particularsWithCursos = $cursoParticularRepository->findOrderedByCount($datefrom, $dateto);
$particularsWithCursos = [];
foreach ($_particularsWithCursos as $_particularsWithCurso) {
$particularsWithCursos[] = [
'doctor' => null,
'particular' => $particularRepository->find($_particularsWithCurso['id']),
'counter' => $_particularsWithCurso['counter'],
];
}
$_doctorsWithCursos = $cursoParticularRepository->findOrderedByCount($datefrom, $dateto);
foreach ($_doctorsWithCursos as $_doctorsWithCurso) {
$particularsWithCursos[] = [
'doctor' => $doctorRespository->find($_doctorsWithCurso['id']),
'particular' => null,
'counter' => $_doctorsWithCurso['counter'],
];
}
$particularsWithCursos = Utils::orderMultiDimensionalArray($particularsWithCursos, 'counter', true);
return $this->render('backend/dashboard/cursos.html.twig', [
'menu_section' => 'dashboard',
'cursos' => $cursos,
'particularsWithCursos' => $particularsWithCursos,
'datepicker_from_value' => $datepicker_from_value,
'datepicker_to_value' => $datepicker_to_value,
]);
}
public function admin_homepage_casos()
{
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$datefrom = $_POST['datepicker_from'].' 00:00:00';
$dateto = $_POST['datepicker_to'].' 23:59:59';
$datepicker_from_value = date('d/m/Y', strtotime($_POST['datepicker_from']));
$datepicker_to_value = date('d/m/Y', strtotime($_POST['datepicker_to']));
} else {
$datefrom = new \DateTime();
$datefrom->modify('-29 days');
$datepicker_from_value = $datefrom->format('d/m/Y');
$datefrom = $datefrom->format('Y-m-d').' 00:00:00';
$dateto = new \DateTime();
$datepicker_to_value = $dateto->format('d/m/Y');
$dateto = $dateto->format('Y-m-d').' 23:59:59';
}
$entityManager = $this->getDoctrine()->getManager();
$repository = $this->getDoctrine()->getRepository(Analytics::class);
$particularRepository = $this->getDoctrine()->getRepository(Particular::class);
$doctorRepository = $this->getDoctrine()->getRepository(Doctor::class);
$cursoParticularRepository = $this->getDoctrine()->getRepository(CursoParticular::class);
$cursoRepository = $this->getDoctrine()->getRepository(Curso::class);
$casoClinicoUserRepository = $this->getDoctrine()->getRepository(CasoClinicoUser::class);
$casoClinicoRepository = $this->getDoctrine()->getRepository(CasoClinico::class);
$_casosclinicos = $casoClinicoRepository->findAll();
$casosclinicos = [];
foreach ($_casosclinicos as $_casosclinico) {
$participants = [];
$userResponses = $casoClinicoUserRepository->getUserResponsesByDate($_casosclinico->getId(), $datefrom, $dateto);
foreach ($userResponses as $userResponse) {
if (!in_array($userResponse->getUserId(), $participants)) {
$participants[] = $userResponse->getUserId();
}
}
$casosclinicos[] = [
'id' => $_casosclinico->getId(),
'title' => $_casosclinico->getTitle(),
'counter' => count($participants),
];
}
$casosclinicos = Utils::orderMultiDimensionalArray($casosclinicos, 'counter', true);
$usersWithCasosClinicos = $casoClinicoUserRepository->findOrderedByCount($datefrom, $dateto);
foreach ($usersWithCasosClinicos as $key => $usersWithCasosClinico) {
$doctor = $doctorRepository->find($usersWithCasosClinico['user_id']);
if ($doctor) {
$usersWithCasosClinicos[$key]['doctor'] = $doctor;
} else {
unset($usersWithCasosClinicos[$key]);
}
}
return $this->render('backend/dashboard/casos.html.twig', [
'menu_section' => 'dashboard',
'casosclinicos' => $casosclinicos,
'usersWithCasosClinicos' => $usersWithCasosClinicos,
'datepicker_from_value' => $datepicker_from_value,
'datepicker_to_value' => $datepicker_to_value,
]);
}
public function admin_homepage_quiz()
{
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$datefrom = $_POST['datepicker_from'].' 00:00:00';
$dateto = $_POST['datepicker_to'].' 23:59:59';
$datepicker_from_value = date('d/m/Y', strtotime($_POST['datepicker_from']));
$datepicker_to_value = date('d/m/Y', strtotime($_POST['datepicker_to']));
} else {
$datefrom = new \DateTime();
$datefrom->modify('-29 days');
$datepicker_from_value = $datefrom->format('d/m/Y');
$datefrom = $datefrom->format('Y-m-d').' 00:00:00';
$dateto = new \DateTime();
$datepicker_to_value = $dateto->format('d/m/Y');
$dateto = $dateto->format('Y-m-d').' 23:59:59';
}
$entityManager = $this->getDoctrine()->getManager();
$repository = $this->getDoctrine()->getRepository(Analytics::class);
$particularRepository = $this->getDoctrine()->getRepository(Particular::class);
$doctorRepository = $this->getDoctrine()->getRepository(Doctor::class);
$cursoParticularRepository = $this->getDoctrine()->getRepository(CursoParticular::class);
$cursoRepository = $this->getDoctrine()->getRepository(Curso::class);
$casoClinicoUserRepository = $this->getDoctrine()->getRepository(CasoClinicoUser::class);
$casoClinicoRepository = $this->getDoctrine()->getRepository(CasoClinico::class);
$quizRepository = $this->getDoctrine()->getRepository(Quiz::class);
$quizResponseRepository = $this->getDoctrine()->getRepository(QuizResponse::class);
$_quizes = $quizRepository->findAll();
$quizes = [];
foreach ($_quizes as $_quiz) {
$participants = [];
$userResponses = $quizResponseRepository->getUserResponsesByDate($_quiz->getId(), $datefrom, $dateto);
foreach ($userResponses as $userResponse) {
if (!in_array($userResponse->getParticular()->getId(), $participants)) {
$participants[] = $userResponse->getParticular()->getId();
}
}
$quizes[] = [
'id' => $_quiz->getId(),
'title' => $_quiz->getTitle(),
'quiztype' => $_quiz->getQuiztype(),
'counter' => count($participants),
];
}
$quizes = Utils::orderMultiDimensionalArray($quizes, 'counter', true);
$_usersWithQuizes = $quizResponseRepository->findOrderedByCount($datefrom, $dateto);
$usersWithQuizes = [];
foreach ($_usersWithQuizes as $key => $usersWithQuiz) {
if (!array_key_exists($usersWithQuiz['id'], $usersWithQuizes)) {
$usersWithQuizes[$usersWithQuiz['id']][] = $usersWithQuiz['quiz_id'];
} else {
if (!in_array($usersWithQuiz['quiz_id'], $usersWithQuizes[$usersWithQuiz['id']])) {
$usersWithQuizes[$usersWithQuiz['id']][] = $usersWithQuiz['quiz_id'];
}
}
}
$finalUsersWithQuizes = [];
foreach ($usersWithQuizes as $key => $usersWithQuiz) {
$finalUsersWithQuizes[] = [
'particular' => $particularRepository->find($key),
'counter' => count($usersWithQuiz),
];
}
$finalUsersWithQuizes = Utils::orderMultiDimensionalArray($finalUsersWithQuizes, 'counter', true);
return $this->render('backend/dashboard/quiz.html.twig', [
'menu_section' => 'dashboard',
'quizes' => $quizes,
'usersWithQuizes' => $finalUsersWithQuizes,
'datepicker_from_value' => $datepicker_from_value,
'datepicker_to_value' => $datepicker_to_value,
]);
}
public function admin_homepage_vademecum()
{
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$datefrom = $_POST['datepicker_from'].' 00:00:00';
$dateto = $_POST['datepicker_to'].' 23:59:59';
$datepicker_from_value = date('d/m/Y', strtotime($_POST['datepicker_from']));
$datepicker_to_value = date('d/m/Y', strtotime($_POST['datepicker_to']));
} else {
$datefrom = new \DateTime();
$datefrom->modify('-29 days');
$datepicker_from_value = $datefrom->format('d/m/Y');
$datefrom = $datefrom->format('Y-m-d').' 00:00:00';
$dateto = new \DateTime();
$datepicker_to_value = $dateto->format('d/m/Y');
$dateto = $dateto->format('Y-m-d').' 23:59:59';
}
$vademecumRepository = $this->getDoctrine()->getRepository(VademecumPresentation::class);
$repository = $this->getDoctrine()->getRepository(Analytics::class);
$_vademecumProducts = $repository->getByItemTypeForDashboard('vademecum', $datefrom, $dateto);
$vademecumProducts = [];
$particularVisitsTotal = [];
$doctorVisitsTotal = [];
$userVisits = [
'particulares' => [],
'doctores' => [],
];
foreach ($_vademecumProducts as $_vademecumProduct) {
if (null != $_vademecumProduct->getDoctor() && (6908 == $_vademecumProduct->getDoctor()->getId() || 836 == $_vademecumProduct->getDoctor()->getId() || 8370 == $_vademecumProduct->getDoctor()->getId())) {
continue;
}
if (null != $_vademecumProduct->getParticular() && (3359 == $_vademecumProduct->getParticular()->getId() || 526 == $_vademecumProduct->getParticular()->getId() || 9901 == $_vademecumProduct->getParticular()->getId() || 4034 == $_vademecumProduct->getParticular()->getId())) {
continue;
}
if (array_key_exists($_vademecumProduct->getItemId(), $vademecumProducts)) {
$vademecumProducts[$_vademecumProduct->getItemId()]['users'][] = [
'particular' => $_vademecumProduct->getParticular(),
'doctor' => $_vademecumProduct->getDoctor(),
'date' => $_vademecumProduct->getCreatedAt(),
'origin' => $_vademecumProduct->getOrigin(),
];
} else {
$vademecumProducts[$_vademecumProduct->getItemId()] = [
'users' => [
[
'particular' => $_vademecumProduct->getParticular(),
'doctor' => $_vademecumProduct->getDoctor(),
'date' => $_vademecumProduct->getCreatedAt(),
'origin' => $_vademecumProduct->getOrigin(),
],
],
'product' => $vademecumRepository->find($_vademecumProduct->getItemId()),
];
}
if (null != $_vademecumProduct->getParticular()) {
if (!in_array($_vademecumProduct->getParticular()->getId(), $particularVisitsTotal)) {
$particularVisitsTotal[] = $_vademecumProduct->getParticular()->getId();
$userVisits['particulares'][$_vademecumProduct->getParticular()->getId()] = [
'entity' => $_vademecumProduct->getParticular(),
'type' => 'particular',
'count' => 1,
];
} else {
++$userVisits['particulares'][$_vademecumProduct->getParticular()->getId()]['count'];
}
} elseif (null != $_vademecumProduct->getDoctor()) {
if (!in_array($_vademecumProduct->getDoctor()->getId(), $doctorVisitsTotal)) {
$doctorVisitsTotal[] = $_vademecumProduct->getDoctor()->getId();
$userVisits['doctores'][$_vademecumProduct->getDoctor()->getId()] = [
'entity' => $_vademecumProduct->getDoctor(),
'type' => 'doctor',
'count' => 1,
];
} else {
++$userVisits['doctores'][$_vademecumProduct->getDoctor()->getId()]['count'];
}
}
$vademecumProducts[$_vademecumProduct->getItemId()]['totalusers'] = count($vademecumProducts[$_vademecumProduct->getItemId()]['users']);
}
foreach ($vademecumProducts as $key => $vademecumProduct) {
$vademecumProducts[$key]['totalusers'] = count($vademecumProduct['users']);
}
$vademecumProducts = Utils::orderMultiDimensionalArray($vademecumProducts, 'totalusers', true);
$finalVisits = [];
foreach ($userVisits['particulares'] as $userVisitParticular) {
$finalVisits[] = $userVisitParticular;
}
foreach ($userVisits['doctores'] as $userVisitDoctor) {
$finalVisits[] = $userVisitDoctor;
}
$finalVisits = Utils::orderMultiDimensionalArray($finalVisits, 'count', true);
return $this->render('backend/dashboard/vademecum.html.twig', [
'menu_section' => 'dashboard',
'vademecumProducts' => $vademecumProducts,
'finalVisits' => $finalVisits,
'datepicker_from_value' => $datepicker_from_value,
'datepicker_to_value' => $datepicker_to_value,
]);
}
public function admin_homepage_impactafaes()
{
if ('POST' === $_SERVER['REQUEST_METHOD']) {
$datefrom = $_POST['datepicker_from'].' 00:00:00';
$dateto = $_POST['datepicker_to'].' 23:59:59';
$datepicker_from_value = date('d/m/Y', strtotime($_POST['datepicker_from']));
$datepicker_to_value = date('d/m/Y', strtotime($_POST['datepicker_to']));
} else {
$datefrom = new \DateTime();
$datefrom->modify('-29 days');
$datepicker_from_value = $datefrom->format('d/m/Y');
$datefrom = $datefrom->format('Y-m-d').' 00:00:00';
$dateto = new \DateTime();
$datepicker_to_value = $dateto->format('d/m/Y');
$dateto = $dateto->format('Y-m-d').' 23:59:59';
}
$entityManager = $this->getDoctrine()->getManager();
$repository = $this->getDoctrine()->getRepository(Analytics::class);
$particularRepository = $this->getDoctrine()->getRepository(Particular::class);
$impRutaFormativaRepository = $this->getDoctrine()->getRepository(ImpRutaFormativa::class);
$impModuloRepository = $this->getDoctrine()->getRepository(ImpModulos::class);
$impPildoraRepository = $this->getDoctrine()->getRepository(ImpPildoras::class);
$impRutaFormativaParticularRepository = $this->getDoctrine()->getRepository(ImpRutasFormativasParticular::class);
$impModulosParticularRepository = $this->getDoctrine()->getRepository(ImpModulosParticular::class);
$impPildorasParticularRepository = $this->getDoctrine()->getRepository(ImpPildorasParticular::class);
// usuarios con acceso a impactafaes
$usersWithAccessToImpactafaes = $particularRepository->findBy(["impactafaes" => 1]);
// usuarios que se han registrado desde impactafaes
$usersRegisteredInImpactafaes = $particularRepository->findBy(["origin" => "impactafaes"]);
// Cursos
$_cursos = $impRutaFormativaRepository->findAll();
$cursos = [];
$cursos_finalizados = [];
foreach ($_cursos as $curso) {
$all_finished = $impRutaFormativaParticularRepository->findAllCompletedByRuta($curso,$datefrom, $dateto);
$all_unfinished = $impRutaFormativaParticularRepository->findAllNotCompletedByRuta($curso,$datefrom, $dateto);
$total_finished = count($all_finished);
$total_unfinished = count($all_unfinished);
$participants = [];
$userParticipations = $impRutaFormativaParticularRepository->getUserResponsesByDate($curso->getId(), $datefrom, $dateto);
foreach ($userParticipations as $userParticipation) {
if (!in_array($userParticipation->getParticular()->getId(), $participants)) {
$participants[] = $userParticipation->getParticular()->getId();
}
}
$cursos[] = [
'id' => $curso->getId(),
'title' => $curso->getTitle(),
'counter' => count($participants),
'all_finished' => $all_finished,
'total_unfinished' => $total_unfinished,
'total_finished' => $total_finished,
];
}
$finalCursos = Utils::orderMultiDimensionalArray($cursos, 'counter', true);
// Módulos
$_modulos = $impModuloRepository->findAll();
$modulos = [];
foreach ($_modulos as $modulo) {
$all_finished = $impModulosParticularRepository->findByModulosfinished($modulo,$datefrom, $dateto);
$participants = [];
$userParticipations = $impModulosParticularRepository->getUserResponsesByDate($modulo->getId(), $datefrom, $dateto);
foreach ($userParticipations as $userParticipation) {
if (!in_array($userParticipation->getParticular()->getId(), $participants)) {
$participants[] = $userParticipation->getParticular()->getId();
}
}
$modulos[] = [
'id' => $modulo->getId(),
'title' => $modulo->getName(),
'counter' => count($participants),
'all_finished' => $all_finished,
'ruta_formativa_id' => $modulo->getRutaFormativa()->getId(),
'ruta_formativa_title' => $modulo->getRutaFormativa()->getTitle(),
];
}
$finalModulos = Utils::orderMultiDimensionalArray($modulos, 'counter', true);
// Píldoras
$_pildoras = $impPildoraRepository->findAll();
$pildoras = [];
foreach ($_pildoras as $pildora) {
$participants = [];
$userParticipations = $impPildorasParticularRepository->getUserResponsesByDate($pildora->getId(), $datefrom, $dateto);
foreach ($userParticipations as $userParticipation) {
if (!in_array($userParticipation->getParticular()->getId(), $participants)) {
$participants[] = $userParticipation->getParticular()->getId();
}
}
$pildoras[] = [
'id' => $pildora->getId(),
'title' => $pildora->getName(),
'counter' => count($participants),
'modulo_id' => $pildora->getImpTema()->getImpModulo()->getId(),
'modulo_title' => $pildora->getImpTema()->getImpModulo()->getName(),
'ruta_formativa_id' => $pildora->getImpTema()->getImpModulo()->getRutaFormativa()->getId(),
'ruta_formativa_title' => $pildora->getImpTema()->getImpModulo()->getRutaFormativa()->getTitle(),
];
}
$finalPildoras = Utils::orderMultiDimensionalArray($pildoras, 'counter', true);
return $this->render('backend/dashboard/impactafaes.html.twig', [
'menu_section' => 'dashboard',
'usersWithAccessToImpactafaes' => $usersWithAccessToImpactafaes,
'usersRegisteredInImpactafaes' => $usersRegisteredInImpactafaes,
'cursos' => $finalCursos,
'modulos' => $finalModulos,
'pildoras' => $finalPildoras,
'datepicker_from_value' => $datepicker_from_value,
'datepicker_to_value' => $datepicker_to_value,
]);
}
}