123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- <?php
- require_once 'Etapa.php';
- require_once 'Usuario.php';
- require_once 'Proyecto.php';
- require_once 'Colores.php';
- class Resultados {
- /********** GENERAL **********/
- private static function obtenerTipoPregunta($pdo, $idtipo){
- $tipos = array();
- if ($idtipo == 0)
- $stmt = $pdo->prepare('Select * from cidit_fs_tipopreguntaxid(null)');
- else{
- $stmt = $pdo->prepare('Select * from cidit_fs_tipopreguntaxid(:id)');
- $stmt->bindParam(':id', $idtipo);
- }
- if($stmt->execute())
- $tipos = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- return $tipos;
- }
-
- private static function obtenerTablaResultadosxPregunta($pdo, $id, $tipo){
- $tabla = '';
- $stmt = $pdo->prepare('Select * from cidit_fs_tablaresultadosxpregunta(:id,:tipo)');
- $stmt->bindParam(':id', $id);
- $stmt->bindParam(':tipo', $tipo);
- if($stmt->execute())
- $tabla = $stmt->fetch();
- $stmt->closeCursor();
- $stmt = null;
- return $tabla;
- }
-
- private static function obtenerValoresOpcionesPregunta($pdo, $idpregunta){
- $valores = array();
- $stmt = $pdo->prepare('Select * from cidit_fs_valoresxpregunta(:id)');
- $stmt->bindParam(':id', $idpregunta);
- if($stmt->execute())
- $valores = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- return $valores;
- }
-
- public static function esPromediable($pdo, $idtipo){
- $tipos = self::obtenerTipoPregunta($pdo, $idtipo);
- $promediable = false;
- switch (mb_strtoupper($tipos[0]['tipo'])){
- case 'ESTRELLA':
- case 'ESTRELLAS':
- case 'RANKING':
- case 'OPCION MULTIPLE':
- case 'OPCIÓN MULTIPLE':
- case 'OPCIÓN MÚLTIPLE':
- case 'OPCION MÚLTIPLE':
- case 'OPCIONES':
- $promediable = true;
- break;
- case 'ABIERTA':
- case 'ABIERTAS':
- $promediable = false;
- break;
- }
- return $promediable;
- }
-
- /********** OBTENER RESULTADOS **********/
- private static function getResultadosEvaluacion($pdo, $etapa, $proyecto, $pregunta){
- $evaluaciones = array();
- if ($proyecto == 0 && $pregunta == 0)
- $stmt = $pdo->prepare('Select * from cidit_fs_evaluacionxetapa(null,null,:etapa)');
- else{
- if ($proyecto == 0){
- $stmt = $pdo->prepare('Select * from cidit_fs_evaluacionxetapa(null,:pregunta,:etapa)');
- $stmt->bindParam(':pregunta', $pregunta);
- } else {
- if ($pregunta == 0){
- $stmt = $pdo->prepare('Select * from cidit_fs_evaluacionxetapa(:proyecto, null,:etapa)');
- $stmt->bindParam(':proyecto', $proyecto);
- } else {
- $stmt = $pdo->prepare('Select * from cidit_fs_evaluacionxetapa(:proyecto,:pregunta,:etapa)');
- $stmt->bindParam(':proyecto', $proyecto);
- $stmt->bindParam(':pregunta', $pregunta);
- }
- }
- }
- $stmt->bindParam(':etapa', $etapa);
- if($stmt->execute())
- $evaluaciones = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- return $evaluaciones;
- }
-
- private static function getResultadosValoracion($pdo, $etapa, $proyecto, $pregunta){
- $valoraciones = array();
- if ($proyecto == 0 && $pregunta == 0)
- $stmt = $pdo->prepare('Select * from cidit_fs_valoracionxetapa(null,null,:etapa)');
- else{
- if ($proyecto == 0){
- $stmt = $pdo->prepare('Select * from cidit_fs_valoracionxetapa(null,:pregunta,:etapa)');
- $stmt->bindParam(':pregunta', $pregunta);
- } else {
- if ($pregunta == 0){
- $stmt = $pdo->prepare('Select * from cidit_fs_valoracionxetapa(:proyecto, null,:etapa)');
- $stmt->bindParam(':proyecto', $proyecto);
- } else {
- $stmt = $pdo->prepare('Select * from cidit_fs_valoracionxetapa(:proyecto,:pregunta,:etapa)');
- $stmt->bindParam(':proyecto', $proyecto);
- $stmt->bindParam(':pregunta', $pregunta);
- }
- }
- }
- $stmt->bindParam(':etapa', $etapa);
- if($stmt->execute())
- $valoraciones = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- return $valoraciones;
- }
-
- private static function determinaTabla($pdo, $etapa, $proyecto, $pregunta, $tabla){
- $resultados = array();
- switch (mb_strtoupper($tabla['tabla'])){
- case 'EVALUACION':
- case 'EVALUACIÓN':
- $resultados = self::getResultadosEvaluacion($pdo, $etapa, $proyecto, $pregunta);
- break;
- case 'VALORACION':
- case 'VALORACIÓN':
- $resultados = self::getResultadosValoracion($pdo, $etapa, $proyecto, $pregunta);
- break;
- }
- return $resultados;
- }
-
- //---------- GRÁFICAS ----------//
- public static function valoresGraficaXPregunta($pdo, $pregunta, $proyecto, $etapa){
- $resultados = 0;
- $tabla = self::obtenerTablaResultadosxPregunta($pdo, $pregunta, 'pregunta');
- if (count($tabla) > 0){
- $resultados_rs = self::determinaTabla($pdo, $etapa, $proyecto, $pregunta, $tabla);
- if (count($resultados_rs) > 0){
- $tipo = $resultados_rs[0]['tipo'];
- if (self::esPromediable($pdo, $tipo)){
- $temp = 0;
- $cont = 0;
- foreach ($resultados_rs as $eval){
- $temp += $eval['respuesta'];
- $cont++;
- }
- if ($cont > 0)
- $resultados = Proyecto::estandarizaNumeros(round($temp/$cont,1));
- }
- }
- }
- return $resultados;
- }
-
- //---------- PROYECTOS ----------//
- public static function evaluacionesXProyecto($pdo, $proyecto, $etapa, $tipoRetorno){
- switch ($tipoRetorno){
- case 'HTML': $tablas = ''; break;
- case 'ARRAY': $tablas = array(); break;
- }
- $resultados = array();
- $rubros = Etapa::getRubrosXEtapa($pdo, $etapa);
- if (count($rubros) > 0){
- foreach($rubros as $rubro){
- $tabla = self::obtenerTablaResultadosxPregunta($pdo, $rubro['idrubro'], 'rubro');
- $resultados = self::determinaTabla($pdo, $etapa, $proyecto, 0, $tabla);
- if (count($resultados) > 0){
- $preguntas = Etapa::getPreguntasXRubro($pdo, $rubro['idrubro']);
- $temp = array_column($resultados, 'idusuario');
- $temp = array_unique($temp);
- $usuarios = array();
- foreach ($temp as $user){
- array_push($usuarios, array('idusuario' => $user) + Usuario::getNombreUsuario($pdo, $user));
- }
- array_multisort(array_column($usuarios, 'apellidos'),SORT_ASC,$usuarios);
- $cont = 1;
- $filtradas = array();
- foreach($preguntas as $pregunta) {
- if (in_array($pregunta['idpregunta'], array_column($resultados, 'idpregunta')) && self::esPromediable($pdo, $pregunta['tipo']))
- array_push($filtradas,$pregunta);
- }
- switch (mb_strtoupper($tabla['tabla'])){
- case 'EVALUACION':
- case 'EVALUACIÓN':
- switch ($tipoRetorno){
- case 'HTML': $tablas .= self::generarTabla($rubro['rubro'], $filtradas, $resultados, $usuarios, true); break;
- case 'ARRAY': array_push($tablas, self::generarArreglo($rubro['rubro'], $filtradas, $resultados, $usuarios, true)); break;
- }
- break;
- case 'VALORACION':
- case 'VALORACIÓN':
- switch ($tipoRetorno){
- case 'HTML': $tablas .= self::generarSeccion($pdo, $filtradas, $resultados); break;
- case 'ARRAY': array_push($tablas,self::generarArregloSeccion($pdo, $filtradas, $resultados)); break;
- }
- break;
- }
- $restantes = array_diff(array_column($pregunta,'idpregunta'), array_column($filtradas,'idpregunta'));
- if (count($restantes) > 0){
- $filtradas = array();
- foreach($restantes as $falta) {
- while($pregunta = current($preguntas)){
- if ($pregunta['idpregunta'] == $falta){
- array_push($filtradas,$pregunta);
- end($resultados);
- }
- next($resultados);
- }
- }
- switch ($tipoRetorno){
- case 'HTML': $tablas .= self::generarTabla($rubro['rubro'], $filtradas, $resultados, $usuarios, false); break;
- case 'ARRAY': array_push($tablas,self::generarArreglo($rubro['rubro'], $filtradas, $resultados, $usuarios, false)); break;
- }
- }
- }
- }
- }
- return $tablas;
- }
-
- private static function generarTabla($rubro, $preguntas, $resultados, $usuarios, $promedio){
- $tablas = '<div class="table-responsive-md mt-2">
- <table class="tablaProyecto table">
- <thead class="text-white">
- <tr>
- <td class="bg-primary align-middle text-right amplio">' . $rubro . '</td>';
- $cont = 1;
- foreach($preguntas as $pregunta) {
- $tablas .= '<td class="text-center align-middle bg-azul' . $cont%14 . '">' . $pregunta['pregunta'] . '</td>';
- $cont++;
- if($cont % 14 == 0)
- $cont++;
- }
- $tablas .= '</tr>
- </thead>';
- foreach ($usuarios as $usuario){
- $tablas .= '<tr>
- <td class="amplio align-middle">' . $usuario['apellidos'] . ' ' . $usuario['nombre'] . '</td>';
- foreach ($preguntas as $pregunta){
- $tablas .= '<td class="text-center align-middle">' . self::obtenerRespuesta($resultados, $usuario['idusuario'], $pregunta) . '</td>';
- }
- $tablas .= '</tr>';
- }
- if($promedio){
- $tablas .= self::getPromedio($resultados, $preguntas, 'HTML');
- }
- $tablas .= '</tbody>
- </table>
- </div>';
- return $tablas;
- }
-
- private static function generarArreglo($rubro, $preguntas, $resultados, $usuarios, $promedio){
- $tabla = array();
- $temp = array();
- array_push($temp,array('texto' => $rubro, 'estilo' => 'RUBRO', 'indice' => 0));
- $cont = 1;
- foreach($preguntas as $pregunta) {
- array_push($temp,array('texto' => $pregunta['pregunta'], 'estilo' => 'AZUL', 'indice' => $cont%14));
- $cont++;
- if($cont % 14 == 0)
- $cont++;
- }
- array_push($tabla,$temp);
- $cont = 1;
- foreach ($usuarios as $usuario){
- $temp = array();
- array_push($temp,array('texto' => $usuario['apellidos'] . ' ' . $usuario['nombre'], 'estilo' => 'PERSONA', 'indice' => $cont%3));
- foreach ($preguntas as $pregunta){
- array_push($temp,array('texto' => self::obtenerRespuesta($resultados, $usuario['idusuario'], $pregunta), 'estilo' => 'RENGLON', 'indice' => $cont%3));
- }
- $cont++;
- if($cont % 3 == 0)
- $cont++;
- array_push($tabla,$temp);
- }
- if($promedio){
- $temp = self::getPromedio($resultados, $preguntas,'ARRAY');
- $temp2 = array();
- if (count($temp) > 0){
- array_push($temp2,array('texto' => '', 'estilo' => 'PROMEDIO', 'indice' => 0));
- foreach ($temp as $t){
- array_push($temp2,array('texto' => $t, 'estilo' => 'PROMEDIO', 'indice' => 0));
- }
- array_push($tabla,$temp2);
- }
- }
- return $tabla;
- }
-
- private static function obtenerRespuesta($resultados, $user, $preg){
- $flag = true;
- $respuesta = '-';
- reset($resultados);
- while($resultado = current($resultados)){
- if ($resultado['idusuario'] == $user && $resultado['idpregunta'] == $preg['idpregunta']){
- switch (mb_strtoupper($preg['tipo'])){
- case 'ESTRELLA':
- case 'ESTRELLAS':
- case 'RANKING':
- $respuesta = '<div class="d-inline-flex">';
- for ($cont = 0; $cont < intval($resultado['respuesta']); $cont++) {
- $respuesta .= '<div class="ing-estrella1 ml-2"></div>';
- }
- $respuesta .= '</div>';
- break;
- case 'OPCION MULTIPLE':
- case 'OPCIÓN MULTIPLE':
- case 'OPCIÓN MÚLTIPLE':
- case 'OPCION MÚLTIPLE':
- case 'OPCIONES':
- if (is_numeric($resultado['respuesta']))
- $respuesta = Proyecto::estandarizaNumeros(floatval($resultado['respuesta']));
- else
- $respuesta = Proyecto::estandarizaNumeros($resultado['respuesta']);
- break;
- case 'ABIERTA':
- case 'ABIERTAS':
- $respuesta = $resultado['respuesta'];
- }
- end($resultados);
- }
- next($resultados);
- }
- return $respuesta;
- }
-
- private static function getPromedio($resultados, $preguntas, $tipoRetorno){
- switch ($tipoRetorno){
- case 'HTML': $promedio = ''; break;
- case 'ARRAY': $promedio = array(); break;
- }
- if (count($resultados) > 0){
- if ($tipoRetorno == 'HTML')
- $promedio = '<tr style="height: 30px;">
- <td class="amplio"></td>';
- foreach($preguntas as $pregunta){
- $cont = 0;
- $calif = 0;
- foreach ($resultados as $res){
- if ($res['idpregunta'] == $pregunta['idpregunta'] && is_numeric($res['respuesta'])){
- $calif += $res['respuesta'];
- $cont++;
- }
- }
- if ($cont > 0) {
- $prom = Proyecto::estandarizaNumeros(round($calif/$cont,1));
- switch ($tipoRetorno){
- case 'HTML': $promedio .= '<td class="position-relative"><div class="promedio position-absolute">'. $prom . '</div></td>'; break;
- case 'ARRAY':
- array_push($promedio, $prom);
- break;
- }
- } else {
- switch ($tipoRetorno){
- case 'HTML': $promedio .= '<td class="position-relative"></td>'; break;
- case 'ARRAY': array_push($promedio, ' '); break;
- }
- }
- }
- if ($tipoRetorno == 'HTML')
- $promedio .= '</tr>';
- }
- return $promedio;
- }
-
- private static function generarSeccion($pdo, $preguntas, $resultados){
- $secciones = '';
- foreach($preguntas as $pregunta) {
- switch (mb_strtoupper($pregunta['tipo'])){
- case 'ESTRELLA':
- case 'ESTRELLAS':
- case 'RANKING':
- case 'OPCION MULTIPLE':
- case 'OPCIÓN MULTIPLE':
- case 'OPCIÓN MÚLTIPLE':
- case 'OPCION MÚLTIPLE':
- case 'OPCIONES':
- $div = self::obtenerEstadistica($pdo, $pregunta, $resultados, 'HTML');
- if ($div != ''){
- $secciones .= '<div class="w-100">' . $div . '</div>';
- }
- break;
- case 'ABIERTA':
- case 'ABIERTAS':
- break;
- }
- }
- return $secciones;
- }
-
- private static function generarArregloSeccion($pdo, $preguntas, $resultados){
- $secciones = array();
- foreach($preguntas as $pregunta) {
- switch (mb_strtoupper($pregunta['tipo'])){
- case 'ESTRELLA':
- case 'ESTRELLAS':
- case 'RANKING':
- case 'OPCION MULTIPLE':
- case 'OPCIÓN MULTIPLE':
- case 'OPCIÓN MÚLTIPLE':
- case 'OPCION MÚLTIPLE':
- case 'OPCIONES':
- $secciones = self::obtenerEstadistica($pdo, $pregunta, $resultados, 'ARRAY');
- break;
- case 'ABIERTA':
- case 'ABIERTAS':
- break;
- }
- }
- return $secciones;
- }
-
- private static function obtenerEstadistica($pdo, $pregunta, $resultados, $tipoRetorno){
- $valores = self::obtenerValoresOpcionesPregunta($pdo, $pregunta['idpregunta']);
- $estadistica = array();
- switch ($tipoRetorno){
- case 'HTML': $div = ''; break;
- case 'ARRAY': $div = array(); break;
- }
- if (count($valores) > 0){
- foreach ($valores as $valor){
- array_push($estadistica, array('texto' => $valor['opcion'],'valor' => $valor['valor'], 'porcentaje' => 0, 'cantidad' => 0));
- }
- reset($estadistica);
- while($est = current($estadistica)){
- $index = key($estadistica);
- foreach ($resultados as $res){
- if ($res['respuesta'] == $est['valor'])
- $estadistica[$index]['cantidad']++;
- }
- next($estadistica);
- }
- $max = max(array_column($estadistica, 'cantidad'));
- reset($estadistica);
- while($est = current($estadistica)){
- $index = key($estadistica);
- $estadistica[$index]['porcentaje'] = Proyecto::estandarizaNumeros(round($estadistica[$index]['cantidad']/$max,1)*100);
- switch (mb_strtoupper($pregunta['tipo'])){
- case 'ESTRELLA':
- case 'ESTRELLAS':
- case 'RANKING':
- $estrellas = intval($estadistica[$index]['valor']);
- switch ($tipoRetorno){
- case 'HTML':
- $estadistica[$index]['valor'] = '<label class="text-primary indivisa-text-italic small mb-0">' . $estadistica[$index]['texto'] . '</label>';
- for($cont = 0; $cont < $estrellas; $cont++){
- $estadistica[$index]['valor'] .= '<div class="ing-estrella1 ml-2"></div>';
- }
- break;
- case 'ARRAY':
- $estadistica[$index]['valor'] = '';
- for($cont = 0; $cont < $estrellas; $cont++){
- $estadistica[$index]['valor'] .= '★';
- }
- break;
- }
- break;
- case 'OPCION MULTIPLE':
- case 'OPCIÓN MULTIPLE':
- case 'OPCIÓN MÚLTIPLE':
- case 'OPCION MÚLTIPLE':
- case 'OPCIONES':
- $estadistica[$index]['valor'] = Proyecto::estandarizaNumeros($estadistica[$index]['valor']);
- break;
- }
- next($estadistica);
- }
- if (count($estadistica) > 0){
- switch ($tipoRetorno){
- case 'HTML':
- $div .= '<div class="row justify-content-md-center mb-3">
- <div class="col-lg-2 align-self-center display-6 text-primary">' . $pregunta['pregunta'] . '</div>
- <div class="estadistica linea position-relative col-lg-7">';
- $cont = 0;
- foreach ($estadistica as $est){
- $div .= '<div class="row align-items-center py-2">
- <div class="col-5 d-flex flex-row justify-content-end align-items-center">' . $est['valor'] . '</div>
- <div class="col-7 d-flex flex-row justify-content-start align-items-center">
- <div class="barra ' . Colores::getBGColor($cont) . '" style="width:' . $est['porcentaje'] .'%"></div>
- <div class="indivisa-text-bold pl-2 text-primary">' . $est['cantidad'] .'</div>
- </div>
- </div>';
- $cont++;
- }
- $div .= '</div>
- </div>';
- break;
- case 'ARRAY':
- $temp = array();
- array_push($temp,array('texto' => ' ', 'estilo' => 'RUBRO', 'indice' => 0));
- array_push($temp,array('texto' => $pregunta['pregunta'], 'estilo' => 'RUBRO', 'indice' => 0));
- array_push($temp,array('texto' => 'Porcentaje de votos', 'estilo' => 'AZUL', 'indice' => 1));
- array_push($temp,array('texto' => 'No. de votos', 'estilo' => 'AZUL', 'indice' => 2));
- array_push($div, $temp);
- $cont = 1;
- foreach ($estadistica as $est){
- $temp = array();
- if (is_numeric($est['valor']))
- array_push($temp,array('texto' => $est['valor'], 'estilo' => 'RENGLON', 'indice' => $cont%3));
- else
- array_push($temp,array('texto' => $est['valor'], 'estilo' => 'ESTRELLAS', 'indice' => $cont%3));
- array_push($temp,array('texto' => $est['texto'], 'estilo' => 'PERSONA', 'indice' => $cont%3));
- array_push($temp,array('texto' => $est['porcentaje'] . '%', 'estilo' => 'RENGLON', 'indice' => $cont%3));
- array_push($temp,array('texto' => $est['cantidad'], 'estilo' => 'RENGLON', 'indice' => $cont%3));
- array_push($div, $temp);
- $cont++;
- if ($cont % 3 == 0)
- $cont++;
- }
- break;
- }
- }
- }
- return $div;
- }
- }
|