PageRenderTime 63ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/frontend/modules/IRNC/actions/actions.class.php

https://github.com/rmoralesm/FONDEF-D08I1205
PHP | 291 lines | 173 code | 54 blank | 64 comment | 12 complexity | e9cc5fa8bf647d28b76dc335557f545b MD5 | raw file
  1. <?php
  2. /**
  3. * IRNC actions.
  4. *
  5. * @package psicologia
  6. * @subpackage IRNC
  7. * @author Gustavo Lacoste <gustavo@lacosox.org>
  8. * @version SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
  9. */
  10. class IRNCActions extends Actions
  11. {
  12. /**
  13. * Executes index action
  14. *
  15. * @param sfRequest $request A request object
  16. */
  17. public function executeIndex(sfWebRequest $request)
  18. {
  19. $this->forward('IRNC','listarBloque');
  20. }
  21. /**
  22. * Executes proximoBloque action
  23. *
  24. * @param sfRequest $request A request object
  25. */
  26. public function executeGuardarInstrumento(sfWebRequest $request)
  27. {
  28. $this->BD_Conectar();
  29. $idUser=$this->getUser()->getGuardUser()->getId();
  30. $this->idEncuestado=$request->getParameter('idEncuestado');
  31. /*si no llega el parametro idEncuestado entonces tirar un error 404*/
  32. $this->forward404If(!$this->idEncuestado);
  33. $arrayRespuestas=$request->getParameterHolder()->getAll();
  34. $sql_borrarcheckbooks="DELETE FROM IRNC_respuestas WHERE `IRNC_respuestas`.`id_user` = '{$idUser}' AND `IRNC_respuestas`.`id_encuestado` = '{$this->idEncuestado}' AND `IRNC_respuestas`.`id_pregunta_IRNC` >= 43";
  35. mysql_query($sql_borrarcheckbooks);
  36. $sql_borrarCOMENTARIOScheckbooks="DELETE FROM IRNC_respuestas_fixed_comxbloque WHERE `IRNC_respuestas_fixed_comxbloque`.`id_user` = '{$idUser}' AND `IRNC_respuestas_fixed_comxbloque`.`id_encuestado` = '{$this->idEncuestado}'";
  37. mysql_query($sql_borrarCOMENTARIOScheckbooks);
  38. foreach ($arrayRespuestas as $r_nombre_parametro => $r_valor_parametro) {
  39. if (substr($r_nombre_parametro,0,strlen("radio_VorF_IRNC_")) == "radio_VorF_IRNC_"){//INICIO
  40. $id_preg=substr($r_nombre_parametro,strlen("radio_VorF_IRNC_"),strlen($r_nombre_parametro));
  41. $valRespuesta=$r_valor_parametro;
  42. $this->sql_update_or_insert_respuesta=
  43. //¿Existe una respuesta registrada para la pregunta {$id_preg} correspondiente
  44. //al encuestado '{$this->idEncuestado}' y registrada por el usuario '{$idUser}'?
  45. $sql_chequear_siexisterespuesta="select count(*) from IRNC_respuestas
  46. where
  47. `id_user`='{$idUser}' AND
  48. `id_encuestado`='{$this->idEncuestado}' AND
  49. `id_pregunta_IRNC`='{$id_preg}'";
  50. $respExiste = mysql_query($sql_chequear_siexisterespuesta);
  51. $respExiste = mysql_fetch_array($respExiste);
  52. // ECHO "EL IF DIJO ->".$respExiste[0]."<-";
  53. if($respExiste[0]>0){
  54. // si la respuesta a la pregunta estaba registrada entonces actualizo la respuesta
  55. $this->sql_regustrar_respuesta="
  56. UPDATE IRNC_respuestas
  57. SET
  58. `respuesta` = '{$valRespuesta}',
  59. `comentario` = '{$arrayRespuestas["comentario_{$id_preg}"]}'
  60. WHERE
  61. `IRNC_respuestas`.`id_user`='{$idUser}' AND
  62. `IRNC_respuestas`.`id_encuestado`='{$this->idEncuestado}' AND
  63. `IRNC_respuestas`.`id_pregunta_IRNC` ='{$id_preg}';";
  64. }
  65. else{
  66. //si la respuesta a la pregunta no estaba registrada entonces la registro como nueva
  67. $this->sql_regustrar_respuesta="
  68. INSERT INTO `IRNC_respuestas` (
  69. `id_user` ,
  70. `respuesta` ,
  71. `comentario` ,
  72. `id_encuestado` ,
  73. `id_pregunta_IRNC`
  74. )
  75. VALUES (
  76. '{$idUser}', '{$valRespuesta}', '{$arrayRespuestas["comentario_{$id_preg}"]}', '{$this->idEncuestado}', '{$id_preg}')";
  77. }
  78. // echo $this->sql_regustrar_respuesta;
  79. mysql_query($this->sql_regustrar_respuesta);
  80. } // <| fiiiin>
  81. //****************************
  82. if (substr($r_nombre_parametro,0,strlen("check_VorF_IRNC_")) == "check_VorF_IRNC_"){//INICIO
  83. $id_preg=substr($r_nombre_parametro,strlen("check_VorF_IRNC_"),strlen($r_nombre_parametro));
  84. $valRespuesta=$r_valor_parametro;
  85. //si la respuesta a la pregunta no estaba registrada entonces la registro como nueva
  86. $sql_regustrar_respuesta="
  87. INSERT INTO `IRNC_respuestas` (
  88. `id_user` ,
  89. `respuesta` ,
  90. `comentario` ,
  91. `id_encuestado` ,
  92. `id_pregunta_IRNC`
  93. )
  94. VALUES (
  95. '{$idUser}', '{$valRespuesta}', '{$arrayRespuestas["check_VorF_IRNComfix_{$id_preg}"]}', '{$this->idEncuestado}', '{$id_preg}')";
  96. // echo $sql_regustrar_respuesta;
  97. mysql_query($sql_regustrar_respuesta);
  98. } // <| fiiiin>
  99. //****************************
  100. if (substr($r_nombre_parametro,0,strlen("comentario_bloque")) == "comentario_bloque"){//INICIO
  101. $num_bloque=substr($r_nombre_parametro,strlen("comentario_bloque"),strlen($r_nombre_parametro));
  102. $valRespuesta=$r_valor_parametro;
  103. //si la respuesta a la pregunta no estaba registrada entonces la registro como nueva
  104. $sql_regustrar_respuesta_cometariosfixed="
  105. INSERT INTO `IRNC_respuestas_fixed_comxbloque` (
  106. `id_user` ,
  107. `comentario` ,
  108. `id_encuestado` ,
  109. `bloque_IRNC`
  110. )
  111. VALUES (
  112. '{$idUser}', '{$valRespuesta}', '{$this->idEncuestado}', '{$num_bloque}')";
  113. //echo $sql_regustrar_respuesta_cometariosfixed;
  114. mysql_query($sql_regustrar_respuesta_cometariosfixed);
  115. } // <| fiiiin>
  116. //****************************
  117. }
  118. if($request->getParameter('esCerrarForm')=="CERRAR"){
  119. $this->forwardIf(($this->getPorcentajeCompletadoIRNC($idUser,$this->idEncuestado)>=100), $this->getModuleName(),'cerrarInstrumento');
  120. }
  121. }
  122. /**
  123. * FINALIZA EL INSTRUMENTO
  124. *
  125. * @param sfRequest $request A request object
  126. */
  127. public function executeCerrarInstrumento(sfWebRequest $request)
  128. {
  129. $idUser=$this->getUser()->getGuardUser()->getId();
  130. $this->idEncuestado=$request->getParameter('idEncuestado');
  131. $sql_actualizar_estadoinistrumento="
  132. UPDATE estados_instrumentos SET
  133. `estado` = 'CERRADO',
  134. `fecha_cierre` = NOW()
  135. WHERE id_encuestado ='{$this->idEncuestado}' AND
  136. id_user='{$idUser}' AND
  137. sigla_instrumento='IRNC' AND
  138. modalidad_respuesta='SOLO';
  139. ";
  140. //echo $sql_actualizar_estadoinistrumento;
  141. mysql_query($sql_actualizar_estadoinistrumento);
  142. }
  143. /**
  144. * Lista las preguntas del formulario
  145. *
  146. * @param sfRequest $request A request object
  147. */
  148. public function executeListarBloque(sfWebRequest $request)
  149. {
  150. $this->BD_Conectar();
  151. $idUser=$this->getUser()->getGuardUser()->getId();
  152. $this->idEncuestado=$request->getParameter('idEncuestado');
  153. /*si no llega el parametro idEncuestado entonces tirar un error 404*/
  154. $this->forward404If(!$this->idEncuestado);
  155. $sql_consulta_si_esta_cerrado="SELECT estado,fecha_cierre,tiempo_total_utilizado FROM estados_instrumentos where id_encuestado='{$this->idEncuestado}' AND id_user='{$idUser}' AND modalidad_respuesta='SOLO'";
  156. //echo $sql_consulta_si_esta_cerrado;
  157. $esCerrado = mysql_query($sql_consulta_si_esta_cerrado);
  158. $esCerrado = mysql_fetch_array($esCerrado);
  159. if(trim($esCerrado[0])!="CERRADO"){
  160. /**
  161. * retorna un array con los numeros de bloques y los respectivos nombres del bloque
  162. */
  163. $sql_listar_bloques="
  164. SELECT pins.`bloque_num`as numBLoque ,pins.bloque_IRNC as textoBloque
  165. FROM IRNC_preguntas pins where bloque_num<=8
  166. group by pins.`bloque_num`";
  167. $bloques_result=mysql_query($sql_listar_bloques);
  168. $this->Preguntas_IRNC=array();
  169. while($bloque = mysql_fetch_array($bloques_result)) {
  170. /**
  171. * Consulta las preguntas a listar para un encuestado administrado por un usuario
  172. * dado, tras la consulta devuelve las primeras 20 preguntas que aún no han sido
  173. * respondidas por el encuestado y las devuelve ordenadas por el número de pregunta;
  174. * el número de pregunta es mas bien el id de la pregunta dado que esta fue
  175. * generada con un autoincrement.
  176. * pins= preguntas del instrumento
  177. * rins= respuestas del instrumento
  178. */
  179. $sql_consulta_preguntas_bloque_IRNC="SELECT pins.id_pregunta_IRNC AS id_pregunta, pins.num_pregunta AS num_pregunta, pins.texto AS texto_pregunta, pins.es_requerido AS es_requerida, pins.bloque_IRNC as textoBloque
  180. FROM IRNC_preguntas pins
  181. WHERE pins.`bloque_num` = '{$bloque["numBLoque"]}'
  182. ORDER BY pins.id_pregunta_IRNC LIMIT 20;";
  183. //echo $sql_consulta_preguntas_bloque_IRNC."<BR><BR>";
  184. $result = mysql_query($sql_consulta_preguntas_bloque_IRNC);
  185. $this->PreguntasDelBloqueArray=array();
  186. /*pasa el resultado (de tipo mysql result) a un arreglo comun para iterarlo en la vista*/
  187. while(($resultArray[] = mysql_fetch_assoc($result)) || array_pop($resultArray)){
  188. $this->PreguntasDelBloqueArray=$resultArray;
  189. }
  190. unset($resultArray);
  191. // print_r($this->PreguntasDelBloqueArray);
  192. // echo "<br>";
  193. $Preguntas_IRNC_local[] = array(
  194. "numBLoque" => $bloque["numBLoque"],
  195. "textoBloque" => $bloque["textoBloque"],
  196. "preguntasDelBloque" => $this->PreguntasDelBloqueArray);
  197. unset($this->PreguntasDelBloqueArray);
  198. mysql_free_result($result);
  199. }
  200. mysql_free_result($bloques_result);
  201. $this->Preguntas_IRNC=$Preguntas_IRNC_local;//fixed error
  202. $sql_respuestas_pordefecto="
  203. SELECT respuesta,comentario,id_pregunta_IRNC FROM IRNC_respuestas
  204. WHERE
  205. `IRNC_respuestas`.`id_user`='{$idUser}' AND
  206. `IRNC_respuestas`.`id_encuestado`='{$this->idEncuestado}'";
  207. $result = mysql_query($sql_respuestas_pordefecto);
  208. $Respuestas=array();
  209. /*pasa el resultado (de tipo mysql result) a un arreglo comun para iterarlo en la vista*/
  210. while(($resultArray[] = mysql_fetch_assoc($result)) || array_pop($resultArray)){
  211. $Respuestas=$resultArray;
  212. }
  213. $this->respuestas=$Respuestas;
  214. $sql_consulta_comentariodebloque9="SELECT comentario FROM IRNC_respuestas_fixed_comxbloque where id_user='{$idUser}' AND id_encuestado='{$this->idEncuestado}' AND bloque_IRNC=9";
  215. $comentariobloque9 = mysql_query($sql_consulta_comentariodebloque9);
  216. $comentariobloque9 = mysql_fetch_array($comentariobloque9);
  217. $this->comentariobloque9=$comentariobloque9[0];
  218. $sql_consulta_comentariodebloque10="SELECT comentario FROM IRNC_respuestas_fixed_comxbloque where id_user='{$idUser}' AND id_encuestado='{$this->idEncuestado}' AND bloque_IRNC=10";
  219. $comentariobloque10 = mysql_query($sql_consulta_comentariodebloque10);
  220. $comentariobloque10 = mysql_fetch_array($comentariobloque10);
  221. $this->comentariobloque10=$comentariobloque10[0];
  222. // echo "DDDD".$this->respuestas[0]["respuesta"]."DDDD";
  223. $this->porcCompletado=$this->getPorcentajeCompletadoIRNC($idUser,$this->idEncuestado);
  224. // $this->porcCompletado=0;
  225. if($this->porcCompletado >0){
  226. $this->is_show_instruccions='false';
  227. }else{
  228. $this->is_show_instruccions='false';//true
  229. }
  230. return sfView::SUCCESS;
  231. }//FIN IF
  232. else{
  233. $this->datocierre="Cerrado el ".$esCerrado[1].", en un tiempo total de respuesta de ".$esCerrado[2];
  234. return sfView::ERROR;
  235. }
  236. }
  237. }