123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- require_once 'Proyecto.php';
- require_once 'Template.php';
- class Cuestionario {
- private $concurso;
- private $etapa;
- private $pdo;
- private $rubros = array();
- private $especiales = array();
- private $periodoValido = false;
- private $usr;
- private $tipoDato;
-
-
- function __construct($pdo, $usr, $concurso, $etapa){
- $this->concurso = $concurso;
- $this->etapa = $etapa;
- $this->usr = $usr;
- $this->pdo = $pdo;
- $this->tipoDato = Proyecto::determinaAccionXEtapa($pdo, $etapa);
- $this->obtenerRubros();
- }
-
- private function obtenerRubros(){
- $stmt = $this->pdo->prepare('Select * from cidit_fs_rubrosxetapa(:etapa)');
- $stmt->bindParam(':etapa', $this->etapa);
- if($stmt->execute()){
- $rubro_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- foreach ($rubro_rs as $rubro) {
- if ($rubro['orden'] != '')
- array_push($this->rubros, array('id' => $rubro['idrubro'],'rubro' => $rubro['rubro'], 'prefijo' => $rubro['prefijo'],'orden' => $rubro['orden'], 'porcentaje' => $rubro['porcentaje']));
- else
- array_push($this->especiales, array('id' => $rubro['idrubro'],'rubro' => $rubro['rubro'], 'prefijo' => $rubro['prefijo'], 'porcentaje' => $rubro['porcentaje']));
- }
- }
- else{
- $stmt->closeCursor();
- $stmt = null;
- }
- }
-
- private function obtenerPreguntas($rubro){
- $preguntas = array();
- $stmt = $this->pdo->prepare('Select * from cidit_fs_preguntasxrubro(:rubro)');
- $stmt->bindParam(':rubro', $rubro);
- if($stmt->execute()){
- $preguntas_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- foreach ($preguntas_rs as $pregunta) {
- array_push($preguntas, array('id' => $pregunta['idpregunta'],'pregunta' => $pregunta['pregunta'], 'instrucciones' => $pregunta['instrucciones'], 'orden' => $pregunta['orden'], 'tipo' => $pregunta['tipo'], 'obligatoria' => $pregunta['obligatoria']));
- }
- }
- else{
- $stmt->closeCursor();
- $stmt = null;
- }
- return $preguntas;
- }
-
- private function obtenerOpciones($pregunta){
- $opciones = array();
- $stmt = $this->pdo->prepare('Select * from cidit_fs_opcionesxpregunta(:pregunta)');
- $stmt->bindParam(':pregunta', $pregunta);
- if($stmt->execute()){
- $opciones_rs = $stmt->fetchAll();
- $stmt->closeCursor();
- $stmt = null;
- foreach ($opciones_rs as $opcion) {
- array_push($opciones, array('id' => $opcion['idopcion'],'opcion' => $opcion['opcion'],'valor' => $opcion['valor']));
- }
- }
- else{
- $stmt->closeCursor();
- $stmt = null;
- }
- return $opciones;
- }
-
- private function preguntasRanking($pregunta, $opciones, $indice){ ?>
- <div class="star-rating">
- <div class="d-flex justify-content-center flex-row-reverse fieldset" data-tipo="radiobutton">
- <?php $cont = count($opciones);
- foreach ($opciones as $opcion){?>
- <input data-indice="<?php echo $indice; ?>" type="radio" id="star<?php echo $cont; ?>" name="pregunta[<?php echo $pregunta; ?>]" value="<?php echo $opcion['id']; ?>" />
- <label for="star<?php echo $cont; ?>"><div></div><span><?php echo $opcion['opcion']; ?></span></label>
- <?php $cont--;
- } ?>
- </div>
- </div>
- <?php }
-
- private function preguntasOpciones($pregunta, $opciones, $indice){
- $preg=1; ?>
- <div class="opciones" data-tipo="radiobutton">
- <?php foreach ($opciones as $opcion){ ?>
- <div>
- <input type="radio" data-indice="<?php echo $indice; ?>" id="preg<?php echo $pregunta . '-' . $preg; ?>" name="pregunta[<?php echo $pregunta; ?>]" value="<?php echo $opcion['id']; ?>">
- <label class="op<?php echo $preg; ?>" for="preg<?php echo $pregunta . '-' . $preg; ?>"><?php echo $opcion['opcion']; ?></label>
- </div>
- <?php $preg++;
- } ?>
- </div>
- <?php }
-
- private function preguntasAbiertas($pregunta, $indice){ ?>
- <div class="abierta" data-tipo="texto">
- <textarea class="richtext" data-indice="<?php echo $indice; ?>" name="pregunta-<?php echo $pregunta; ?>" rows="5" placeholder="Escribe aquí"></textarea>
- </div>
- <?php }
-
- private function tipoPregunta($pregunta, $indice){
- if ($pregunta['instrucciones'] != ''){ ?>
- <div class="instrucciones"><?php echo $pregunta['instrucciones']; ?></div>
- <?php }
- $opciones = $this->obtenerOpciones($pregunta['id']);
- switch (mb_strtoupper($pregunta['tipo'])){
- case 'ESTRELLA':
- case 'ESTRELLAS':
- case 'RANKING':
- $this->preguntasRanking($pregunta['id'], $opciones, $indice);
- break;
- case 'OPCION MULTIPLE':
- case 'OPCIÓN MULTIPLE':
- case 'OPCIÓN MÚLTIPLE':
- case 'OPCION MÚLTIPLE':
- case 'OPCIONES':
- $this->preguntasOpciones($pregunta['id'], $opciones, $indice);
- break;
- case 'ABIERTA':
- case 'ABIERTAS':
- $this->preguntasAbiertas($pregunta['id'], $indice);
- }
- }
-
- private function generaPreguntas(){?>
- <div class="formaVoto">
- <form class="d-flex flex-column" id="formaVoto" method="post" action="action/cuestionario_action.php">
- <?php if (count($this->rubros) > 0){
- $cont = 1;
- foreach($this->rubros as $rubro) {?>
- <h3 class='mb-3 eval <?php echo strtolower($rubro['rubro']); ?>'>
- Evaluación <?php if(isset($rubro['prefijo'])){ echo $rubro['prefijo'] . ' '; } echo $rubro['rubro'];
- if(isset($rubro['porcentaje'])){ ?>
- <small>(<?php echo Proyecto::estandarizaNumeros($rubro['porcentaje']); ?>% de la calificación final)</small>
- <?php } ?>
- </h3>
- <section class="<?php echo strtolower($rubro['rubro']); ?>">
- <?php $preguntas = $this->obtenerPreguntas($rubro['id']);
- foreach ($preguntas as $pregunta){ ?>
- <div class="pregunta" data-tipo="<?php echo (int)$pregunta['obligatoria']; ?>">
- <div class='subtituloEval'><h5><?php echo $pregunta['pregunta']; if ($pregunta['obligatoria']) { ?><label class="text-danger errorTit" style="display:none">*</label><?php } ?></h5></div>
- <?php $this->tipoPregunta($pregunta, $cont);
- $cont++; ?>
- </div>
- <?php } ?>
- </section>
- <?php } ?>
- <div id="errorLblEval" style="display:none">
- <div class="d-flex flex-column justify-content-center align-items-center text-danger">
- <div class="indivisa-text-bold-italic">Es necesario contestar todas las preguntas.</div>
- <div>Las preguntas faltantes se encuentran marcadas en rojo.</div>
- </div>
- </div>
- <div class="d-flex mx-auto mt-3">
- <button type="submit" class="btn btn-ing btn-outline-primary arrow mx-2" id="btnVotar" name="voto" data-etapa="<?php echo $this->etapa; ?>" value=""><?php /*echo ucfirst($this->tipoDato['accion']);*/ echo 'Guardar'; ?></button>
- <button type="reset" class="btn btn-ing btn-outline-danger arrow mx-2" id="btnLimpiar">Cancelar</button>
- </div>
- <?php } else { ?>
- <div class="fondoAnuncio">
- <div class="d-flex flex-column justify-content-center align-items-center">
- <div class="text-primary text-center mt-5 tit">¡Lo sentimos!</div>
- <div class="text-primary text-center small m-3 msg">Por el momento no podemos mostrar la <?php echo $this->tipoDato['accion']; ?> de proyectos participantes.</div>
- <div><div class="ing-no-cargado mb-2"></div></div>
- </div>
- </div>
- <?php } ?>
- </form>
- </div>
- <?php }
-
- private function generaPreguntasEspeciales(){ ?>
- <section class="formaVoto fondoAnuncio">
- <div class="d-flex flex-column justify-content-center align-items-center p-4" id="formaVoto" method="post" action="action/cuestionario_action.php">
- <?php if (count($this->especiales) > 0){
- $cont = 1;
- foreach($this->especiales as $rubro) { ?>
- <?php $preguntas = $this->obtenerPreguntas($rubro['id']);
- foreach ($preguntas as $pregunta){ ?>
- <div class="pregunta" data-tipo="<?php echo (int)$pregunta['obligatoria']; ?>">
- <div class="text-primary text-center mb-3 msg"><?php echo $pregunta['pregunta']; if ($pregunta['obligatoria']) { ?><label class="text-danger errorTit" style="display:none">*</label><?php } ?></div>
- <?php $this->tipoPregunta($pregunta, $cont);
- $cont++; ?>
- </div>
- <?php }
- } ?>
- <div id="errorLblEval" style="display:none">
- <div class="d-flex flex-column justify-content-center align-items-center text-danger">
- <div class="indivisa-text-bold-italic">Es necesario contestar las preguntas.</div>
- </div>
- </div>
- <button type="submit" class="btn btn-ing btn-outline-primary arrow mx-auto mt-4" id="btnVotar" name="voto" data-etapa="<?php echo $this->etapa; ?>" value="">Votar</button>
- <?php } else { ?>
- <div class="d-flex flex-column justify-content-center align-items-center">
- <div class="text-primary text-center mt-5 tit">¡Lo sentimos!</div>
- <div class="text-primary text-center small my-3 msg">Por el momento no podemos mostrar la <?php echo $this->tipoDato['accion']; ?> de proyectos participantes.</div>
- <div><div class="ing-no-cargado mb-2"></div></div>
- </div>
- <?php } ?>
- </div>
- </section>
- <?php }
-
- function generaCuestionario(){
- $idasignacion = Proyecto::existeAsignacion($this->pdo, $this->usr, 0, $this->etapa); // 0 para mostrar todos los carteles
- if ($idasignacion > -1) {
- if ($idasignacion == 0)
- $this->generaPreguntasEspeciales();
- else
- $this->generaPreguntas();
- }
- }
- function estaEvaluado($proyecto){
- $evaluado = false;
- $stmt = $this->pdo->prepare("Select * from cidit_fs_existenevaluacionesxetapa(:usr,:proyecto,:etapa)");
- $stmt->bindParam(':usr', $this->usr);
- $stmt->bindParam(':proyecto', $proyecto);
- $stmt->bindParam(':etapa', $this->etapa);
- if($stmt->execute()){
- $evalua_rs = $stmt->fetch();
- $evaluado = (bool)$evalua_rs["existe"];
- }
- $stmt->closeCursor();
- $stmt = null;
- return $evaluado;
- }
-
- function faltantes() {
- $espacio = '';
- if (Proyecto::existeAsignacion($this->pdo, $this->usr, 0, $this->etapa) > 0) {
- if (strpos($_SERVER["SCRIPT_FILENAME"],'galeria'))
- $espacio = ' mb-3';
- $total = Etapa::totalFaltantes($this->pdo, $this->usr, $this->etapa);
- if ($total > 0){ ?>
- <div id="faltantes" class="<?php echo $espacio; ?>">
- <div class="d-flex flex-row align-items-center">
- <div class="ing-importante mr-2"></div>
- <div id="msgFaltantes" class="d-flex flex-row">
- <?php if ($total == 1)
- echo 'Sólo te falta ' . $this->tipoDato['verbo'] . ' <div class="num mx-2">1</div> proyecto.';
- else
- echo 'Te faltan <div class="num mx-2">' . $total . '</div> proyectos por ' . $this->tipoDato['verbo'] . '.'; ?>
- </div>
- </div>
- </div>
- <div class="modal fade modalMarco" id="modalAlerta">
- <div class="modal-dialog modal-lg modal-dialog-centered">
- <div class="modal-content p-3">
- <?php Template::agregaLoading('loaderFaltantes', 'h-100', false) ?>
- <div id="contenidoFaltantes" style="display:none">
- <div class="modal-header p-0" >
- <div class="d-flex flex-row align-items-center justify-content-start w-100 m-3">
- <div class="ing-importante text-warning display-4"></div>
- <div id="tituloAlerta" class="text-danger display-5 indivisa-text-bold-italic ml-3 flex-grow-1"></div>
- </div>
- <button type="button" class="cerrar" data-dismiss="modal"><div class="ing-cancelar"></div></button>
- </div>
- <div class="modal-body d-flex flex-row align-items-start justify-content-center p-0" style="display:none">
- <div id="listaAlerta" class="d-flex flex-column w-100 px-3 mb-3"></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <?php }
- }
- }
- }
|