PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ieducar/intranet/include/pmieducar/clsPmieducarCurso.inc.php

https://github.com/ViniciusRangel/ieducar
PHP | 840 lines | 589 code | 120 blank | 131 comment | 146 complexity | 699d10d1360328767e89d74f50873129 MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /**
  3. * i-Educar - Sistema de gestדo escolar
  4. *
  5. * Copyright (C) 2006 Prefeitura Municipal de Itajaם
  6. * <ctima@itajai.sc.gov.br>
  7. *
  8. * Este programa י software livre; vocך pode redistribuם-lo e/ou modificב-lo
  9. * sob os termos da Licenחa Pתblica Geral GNU conforme publicada pela Free
  10. * Software Foundation; tanto a versדo 2 da Licenחa, como (a seu critיrio)
  11. * qualquer versדo posterior.
  12. *
  13. * Este programa י distribuם­do na expectativa de que seja תtil, porיm, SEM
  14. * NENHUMA GARANTIA; nem mesmo a garantia implם­cita de COMERCIABILIDADE OU
  15. * ADEQUAֳַO A UMA FINALIDADE ESPECֽFICA. Consulte a Licenחa Pתblica Geral
  16. * do GNU para mais detalhes.
  17. *
  18. * Vocך deve ter recebido uma cףpia da Licenחa Pתblica Geral do GNU junto
  19. * com este programa; se nדo, escreva para a Free Software Foundation, Inc., no
  20. * endereחo 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
  21. *
  22. * @author Prefeitura Municipal de Itajaם <ctima@itajai.sc.gov.br>
  23. * @category i-Educar
  24. * @license @@license@@
  25. * @package iEd_Pmieducar
  26. * @since Arquivo disponםvel desde a versדo 1.0.0
  27. * @version $Id$
  28. */
  29. require_once 'include/pmieducar/geral.inc.php';
  30. /**
  31. * clsPmieducarSerie class.
  32. *
  33. * @author Prefeitura Municipal de Itajaם <ctima@itajai.sc.gov.br>
  34. * @category i-Educar
  35. * @license @@license@@
  36. * @package iEd_Pmieducar
  37. * @since Classe disponםvel desde a versדo 1.0.0
  38. * @version @@package_version@@
  39. */
  40. class clsPmieducarCurso
  41. {
  42. var $cod_curso;
  43. var $ref_usuario_cad;
  44. var $ref_cod_tipo_regime;
  45. var $ref_cod_nivel_ensino;
  46. var $ref_cod_tipo_ensino;
  47. var $nm_curso;
  48. var $sgl_curso;
  49. var $qtd_etapas;
  50. var $carga_horaria;
  51. var $ato_poder_publico;
  52. var $objetivo_curso;
  53. var $publico_alvo;
  54. var $data_cadastro;
  55. var $data_exclusao;
  56. var $ativo;
  57. var $ref_usuario_exc;
  58. var $ref_cod_instituicao;
  59. var $padrao_ano_escolar;
  60. var $hora_falta;
  61. /**
  62. * Armazena o total de resultados obtidos na תltima chamada ao mיtodo lista().
  63. * @var int
  64. */
  65. var $_total;
  66. /**
  67. * Nome do schema.
  68. * @var string
  69. */
  70. var $_schema;
  71. /**
  72. * Nome da tabela.
  73. * @var string
  74. */
  75. var $_tabela;
  76. /**
  77. * Lista separada por vםrgula, com os campos que devem ser selecionados na
  78. * prףxima chamado ao mיtodo lista().
  79. * @var string
  80. */
  81. var $_campos_lista;
  82. /**
  83. * Lista com todos os campos da tabela separados por vםrgula, padrדo para
  84. * seleחדo no mיtodo lista.
  85. * @var string
  86. */
  87. var $_todos_campos;
  88. /**
  89. * Valor que define a quantidade de registros a ser retornada pelo mיtodo lista().
  90. * @var int
  91. */
  92. var $_limite_quantidade;
  93. /**
  94. * Define o valor de offset no retorno dos registros no mיtodo lista().
  95. * @var int
  96. */
  97. var $_limite_offset;
  98. /**
  99. * Define o campo para ser usado como padrדo de ordenaחדo no mיtodo lista().
  100. * @var string
  101. */
  102. var $_campo_order_by;
  103. /**
  104. * Construtor.
  105. *
  106. * @todo Os parגmetros $frequencia_minima, $edicao_final,
  107. * $ref_cod_tipo_avaliacao, $media, $media_exame, $falta_ch_globalizada e
  108. * $avaliacao_globalizada serדo removidos do construtor. Seus valores sדo
  109. * ignorados.
  110. */
  111. function clsPmieducarCurso($cod_curso = NULL, $ref_usuario_cad = NULL,
  112. $ref_cod_tipo_regime = NULL, $ref_cod_nivel_ensino = NULL,
  113. $ref_cod_tipo_ensino = NULL, $ref_cod_tipo_avaliacao = NULL, $nm_curso = NULL,
  114. $sgl_curso = NULL, $qtd_etapas = NULL, $frequencia_minima = NULL, $media = NULL,
  115. $media_exame = NULL, $falta_ch_globalizada = NULL, $carga_horaria = NULL,
  116. $ato_poder_publico = NULL, $edicao_final = NULL, $objetivo_curso = NULL,
  117. $publico_alvo = NULL, $data_cadastro = NULL, $data_exclusao = NULL,
  118. $ativo = NULL, $ref_usuario_exc = NULL, $ref_cod_instituicao = NULL,
  119. $padrao_ano_escolar = NULL, $hora_falta = NULL, $avaliacao_globalizada = NULL, $multi_seriado = NULL)
  120. {
  121. $db = new clsBanco();
  122. $this->_schema = 'pmieducar.';
  123. $this->_tabela = $this->_schema . 'curso';
  124. $this->_campos_lista = $this->_todos_campos = 'cod_curso, ref_usuario_cad, ref_cod_tipo_regime, ref_cod_nivel_ensino, ref_cod_tipo_ensino, nm_curso, sgl_curso, qtd_etapas, carga_horaria, ato_poder_publico, objetivo_curso, publico_alvo, data_cadastro, data_exclusao, ativo, ref_usuario_exc, ref_cod_instituicao, padrao_ano_escolar, hora_falta, multi_seriado';
  125. if (is_numeric($ref_cod_instituicao)) {
  126. if (class_exists('clsPmieducarInstituicao')) {
  127. $tmp_obj = new clsPmieducarInstituicao($ref_cod_instituicao);
  128. if (method_exists( $tmp_obj, 'existe')) {
  129. if ($tmp_obj->existe()) {
  130. $this->ref_cod_instituicao = $ref_cod_instituicao;
  131. }
  132. }
  133. else if(method_exists($tmp_obj, 'detalhe')) {
  134. if ($tmp_obj->detalhe()) {
  135. $this->ref_cod_instituicao = $ref_cod_instituicao;
  136. }
  137. }
  138. }
  139. else {
  140. if ($db->CampoUnico("SELECT 1 FROM pmieducar.instituicao WHERE cod_instituicao = '{$ref_cod_instituicao}'")) {
  141. $this->ref_cod_instituicao = $ref_cod_instituicao;
  142. }
  143. }
  144. }
  145. if (is_numeric($ref_usuario_exc)) {
  146. if (class_exists('clsPmieducarUsuario')) {
  147. $tmp_obj = new clsPmieducarUsuario( $ref_usuario_exc );
  148. if (method_exists($tmp_obj, 'existe')) {
  149. if ($tmp_obj->existe()) {
  150. $this->ref_usuario_exc = $ref_usuario_exc;
  151. }
  152. }
  153. else if( method_exists($tmp_obj, 'detalhe')) {
  154. if($tmp_obj->detalhe()) {
  155. $this->ref_usuario_exc = $ref_usuario_exc;
  156. }
  157. }
  158. }
  159. else {
  160. if ($db->CampoUnico("SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_exc}'")) {
  161. $this->ref_usuario_exc = $ref_usuario_exc;
  162. }
  163. }
  164. }
  165. if (is_numeric($ref_cod_tipo_regime)) {
  166. if (class_exists('clsPmieducarTipoRegime')) {
  167. $tmp_obj = new clsPmieducarTipoRegime( $ref_cod_tipo_regime );
  168. if (method_exists($tmp_obj, 'existe')) {
  169. if ($tmp_obj->existe()) {
  170. $this->ref_cod_tipo_regime = $ref_cod_tipo_regime;
  171. }
  172. }
  173. else if (method_exists($tmp_obj, 'detalhe')) {
  174. if ($tmp_obj->detalhe()) {
  175. $this->ref_cod_tipo_regime = $ref_cod_tipo_regime;
  176. }
  177. }
  178. }
  179. else {
  180. if ($db->CampoUnico("SELECT 1 FROM pmieducar.tipo_regime WHERE cod_tipo_regime = '{$ref_cod_tipo_regime}'")) {
  181. $this->ref_cod_tipo_regime = $ref_cod_tipo_regime;
  182. }
  183. }
  184. }
  185. if (is_numeric($ref_cod_nivel_ensino)) {
  186. if (class_exists('clsPmieducarNivelEnsino')) {
  187. $tmp_obj = new clsPmieducarNivelEnsino($ref_cod_nivel_ensino);
  188. if (method_exists($tmp_obj, 'existe')) {
  189. if ($tmp_obj->existe()) {
  190. $this->ref_cod_nivel_ensino = $ref_cod_nivel_ensino;
  191. }
  192. }
  193. else if (method_exists($tmp_obj, 'detalhe')) {
  194. if ($tmp_obj->detalhe()) {
  195. $this->ref_cod_nivel_ensino = $ref_cod_nivel_ensino;
  196. }
  197. }
  198. }
  199. else {
  200. if ($db->CampoUnico("SELECT 1 FROM pmieducar.nivel_ensino WHERE cod_nivel_ensino = '{$ref_cod_nivel_ensino}'")) {
  201. $this->ref_cod_nivel_ensino = $ref_cod_nivel_ensino;
  202. }
  203. }
  204. }
  205. if (is_numeric($ref_cod_tipo_ensino)) {
  206. if( class_exists('clsPmieducarTipoEnsino')) {
  207. $tmp_obj = new clsPmieducarTipoEnsino( $ref_cod_tipo_ensino );
  208. if (method_exists($tmp_obj, 'existe')) {
  209. if ($tmp_obj->existe()) {
  210. $this->ref_cod_tipo_ensino = $ref_cod_tipo_ensino;
  211. }
  212. }
  213. else if(method_exists($tmp_obj, 'detalhe')) {
  214. if ($tmp_obj->detalhe()) {
  215. $this->ref_cod_tipo_ensino = $ref_cod_tipo_ensino;
  216. }
  217. }
  218. }
  219. else {
  220. if ($db->CampoUnico("SELECT 1 FROM pmieducar.tipo_ensino WHERE cod_tipo_ensino = '{$ref_cod_tipo_ensino}'")) {
  221. $this->ref_cod_tipo_ensino = $ref_cod_tipo_ensino;
  222. }
  223. }
  224. }
  225. if (is_numeric($ref_usuario_cad)) {
  226. if (class_exists('clsPmieducarUsuario')) {
  227. $tmp_obj = new clsPmieducarUsuario( $ref_usuario_cad );
  228. if (method_exists($tmp_obj, 'existe')) {
  229. if ($tmp_obj->existe()) {
  230. $this->ref_usuario_cad = $ref_usuario_cad;
  231. }
  232. }
  233. else if (method_exists($tmp_obj, 'detalhe')) {
  234. if ($tmp_obj->detalhe()) {
  235. $this->ref_usuario_cad = $ref_usuario_cad;
  236. }
  237. }
  238. }
  239. else {
  240. if ($db->CampoUnico("SELECT 1 FROM pmieducar.usuario WHERE cod_usuario = '{$ref_usuario_cad}'")) {
  241. $this->ref_usuario_cad = $ref_usuario_cad;
  242. }
  243. }
  244. }
  245. if (is_numeric($cod_curso)) {
  246. $this->cod_curso = $cod_curso;
  247. }
  248. if (is_string($nm_curso)) {
  249. $this->nm_curso = $nm_curso;
  250. }
  251. if (is_string($sgl_curso)) {
  252. $this->sgl_curso = $sgl_curso;
  253. }
  254. if (is_numeric($qtd_etapas)) {
  255. $this->qtd_etapas = $qtd_etapas;
  256. }
  257. if (is_numeric($carga_horaria)) {
  258. $this->carga_horaria = $carga_horaria;
  259. }
  260. if (is_string($ato_poder_publico)) {
  261. $this->ato_poder_publico = $ato_poder_publico;
  262. }
  263. if (is_string($objetivo_curso)) {
  264. $this->objetivo_curso = $objetivo_curso;
  265. }
  266. if (is_string($publico_alvo)) {
  267. $this->publico_alvo = $publico_alvo;
  268. }
  269. if (is_string($data_cadastro)) {
  270. $this->data_cadastro = $data_cadastro;
  271. }
  272. if (is_string($data_exclusao)) {
  273. $this->data_exclusao = $data_exclusao;
  274. }
  275. if (is_numeric($ativo)) {
  276. $this->ativo = $ativo;
  277. }
  278. if (is_numeric($padrao_ano_escolar)) {
  279. $this->padrao_ano_escolar = $padrao_ano_escolar;
  280. }
  281. if (is_numeric($hora_falta)) {
  282. $this->hora_falta = $hora_falta;
  283. }
  284. $this->multi_seriado = $multi_seriado;
  285. }
  286. /**
  287. * Cria um novo registro.
  288. * @return bool
  289. */
  290. function cadastra()
  291. {
  292. if (is_numeric($this->ref_usuario_cad) && is_numeric($this->ref_cod_nivel_ensino) &&
  293. is_numeric($this->ref_cod_tipo_ensino) && is_string($this->nm_curso) &&
  294. is_string($this->sgl_curso) && is_numeric($this->qtd_etapas) &&
  295. is_numeric($this->carga_horaria) && is_numeric($this->ref_cod_instituicao))
  296. {
  297. $db = new clsBanco();
  298. $campos = '';
  299. $valores = '';
  300. $gruda = '';
  301. if (is_numeric($this->ref_usuario_cad)) {
  302. $campos .= "{$gruda}ref_usuario_cad";
  303. $valores .= "{$gruda}'{$this->ref_usuario_cad}'";
  304. $gruda = ", ";
  305. }
  306. if (is_numeric($this->ref_cod_tipo_regime)) {
  307. $campos .= "{$gruda}ref_cod_tipo_regime";
  308. $valores .= "{$gruda}'{$this->ref_cod_tipo_regime}'";
  309. $gruda = ", ";
  310. }
  311. if (is_numeric($this->ref_cod_nivel_ensino)) {
  312. $campos .= "{$gruda}ref_cod_nivel_ensino";
  313. $valores .= "{$gruda}'{$this->ref_cod_nivel_ensino}'";
  314. $gruda = ", ";
  315. }
  316. if (is_numeric($this->ref_cod_tipo_ensino)) {
  317. $campos .= "{$gruda}ref_cod_tipo_ensino";
  318. $valores .= "{$gruda}'{$this->ref_cod_tipo_ensino}'";
  319. $gruda = ", ";
  320. }
  321. if (is_string($this->nm_curso)) {
  322. $campos .= "{$gruda}nm_curso";
  323. $valores .= "{$gruda}'{$this->nm_curso}'";
  324. $gruda = ", ";
  325. }
  326. if (is_string($this->sgl_curso)) {
  327. $campos .= "{$gruda}sgl_curso";
  328. $valores .= "{$gruda}'{$this->sgl_curso}'";
  329. $gruda = ", ";
  330. }
  331. if (is_numeric($this->qtd_etapas)) {
  332. $campos .= "{$gruda}qtd_etapas";
  333. $valores .= "{$gruda}'{$this->qtd_etapas}'";
  334. $gruda = ", ";
  335. }
  336. if (is_numeric($this->carga_horaria)) {
  337. $campos .= "{$gruda}carga_horaria";
  338. $valores .= "{$gruda}'{$this->carga_horaria}'";
  339. $gruda = ", ";
  340. }
  341. if (is_string($this->ato_poder_publico)) {
  342. $campos .= "{$gruda}ato_poder_publico";
  343. $valores .= "{$gruda}'{$this->ato_poder_publico}'";
  344. $gruda = ", ";
  345. }
  346. if (is_string($this->objetivo_curso)) {
  347. $campos .= "{$gruda}objetivo_curso";
  348. $valores .= "{$gruda}'{$this->objetivo_curso}'";
  349. $gruda = ", ";
  350. }
  351. if (is_string($this->publico_alvo)) {
  352. $campos .= "{$gruda}publico_alvo";
  353. $valores .= "{$gruda}'{$this->publico_alvo}'";
  354. $gruda = ", ";
  355. }
  356. $campos .= "{$gruda}data_cadastro";
  357. $valores .= "{$gruda}NOW()";
  358. $gruda = ", ";
  359. $campos .= "{$gruda}ativo";
  360. $valores .= "{$gruda}'1'";
  361. $gruda = ", ";
  362. if (is_numeric( $this->ref_cod_instituicao)) {
  363. $campos .= "{$gruda}ref_cod_instituicao";
  364. $valores .= "{$gruda}'{$this->ref_cod_instituicao}'";
  365. $gruda = ", ";
  366. }
  367. if (is_numeric( $this->padrao_ano_escolar)) {
  368. $campos .= "{$gruda}padrao_ano_escolar";
  369. $valores .= "{$gruda}'{$this->padrao_ano_escolar}'";
  370. $gruda = ", ";
  371. }
  372. if (is_numeric( $this->hora_falta)) {
  373. $campos .= "{$gruda}hora_falta";
  374. $valores .= "{$gruda}'{$this->hora_falta}'";
  375. $gruda = ", ";
  376. }
  377. if (is_numeric($multi_seriado)) {
  378. $campos .= "{$gruda}multi_seriado";
  379. $valores .= "{$gruda}'{$this->multi_seriado}'";
  380. $gruda = ", ";
  381. }
  382. $db->Consulta("INSERT INTO {$this->_tabela} ( $campos ) VALUES( $valores )");
  383. return $db->InsertId("{$this->_tabela}_cod_curso_seq");
  384. }
  385. return FALSE;
  386. }
  387. /**
  388. * Edita os dados de um registro
  389. * @return bool
  390. */
  391. function edita()
  392. {
  393. if (is_numeric($this->cod_curso) && is_numeric($this->ref_usuario_exc)) {
  394. $db = new clsBanco();
  395. $set = '';
  396. if (is_numeric($this->ref_usuario_cad)) {
  397. $set .= "{$gruda}ref_usuario_cad = '{$this->ref_usuario_cad}'";
  398. $gruda = ", ";
  399. }
  400. if (is_numeric($this->ref_cod_tipo_regime)) {
  401. $set .= "{$gruda}ref_cod_tipo_regime = '{$this->ref_cod_tipo_regime}'";
  402. $gruda = ", ";
  403. }
  404. if (is_numeric($this->ref_cod_nivel_ensino)) {
  405. $set .= "{$gruda}ref_cod_nivel_ensino = '{$this->ref_cod_nivel_ensino}'";
  406. $gruda = ", ";
  407. }
  408. if (is_numeric($this->ref_cod_tipo_ensino)) {
  409. $set .= "{$gruda}ref_cod_tipo_ensino = '{$this->ref_cod_tipo_ensino}'";
  410. $gruda = ", ";
  411. }
  412. if (is_string($this->nm_curso)) {
  413. $set .= "{$gruda}nm_curso = '{$this->nm_curso}'";
  414. $gruda = ", ";
  415. }
  416. if (is_string($this->sgl_curso)) {
  417. $set .= "{$gruda}sgl_curso = '{$this->sgl_curso}'";
  418. $gruda = ", ";
  419. }
  420. if (is_numeric($this->qtd_etapas)) {
  421. $set .= "{$gruda}qtd_etapas = '{$this->qtd_etapas}'";
  422. $gruda = ", ";
  423. }
  424. if (is_numeric($this->carga_horaria)) {
  425. $set .= "{$gruda}carga_horaria = '{$this->carga_horaria}'";
  426. $gruda = ", ";
  427. }
  428. if (is_string($this->ato_poder_publico)) {
  429. $set .= "{$gruda}ato_poder_publico = '{$this->ato_poder_publico}'";
  430. $gruda = ", ";
  431. }
  432. if (is_string($this->objetivo_curso)) {
  433. $set .= "{$gruda}objetivo_curso = '{$this->objetivo_curso}'";
  434. $gruda = ", ";
  435. }
  436. if (is_string($this->publico_alvo)) {
  437. $set .= "{$gruda}publico_alvo = '{$this->publico_alvo}'";
  438. $gruda = ", ";
  439. }
  440. if (is_string($this->data_cadastro)) {
  441. $set .= "{$gruda}data_cadastro = '{$this->data_cadastro}'";
  442. $gruda = ", ";
  443. }
  444. $set .= "{$gruda}data_exclusao = NOW()";
  445. $gruda = ", ";
  446. if (is_numeric($this->ativo)) {
  447. $set .= "{$gruda}ativo = '{$this->ativo}'";
  448. $gruda = ", ";
  449. }
  450. if (is_numeric($this->ref_usuario_exc)) {
  451. $set .= "{$gruda}ref_usuario_exc = '{$this->ref_usuario_exc}'";
  452. $gruda = ", ";
  453. }
  454. if (is_numeric($this->ref_cod_instituicao)) {
  455. $set .= "{$gruda}ref_cod_instituicao = '{$this->ref_cod_instituicao}'";
  456. $gruda = ", ";
  457. }
  458. if (is_numeric($this->padrao_ano_escolar)) {
  459. $set .= "{$gruda}padrao_ano_escolar = '{$this->padrao_ano_escolar}'";
  460. $gruda = ", ";
  461. }
  462. if (is_numeric($this->hora_falta)) {
  463. $set .= "{$gruda}hora_falta = '{$this->hora_falta}'";
  464. $gruda = ", ";
  465. }
  466. else {
  467. $set .= "{$gruda}hora_falta = 0";
  468. $gruda = ", ";
  469. }
  470. if( is_numeric( $this->multi_seriado))
  471. {
  472. $set .= "{$gruda}multi_seriado = '{$this->multi_seriado}'";
  473. $gruda = ", ";
  474. }
  475. if ($set) {
  476. $db->Consulta("UPDATE {$this->_tabela} SET $set WHERE cod_curso = '{$this->cod_curso}'");
  477. return TRUE;
  478. }
  479. }
  480. return FALSE;
  481. }
  482. /**
  483. * Retorna uma lista de registros filtrados de acordo com os parגmetros.
  484. * @return array
  485. * @todo Os argumentos $int_ref_cod_tipo_avaliacao, $int_media,
  486. * $int_media_exame, $int_falta_ch_globalizada, $int_edicao_final,
  487. * $bool_avaliacao_globalizada serדo removidas da assinatura do mיtodo.
  488. * Por enquanto, seus valores sדo ignorados.
  489. */
  490. function lista($int_cod_curso = NULL, $int_ref_usuario_cad = NULL,
  491. $int_ref_cod_tipo_regime = NULL, $int_ref_cod_nivel_ensino = NULL,
  492. $int_ref_cod_tipo_ensino = NULL, $int_ref_cod_tipo_avaliacao = NULL,
  493. $str_nm_curso = NULL, $str_sgl_curso = NULL, $int_qtd_etapas = NULL,
  494. $int_frequencia_minima = NULL, $int_media = NULL, $int_media_exame = NULL,
  495. $int_falta_ch_globalizada = NULL, $int_carga_horaria = NULL,
  496. $str_ato_poder_publico = NULL, $int_edicao_final = NULL,
  497. $str_objetivo_curso = NULL, $str_publico_alvo = NULL,
  498. $date_data_cadastro_ini = NULL, $date_data_cadastro_fim = NULL,
  499. $date_data_exclusao_ini = NULL, $date_data_exclusao_fim = NULL,
  500. $int_ativo = NULL, $int_ref_usuario_exc = NULL,
  501. $int_ref_cod_instituicao = NULL, $int_padrao_ano_escolar = NULL,
  502. $int_hora_falta = NULL, $bool_avaliacao_globalizada = NULL)
  503. {
  504. $sql = "SELECT {$this->_campos_lista} FROM {$this->_tabela}";
  505. $filtros = '';
  506. $whereAnd = ' WHERE ';
  507. if (is_numeric($int_cod_curso)) {
  508. $filtros .= "{$whereAnd} cod_curso = '{$int_cod_curso}'";
  509. $whereAnd = " AND ";
  510. }
  511. if (is_numeric($int_ref_usuario_cad)) {
  512. $filtros .= "{$whereAnd} ref_usuario_cad = '{$int_ref_usuario_cad}'";
  513. $whereAnd = " AND ";
  514. }
  515. if (is_numeric($int_ref_cod_tipo_regime)) {
  516. $filtros .= "{$whereAnd} ref_cod_tipo_regime = '{$int_ref_cod_tipo_regime}'";
  517. $whereAnd = " AND ";
  518. }
  519. if (is_numeric($int_ref_cod_nivel_ensino)) {
  520. $filtros .= "{$whereAnd} ref_cod_nivel_ensino = '{$int_ref_cod_nivel_ensino}'";
  521. $whereAnd = " AND ";
  522. }
  523. if (is_numeric($int_ref_cod_tipo_ensino)) {
  524. $filtros .= "{$whereAnd} ref_cod_tipo_ensino = '{$int_ref_cod_tipo_ensino}'";
  525. $whereAnd = " AND ";
  526. }
  527. if (is_string($str_nm_curso)) {
  528. $filtros .= "{$whereAnd} nm_curso LIKE '%{$str_nm_curso}%'";
  529. $whereAnd = " AND ";
  530. }
  531. if (is_string($str_sgl_curso)) {
  532. $filtros .= "{$whereAnd} sgl_curso LIKE '%{$str_sgl_curso}%'";
  533. $whereAnd = " AND ";
  534. }
  535. if (is_numeric($int_qtd_etapas)) {
  536. $filtros .= "{$whereAnd} qtd_etapas = '{$int_qtd_etapas}'";
  537. $whereAnd = " AND ";
  538. }
  539. if (is_numeric($int_carga_horaria)) {
  540. $filtros .= "{$whereAnd} carga_horaria = '{$int_carga_horaria}'";
  541. $whereAnd = " AND ";
  542. }
  543. if (is_string($str_ato_poder_publico)) {
  544. $filtros .= "{$whereAnd} ato_poder_publico LIKE '%{$str_ato_poder_publico}%'";
  545. $whereAnd = " AND ";
  546. }
  547. if (is_string($str_objetivo_curso)) {
  548. $filtros .= "{$whereAnd} objetivo_curso LIKE '%{$str_objetivo_curso}%'";
  549. $whereAnd = " AND ";
  550. }
  551. if (is_string($str_publico_alvo)) {
  552. $filtros .= "{$whereAnd} publico_alvo LIKE '%{$str_publico_alvo}%'";
  553. $whereAnd = " AND ";
  554. }
  555. if (is_string($date_data_cadastro_ini)) {
  556. $filtros .= "{$whereAnd} data_cadastro >= '{$date_data_cadastro_ini}'";
  557. $whereAnd = " AND ";
  558. }
  559. if (is_string($date_data_cadastro_fim)) {
  560. $filtros .= "{$whereAnd} data_cadastro <= '{$date_data_cadastro_fim}'";
  561. $whereAnd = " AND ";
  562. }
  563. if (is_string($date_data_exclusao_ini)) {
  564. $filtros .= "{$whereAnd} data_exclusao >= '{$date_data_exclusao_ini}'";
  565. $whereAnd = " AND ";
  566. }
  567. if (is_string($date_data_exclusao_fim)) {
  568. $filtros .= "{$whereAnd} data_exclusao <= '{$date_data_exclusao_fim}'";
  569. $whereAnd = " AND ";
  570. }
  571. if (is_null($int_ativo) || $int_ativo) {
  572. $filtros .= "{$whereAnd} ativo = '1'";
  573. $whereAnd = " AND ";
  574. }
  575. else {
  576. $filtros .= "{$whereAnd} ativo = '0'";
  577. $whereAnd = " AND ";
  578. }
  579. if (is_numeric($int_ref_usuario_exc)) {
  580. $filtros .= "{$whereAnd} ref_usuario_exc = '{$int_ref_usuario_exc}'";
  581. $whereAnd = " AND ";
  582. }
  583. if (is_numeric($int_ref_cod_instituicao)) {
  584. $filtros .= "{$whereAnd} ref_cod_instituicao = '{$int_ref_cod_instituicao}'";
  585. $whereAnd = " AND ";
  586. }
  587. if (is_numeric($int_padrao_ano_escolar)) {
  588. $filtros .= "{$whereAnd} padrao_ano_escolar = '{$int_padrao_ano_escolar}'";
  589. $whereAnd = " AND ";
  590. }
  591. if (is_numeric($int_hora_falta)) {
  592. $filtros .= "{$whereAnd} hora_falta = '{$int_hora_falta}'";
  593. $whereAnd = " AND ";
  594. }
  595. $db = new clsBanco();
  596. $countCampos = count(explode(',', $this->_campos_lista));
  597. $resultado = array();
  598. $sql .= $filtros . $this->getOrderby() . $this->getLimite();
  599. $this->_total = $db->CampoUnico("SELECT COUNT(0) FROM {$this->_tabela} {$filtros}");
  600. $db->Consulta($sql);
  601. if ($countCampos > 1) {
  602. while ($db->ProximoRegistro()) {
  603. $tupla = $db->Tupla();
  604. $tupla["_total"] = $this->_total;
  605. $resultado[] = $tupla;
  606. }
  607. }
  608. else {
  609. while ($db->ProximoRegistro()) {
  610. $tupla = $db->Tupla();
  611. $resultado[] = $tupla[$this->_campos_lista];
  612. }
  613. }
  614. if (count($resultado)) {
  615. return $resultado;
  616. }
  617. return FALSE;
  618. }
  619. /**
  620. * Retorna um array com os dados de um registro.
  621. * @return array
  622. */
  623. function detalhe()
  624. {
  625. if (is_numeric($this->cod_curso)) {
  626. $db = new clsBanco();
  627. $db->Consulta( "SELECT {$this->_todos_campos},fcn_upper(nm_curso) as nm_curso_upper FROM {$this->_tabela} WHERE cod_curso = '{$this->cod_curso}'" );
  628. $db->ProximoRegistro();
  629. return $db->Tupla();
  630. }
  631. return FALSE;
  632. }
  633. /**
  634. * Retorna um array com os dados de um registro ou FALSE caso nדo exista.
  635. * @return array|bool
  636. */
  637. function existe()
  638. {
  639. if (is_numeric($this->cod_curso)) {
  640. $db = new clsBanco();
  641. $db->Consulta("SELECT 1 FROM {$this->_tabela} WHERE cod_curso = '{$this->cod_curso}'");
  642. $db->ProximoRegistro();
  643. return $db->Tupla();
  644. }
  645. return FALSE;
  646. }
  647. /**
  648. * Exclui um registro.
  649. * @return bool
  650. */
  651. function excluir()
  652. {
  653. if (is_numeric($this->cod_curso) && is_numeric($this->ref_usuario_exc)) {
  654. $this->ativo = 0;
  655. return $this->edita();
  656. }
  657. return FALSE;
  658. }
  659. /**
  660. * Define quais campos da tabela serדo selecionados no mיtodo Lista().
  661. */
  662. function setCamposLista($str_campos)
  663. {
  664. $this->_campos_lista = $str_campos;
  665. }
  666. /**
  667. * Define que o mיtodo Lista() deverpa retornar todos os campos da tabela.
  668. */
  669. function resetCamposLista()
  670. {
  671. $this->_campos_lista = $this->_todos_campos;
  672. }
  673. /**
  674. * Define limites de retorno para o mיtodo Lista().
  675. */
  676. function setLimite($intLimiteQtd, $intLimiteOffset = NULL)
  677. {
  678. $this->_limite_quantidade = $intLimiteQtd;
  679. $this->_limite_offset = $intLimiteOffset;
  680. }
  681. /**
  682. * Retorna a string com o trecho da query responsבvel pelo limite de
  683. * registros retornados/afetados.
  684. *
  685. * @return string
  686. */
  687. function getLimite()
  688. {
  689. if (is_numeric($this->_limite_quantidade)) {
  690. $retorno = " LIMIT {$this->_limite_quantidade}";
  691. if (is_numeric($this->_limite_offset)) {
  692. $retorno .= " OFFSET {$this->_limite_offset} ";
  693. }
  694. return $retorno;
  695. }
  696. return '';
  697. }
  698. /**
  699. * Define o campo para ser utilizado como ordenaחדo no mיtodo Lista().
  700. */
  701. function setOrderby($strNomeCampo)
  702. {
  703. if (is_string($strNomeCampo) && $strNomeCampo) {
  704. $this->_campo_order_by = $strNomeCampo;
  705. }
  706. }
  707. /**
  708. * Retorna a string com o trecho da query responsבvel pela Ordenaחדo dos
  709. * registros.
  710. *
  711. * @return string
  712. */
  713. function getOrderby()
  714. {
  715. if (is_string($this->_campo_order_by)) {
  716. return " ORDER BY {$this->_campo_order_by} ";
  717. }
  718. return '';
  719. }
  720. }