Commit 71b852ce7f2874abb55d3ceb19be5477b362fea8
1 parent
fe475b0f
Exists in
master
Adicionado finders para biblioteca, escola, curso, turma e aluno
Showing
1 changed file
with
281 additions
and
31 deletions
Show diff stats
ieducar/lib/App/Model/IedFinder.php
... | ... | @@ -63,6 +63,46 @@ class App_Model_IedFinder extends CoreExt_Entity |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | + * Retorna um array com as informações de escola a partir de seu código. | |
67 | + * @param int $id | |
68 | + * @return array | |
69 | + */ | |
70 | + public static function getEscola($id) | |
71 | + { | |
72 | + $escola = self::addClassToStorage('clsPmieducarEscola', NULL, | |
73 | + 'include/pmieducar/clsPmieducarEscola.inc.php'); | |
74 | + $escola->cod_escola = $id; | |
75 | + $escola = $escola->detalhe(); | |
76 | + | |
77 | + if (FALSE === $escola) { | |
78 | + throw new App_Model_Exception( | |
79 | + sprintf('Escola com o código "%d" não existe.', $id) | |
80 | + ); | |
81 | + } | |
82 | + | |
83 | + return $escola; | |
84 | + } | |
85 | + | |
86 | + /** | |
87 | + * Retorna todas as escolas cadastradas na tabela pmieducar.escola, selecionando | |
88 | + * opcionalmente pelo código da instituição. | |
89 | + * @param int $instituicaoId | |
90 | + * @return array | |
91 | + */ | |
92 | + public static function getEscolas($instituicaoId = NULL) | |
93 | + { | |
94 | + $_escolas = self::addClassToStorage('clsPmieducarEscola', NULL, | |
95 | + 'include/pmieducar/clsPmieducarEscola.inc.php'); | |
96 | + | |
97 | + $escolas = array(); | |
98 | + foreach ($_escolas->lista(NULL, NULL, NULL, $instituicaoId) as $escola) { | |
99 | + $escolas[$escola['cod_escola']] = $escola['nome']; | |
100 | + } | |
101 | + | |
102 | + return $escolas; | |
103 | + } | |
104 | + | |
105 | + /** | |
66 | 106 | * Retorna um nome de curso, procurando pelo seu código. |
67 | 107 | * @param int $id |
68 | 108 | * @return string|FALSE |
... | ... | @@ -77,6 +117,31 @@ class App_Model_IedFinder extends CoreExt_Entity |
77 | 117 | } |
78 | 118 | |
79 | 119 | /** |
120 | + * Retorna todos os cursos cadastradas na tabela pmieducar.escola_curso, selecionando | |
121 | + * opcionalmente pelo código da escola. | |
122 | + * @param int $escolaId | |
123 | + * @return array | |
124 | + */ | |
125 | + public static function getCursos($escolaId = NULL) | |
126 | + { | |
127 | + $escola_curso = self::addClassToStorage('clsPmieducarEscolaCurso', NULL, | |
128 | + 'include/pmieducar/clsPmieducarEscolaCurso.inc.php'); | |
129 | + | |
130 | + // Carrega os cursos | |
131 | + $escola_curso->setOrderby('ref_cod_escola ASC, cod_curso ASC'); | |
132 | + $escola_curso = $escola_curso->lista($escolaId); | |
133 | + | |
134 | + $cursos = array(); | |
135 | + foreach ($escola_curso as $key => $val) { | |
136 | + $nomeCurso = self::getCurso($val['ref_cod_curso']); | |
137 | + $cursos[$val['ref_cod_curso']] = $nomeCurso; | |
138 | + } | |
139 | + | |
140 | + return $cursos; | |
141 | + } | |
142 | + | |
143 | + | |
144 | + /** | |
80 | 145 | * Retorna um array com as informações da série a partir de seu código. |
81 | 146 | * |
82 | 147 | * @param int $codSerie |
... | ... | @@ -104,41 +169,71 @@ class App_Model_IedFinder extends CoreExt_Entity |
104 | 169 | |
105 | 170 | /** |
106 | 171 | * Retorna todas as séries cadastradas na tabela pmieducar.serie, selecionando |
107 | - * opcionalmente pelo código da instituição. | |
172 | + * opcionalmente pelo código da instituição, da escola ou do curso. | |
108 | 173 | * @param int $instituicaoId |
174 | + * @param int $escolaId | |
175 | + * @param int $cursoId | |
109 | 176 | * @return array |
110 | 177 | */ |
111 | - public static function getSeries($instituicaoId = NULL) | |
178 | + public static function getSeries($instituicaoId = NULL, $escolaId = NULL, $cursoId = NULL) | |
112 | 179 | { |
113 | - $serie = self::addClassToStorage('clsPmieducarSerie', NULL, | |
114 | - 'include/pmieducar/clsPmieducarSerie.inc.php'); | |
180 | + $series = self::addClassToStorage('clsPmieducarSerie', NULL, | |
181 | + 'include/pmieducar/clsPmieducarSerie.inc.php'); | |
182 | + | |
183 | + $series->setOrderby('ref_cod_curso ASC, cod_serie ASC, etapa_curso ASC'); | |
184 | + $series = $series->lista(NULL, NULL, NULL, $cursoId, NULL, NULL, NULL, NULL, NULL, | |
185 | + NULL, NULL, NULL, NULL, $instituicaoId, NULL, NULL, NULL, $escolaId); | |
186 | + | |
187 | + $_series = array(); | |
188 | + | |
189 | + foreach ($series as $serie) { | |
190 | + //$series[$val['cod_serie']] = $val; | |
191 | + $_series[$serie['cod_serie']] = $serie['nm_serie']; | |
192 | + } | |
193 | + | |
194 | + return $_series; | |
195 | + } | |
196 | + | |
197 | + /** | |
198 | + * Retorna um array com as informações da turma a partir de seu código. | |
199 | + * | |
200 | + * @param int $codTurma | |
201 | + * @return array | |
202 | + * @throws App_Model_Exception | |
203 | + */ | |
204 | + public static function getTurma($codTurma) | |
205 | + { | |
206 | + // Recupera clsPmieducarTurma do storage de classe estático | |
207 | + $turma = self::addClassToStorage('clsPmieducarTurma', NULL, | |
208 | + 'include/pmieducar/clsPmieducarTurma.inc.php'); | |
115 | 209 | |
116 | - // Carrega as séries | |
117 | - $serie->setOrderby('ref_cod_curso ASC, cod_serie ASC, etapa_curso ASC'); | |
118 | - $serie = $serie->lista(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, | |
119 | - NULL, NULL, NULL, NULL, $instituicaoId); | |
210 | + // Usa o atributo público para depois chamar o método detalhe() | |
211 | + $turma->cod_turma = $codTurma; | |
212 | + $turma = $turma->detalhe(); | |
120 | 213 | |
121 | - $series = array(); | |
122 | - foreach ($serie as $key => $val) { | |
123 | - $series[$val['cod_serie']] = $val; | |
214 | + if (FALSE === $turma) { | |
215 | + throw new App_Model_Exception( | |
216 | + sprintf('Turma com o código "%d" não existe.', $codTurma) | |
217 | + ); | |
124 | 218 | } |
125 | 219 | |
126 | - return $series; | |
220 | + return $turma; | |
127 | 221 | } |
128 | 222 | |
129 | 223 | /** |
130 | - * Retorna as turmas de uma escola. | |
131 | - * @param int $escola | |
224 | + * Retorna as turmas de uma escola, selecionando opcionalmente pelo código da série. | |
225 | + * @param int $escolaId | |
226 | + * @param int $serieId | |
132 | 227 | * @return array (cod_turma => nm_turma) |
133 | 228 | */ |
134 | - public static function getTurmas($escola) | |
229 | + public static function getTurmas($escolaId, $serieId = NULL) | |
135 | 230 | { |
136 | 231 | $turma = self::addClassToStorage('clsPmieducarTurma', NULL, |
137 | 232 | 'include/pmieducar/clsPmieducarTurma.inc.php'); |
138 | 233 | |
139 | 234 | // Carrega as turmas da escola |
140 | 235 | $turma->setOrderBy('nm_turma ASC'); |
141 | - $turmas = $turma->lista(NULL, NULL, NULL, NULL, $escola); | |
236 | + $turmas = $turma->lista(NULL, NULL, NULL, $serieId, $escolaId); | |
142 | 237 | |
143 | 238 | $ret = array(); |
144 | 239 | foreach ($turmas as $turma) { |
... | ... | @@ -190,13 +285,14 @@ class App_Model_IedFinder extends CoreExt_Entity |
190 | 285 | |
191 | 286 | // Pela restrição na criação de anos letivos, eu posso confiar no primeiro |
192 | 287 | // e único resultado que deve ter retornado |
193 | - if (FALSE !== $anosEmAndamento && 1 == count($anosEmAndamento)) { | |
194 | - $ano = array_shift($anosEmAndamento); | |
195 | - $ano = $ano['ano']; | |
196 | - } | |
197 | - else { | |
198 | - throw new App_Model_Exception('Existem vários anos escolares em andamento.'); | |
199 | - } | |
288 | + if (FALSE == $anosEmAndamento || count($anosEmAndamento) < 1) | |
289 | + throw new App_Model_Exception('Não foi encontrado um ano escolar em andamento.'); | |
290 | + | |
291 | + elseif (count($anosEmAndamento) > 1) | |
292 | + throw new App_Model_Exception('Existe mais de um ano escolar em andamento.'); | |
293 | + | |
294 | + $ano = array_shift($anosEmAndamento); | |
295 | + $ano = $ano['ano']; | |
200 | 296 | |
201 | 297 | $anoLetivoModulo = self::addClassToStorage('clsPmieducarAnoLetivoModulo', |
202 | 298 | NULL, 'include/pmieducar/clsPmieducarAnoLetivoModulo.inc.php'); |
... | ... | @@ -250,13 +346,14 @@ class App_Model_IedFinder extends CoreExt_Entity |
250 | 346 | * atribuídos ao ano escolar/série da escola. |
251 | 347 | */ |
252 | 348 | public static function getEscolaSerieDisciplina($anoEscolar, $escola, |
253 | - ComponenteCurricular_Model_ComponenteDataMapper $mapper = NULL) | |
349 | + ComponenteCurricular_Model_ComponenteDataMapper $mapper = NULL, | |
350 | + $disciplinaId = null) | |
254 | 351 | { |
255 | 352 | // Disciplinas na série na escola |
256 | 353 | $escolaSerieDisciplina = self::addClassToStorage('clsPmieducarEscolaSerieDisciplina', |
257 | 354 | NULL, 'include/pmieducar/clsPmieducarEscolaSerieDisciplina.inc.php'); |
258 | 355 | |
259 | - $disciplinas = $escolaSerieDisciplina->lista($anoEscolar, $escola, NULL, 1); | |
356 | + $disciplinas = $escolaSerieDisciplina->lista($anoEscolar, $escola, $disciplinaId, 1); | |
260 | 357 | |
261 | 358 | if (FALSE === $disciplinas) { |
262 | 359 | throw new App_Model_Exception(sprintf( |
... | ... | @@ -294,18 +391,24 @@ class App_Model_IedFinder extends CoreExt_Entity |
294 | 391 | */ |
295 | 392 | public static function getComponentesTurma($anoEscolar, $escola, $turma, |
296 | 393 | ComponenteCurricular_Model_TurmaDataMapper $mapper = NULL, |
297 | - ComponenteCurricular_Model_ComponenteDataMapper $componenteMapper = NULL) | |
394 | + ComponenteCurricular_Model_ComponenteDataMapper $componenteMapper = NULL, | |
395 | + $componenteCurricularId = null) | |
298 | 396 | { |
299 | 397 | if (is_null($mapper)) { |
300 | 398 | require_once 'ComponenteCurricular/Model/TurmaDataMapper.php'; |
301 | 399 | $mapper = new ComponenteCurricular_Model_TurmaDataMapper(); |
302 | 400 | } |
303 | 401 | |
304 | - $componentesTurma = $mapper->findAll(array(), array('turma' => $turma)); | |
402 | + $where = array('turma' => $turma); | |
403 | + | |
404 | + if (is_numeric($componenteCurricularId)) | |
405 | + $where['componente_curricular_id'] = $componenteCurricularId; | |
406 | + | |
407 | + $componentesTurma = $mapper->findAll(array(), $where); | |
305 | 408 | |
306 | 409 | // Não existem componentes específicos para a turma |
307 | 410 | if (0 == count($componentesTurma)) { |
308 | - return self::getEscolaSerieDisciplina($anoEscolar, $escola, $componenteMapper); | |
411 | + return self::getEscolaSerieDisciplina($anoEscolar, $escola, $componenteMapper, $componenteCurricularId); | |
309 | 412 | } |
310 | 413 | |
311 | 414 | $componentes = array(); |
... | ... | @@ -412,6 +515,7 @@ class App_Model_IedFinder extends CoreExt_Entity |
412 | 515 | $matricula['curso_carga_horaria'] = $curso['carga_horaria']; |
413 | 516 | $matricula['curso_hora_falta'] = $curso['hora_falta']; |
414 | 517 | $matricula['serie_carga_horaria'] = $serie['carga_horaria']; |
518 | + $matricula['serie_dias_letivos'] = $serie['dias_letivos']; | |
415 | 519 | |
416 | 520 | $matricula['curso_nome'] = isset($curso['nm_curso']) ? $curso['nm_curso'] : NULL; |
417 | 521 | $matricula['serie_nome'] = isset($serie['nm_serie']) ? $serie['nm_serie'] : NULL; |
... | ... | @@ -458,7 +562,8 @@ class App_Model_IedFinder extends CoreExt_Entity |
458 | 562 | */ |
459 | 563 | public static function getComponentesPorMatricula($codMatricula, |
460 | 564 | ComponenteCurricular_Model_ComponenteDataMapper $componenteMapper = NULL, |
461 | - ComponenteCurricular_Model_TurmaDataMapper $turmaMapper = NULL) | |
565 | + ComponenteCurricular_Model_TurmaDataMapper $turmaMapper = NULL, | |
566 | + $componenteCurricularId = null) | |
462 | 567 | { |
463 | 568 | $matricula = self::getMatricula($codMatricula); |
464 | 569 | |
... | ... | @@ -470,7 +575,7 @@ class App_Model_IedFinder extends CoreExt_Entity |
470 | 575 | |
471 | 576 | // Disciplinas da escola na série em que o aluno está matriculado |
472 | 577 | $componentes = self::getComponentesTurma( |
473 | - $codSerie, $codEscola, $turma, $turmaMapper, $componenteMapper | |
578 | + $codSerie, $codEscola, $turma, $turmaMapper, $componenteMapper, $componenteCurricularId | |
474 | 579 | ); |
475 | 580 | |
476 | 581 | // Dispensas do aluno |
... | ... | @@ -541,10 +646,155 @@ class App_Model_IedFinder extends CoreExt_Entity |
541 | 646 | } |
542 | 647 | |
543 | 648 | /** |
649 | + * Retorna um array com as informações de biblioteca a partir de seu código. | |
650 | + * @param int $id | |
651 | + * @return array | |
652 | + */ | |
653 | + public static function getBiblioteca($id) | |
654 | + { | |
655 | + $biblioteca = self::addClassToStorage('clsPmieducarBiblioteca', NULL, | |
656 | + 'include/pmieducar/clsPmieducarBiblioteca.inc.php'); | |
657 | + $biblioteca->cod_biblioteca = $id; | |
658 | + $biblioteca = $biblioteca->detalhe(); | |
659 | + | |
660 | + if (FALSE === $biblioteca) { | |
661 | + throw new App_Model_Exception( | |
662 | + sprintf('Biblioteca com o código "%d" não existe.', $id) | |
663 | + ); | |
664 | + } | |
665 | + | |
666 | + return $biblioteca; | |
667 | + } | |
668 | + | |
669 | + /** | |
670 | + * Retorna todas as bibliotecas cadastradas na tabela pmieducar.biblioteca, selecionando | |
671 | + * opcionalmente pelo código da instituição e/ ou escola. | |
672 | + * @param int $instituicaoId | |
673 | + * @return array | |
674 | + */ | |
675 | + public static function getBibliotecas($instituicaoId = NULL, $escolaId = NULL) | |
676 | + { | |
677 | + $_bibliotecas = self::addClassToStorage('clsPmieducarBiblioteca', NULL, | |
678 | + 'include/pmieducar/clsPmieducarBiblioteca.inc.php'); | |
679 | + | |
680 | + $bibliotecas = array(); | |
681 | + foreach ($_bibliotecas->lista(NULL, $instituicaoId, $escolaId) as $biblioteca) { | |
682 | + $bibliotecas[$biblioteca['cod_biblioteca']] = $biblioteca['nm_biblioteca']; | |
683 | + } | |
684 | + | |
685 | + return $bibliotecas; | |
686 | + } | |
687 | + | |
688 | + /** | |
689 | + * Retorna todas as situações cadastradas para as bibliotecas na tabela pmieducar.situacao, selecionando | |
690 | + * opcionalmente pelo código da biblioteca. | |
691 | + * @param int $bibliotecaId | |
692 | + * @return array | |
693 | + */ | |
694 | + public static function getBibliotecaSituacoes($bibliotecaId = NULL) | |
695 | + { | |
696 | + $_situacoes = self::addClassToStorage('clsPmieducarSituacao', NULL, | |
697 | + 'include/pmieducar/clsPmieducarSituacao.inc.php'); | |
698 | + | |
699 | + $situacoes = array(); | |
700 | + foreach ($_situacoes->lista(null, null, null, null, null, null, null, null, null, null, null, null, null, $bibliotecaId) as $situacao) { | |
701 | + $situacoes[$situacao['cod_situacao']] = $situacao['nm_situacao']; | |
702 | + } | |
703 | + | |
704 | + return $situacoes; | |
705 | + } | |
706 | + | |
707 | + /** | |
708 | + * Retorna todas as fontes cadastradas para as bibliotecas na tabela pmieducar.fonte, selecionando | |
709 | + * opcionalmente pelo código da biblioteca. | |
710 | + * @param int $bibliotecaId | |
711 | + * @return array | |
712 | + */ | |
713 | + public static function getBibliotecaFontes($bibliotecaId = NULL) | |
714 | + { | |
715 | + $_fontes = self::addClassToStorage('clsPmieducarFonte', NULL, | |
716 | + 'include/pmieducar/clsPmieducarFonte.inc.php'); | |
717 | + | |
718 | + $fontes = array(); | |
719 | + foreach ($_fontes->lista(null,null,null,null,null,null,null,null,null,1, $bibliotecaId) as $fonte) { | |
720 | + $fontes[$fonte['cod_fonte']] = $fonte['nm_fonte']; | |
721 | + } | |
722 | + | |
723 | + return $fontes; | |
724 | + } | |
725 | + | |
726 | + /** | |
727 | + * Retorna uma obra cadastrada para uma biblioteca na tabela pmieducar.acervo, selecionando | |
728 | + * obrigatóriamente pelo código da biblioteca e opcionalmente pelo código da obra. | |
729 | + * @param int $bibliotecaId | |
730 | + * @return array | |
731 | + */ | |
732 | + public static function getBibliotecaObra($bibliotecaId, $id = NULL) | |
733 | + { | |
734 | + $obra = self::addClassToStorage('clsPmieducarAcervo', NULL, | |
735 | + 'include/pmieducar/clsPmieducarAcervo.inc.php'); | |
736 | + | |
737 | + $obra->ref_cod_biblioteca = $$bibliotecaId; | |
738 | + $obra->cod_acervo = $id; | |
739 | + $obra = $obra->detalhe(); | |
740 | + | |
741 | + if (FALSE === $obra) { | |
742 | + throw new App_Model_Exception( | |
743 | + sprintf('Obra com o código "%d" não existe.', $id) | |
744 | + ); | |
745 | + } | |
746 | + | |
747 | + return $obra; | |
748 | + } | |
749 | + | |
750 | + /** | |
751 | + * Retorna um aluno cadastrado para uma escola na tabela pmieducar.aluno, selecionando | |
752 | + * obrigatóriamente pelo código da escola e opcionalmente pelo código do aluno. | |
753 | + * @param int $id | |
754 | + * @return array | |
755 | + */ | |
756 | + public static function getAluno($escolaId, $id) | |
757 | + { | |
758 | + $aluno = self::addClassToStorage('clsPmieducarAluno', NULL, | |
759 | + 'include/pmieducar/clsPmieducarAluno.inc.php'); | |
760 | + #$aluno->cod_aluno = $id; | |
761 | + #$aluno = $aluno->detalhe(); | |
762 | + | |
763 | + $aluno = $aluno->lista($id, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, $escolaId); | |
764 | + | |
765 | + if (FALSE === $aluno) { | |
766 | + throw new App_Model_Exception( | |
767 | + sprintf('Aluno com o código "%d" não existe.', $id) | |
768 | + ); | |
769 | + } | |
770 | + | |
771 | + return $aluno[0]; | |
772 | + } | |
773 | + | |
774 | + /** | |
775 | + * Retorna todos os tipos de cliente cadastrados para determinada biblioteca na tabela | |
776 | + * pmieducar.cliente_tipo, selecionando obrigatoriamente pelo código da biblioteca. | |
777 | + * @param int $bibliotecaId | |
778 | + * @return array | |
779 | + */ | |
780 | + public static function getBibliotecaTiposCliente($bibliotecaId) | |
781 | + { | |
782 | + $resources = self::addClassToStorage('clsPmieducarClienteTipo', NULL, | |
783 | + 'include/pmieducar/clsPmieducarClienteTipo.inc.php'); | |
784 | + | |
785 | + $filtered_resources = array(); | |
786 | + foreach ($resources->lista(null, $bibliotecaId) as $resource) { | |
787 | + $filtered_resources[$resource['cod_cliente_tipo']] = $resource['nm_tipo']; | |
788 | + } | |
789 | + | |
790 | + return $filtered_resources; | |
791 | + } | |
792 | + | |
793 | + /** | |
544 | 794 | * @see CoreExt_Entity_Validatable#getDefaultValidatorCollection() |
545 | 795 | */ |
546 | 796 | public function getDefaultValidatorCollection() |
547 | 797 | { |
548 | 798 | return array(); |
549 | 799 | } |
550 | -} | |
551 | 800 | \ No newline at end of file |
801 | +} | ... | ... |