PageRenderTime 59ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/application/controllers/test.php

http://findresources.googlecode.com/
PHP | 451 lines | 341 code | 63 blank | 47 comment | 46 complexity | 86191dea16ea67787635c7419546d356 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. class Test extends CI_Controller {
  3. public $sep = ";";
  4. function __construct() {
  5. parent::__construct();
  6. $this->load->database();
  7. $this->load->library('oracledb');
  8. $this->load->library('session');
  9. }
  10. function inicio(){
  11. $data["source"] ="inicio";
  12. $this->load->view('view_tests',$data);
  13. }
  14. function fin(){
  15. $data["source"] ="fin";
  16. $this->load->view('view_tests',$data);
  17. }
  18. function index() {
  19. /* Obtengo el separador */
  20. $query = $this->db->query('SELECT PKG_UTIL.FU_OBTIENE_SEPARADOR_SPLIT() SEPARADOR FROM DUAL');
  21. $row = $query->row_array();
  22. $this->sep = $row["SEPARADOR"];
  23. /** REALIZAR VALIDACION DE LOS TESTS A REALIZAR POR EL USUARIO**/
  24. /** E IR LLAMANDO A LOS TESTS QUE CORRESPONDAN VALIDANDO CON **/
  25. /** LO QUE LE FALTA REALIZAR SEGÚN LA INFO OBTENIDA DE LA BD **/
  26. /* USUARIO DE PRUEBA HASTA PODER TOMAR EL USUARIO REAL GUARDADO EN SESION */
  27. $idUsuario = $this->functionutils->getSession('SESSION_ID_USUARIO');
  28. if(!$idUsuario){
  29. redirect('login');
  30. /////////////HARDCODED//////////////////////////
  31. /////////////HARDCODED//////////////////////////
  32. //$idUsuario = "juan@juan.com";
  33. //$this->functionutils->setSession('SESSION_ID_USUARIO',$idUsuario);
  34. /////////////HARDCODED//////////////////////////
  35. /////////////HARDCODED//////////////////////////
  36. }
  37. $tests_del_usuario = $this->Test_model->getTestsPendientes($idUsuario);
  38. if (!array_key_exists(0, $tests_del_usuario["test_pendientes"])) {
  39. redirect('/Test/fin', 'refresh');
  40. }
  41. switch (strtolower($tests_del_usuario["test_pendientes"][0]->nombre_test)) {
  42. case "luscher":
  43. $this->luscher("1");
  44. break;
  45. case "d48":
  46. $this->d48("2");
  47. break;
  48. case "raven":
  49. $this->raven("3");
  50. break;
  51. case "mips":
  52. $this->mips("4");
  53. break;
  54. case "rorschach":
  55. $this->rorschach("5");
  56. break;
  57. default :
  58. $this->fin();
  59. }
  60. }
  61. /** METODOS SOLO PARA PRUEBAS INTERNAS **/
  62. function t1(){
  63. $this->luscher("1");
  64. }
  65. function t2(){
  66. $this->d48("2");
  67. }
  68. function t3(){
  69. $this->raven("3");
  70. }
  71. function t4(){
  72. $this->mips("4");
  73. }
  74. function t5(){
  75. $this->rorschach("5");
  76. }
  77. /** METODOS SOLO PARA PRUEBAS INTERNAS **/
  78. /**
  79. * Test de Luscher
  80. */
  81. function luscher($num = 1){
  82. //echo $num;
  83. $data['num'] = $num;
  84. $data['c1'] = '';
  85. $data['c2'] = '';
  86. $data['sep'] = $this->sep;
  87. switch ($this->input->post('source')) {
  88. case 'init_test' :
  89. $data['source'] = "select_colors1";
  90. $this->load->view('view_test_luscher',$data);
  91. break;
  92. case 'select_colors1' :
  93. $data['c1'] = $this->input->post('colors1');
  94. $data['source'] = "select_colors2";
  95. $this->load->view('view_test_luscher',$data);
  96. break;
  97. case 'select_colors2' :
  98. $usuario = $this->functionutils->getSession('SESSION_ID_USUARIO');
  99. $seleccion_luscher1 = $this->input->post('colors1');
  100. $seleccion_luscher2 = $this->input->post('colors2');
  101. $data['source'] = "test_finished";
  102. try {
  103. $result = $this->Test_model->setLuscherResults($usuario,$seleccion_luscher1,$seleccion_luscher2);
  104. if ($result["error"] == "0" )
  105. $data["result"] = "OK";
  106. else
  107. $data["result"] = "ERROR (".$result["error"].") :".$result["desc"];
  108. $this->load->view('view_test_luscher',$data);
  109. } catch (Exception $e) {
  110. $data["result"] = "ERROR (".$e->getMessage().")";
  111. $this->load->view('view_test_luscher',$data);
  112. }
  113. break;
  114. default :
  115. $data['source'] = "init_test";
  116. $this->load->view('view_test_luscher',$data);
  117. }
  118. }
  119. /**
  120. * Test de Raven
  121. */
  122. function raven($num = 3){
  123. $data['num'] = $num;
  124. $data['timer'] = '';
  125. /* Obtengo el valor de todas las fichas */
  126. $id = 1;
  127. while ($id <= 60) {
  128. $data['s'.$id] = intval($this->input->post('s'.$id));
  129. $id++;
  130. }
  131. /* Actualizo el valor seleccionado en la placa actual */
  132. $data['placa'] = intval($this->input->post('placa'));
  133. if($data['placa'] >= 1 AND $data['placa'] <= 60) {
  134. $data['s'.$data['placa']] = intval($this->input->post('item'));
  135. }
  136. $data['placa'] = $data['placa']+1;
  137. switch ($this->input->post('source')) {
  138. case 'init_test' :
  139. $data['source'] = "select_pieza";
  140. $this->load->view('view_test_raven',$data);
  141. break;
  142. case 'select_pieza' :
  143. $data['timer'] = $this->input->post('timer');
  144. $data['source'] = "select_pieza";
  145. $this->load->view('view_test_raven',$data);
  146. break;
  147. case 'select_pieza_final' :
  148. case 'timeout' :
  149. $data['timer'] = $this->input->post('timer');
  150. $data['source'] = "test_finished";
  151. $correctAnswers = $this->Test_model->getRavenCorrectAnswers($data);
  152. $usuario = $this->functionutils->getSession('SESSION_ID_USUARIO');
  153. try{
  154. $result = $this->Test_model->setRavenResults($usuario,$correctAnswers);
  155. if ($result["error"] == "0" )
  156. $data["result"] = "OK";
  157. else
  158. $data["result"] = "ERROR (".$result["error"].") :".$result["desc"];
  159. $this->load->view('view_test_raven',$data);
  160. } catch (Exception $e) {
  161. $data["result"] = "ERROR (".$e->getMessage().")";
  162. $this->load->view('view_test_raven',$data);
  163. }
  164. break;
  165. default :
  166. $data['source'] = "init_test";
  167. $this->load->view('view_test_raven',$data);
  168. }
  169. }
  170. /**
  171. * Test de Domino D48
  172. */
  173. function d48($num = 2){
  174. $data['num'] = $num;
  175. $data['timer'] = '';
  176. /* Obtengo el valor de todas las fichas */
  177. $id = 1;
  178. while ($id <= 48) {
  179. $data['s'.$id] = $this->input->post('s'.$id);
  180. $id++;
  181. }
  182. /* Actualizo el valor seleccionado en la placa actual */
  183. $data['placa'] = intval($this->input->post('placa'));
  184. /* Guardo el valor de la ficha */
  185. if($data['placa'] >= 1 AND $data['placa'] <= 48) {
  186. $data['s'.$data['placa']] = intval($this->input->post('item1')).intval($this->input->post('item2'));
  187. }
  188. $data['placa'] = $data['placa']+1;
  189. switch ($this->input->post('source')) {
  190. case 'init_test' :
  191. $data['source'] = "select_ficha";
  192. $this->load->view('view_test_d48',$data);
  193. break;
  194. case 'select_ficha' :
  195. $data['timer'] = $this->input->post('timer');
  196. $data['source'] = "select_ficha";
  197. $this->load->view('view_test_d48',$data);
  198. break;
  199. case 'select_ficha_final' :
  200. case 'timeout' :
  201. $data['timer'] = $this->input->post('timer');
  202. $data['source'] = "test_finished";
  203. $correctAnswers = $this->Test_model->getD48CorrectAnswers($data);
  204. $usuario = $this->functionutils->getSession('SESSION_ID_USUARIO');
  205. try {
  206. $result = $this->Test_model->setD48Results($usuario,$correctAnswers);
  207. if ($result["error"] == "0" )
  208. $data["result"] = "OK";
  209. else
  210. $data["result"] = "ERROR (".$result["error"].") :".$result["desc"];
  211. $this->load->view('view_test_d48',$data);
  212. } catch (Exception $e) {
  213. $data["result"] = "ERROR (".$e->getMessage().")";
  214. $this->load->view('view_test_d48',$data);
  215. }
  216. break;
  217. default :
  218. $data['source'] = "init_test";
  219. $this->load->view('view_test_d48',$data);
  220. }
  221. }
  222. /**
  223. * Test de MIPS
  224. */
  225. function mips($num = 4){
  226. $data['num'] = $num;
  227. $data['timer'] = '';
  228. switch ($this->input->post('source')) {
  229. case 'init_test' :
  230. $data['source'] = "select_questions";
  231. $this->load->view('view_test_mips',$data);
  232. break;
  233. case 'select_questions' :
  234. $codError = NULL;
  235. $descError = NULL;
  236. $usuario = $this->functionutils->getSession('SESSION_ID_USUARIO');
  237. $data['source'] = "test_finished";
  238. /* Obtengo el valor de todas las placas */
  239. $data['q1'] = $this->input->post('q1');
  240. $id = 2;
  241. while ($id <= 180) {
  242. $data['q'.$id] = $this->input->post('q'.$id);
  243. $id++;
  244. }
  245. $correctAnswers = $this->Test_model->getMIPSCorrectAnswers($data);
  246. try {
  247. $result = $this->Test_model->setMIPSResults($usuario,$correctAnswers);
  248. if ($result["error"] == "0" )
  249. $data["result"] = "OK";
  250. else
  251. $data["result"] = "ERROR (".$result["error"].") :".$result["desc"];
  252. $this->load->view('view_test_mips',$data);
  253. } catch (Exception $e) {
  254. $data["result"] = "ERROR (".$e->getMessage().")";
  255. $this->load->view('view_test_mips',$data);
  256. }
  257. break;
  258. default :
  259. $data['source'] = "init_test";
  260. $this->load->view('view_test_mips',$data);
  261. }
  262. }
  263. /**
  264. * Test de Rorschach
  265. */
  266. function rorschach($num = 5){
  267. $data['num'] = $num;
  268. /* Si no está seteado el número de mancha, fijo la 1. */
  269. $p = $this->input->post('pic');
  270. if($p == ""){
  271. $pic = 1;
  272. } else {
  273. $pic = intval($p);
  274. }
  275. /* Seteo el nombre de la key del array */
  276. $key = "img".$pic;
  277. /* Si borran un tag */
  278. $d = $this->input->post('del');
  279. if($d != ""){
  280. $del = intval($d);
  281. $rdata = $this->functionutils->getSession('RORSCHACH_DATA');
  282. unset($rdata[$key][$del]);
  283. $this->functionutils->setSession('RORSCHACH_DATA',$rdata);
  284. //Modifico el source para que no entre en el switch final
  285. $_POST["source"] = "select_img";
  286. }
  287. /* Agregado de un tag */
  288. if($this->input->post('description') != ""){
  289. foreach($_POST as $id => $val){
  290. $$id = addslashes($val);
  291. }
  292. $tag['pictureid'] = $pic;
  293. $tag['top'] = $top;
  294. $tag['left'] = $left;
  295. $tag['width'] = $width;
  296. $tag['height'] = $height;
  297. $tag['description'] = $description;
  298. $rdata = $this->functionutils->getSession('RORSCHACH_DATA');
  299. $rdata[$key][] = $tag;
  300. $this->functionutils->setSession('RORSCHACH_DATA',$rdata);
  301. //Modifico el source para que no entre en el switch final
  302. $_POST["source"] = "select_img";
  303. }
  304. /* Obtengo el valor de todas las placas */
  305. $rdata = $this->functionutils->getSession('RORSCHACH_DATA');
  306. /* La primera vez que se usa hay que setearlo como array para que no tire error el array_key_exists*/
  307. if(!is_array($rdata)) {
  308. $rdata = array();
  309. }
  310. /* Para que no tire warning por que no existe la key del array */
  311. if (array_key_exists($key, $rdata)) {
  312. $data["session_img"] = $rdata[$key];
  313. } else {
  314. $data["session_img"] = "";
  315. }
  316. /* Guardo el número de mancha */
  317. $data["pic"] = $pic;
  318. /* Derivo según la etapa en la que estoy */
  319. switch ($this->input->post('source')) {
  320. case 'init_test' :
  321. $data['source'] = "select_img";
  322. $this->load->view('view_test_rorschach',$data);
  323. break;
  324. case 'select_img' :
  325. $data['source'] = "select_img";
  326. $this->load->view('view_test_rorschach',$data);
  327. break;
  328. case 'select_img_final' :
  329. $data['source'] = "test_finished";
  330. $answers = $this->functionutils->getSession('RORSCHACH_DATA');
  331. $usuario = $this->functionutils->getSession('SESSION_ID_USUARIO');
  332. try {
  333. $result["error"] = 0;
  334. $result["desc"] = "";
  335. $tagdata = "";
  336. if (is_array($answers)){
  337. foreach($answers as $tags){
  338. foreach($tags as $tag){
  339. $tagdata .= $tag['pictureid'].$this->sep;
  340. $tagdata .= $tag['top'].$this->sep;
  341. $tagdata .= $tag['left'].$this->sep;
  342. $tagdata .= $tag['width'].$this->sep;
  343. $tagdata .= $tag['height'].$this->sep;
  344. $tagdata .= $tag['description'].$this->sep;
  345. }
  346. }
  347. /** Elimino el último separador **/
  348. $tagdata = substr($tagdata,0,-1);
  349. $result = $this->Test_model->setRorschachResults($usuario,$tagdata);
  350. if ($result["error"] == "0" )
  351. $data["result"] = "OK";
  352. else {
  353. $data["result"] = "ERROR (".$result["error"].") :".$result["desc"];
  354. break;
  355. }
  356. } else {
  357. $result["error"] = "999";
  358. $result["desc"] = "No se ingresaron datos";
  359. }
  360. $this->functionutils->unsetSession('RORSCHACH_DATA');
  361. $this->load->view('view_test_rorschach',$data);
  362. } catch (Exception $e) {
  363. $data["result"] = "ERROR (".$e->getMessage().")";
  364. $this->load->view('view_test_rorschach',$data);
  365. }
  366. break;
  367. default :
  368. $data['source'] = "init_test";
  369. $this->load->view('view_test_rorschach',$data);
  370. }
  371. }
  372. public function informe(){
  373. $usuario = $this->input->post("informe_usuario");
  374. if(!$usuario || $usuario == ""){
  375. $usuario = @$_GET["usuario"];
  376. }
  377. if(!$usuario || $usuario == ""){
  378. echo "No se seleccionó un usuario";
  379. exit;
  380. }
  381. $informe = $this->Test_model->getInforme($usuario);
  382. $data['informe'] = $informe["informe_info"];
  383. $data['usuarioData'] = $this->Usuario_model->getUsuario($usuario);
  384. $data['perfil'] = "empresa"; // por ahora solo la empresa ingresa aqui.
  385. $this->load->view('view_test_informe', $data);
  386. }
  387. }
  388. ?>