123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- <?php
- /*
- * Copyright (C) 2021 Echedey López Romero <elr@disroot.org>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- function ImprimirResultado($Comprobar, &$Puntuaciones) {
- $HTML = '';
- if ($Comprobar) {
- for ($Posicion = 0; $Posicion < count(array_keys($Puntuaciones)); $Posicion++) {
- $HTML .= '<div class="row my-1">' . PHP_EOL;
- $HTML .= '<div class="col-md-3 col-sm-2 col"></div>' . PHP_EOL;
- if ($Posicion == 0) {
- $HTML .= '<span class="d-block col-md-6 col-sm-8 col-12 '
- . 'bg-success rounded text-white text-center">'
- . '<strong>' . array_keys($Puntuaciones)[$Posicion]
- . ': </strong>'
- . $Puntuaciones[array_keys($Puntuaciones)[$Posicion]]
- . '</span>' . PHP_EOL;
- } else if ($Posicion == 1) {
- $HTML .= '<span class="d-block col-md-6 col-sm-8 col-12 '
- . 'bg-danger rounded text-white text-center">'
- . '<strong>' . array_keys($Puntuaciones)[$Posicion]
- . ': </strong>'
- . $Puntuaciones[array_keys($Puntuaciones)[$Posicion]]
- . '</span>' . PHP_EOL;
- } else {
- $HTML .= '<span class="d-block col-md-6 col-sm-8 col-12 '
- . 'bg-warning rounded text-white text-center">'
- . '<strong>' . array_keys($Puntuaciones)[$Posicion]
- . ': </strong>'
- . $Puntuaciones[array_keys($Puntuaciones)[$Posicion]]
- . '</span>' . PHP_EOL;
- }
- $HTML .= '<div class="col-md-3 col-sm-2 col"></div>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- }
- } else {
- $HTML .= '<span class="d-block text-center">--</span>' . PHP_EOL;
- }
- return $HTML;
- }
- function ComprobarRespuesta($Pregunta, $RespuestaUsuario, &$Puntuaciones) {
- $Respuesta = $Pregunta['respuesta'];
- $TextoRespuesta = $Pregunta['opciones'][$Respuesta];
- $HTML = '';
- if (!is_null($RespuestaUsuario)) {
- if ($RespuestaUsuario == $Respuesta) {
- $HTML .= '<div class="row bg-success rounded text-white" '
- . 'id="comprobacion_' . $Pregunta['numero'] . '">' . PHP_EOL;
- $HTML .= '<span class="d-block col-12 text-center my-md-auto '
- . 'font-weight-bold">Respuesta correcta.</span>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- $Puntuaciones[array_keys($Puntuaciones)[0]]++;
- } else {
- $HTML .= '<div class="row bg-danger rounded text-white" '
- . 'id="comprobacion_' . $Pregunta['numero'] . '">' . PHP_EOL;
- $HTML .= '<span class="d-block col-md-4 col-12 mb-md-0 mb-1 '
- . 'my-md-auto text-center font-weight-bold">'
- . 'Respuesta incorrecta.</span>' . PHP_EOL;
- $HTML .= '<span class="d-block col-md-8 col-12 text-center '
- . 'my-md-auto"><strong>La respuesta correcta es: </strong>'
- . $TextoRespuesta . '</span>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- $Puntuaciones[array_keys($Puntuaciones)[1]]++;
- }
- } else {
- $HTML .= '<div class="row bg-warning rounded text-white" '
- . 'id="comprobacion_' . $Pregunta['numero'] . '">' . PHP_EOL;
- $HTML .= '<span class="d-block col-md-4 col-12 mb-md-0 mb-1 '
- . 'my-md-auto text-center font-weight-bold">'
- . 'Respuesta no contestada.</span>' . PHP_EOL;
- $HTML .= '<span class="d-block col-md-8 col-12 text-center '
- . 'my-md-auto"><strong>La respuesta correcta es: </strong>'
- . $TextoRespuesta . '</span>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- $Puntuaciones[array_keys($Puntuaciones)[2]]++;
- }
- return $HTML;
- }
- function CrearOpciones(&$Pregunta, $RespuestaUsuario) {
- $HTML = '';
- $HTML .= '<div class="col-md-8 col-12 my-auto">' . PHP_EOL;
- foreach ($Pregunta['opciones'] as $Posicion => $Opcion) {
- $HTML .= '<div class="form-check">' . PHP_EOL;
- if (!is_null($RespuestaUsuario) && $RespuestaUsuario == $Posicion) {
- $HTML .= '<input class="form-check-input" type="radio" '
- . 'name="respuesta_' . $Pregunta['numero'] . '" value="'
- . $Posicion . '" id="respuesta_' . $Pregunta['numero']
- . '_' . $Posicion . '" checked="" />' . PHP_EOL;
- } else {
- $HTML .= '<input class="form-check-input" type="radio" '
- . 'name="respuesta_' . $Pregunta['numero'] . '" value="'
- . $Posicion . '" id="respuesta_' . $Pregunta['numero']
- . '_' . $Posicion . '" />' . PHP_EOL;
- }
- $HTML .= '<label class="form-check-label" for="respuesta_'
- . $Pregunta['numero'] . '_' . $Posicion . '">' . $Opcion
- . '</label>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- }
- $HTML .= '</div>' . PHP_EOL;
- return $HTML;
- }
- function CrearPreguntas(&$Preguntas, &$RespuestasUsuario, $Comprobar,
- &$Puntuaciones) {
- $HTML = '';
- $HTML = '<div class="container mb-3">' . PHP_EOL;
- foreach ($Preguntas as $Pregunta) {
- $RespuestaUsuario = null;
- $HTML .= '<div class="row mb-2 border border-primary rounded p-2">'
- . PHP_EOL;
- $HTML .= '<div class="container">' . PHP_EOL;
- $HTML .= '<div class="row mb-2">' . PHP_EOL;
- $HTML .= '<span class="d-block col-lg-1 col-2 my-auto py-1 text-center '
- . ' text-white bg-primary rounded-pill font-weight-bold">'
- . $Pregunta['numero'] . '</span> ' . PHP_EOL;
- $HTML .= '<span class="d-block col-lg-11 col-10 text-center">'
- . $Pregunta['pregunta'] . '</span>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- if ($Comprobar) {
- $HTML .= '<div class="row mb-2">' . PHP_EOL;
- $RespuestaUsuario = $RespuestasUsuario[
- 'respuesta_' . $Pregunta['numero']
- ];
- $HTML .= '<div class="col-md-4 col-12 my-md-auto mb-2">' . PHP_EOL;
- $HTML .= '<img class="rounded mx-auto d-block w-100" '
- . 'src="' . $Pregunta['imagen'] . '" />' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- $HTML .= CrearOpciones($Pregunta, $RespuestaUsuario);
- $HTML .= '</div>' . PHP_EOL;
- $HTML .= ComprobarRespuesta($Pregunta, $RespuestaUsuario, $Puntuaciones);
- } else {
- $HTML .= '<div class="row">' . PHP_EOL;
- $HTML .= '<div class="col-md-4 col-12 my-md-auto mb-2">' . PHP_EOL;
- $HTML .= '<img class="rounded mx-auto d-block w-100" '
- . 'src="' . $Pregunta['imagen'] . '" />' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- $HTML .= CrearOpciones($Pregunta, $RespuestaUsuario);
- $HTML .= '</div>' . PHP_EOL;
- }
- $HTML .= '</div>' . PHP_EOL;
- $HTML .= '</div>' . PHP_EOL;
- }
- $HTML .= '</div>' . PHP_EOL;
- return $HTML;
- }
|