Commit ab29fb0bc3a088c4cdcd684e1f3aaa3ef1ddf555
1 parent
2ffa8db7
Exists in
master
Adicionado controllers APIs json
Showing
10 changed files
with
1684 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,774 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'include/pmieducar/clsPmieducarAluno.inc.php'; | |
36 | + | |
37 | +require_once 'App/Model/MatriculaSituacao.php'; | |
38 | + | |
39 | +require_once 'Portabilis/Controller/ApiCoreController.php'; | |
40 | +require_once 'Portabilis/Array/Utils.php'; | |
41 | +require_once 'Portabilis/String/Utils.php'; | |
42 | +require_once 'Portabilis/Array/Utils.php'; | |
43 | +require_once 'Portabilis/Date/Utils.php'; | |
44 | + | |
45 | +require_once 'Transporte/Model/Responsavel.php'; | |
46 | + | |
47 | +class AlunoController extends ApiCoreController | |
48 | +{ | |
49 | + protected $_processoAp = 578; | |
50 | + protected $_nivelAcessoOption = App_Model_NivelAcesso::SOMENTE_ESCOLA; | |
51 | + | |
52 | + | |
53 | + // validators | |
54 | + | |
55 | + protected function validatesPessoaId() { | |
56 | + $existenceOptions = array('schema_name' => 'cadastro', 'field_name' => 'idpes'); | |
57 | + | |
58 | + return $this->validatesPresenceOf('pessoa_id') && | |
59 | + $this->validatesExistenceOf('fisica', $this->getRequest()->pessoa_id, $existenceOptions); | |
60 | + } | |
61 | + | |
62 | + | |
63 | + protected function validatesReligiaoId() { | |
64 | + $isValid = true; | |
65 | + | |
66 | + // beneficio is optional | |
67 | + if (is_numeric($this->getRequest()->religiao_id)) { | |
68 | + $isValid = $this->validatesPresenceOf('religiao_id') && | |
69 | + $this->validatesExistenceOf('religiao', $this->getRequest()->religiao_id); | |
70 | + } | |
71 | + | |
72 | + return $isValid; | |
73 | + } | |
74 | + | |
75 | + | |
76 | + protected function validatesBeneficioId() { | |
77 | + $isValid = true; | |
78 | + | |
79 | + // beneficio is optional | |
80 | + if (is_numeric($this->getRequest()->beneficio_id)) { | |
81 | + $isValid = $this->validatesPresenceOf('beneficio_id') && | |
82 | + $this->validatesExistenceOf('aluno_beneficio', $this->getRequest()->beneficio_id); | |
83 | + } | |
84 | + | |
85 | + return $isValid; | |
86 | + } | |
87 | + | |
88 | + | |
89 | + protected function validatesResponsavelId() { | |
90 | + $isValid = true; | |
91 | + | |
92 | + if ($this->getRequest()->tipo_responsavel == 'outra_pessoa') { | |
93 | + $existenceOptions = array('schema_name' => 'cadastro', 'field_name' => 'idpes'); | |
94 | + | |
95 | + $isValid = $this->validatesPresenceOf('responsavel_id') && | |
96 | + $this->validatesExistenceOf('fisica', $this->getRequest()->responsavel_id, $existenceOptions); | |
97 | + } | |
98 | + | |
99 | + return $isValid; | |
100 | + } | |
101 | + | |
102 | + | |
103 | + protected function validatesResponsavelTipo() { | |
104 | + $expectedValues = array('mae', 'pai', 'outra_pessoa'); | |
105 | + | |
106 | + return $this->validatesPresenceOf('tipo_responsavel') && | |
107 | + $this->validator->validatesValueInSetOf($this->getRequest()->tipo_responsavel, | |
108 | + $expectedValues, 'tipo_responsavel'); | |
109 | + } | |
110 | + | |
111 | + | |
112 | + protected function validatesResponsavel() { | |
113 | + return $this->validatesResponsavelTipo() && | |
114 | + $this->validatesResponsavelId(); | |
115 | + } | |
116 | + | |
117 | + | |
118 | + protected function validatesTransporte() { | |
119 | + $expectedValues = array('nenhum', 'municipal', 'estadual'); | |
120 | + | |
121 | + return $this->validatesPresenceOf('tipo_transporte') && | |
122 | + $this->validator->validatesValueInSetOf($this->getRequest()->tipo_transporte, | |
123 | + $expectedValues, 'tipo_transporte'); | |
124 | + } | |
125 | + | |
126 | + | |
127 | + protected function validatesUniquenessOfAlunoByPessoaId() { | |
128 | + $existenceOptions = array('schema_name' => 'pmieducar', 'field_name' => 'ref_idpes', 'add_msg_on_error' => false); | |
129 | + | |
130 | + if( ! $this->validatesUniquenessOf('aluno', $this->getRequest()->pessoa_id, $existenceOptions)) { | |
131 | + $this->messenger->append("Já existe um aluno cadastrado para a pessoa {$this->getRequest()->pessoa_id}."); | |
132 | + return false; | |
133 | + } | |
134 | + | |
135 | + return true; | |
136 | + } | |
137 | + | |
138 | + | |
139 | + protected function validatesUniquenessOfAlunoInepId() { | |
140 | + if ($this->getRequest()->aluno_inep_id) { | |
141 | + $where = array('alunoInep' => '$1'); | |
142 | + $params = array($this->getRequest()->aluno_inep_id); | |
143 | + | |
144 | + if ($this->getRequest()->id) { | |
145 | + $where['aluno'] = '!= $2'; | |
146 | + $params[] = $this->getRequest()->id; | |
147 | + } | |
148 | + | |
149 | + $dataMapper = $this->getDataMapperFor('educacenso', 'aluno'); | |
150 | + $entity = $dataMapper->findAllUsingPreparedQuery(array('aluno'), $where, $params, array(), false); | |
151 | + | |
152 | + if (count($entity) && $entity[0]->get('aluno')) { | |
153 | + $this->messenger->append("Já existe o aluno {$entity[0]->get('aluno')} cadastrado com código inep ". | |
154 | + "{$this->getRequest()->aluno_inep_id}."); | |
155 | + | |
156 | + return false; | |
157 | + } | |
158 | + } | |
159 | + | |
160 | + return true; | |
161 | + } | |
162 | + | |
163 | + | |
164 | + protected function validatesUniquenessOfAlunoEstadoId() { | |
165 | + if ($this->getRequest()->aluno_estado_id) { | |
166 | + $sql = "select cod_aluno from pmieducar.aluno where aluno_estado_id = $1"; | |
167 | + $params = array($this->getRequest()->aluno_estado_id); | |
168 | + | |
169 | + if($this->getRequest()->id) { | |
170 | + $sql .= " and cod_aluno != $2"; | |
171 | + $params[] = $this->getRequest()->id; | |
172 | + } | |
173 | + | |
174 | + $alunoId = $this->fetchPreparedQuery($sql, $params, true, 'first-field'); | |
175 | + | |
176 | + if ($alunoId) { | |
177 | + $this->messenger->append("Já existe o aluno $alunoId cadastrado com código estado ". | |
178 | + "{$this->getRequest()->aluno_estado_id}."); | |
179 | + | |
180 | + return false; | |
181 | + } | |
182 | + } | |
183 | + | |
184 | + return true; | |
185 | + } | |
186 | + | |
187 | + // validations | |
188 | + | |
189 | + protected function canGetMatriculas() { | |
190 | + return $this->validatesId('aluno'); | |
191 | + } | |
192 | + | |
193 | + protected function canChange() { | |
194 | + return $this->validatesPessoaId() && | |
195 | + $this->validatesResponsavel() && | |
196 | + $this->validatesTransporte() && | |
197 | + $this->validatesReligiaoId() && | |
198 | + $this->validatesBeneficioId() && | |
199 | + $this->validatesUniquenessOfAlunoInepId() && | |
200 | + $this->validatesUniquenessOfAlunoEstadoId(); | |
201 | + } | |
202 | + | |
203 | + protected function canPost() { | |
204 | + return parent::canPost() && | |
205 | + $this->validatesUniquenessOfAlunoByPessoaId(); | |
206 | + } | |
207 | + | |
208 | + | |
209 | + protected function canGetOcorrenciasDisciplinares() { | |
210 | + return $this->validatesId('escola') && | |
211 | + $this->validatesId('aluno'); | |
212 | + } | |
213 | + | |
214 | + // load resources | |
215 | + | |
216 | + protected function loadNomeAluno($alunoId) { | |
217 | + $sql = "select nome from cadastro.pessoa, pmieducar.aluno where idpes = ref_idpes and cod_aluno = $1"; | |
218 | + $nome = $this->fetchPreparedQuery($sql, $alunoId, false, 'first-field'); | |
219 | + | |
220 | + return $this->toUtf8($nome, array('transform' => true)); | |
221 | + } | |
222 | + | |
223 | + | |
224 | + protected function loadTransporte($alunoId) { | |
225 | + | |
226 | + $tiposTransporte = array( | |
227 | + Transporte_Model_Responsavel::NENHUM => 'nenhum', | |
228 | + Transporte_Model_Responsavel::MUNICIPAL => 'municipal', | |
229 | + Transporte_Model_Responsavel::ESTADUAL =>'estadual' | |
230 | + ); | |
231 | + | |
232 | + $dataMapper = $this->getDataMapperFor('transporte', 'aluno'); | |
233 | + $entity = $this->tryGetEntityOf($dataMapper, $alunoId); | |
234 | + | |
235 | + // no antigo cadastro de alunos era considerado como não utiliza transporte, | |
236 | + // quando não existia dados, para o novo cadastro foi adicionado a opcao 0 (nenhum), | |
237 | + // então por compatibilidade esta API retorna nenhum, quando não foi encontrado dados. | |
238 | + if (is_null($entity)) | |
239 | + $tipo = $tiposTransporte[Transporte_Model_Responsavel::NENHUM]; | |
240 | + else | |
241 | + $tipo = $tiposTransporte[$entity->get('responsavel')]; | |
242 | + | |
243 | + return $tipo; | |
244 | + } | |
245 | + | |
246 | + | |
247 | + protected function createOrUpdateTransporte($alunoId) { | |
248 | + $tiposTransporte = array( | |
249 | + 'nenhum' => Transporte_Model_Responsavel::NENHUM, | |
250 | + 'municipal' => Transporte_Model_Responsavel::MUNICIPAL, | |
251 | + 'estadual' => Transporte_Model_Responsavel::ESTADUAL | |
252 | + ); | |
253 | + | |
254 | + $data = array( | |
255 | + 'aluno' => $alunoId, | |
256 | + 'responsavel' => $tiposTransporte[$this->getRequest()->tipo_transporte], | |
257 | + 'user' => $this->getSession()->id_pessoa, | |
258 | + | |
259 | + // always setting now... | |
260 | + 'created_at' => 'NOW()', | |
261 | + ); | |
262 | + | |
263 | + $dataMapper = $this->getDataMapperFor('transporte', 'aluno'); | |
264 | + $entity = $this->getOrCreateEntityOf($dataMapper, $alunoId); | |
265 | + $entity->setOptions($data); | |
266 | + | |
267 | + return $this->saveEntity($dataMapper, $entity); | |
268 | + } | |
269 | + | |
270 | + | |
271 | + protected function loadAlunoInepId($alunoId) { | |
272 | + $dataMapper = $this->getDataMapperFor('educacenso', 'aluno'); | |
273 | + $entity = $this->tryGetEntityOf($dataMapper, $alunoId); | |
274 | + | |
275 | + return (is_null($entity) ? null : $entity->get('alunoInep')); | |
276 | + } | |
277 | + | |
278 | + | |
279 | + protected function createUpdateOrDestroyEducacensoAluno($alunoId) { | |
280 | + $dataMapper = $this->getDataMapperFor('educacenso', 'aluno'); | |
281 | + | |
282 | + if (empty($this->getRequest()->aluno_inep_id)) | |
283 | + $result = $this->deleteEntityOf($dataMapper, $alunoId); | |
284 | + else { | |
285 | + $data = array( | |
286 | + 'aluno' => $alunoId, | |
287 | + 'alunoInep' => $this->getRequest()->aluno_inep_id, | |
288 | + | |
289 | + // campos deprecados? | |
290 | + 'fonte' => 'fonte', | |
291 | + 'nomeInep' => '-', | |
292 | + | |
293 | + // always setting now... | |
294 | + 'created_at' => 'NOW()', | |
295 | + ); | |
296 | + | |
297 | + $entity = $this->getOrCreateEntityOf($dataMapper, $alunoId); | |
298 | + $entity->setOptions($data); | |
299 | + | |
300 | + $result = $this->saveEntity($dataMapper, $entity); | |
301 | + } | |
302 | + | |
303 | + return $result; | |
304 | + } | |
305 | + | |
306 | + | |
307 | + // #TODO mover updateResponsavel e updateDeficiencias para API pessoa ? | |
308 | + | |
309 | + protected function updateResponsavel() { | |
310 | + $pessoa = new clsFisica(); | |
311 | + $pessoa->idpes = $this->getRequest()->pessoa_id; | |
312 | + $pessoa->nome_responsavel = ''; | |
313 | + | |
314 | + if ($this->getRequest()->tipo_responsavel == 'outra_pessoa') | |
315 | + $pessoa->idpes_responsavel = $this->getRequest()->responsavel_id; | |
316 | + else | |
317 | + $pessoa->idpes_responsavel = 'NULL'; | |
318 | + | |
319 | + return $pessoa->edita(); | |
320 | + } | |
321 | + | |
322 | + | |
323 | + protected function updateDeficiencias() { | |
324 | + $sql = "delete from cadastro.fisica_deficiencia where ref_idpes = $1"; | |
325 | + $this->fetchPreparedQuery($sql, $this->getRequest()->pessoa_id, false); | |
326 | + | |
327 | + foreach ($this->getRequest()->deficiencias as $id) { | |
328 | + if (! empty($id)) { | |
329 | + $deficiencia = new clsCadastroFisicaDeficiencia($this->getRequest()->pessoa_id, $id); | |
330 | + $deficiencia->cadastra(); | |
331 | + } | |
332 | + } | |
333 | + } | |
334 | + | |
335 | + | |
336 | + protected function createOrUpdateAluno($id = null){ | |
337 | + $tiposResponsavel = array('pai' => 'p', 'mae' => 'm', 'outra_pessoa' => 'r'); | |
338 | + | |
339 | + $aluno = new clsPmieducarAluno(); | |
340 | + $aluno->cod_aluno = $id; | |
341 | + $aluno->aluno_estado_id = $this->getRequest()->aluno_estado_id; | |
342 | + | |
343 | + // após cadastro não muda mais id pessoa | |
344 | + if (is_null($id)) | |
345 | + $aluno->ref_idpes = $this->getRequest()->pessoa_id; | |
346 | + | |
347 | + $aluno->ref_cod_aluno_beneficio = $this->getRequest()->beneficio_id; | |
348 | + $aluno->ref_cod_religiao = $this->getRequest()->religiao_id; | |
349 | + $aluno->analfabeto = $this->getRequest()->alfabetizado ? 0 : 1; | |
350 | + $aluno->tipo_responsavel = $tiposResponsavel[$this->getRequest()->tipo_responsavel]; | |
351 | + $aluno->ref_usuario_exc = $this->getSession()->id_pessoa; | |
352 | + | |
353 | + return (is_null($id) ? $aluno->cadastra() : $aluno->edita()); | |
354 | + } | |
355 | + | |
356 | + protected function loadTurmaByMatriculaId($matriculaId) { | |
357 | + $sql = 'select ref_cod_turma as id, turma.nm_turma as nome from pmieducar.matricula_turma, | |
358 | + pmieducar.turma where ref_cod_matricula = $1 and matricula_turma.ativo = 1 and | |
359 | + turma.cod_turma = ref_cod_turma limit 1'; | |
360 | + | |
361 | + $turma = Portabilis_Utils_Database::selectRow($sql, $matriculaId); | |
362 | + $turma['nome'] = $this->toUtf8($turma['nome'], array('transform' => true)); | |
363 | + | |
364 | + return $turma; | |
365 | + } | |
366 | + | |
367 | + protected function loadEscolaNome($id) { | |
368 | + $escola = new clsPmieducarEscola(); | |
369 | + $escola->cod_escola = $id; | |
370 | + $escola = $escola->detalhe(); | |
371 | + | |
372 | + return $this->toUtf8($escola['nome'], array('transform' => true)); | |
373 | + } | |
374 | + | |
375 | + protected function loadCursoNome($id) { | |
376 | + $curso = new clsPmieducarCurso(); | |
377 | + $curso->cod_curso = $id; | |
378 | + $curso = $curso->detalhe(); | |
379 | + | |
380 | + return $this->toUtf8($curso['nm_curso'], array('transform' => true)); | |
381 | + } | |
382 | + | |
383 | + protected function loadSerieNome($id) { | |
384 | + $serie = new clsPmieducarSerie(); | |
385 | + $serie->cod_serie = $id; | |
386 | + $serie = $serie->detalhe(); | |
387 | + | |
388 | + return $this->toUtf8($serie['nm_serie'], array('transform' => true)); | |
389 | + } | |
390 | + | |
391 | + protected function loadTransferenciaDataEntrada($matriculaId) { | |
392 | + $sql = "select to_char(data_transferencia, 'DD/MM/YYYY') from | |
393 | + pmieducar.transferencia_solicitacao where ref_cod_matricula_entrada = $1 and ativo = 1"; | |
394 | + | |
395 | + return Portabilis_Utils_Database::selectField($sql, $matriculaId); | |
396 | + } | |
397 | + | |
398 | + protected function loadTransferenciaDataSaida($matriculaId) { | |
399 | + $sql = "select to_char(data_transferencia, 'DD/MM/YYYY') from | |
400 | + pmieducar.transferencia_solicitacao where ref_cod_matricula_saida = $1 and ativo = 1"; | |
401 | + | |
402 | + return Portabilis_Utils_Database::selectField($sql, $matriculaId); | |
403 | + } | |
404 | + | |
405 | + protected function possuiTransferenciaEmAberto($matriculaId) { | |
406 | + $sql = "select count(cod_transferencia_solicitacao) from pmieducar.transferencia_solicitacao where | |
407 | + ativo = 1 and ref_cod_matricula_saida = $1 and ref_cod_matricula_entrada is null and | |
408 | + data_transferencia is null"; | |
409 | + | |
410 | + return (Portabilis_Utils_Database::selectField($sql, $matriculaId) > 0); | |
411 | + } | |
412 | + | |
413 | + protected function loadTipoOcorrenciaDisciplinar($id) { | |
414 | + if (! isset($this->_tiposOcorrenciasDisciplinares)) | |
415 | + $this->_tiposOcorrenciasDisciplinares = array(); | |
416 | + | |
417 | + if (! isset($this->_tiposOcorrenciasDisciplinares[$id])) { | |
418 | + $ocorrencia = new clsPmieducarTipoOcorrenciaDisciplinar; | |
419 | + $ocorrencia->cod_tipo_ocorrencia_disciplinar = $id; | |
420 | + $ocorrencia = $ocorrencia->detalhe(); | |
421 | + | |
422 | + $this->_tiposOcorrenciasDisciplinares[$id] = $this->toUtf8( | |
423 | + $ocorrencia['nm_tipo'], | |
424 | + array('transform' => true) | |
425 | + ); | |
426 | + | |
427 | + } | |
428 | + | |
429 | + return $this->_tiposOcorrenciasDisciplinares[$id]; | |
430 | + } | |
431 | + | |
432 | + | |
433 | + protected function loadOcorrenciasDisciplinares() { | |
434 | + $ocorrenciasAluno = array(); | |
435 | + | |
436 | + $sql = "select cod_matricula as id from pmieducar.matricula, pmieducar.escola where | |
437 | + cod_escola = ref_ref_cod_escola and ref_cod_aluno = $1 and ref_ref_cod_escola = | |
438 | + $2 and matricula.ativo = 1 order by ano desc, id"; | |
439 | + | |
440 | + $params = array($this->getRequest()->aluno_id, $this->getRequest()->escola_id); | |
441 | + $matriculas = $this->fetchPreparedQuery($sql, $params); | |
442 | + | |
443 | + $_ocorrenciasMatricula = new clsPmieducarMatriculaOcorrenciaDisciplinar(); | |
444 | + | |
445 | + foreach($matriculas as $matricula) { | |
446 | + $ocorrenciasMatricula = $_ocorrenciasMatricula->lista($matricula['id'], | |
447 | + null, | |
448 | + null, | |
449 | + null, | |
450 | + null, | |
451 | + null, | |
452 | + null, | |
453 | + null, | |
454 | + null, | |
455 | + null, | |
456 | + 1, | |
457 | + $visivel_pais = 1); | |
458 | + | |
459 | + if (is_array($ocorrenciasMatricula)) { | |
460 | + $attrsFilter = array('ref_cod_tipo_ocorrencia_disciplinar' => 'tipo', | |
461 | + 'data_cadastro' => 'data_hora', | |
462 | + 'observacao' => 'descricao'); | |
463 | + | |
464 | + $ocorrenciasMatricula = Portabilis_Array_Utils::filterSet($ocorrenciasMatricula, $attrsFilter); | |
465 | + | |
466 | + foreach($ocorrenciasMatricula as $ocorrenciaMatricula) { | |
467 | + $ocorrenciaMatricula['tipo'] = $this->loadTipoOcorrenciaDisciplinar($ocorrenciaMatricula['tipo']); | |
468 | + $ocorrenciaMatricula['data_hora'] = Portabilis_Date_Utils::pgSQLToBr($ocorrenciaMatricula['data_hora']); | |
469 | + $ocorrenciaMatricula['descricao'] = $this->toUtf8($ocorrenciaMatricula['descricao']); | |
470 | + $ocorrenciasAluno[] = $ocorrenciaMatricula; | |
471 | + } | |
472 | + } | |
473 | + } | |
474 | + | |
475 | + return array('ocorrencias_disciplinares' => $ocorrenciasAluno); | |
476 | + } | |
477 | + | |
478 | + // search options | |
479 | + | |
480 | + protected function searchOptions() { | |
481 | + return array('sqlParams' => array($this->getRequest()->escola_id), | |
482 | + 'selectFields' => array('matricula_id')); | |
483 | + } | |
484 | + | |
485 | + protected function sqlsForNumericSearch() { | |
486 | + $sqls = array(); | |
487 | + | |
488 | + // caso nao receba id da escola, pesquisa por codigo aluno em todas as escolas | |
489 | + if (! $this->getRequest()->escola_id) { | |
490 | + $sqls[] = "select distinct aluno.cod_aluno as id, pessoa.nome as name from | |
491 | + pmieducar.aluno, cadastro.pessoa where pessoa.idpes = aluno.ref_idpes | |
492 | + and aluno.ativo = 1 and aluno.cod_aluno like $1||'%' and $2 = $2 order by cod_aluno limit 15"; | |
493 | + } | |
494 | + | |
495 | + // seleciona por (codigo matricula ou codigo aluno) e/ou codigo escola | |
496 | + $sqls[] = "select * from (select distinct ON (aluno.cod_aluno) aluno.cod_aluno as id, | |
497 | + matricula.cod_matricula as matricula_id, pessoa.nome as name from pmieducar.matricula, | |
498 | + pmieducar.aluno, cadastro.pessoa where aluno.cod_aluno = matricula.ref_cod_aluno and | |
499 | + pessoa.idpes = aluno.ref_idpes and aluno.ativo = matricula.ativo and | |
500 | + matricula.ativo = 1 and | |
501 | + (select case when $2 != 0 then matricula.ref_ref_cod_escola = $2 else 1=1 end) and | |
502 | + (matricula.cod_matricula like $1||'%' or matricula.ref_cod_aluno like $1||'%') and | |
503 | + matricula.aprovado in (1, 2, 3, 7, 8, 9) limit 15) as alunos order by id"; | |
504 | + | |
505 | + return $sqls; | |
506 | + } | |
507 | + | |
508 | + | |
509 | + protected function sqlsForStringSearch() { | |
510 | + $sqls = array(); | |
511 | + | |
512 | + // caso nao receba id da escola, pesquisa por codigo aluno em todas as escolas | |
513 | + if (! $this->getRequest()->escola_id) { | |
514 | + $sqls[] = "select distinct aluno.cod_aluno as id, | |
515 | + pessoa.nome as name from pmieducar.aluno, cadastro.pessoa where | |
516 | + pessoa.idpes = aluno.ref_idpes and aluno.ativo = 1 and | |
517 | + lower(to_ascii(pessoa.nome)) like lower(to_ascii($1))||'%' and $2 = $2 | |
518 | + order by nome limit 15"; | |
519 | + } | |
520 | + | |
521 | + // seleciona por nome aluno e/ou codigo escola | |
522 | + $sqls[] = "select * from(select distinct ON (aluno.cod_aluno) aluno.cod_aluno as id, | |
523 | + matricula.cod_matricula as matricula_id, pessoa.nome as name from pmieducar.matricula, | |
524 | + pmieducar.aluno, cadastro.pessoa where aluno.cod_aluno = matricula.ref_cod_aluno and | |
525 | + pessoa.idpes = aluno.ref_idpes and aluno.ativo = matricula.ativo and | |
526 | + matricula.ativo = 1 and (select case when $2 != 0 then matricula.ref_ref_cod_escola = $2 | |
527 | + else 1=1 end) and | |
528 | + lower(to_ascii(pessoa.nome)) like lower(to_ascii($1))||'%' and matricula.aprovado in | |
529 | + (1, 2, 3, 7, 8, 9) limit 15) as alunos order by name"; | |
530 | + | |
531 | + return $sqls; | |
532 | + } | |
533 | + | |
534 | + // api | |
535 | + | |
536 | + protected function tipoResponsavel($aluno) { | |
537 | + $tipos = array('p' => 'pai', 'm' => 'mae', 'r' => 'outra_pessoa'); | |
538 | + $tipo = $tipos[$aluno['tipo_responsavel']]; | |
539 | + | |
540 | + // no antigo cadastro de aluno, caso não fosse encontrado um tipo de responsavel | |
541 | + // verificava se a pessoa possua responsavel, pai ou mãe, considerando como | |
542 | + // responsavel um destes, na respectiva ordem, sendo assim esta api mantem | |
543 | + // compatibilidade com o antigo cadastro. | |
544 | + if (! $tipo) { | |
545 | + $pessoa = new clsFisica(); | |
546 | + $pessoa->idpes = $aluno['pessoa_id']; | |
547 | + $pessoa = $pessoa->detalhe(); | |
548 | + | |
549 | + if ($pessoa['idpes_responsavel'] || $pessoa['nome_responsavel']) | |
550 | + $tipo = $tipos['r']; | |
551 | + elseif ($pessoa['idpes_pai'] || $pessoa['nome_pai']) | |
552 | + $tipo = $tipos['p']; | |
553 | + elseif ($pessoa['idpes_mae'] || $pessoa['nome_mae']) | |
554 | + $tipo = $tipos['m']; | |
555 | + } | |
556 | + | |
557 | + return $tipo; | |
558 | + } | |
559 | + | |
560 | + protected function get() { | |
561 | + if ($this->canGet()) { | |
562 | + $id = $this->getRequest()->id; | |
563 | + | |
564 | + $aluno = new clsPmieducarAluno(); | |
565 | + $aluno->cod_aluno = $id; | |
566 | + $aluno = $aluno->detalhe(); | |
567 | + | |
568 | + $attrs = array( | |
569 | + 'cod_aluno' => 'id', | |
570 | + 'ref_cod_aluno_beneficio' => 'beneficio_id', | |
571 | + 'ref_cod_religiao' => 'religiao_id', | |
572 | + 'ref_idpes' => 'pessoa_id', | |
573 | + 'tipo_responsavel' => 'tipo_responsavel', | |
574 | + 'ref_usuario_exc' => 'destroyed_by', | |
575 | + 'data_exclusao' => 'destroyed_at', | |
576 | + 'analfabeto', | |
577 | + 'ativo', | |
578 | + 'aluno_estado_id' | |
579 | + ); | |
580 | + | |
581 | + $aluno = Portabilis_Array_Utils::filter($aluno, $attrs); | |
582 | + | |
583 | + $aluno['nome'] = $this->loadNomeAluno($id); | |
584 | + $aluno['tipo_transporte'] = $this->loadTransporte($id); | |
585 | + $aluno['tipo_responsavel'] = $this->tipoResponsavel($aluno); | |
586 | + $aluno['aluno_inep_id'] = $this->loadAlunoInepId($id); | |
587 | + $aluno['ativo'] = $aluno['ativo'] == 1; | |
588 | + | |
589 | + $aluno['alfabetizado'] = $aluno['analfabeto'] == 0; | |
590 | + unset($aluno['analfabeto']); | |
591 | + | |
592 | + // destroyed_by username | |
593 | + $dataMapper = $this->getDataMapperFor('usuario', 'funcionario'); | |
594 | + $entity = $this->tryGetEntityOf($dataMapper, $aluno['destroyed_by']); | |
595 | + $aluno['destroyed_by'] = is_null($entity) ? null : $entity->get('matricula'); | |
596 | + | |
597 | + $aluno['destroyed_at'] = Portabilis_Date_Utils::pgSQLToBr($aluno['destroyed_at']); | |
598 | + | |
599 | + return $aluno; | |
600 | + } | |
601 | + } | |
602 | + | |
603 | + protected function getMatriculas() { | |
604 | + if ($this->canGetMatriculas()) { | |
605 | + $matriculas = new clsPmieducarMatricula(); | |
606 | + $matriculas->setOrderby('ano DESC, ref_ref_cod_serie DESC, cod_matricula DESC, aprovado'); | |
607 | + | |
608 | + $matriculas = $matriculas->lista( | |
609 | + null, | |
610 | + null, | |
611 | + null, | |
612 | + null, | |
613 | + null, | |
614 | + null, | |
615 | + $this->getRequest()->aluno_id, | |
616 | + null, | |
617 | + null, | |
618 | + null, | |
619 | + null, | |
620 | + null, | |
621 | + 1 | |
622 | + ); | |
623 | + | |
624 | + $attrs = array( | |
625 | + 'cod_matricula' => 'id', | |
626 | + 'ref_cod_instituicao' => 'instituicao_id', | |
627 | + 'ref_ref_cod_escola' => 'escola_id', | |
628 | + 'ref_cod_curso' => 'curso_id', | |
629 | + 'ref_ref_cod_serie' => 'serie_id', | |
630 | + 'ref_cod_aluno' => 'aluno_id', | |
631 | + 'nome' => 'aluno_nome', | |
632 | + 'aprovado' => 'situacao', | |
633 | + 'ano' | |
634 | + ); | |
635 | + | |
636 | + $matriculas = Portabilis_Array_Utils::filterSet($matriculas, $attrs); | |
637 | + | |
638 | + foreach ($matriculas as $index => $matricula) { | |
639 | + $turma = $this->loadTurmaByMatriculaId($matricula['id']); | |
640 | + | |
641 | + $matriculas[$index]['aluno_nome'] = $this->toUtf8($matricula['aluno_nome'], array('transform' => true)); | |
642 | + $matriculas[$index]['turma_id'] = $turma['id']; | |
643 | + $matriculas[$index]['turma_nome'] = $turma['nome']; | |
644 | + $matriculas[$index]['escola_nome'] = $this->loadEscolaNome($matricula['escola_id']); | |
645 | + $matriculas[$index]['curso_nome'] = $this->loadCursoNome($matricula['curso_id']); | |
646 | + $matriculas[$index]['serie_nome'] = $this->loadSerieNome($matricula['serie_id']); | |
647 | + | |
648 | + $matriculas[$index]['data_entrada'] = $this->loadTransferenciaDataEntrada($matricula['id']); | |
649 | + $matriculas[$index]['data_saida'] = $this->loadTransferenciaDataSaida($matricula['id']); | |
650 | + | |
651 | + $matriculas[$index]['situacao'] = App_Model_MatriculaSituacao::getInstance()->getValue( | |
652 | + $matricula['situacao'] | |
653 | + ); | |
654 | + | |
655 | + $matriculas[$index]['user_can_access'] = Portabilis_Utils_User::canAccessEscola($matricula['escola_id']); | |
656 | + $matriculas[$index]['transferencia_em_aberto'] = $this->possuiTransferenciaEmAberto($matricula['id']); | |
657 | + } | |
658 | + | |
659 | + return array('matriculas' => $matriculas); | |
660 | + } | |
661 | + } | |
662 | + | |
663 | + protected function getOcorrenciasDisciplinares() { | |
664 | + if ($this->canGetOcorrenciasDisciplinares()) | |
665 | + return $this->loadOcorrenciasDisciplinares(); | |
666 | + } | |
667 | + | |
668 | + protected function post() { | |
669 | + if ($this->canPost()) { | |
670 | + $id = $this->createOrUpdateAluno(); | |
671 | + | |
672 | + if (is_numeric($id)) { | |
673 | + $this->updateResponsavel(); | |
674 | + $this->createOrUpdateTransporte($id); | |
675 | + $this->createUpdateOrDestroyEducacensoAluno($id); | |
676 | + $this->updateDeficiencias(); | |
677 | + | |
678 | + $this->messenger->append('Cadastrado realizado com sucesso', 'success', false, 'error'); | |
679 | + } | |
680 | + else | |
681 | + $this->messenger->append('Aparentemente o aluno não pode ser cadastrado, por favor, verifique.'); | |
682 | + } | |
683 | + | |
684 | + return array('id' => $id); | |
685 | + } | |
686 | + | |
687 | + protected function put() { | |
688 | + $id = $this->getRequest()->id; | |
689 | + | |
690 | + if ($this->canPut() && $this->createOrUpdateAluno($id)) { | |
691 | + $this->updateResponsavel(); | |
692 | + $this->createOrUpdateTransporte($id); | |
693 | + $this->createUpdateOrDestroyEducacensoAluno($id); | |
694 | + $this->updateDeficiencias(); | |
695 | + | |
696 | + $this->messenger->append('Cadastro alterado com sucesso', 'success', false, 'error'); | |
697 | + } | |
698 | + else | |
699 | + $this->messenger->append('Aparentemente o cadastro não pode ser alterado, por favor, verifique.', | |
700 | + 'error', false, 'error'); | |
701 | + | |
702 | + return array('id' => $id); | |
703 | + } | |
704 | + | |
705 | + | |
706 | + protected function enable() { | |
707 | + $id = $this->getRequest()->id; | |
708 | + | |
709 | + if ($this->canEnable()) { | |
710 | + $aluno = new clsPmieducarAluno(); | |
711 | + $aluno->cod_aluno = $id; | |
712 | + $aluno->ref_usuario_exc = $this->getSession()->id_pessoa; | |
713 | + $aluno->ativo = 1; | |
714 | + | |
715 | + if($aluno->edita()) | |
716 | + $this->messenger->append('Cadastro ativado com sucesso', 'success', false, 'error'); | |
717 | + else | |
718 | + $this->messenger->append('Aparentemente o cadastro não pode ser ativado, por favor, verifique.', | |
719 | + 'error', false, 'error'); | |
720 | + } | |
721 | + | |
722 | + return array('id' => $id); | |
723 | + } | |
724 | + | |
725 | + protected function delete() { | |
726 | + $id = $this->getRequest()->id; | |
727 | + | |
728 | + if ($this->canDelete()) { | |
729 | + $aluno = new clsPmieducarAluno(); | |
730 | + $aluno->cod_aluno = $id; | |
731 | + $aluno->ref_usuario_exc = $this->getSession()->id_pessoa; | |
732 | + | |
733 | + if($aluno->excluir()) | |
734 | + $this->messenger->append('Cadastro removido com sucesso', 'success', false, 'error'); | |
735 | + else | |
736 | + $this->messenger->append('Aparentemente o cadastro não pode ser removido, por favor, verifique.', | |
737 | + 'error', false, 'error'); | |
738 | + } | |
739 | + | |
740 | + return array('id' => $id); | |
741 | + } | |
742 | + | |
743 | + | |
744 | + public function Gerar() { | |
745 | + if ($this->isRequestFor('get', 'aluno')) | |
746 | + $this->appendResponse($this->get()); | |
747 | + | |
748 | + elseif ($this->isRequestFor('get', 'aluno-search')) | |
749 | + $this->appendResponse($this->search()); | |
750 | + | |
751 | + elseif ($this->isRequestFor('get', 'matriculas')) | |
752 | + $this->appendResponse($this->getMatriculas()); | |
753 | + | |
754 | + elseif ($this->isRequestFor('get', 'ocorrencias_disciplinares')) | |
755 | + $this->appendResponse($this->getOcorrenciasDisciplinares()); | |
756 | + | |
757 | + // create | |
758 | + elseif ($this->isRequestFor('post', 'aluno')) | |
759 | + $this->appendResponse($this->post()); | |
760 | + | |
761 | + // update | |
762 | + elseif ($this->isRequestFor('put', 'aluno')) | |
763 | + $this->appendResponse($this->put()); | |
764 | + | |
765 | + elseif ($this->isRequestFor('enable', 'aluno')) | |
766 | + $this->appendResponse($this->enable()); | |
767 | + | |
768 | + elseif ($this->isRequestFor('delete', 'aluno')) | |
769 | + $this->appendResponse($this->delete()); | |
770 | + | |
771 | + else | |
772 | + $this->notImplementedOperationError(); | |
773 | + } | |
774 | +} | ... | ... |
ieducar/modules/Api/Views/ComponenteCurricularController.php
0 → 100644
... | ... | @@ -0,0 +1,64 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | +require_once 'lib/Portabilis/Array/Utils.php'; | |
37 | +require_once 'lib/Portabilis/String/Utils.php'; | |
38 | + | |
39 | +class ComponenteCurricularController extends ApiCoreController | |
40 | +{ | |
41 | + // search options | |
42 | + | |
43 | + protected function searchOptions() { | |
44 | + return array('namespace' => 'modules', 'idAttr' => 'id'); | |
45 | + } | |
46 | + | |
47 | + // subescreve para pesquisar %query%, e nao query% como por padrão | |
48 | + protected function sqlsForStringSearch() { | |
49 | + return "select distinct id, nome as name from modules.componente_curricular | |
50 | + where lower(to_ascii(nome)) like '%'||lower(to_ascii($1))||'%' order by nome limit 15"; | |
51 | + } | |
52 | + | |
53 | + // subscreve formatResourceValue para não adicionar 'id -' a frente do resultado | |
54 | + protected function formatResourceValue($resource) { | |
55 | + return $this->toUtf8(mb_strtoupper($resource['name'])); | |
56 | + } | |
57 | + | |
58 | + public function Gerar() { | |
59 | + if ($this->isRequestFor('get', 'componente_curricular-search')) | |
60 | + $this->appendResponse($this->search()); | |
61 | + else | |
62 | + $this->notImplementedOperationError(); | |
63 | + } | |
64 | +} | ... | ... |
... | ... | @@ -0,0 +1,57 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | +require_once 'lib/Portabilis/Array/Utils.php'; | |
37 | +require_once 'lib/Portabilis/String/Utils.php'; | |
38 | + | |
39 | +class DeficienciaController extends ApiCoreController | |
40 | +{ | |
41 | + // search options | |
42 | + | |
43 | + protected function searchOptions() { | |
44 | + return array('namespace' => 'cadastro', 'labelAttr' => 'nm_deficiencia', 'idAttr' => 'cod_deficiencia'); | |
45 | + } | |
46 | + | |
47 | + protected function formatResourceValue($resource) { | |
48 | + return $this->toUtf8($resource['name'], array('transform' => true)); | |
49 | + } | |
50 | + | |
51 | + public function Gerar() { | |
52 | + if ($this->isRequestFor('get', 'deficiencia-search')) | |
53 | + $this->appendResponse($this->search()); | |
54 | + else | |
55 | + $this->notImplementedOperationError(); | |
56 | + } | |
57 | +} | ... | ... |
... | ... | @@ -0,0 +1,118 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | + | |
37 | +class EscolaController extends ApiCoreController | |
38 | +{ | |
39 | + protected $_processoAp = 561; | |
40 | + protected $_nivelAcessoOption = App_Model_NivelAcesso::SOMENTE_ESCOLA; | |
41 | + | |
42 | + | |
43 | + protected function canChange() { | |
44 | + return true; | |
45 | + } | |
46 | + | |
47 | + protected function loadEscolaInepId($escolaId) { | |
48 | + $dataMapper = $this->getDataMapperFor('educacenso', 'escola'); | |
49 | + $entity = $this->tryGetEntityOf($dataMapper, $escolaId); | |
50 | + | |
51 | + return (is_null($entity) ? null : $entity->get('escolaInep')); | |
52 | + } | |
53 | + | |
54 | + | |
55 | + protected function createUpdateOrDestroyEducacensoEscola($escolaId) { | |
56 | + $dataMapper = $this->getDataMapperFor('educacenso', 'escola'); | |
57 | + | |
58 | + if (empty($this->getRequest()->escola_inep_id)) | |
59 | + $result = $this->deleteEntityOf($dataMapper, $escolaId); | |
60 | + else { | |
61 | + $data = array( | |
62 | + 'escola' => $escolaId, | |
63 | + 'escolaInep' => $this->getRequest()->escola_inep_id, | |
64 | + | |
65 | + // campos deprecados? | |
66 | + 'fonte' => 'fonte', | |
67 | + 'nomeInep' => '-', | |
68 | + | |
69 | + // always setting now... | |
70 | + 'created_at' => 'NOW()', | |
71 | + ); | |
72 | + | |
73 | + $entity = $this->getOrCreateEntityOf($dataMapper, $escolaId); | |
74 | + $entity->setOptions($data); | |
75 | + | |
76 | + $result = $this->saveEntity($dataMapper, $entity); | |
77 | + } | |
78 | + | |
79 | + return $result; | |
80 | + } | |
81 | + | |
82 | + protected function get() { | |
83 | + if ($this->canGet()) { | |
84 | + $id = $this->getRequest()->id; | |
85 | + | |
86 | + $escola = array(); | |
87 | + $escola['escola_inep_id'] = $this->loadEscolaInepId($id); | |
88 | + | |
89 | + return $escola; | |
90 | + } | |
91 | + } | |
92 | + | |
93 | + protected function put() { | |
94 | + $id = $this->getRequest()->id; | |
95 | + | |
96 | + if ($this->canPut()) { | |
97 | + $this->createUpdateOrDestroyEducacensoEscola($id); | |
98 | + | |
99 | + $this->messenger->append('Cadastro alterado com sucesso', 'success', false, 'error'); | |
100 | + } | |
101 | + else | |
102 | + $this->messenger->append('Aparentemente o cadastro não pode ser alterado, por favor, verifique.', | |
103 | + 'error', false, 'error'); | |
104 | + | |
105 | + return array('id' => $id); | |
106 | + } | |
107 | + | |
108 | + public function Gerar() { | |
109 | + if ($this->isRequestFor('get', 'escola')) | |
110 | + $this->appendResponse($this->get()); | |
111 | + | |
112 | + elseif ($this->isRequestFor('put', 'escola')) | |
113 | + $this->appendResponse($this->put()); | |
114 | + | |
115 | + else | |
116 | + $this->notImplementedOperationError(); | |
117 | + } | |
118 | +} | |
0 | 119 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,199 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | +require_once 'lib/Portabilis/Array/Utils.php'; | |
37 | +require_once 'lib/Portabilis/String/Utils.php'; | |
38 | + | |
39 | +class MatriculaController extends ApiCoreController | |
40 | +{ | |
41 | + | |
42 | + protected function canGetMatriculas() { | |
43 | + return $this->validatesId('escola') && | |
44 | + $this->validatesId('aluno'); | |
45 | + } | |
46 | + | |
47 | + // search options | |
48 | + | |
49 | + protected function searchOptions() { | |
50 | + return array('sqlParams' => array($this->getRequest()->escola_id, $this->getRequest()->ano), | |
51 | + 'selectFields' => array('aluno_id')); | |
52 | + } | |
53 | + | |
54 | + protected function sqlsForNumericSearch() { | |
55 | + | |
56 | + return "select distinct ON (aluno.cod_aluno) aluno.cod_aluno as aluno_id, | |
57 | + matricula.cod_matricula as id, pessoa.nome as name from pmieducar.matricula, | |
58 | + pmieducar.aluno, cadastro.pessoa where aluno.cod_aluno = matricula.ref_cod_aluno and | |
59 | + pessoa.idpes = aluno.ref_idpes and aluno.ativo = matricula.ativo and | |
60 | + matricula.ativo = 1 and matricula.ref_ref_cod_escola = $2 and | |
61 | + (matricula.cod_matricula like $1 or matricula.ref_cod_aluno like $1) and | |
62 | + matricula.aprovado in (1, 2, 3, 7, 8, 9) and ano = $3 limit 15"; | |
63 | + } | |
64 | + | |
65 | + | |
66 | + protected function sqlsForStringSearch() { | |
67 | + return "select distinct ON (aluno.cod_aluno) aluno.cod_aluno as aluno_id, | |
68 | + matricula.cod_matricula as id, pessoa.nome as name from pmieducar.matricula, | |
69 | + pmieducar.aluno, cadastro.pessoa where aluno.cod_aluno = matricula.ref_cod_aluno and | |
70 | + pessoa.idpes = aluno.ref_idpes and aluno.ativo = matricula.ativo and | |
71 | + matricula.ativo = 1 and matricula.ref_ref_cod_escola = $2 and | |
72 | + lower(to_ascii(pessoa.nome)) like lower(to_ascii($1))||'%' and matricula.aprovado in (1, 2, 3, 7, 8, 9) | |
73 | + and ano = $3 limit 15"; | |
74 | + } | |
75 | + | |
76 | + | |
77 | + protected function formatResourceValue($resource) { | |
78 | + $alunoId = $resource['aluno_id']; | |
79 | + $nome = $this->toUtf8($resource['name'], array('transform' => true)); | |
80 | + | |
81 | + return $resource['id'] . " - ($alunoId) $nome"; | |
82 | + } | |
83 | + | |
84 | + | |
85 | + // load | |
86 | + | |
87 | + protected function loadNomeEscola($escolaId) { | |
88 | + $sql = "select nome from cadastro.pessoa, pmieducar.escola where idpes = ref_idpes and cod_escola = $1"; | |
89 | + $nome = $this->fetchPreparedQuery($sql, $escolaId, false, 'first-field'); | |
90 | + | |
91 | + return $this->safeString($nome); | |
92 | + } | |
93 | + | |
94 | + protected function loadNameFor($resourceName, $id){ | |
95 | + $sql = "select nm_{$resourceName} from pmieducar.{$resourceName} where cod_{$resourceName} = $1"; | |
96 | + $nome = $this->fetchPreparedQuery($sql, $id, false, 'first-field'); | |
97 | + | |
98 | + return $this->safeString($nome); | |
99 | + } | |
100 | + | |
101 | + protected function loadDadosForMatricula($matriculaId){ | |
102 | + $sql = "select cod_matricula as id, ref_cod_aluno as aluno_id, matricula.ano, | |
103 | + escola.ref_cod_instituicao as instituicao_id, matricula.ref_ref_cod_escola | |
104 | + as escola_id, matricula.ref_cod_curso as curso_id, matricula.ref_ref_cod_serie | |
105 | + as serie_id, matricula_turma.ref_cod_turma as turma_id from | |
106 | + pmieducar.matricula_turma, pmieducar.matricula, pmieducar.escola where escola.cod_escola = | |
107 | + matricula.ref_ref_cod_escola and ref_cod_matricula = cod_matricula and ref_cod_matricula = | |
108 | + $1 and matricula.ativo = matricula_turma.ativo and matricula_turma.ativo = 1 order by | |
109 | + matricula_turma.sequencial limit 1"; | |
110 | + | |
111 | + $dadosMatricula = $this->fetchPreparedQuery($sql, $matriculaId, false, 'first-row'); | |
112 | + | |
113 | + $attrs = array('id', 'aluno_id', 'ano', 'instituicao_id', 'escola_id', | |
114 | + 'curso_id', 'serie_id', 'turma_id'); | |
115 | + | |
116 | + return Portabilis_Array_Utils::filter($dadosMatricula, $attrs); | |
117 | + } | |
118 | + | |
119 | + protected function tryLoadMatriculaTurma($matriculaId) { | |
120 | + $sql = "select ref_cod_turma as turma_id, turma.tipo_boletim from pmieducar.matricula_turma, | |
121 | + pmieducar.turma where ref_cod_turma = cod_turma and ref_cod_matricula = $1 and | |
122 | + matricula_turma.ativo = 1 limit 1"; | |
123 | + | |
124 | + $matriculaTurma = $this->fetchPreparedQuery($sql, $matriculaId, false, 'first-row'); | |
125 | + | |
126 | + if (is_array($matriculaTurma) and count($matriculaTurma) > 0) { | |
127 | + $attrs = array('turma_id', 'tipo_boletim'); | |
128 | + | |
129 | + $matriculaTurma = Portabilis_Array_Utils::filter($matriculaTurma, $attrs); | |
130 | + $matriculaTurma['nome_turma'] = $this->loadNameFor('turma', $matriculaTurma['turma_id']); | |
131 | + } | |
132 | + | |
133 | + return $matriculaTurma; | |
134 | + } | |
135 | + | |
136 | + protected function loadMatriculasAluno($alunoId, $escolaId) { | |
137 | + // #TODO mostrar o nome da situação da matricula | |
138 | + | |
139 | + // seleciona somente matriculas em andamento, aprovado, reprovado, em exame, aprovado apos exame e retido faltas | |
140 | + $sql = "select cod_matricula as id, ano, ref_cod_instituicao as instituicao_id, ref_ref_cod_escola as | |
141 | + escola_id, ref_cod_curso as curso_id, ref_ref_cod_serie as serie_id from pmieducar.matricula, | |
142 | + pmieducar.escola where cod_escola = ref_ref_cod_escola and ref_cod_aluno = $1 and ref_ref_cod_escola = | |
143 | + $2 and matricula.ativo = 1 and matricula.aprovado in (1, 2, 3, 7, 8, 9) order by ano desc, id"; | |
144 | + | |
145 | + $params = array($alunoId, $escolaId); | |
146 | + $matriculas = $this->fetchPreparedQuery($sql, $params, false); | |
147 | + | |
148 | + if (is_array($matriculas) && count($matriculas) > 0) { | |
149 | + $attrs = array('id', 'ano', 'instituicao_id', 'escola_id', 'curso_id', 'serie_id'); | |
150 | + $matriculas = Portabilis_Array_Utils::filterSet($matriculas, $attrs); | |
151 | + | |
152 | + foreach($matriculas as $key => $matricula) { | |
153 | + $matriculas[$key]['nome_curso'] = $this->loadNameFor('curso', $matricula['curso_id']); | |
154 | + $matriculas[$key]['nome_escola'] = $this->loadNomeEscola($this->getRequest()->escola_id); | |
155 | + $matriculas[$key]['nome_serie'] = $this->loadNameFor('serie', $matricula['serie_id']); | |
156 | + $matriculas[$key]['situacao'] = '#TODO'; | |
157 | + $turma = $this->tryLoadMatriculaTurma($matricula['id']); | |
158 | + | |
159 | + if (is_array($turma) and count($turma) > 0) { | |
160 | + $matriculas[$key]['turma_id'] = $turma['turma_id']; | |
161 | + $matriculas[$key]['nome_turma'] = $turma['nome_turma']; | |
162 | + $matriculas[$key]['report_boletim_template'] = $turma['report_boletim_template']; | |
163 | + } | |
164 | + } | |
165 | + } | |
166 | + | |
167 | + return $matriculas; | |
168 | + } | |
169 | + | |
170 | + // api | |
171 | + | |
172 | + protected function get() { | |
173 | + if ($this->canGet()) | |
174 | + return $this->loadDadosForMatricula($this->getRequest()->id); | |
175 | + } | |
176 | + | |
177 | + | |
178 | + protected function getMatriculas() { | |
179 | + if ($this->canGetMatriculas()) { | |
180 | + $matriculas = $this->loadMatriculasAluno($this->getRequest()->aluno_id, $this->getRequest()->escola_id); | |
181 | + return array('matriculas' => $matriculas); | |
182 | + } | |
183 | + } | |
184 | + | |
185 | + | |
186 | + public function Gerar() { | |
187 | + if ($this->isRequestFor('get', 'matricula')) | |
188 | + $this->appendResponse($this->get()); | |
189 | + | |
190 | + elseif ($this->isRequestFor('get', 'matriculas')) | |
191 | + $this->appendResponse($this->getMatriculas()); | |
192 | + | |
193 | + elseif ($this->isRequestFor('get', 'matricula-search')) | |
194 | + $this->appendResponse($this->search()); | |
195 | + | |
196 | + else | |
197 | + $this->notImplementedOperationError(); | |
198 | + } | |
199 | +} | ... | ... |
... | ... | @@ -0,0 +1,62 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | +require_once 'lib/Portabilis/Array/Utils.php'; | |
37 | +require_once 'lib/Portabilis/String/Utils.php'; | |
38 | + | |
39 | +class MunicipioController extends ApiCoreController | |
40 | +{ | |
41 | + // search options | |
42 | + | |
43 | + protected function searchOptions() { | |
44 | + return array('namespace' => 'public', 'idAttr' => 'idmun', 'selectFields' => array('sigla_uf')); | |
45 | + } | |
46 | + | |
47 | + // subscreve formatResourceValue para adicionar a sigla do estado ao final do valor, | |
48 | + // "<id_municipio> - <nome_municipio> (<sigla_uf>)", ex: "1 - Içara (SC)" | |
49 | + protected function formatResourceValue($resource) { | |
50 | + $siglaUf = $resource['sigla_uf']; | |
51 | + $nome = $this->toUtf8($resource['name'], array('transform' => true)); | |
52 | + | |
53 | + return $resource['id'] . " - $nome ($siglaUf)"; | |
54 | + } | |
55 | + | |
56 | + public function Gerar() { | |
57 | + if ($this->isRequestFor('get', 'municipio-search')) | |
58 | + $this->appendResponse($this->search()); | |
59 | + else | |
60 | + $this->notImplementedOperationError(); | |
61 | + } | |
62 | +} | ... | ... |
... | ... | @@ -0,0 +1,53 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | +require_once 'lib/Portabilis/Array/Utils.php'; | |
37 | +require_once 'lib/Portabilis/String/Utils.php'; | |
38 | + | |
39 | +class PaisController extends ApiCoreController | |
40 | +{ | |
41 | + // search options | |
42 | + | |
43 | + protected function searchOptions() { | |
44 | + return array('namespace' => 'public', 'idAttr' => 'idpais'); | |
45 | + } | |
46 | + | |
47 | + public function Gerar() { | |
48 | + if ($this->isRequestFor('get', 'pais-search')) | |
49 | + $this->appendResponse($this->search()); | |
50 | + else | |
51 | + $this->notImplementedOperationError(); | |
52 | + } | |
53 | +} | ... | ... |
... | ... | @@ -0,0 +1,171 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | +require_once 'lib/Portabilis/Array/Utils.php'; | |
37 | +require_once 'lib/Portabilis/String/Utils.php'; | |
38 | + | |
39 | +class PessoaController extends ApiCoreController | |
40 | +{ | |
41 | + | |
42 | + // validators | |
43 | + | |
44 | + // overwrite api core validator | |
45 | + protected function validatesResourceId() { | |
46 | + $existenceOptions = array('schema_name' => 'cadastro', 'field_name' => 'idpes'); | |
47 | + | |
48 | + return $this->validatesPresenceOf('id') && | |
49 | + $this->validatesExistenceOf('fisica', $this->getRequest()->id, $existenceOptions); | |
50 | + } | |
51 | + | |
52 | + | |
53 | + // load resources | |
54 | + | |
55 | + protected function tryLoadAlunoId($pessoaId) { | |
56 | + $sql = "select cod_aluno as id from pmieducar.aluno where ref_idpes = $1"; | |
57 | + $id = $this->fetchPreparedQuery($sql, $pessoaId, false, 'first-field'); | |
58 | + | |
59 | + // when not exists, returns an empty array that causes error on loadDetails | |
60 | + if (empty($id)) | |
61 | + $id = null; | |
62 | + | |
63 | + return $id; | |
64 | + } | |
65 | + | |
66 | + protected function loadPessoa($id = null) { | |
67 | + $sql = "select idpes as id, nome from cadastro.pessoa where idpes = $1"; | |
68 | + | |
69 | + $pessoa = $this->fetchPreparedQuery($sql, $id, false, 'first-row'); | |
70 | + $pessoa['nome'] = $this->toUtf8($pessoa['nome'], array('transform' => true)); | |
71 | + | |
72 | + return $pessoa; | |
73 | + } | |
74 | + | |
75 | + protected function loadDetails($pessoaId = null) { | |
76 | + $alunoId = $this->tryLoadAlunoId($pessoaId); | |
77 | + | |
78 | + $sql = "select cpf, idpes_pai as pai_id, idpes_mae as mae_id, idpes_responsavel as responsavel_id, | |
79 | + coalesce((select nome from cadastro.pessoa where idpes = fisica.idpes_pai), | |
80 | + (select nm_pai from pmieducar.aluno where cod_aluno = $1)) as nome_pai, | |
81 | + coalesce((select nome from cadastro.pessoa where idpes = fisica.idpes_mae), | |
82 | + (select nm_mae from pmieducar.aluno where cod_aluno = $1)) as nome_mae, | |
83 | + (select nome from cadastro.pessoa where idpes = fisica.idpes_responsavel) as nome_responsavel, | |
84 | + (select rg from cadastro.documento where documento.idpes = fisica.idpes) as rg | |
85 | + from cadastro.fisica where idpes = $2"; | |
86 | + | |
87 | + $details = $this->fetchPreparedQuery($sql, array($alunoId, $pessoaId), false, 'first-row'); | |
88 | + | |
89 | + $attrs = array('cpf', 'rg', 'pai_id', 'mae_id', 'responsavel_id', 'nome_pai', 'nome_mae', 'nome_responsavel'); | |
90 | + $details = Portabilis_Array_Utils::filter($details, $attrs); | |
91 | + | |
92 | + $details['aluno_id'] = $alunoId; | |
93 | + $details['nome_mae'] = $this->toUtf8($details['nome_mae'], array('transform' => true)); | |
94 | + $details['nome_pai'] = $this->toUtf8($details['nome_pai'], array('transform' => true)); | |
95 | + $details['nome_responsavel'] = $this->toUtf8($details['nome_responsavel'], array('transform' => true)); | |
96 | + | |
97 | + return $details; | |
98 | + } | |
99 | + | |
100 | + protected function loadDeficiencias($pessoaId) { | |
101 | + $sql = "select cod_deficiencia as id, nm_deficiencia as nome from cadastro.fisica_deficiencia, | |
102 | + cadastro.deficiencia where cod_deficiencia = ref_cod_deficiencia and ref_idpes = $1"; | |
103 | + | |
104 | + $deficiencias = $this->fetchPreparedQuery($sql, $pessoaId, false); | |
105 | + | |
106 | + // transforma array de arrays em array chave valor | |
107 | + $_deficiencias = array(); | |
108 | + | |
109 | + foreach ($deficiencias as $deficiencia) { | |
110 | + $nome = $this->toUtf8($deficiencia['nome'], array('transform' => true)); | |
111 | + $_deficiencias[$deficiencia['id']] = $nome; | |
112 | + } | |
113 | + | |
114 | + return $_deficiencias; | |
115 | + } | |
116 | + | |
117 | + | |
118 | + // search | |
119 | + | |
120 | + protected function searchOptions() { | |
121 | + return array('namespace' => 'cadastro', 'idAttr' => 'idpes'); | |
122 | + } | |
123 | + | |
124 | + protected function sqlsForNumericSearch() { | |
125 | + $sqls = array(); | |
126 | + | |
127 | + // search by idpes or cpf | |
128 | + $sqls[] = "select distinct pessoa.idpes as id, pessoa.nome as name from cadastro.pessoa, | |
129 | + cadastro.fisica where fisica.idpes = pessoa.idpes and (pessoa.idpes like $1||'%' or | |
130 | + trim(leading '0' from fisica.cpf) like trim(leading '0' from $1)||'%' or | |
131 | + fisica.cpf like $1||'%') order by id limit 15"; | |
132 | + | |
133 | + // search by rg | |
134 | + $sqls[] = "select distinct pessoa.idpes as id, pessoa.nome as name from cadastro.pessoa, cadastro.documento | |
135 | + where pessoa.idpes = documento.idpes and ((documento.rg like $1||'%') or | |
136 | + trim(leading '0' from documento.rg) like trim(leading '0' from $1)||'%') order by id limit 15"; | |
137 | + | |
138 | + return $sqls; | |
139 | + } | |
140 | + | |
141 | + // api responders | |
142 | + | |
143 | + protected function get() { | |
144 | + $pessoa = array(); | |
145 | + | |
146 | + if ($this->canGet()) { | |
147 | + $attrs = array('id', 'nome'); | |
148 | + | |
149 | + $pessoa = $this->loadPessoa($this->getRequest()->id); | |
150 | + $pessoa = Portabilis_Array_Utils::filter($pessoa, $attrs); | |
151 | + | |
152 | + $details = $this->loadDetails($this->getRequest()->id); | |
153 | + $pessoa = Portabilis_Array_Utils::merge($pessoa, $details); | |
154 | + | |
155 | + $pessoa['deficiencias'] = $this->loadDeficiencias($this->getRequest()->id); | |
156 | + } | |
157 | + | |
158 | + return $pessoa; | |
159 | + } | |
160 | + | |
161 | + | |
162 | + public function Gerar() { | |
163 | + if ($this->isRequestFor('get', 'pessoa-search')) | |
164 | + $this->appendResponse($this->search()); | |
165 | + | |
166 | + elseif ($this->isRequestFor('get', 'pessoa')) | |
167 | + $this->appendResponse($this->get()); | |
168 | + else | |
169 | + $this->notImplementedOperationError(); | |
170 | + } | |
171 | +} | ... | ... |
... | ... | @@ -0,0 +1,102 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | +require_once "Reports/Reports/BoletimReport.php"; | |
37 | + | |
38 | +class ReportController extends ApiCoreController | |
39 | +{ | |
40 | + | |
41 | + // validations | |
42 | + | |
43 | + protected function canGetBoletim() { | |
44 | + return $this->validatesId('escola') && | |
45 | + $this->validatesId('matricula'); | |
46 | + } | |
47 | + | |
48 | + | |
49 | + // load | |
50 | + | |
51 | + protected function loadDadosForMatricula($matriculaId){ | |
52 | + $sql = "select cod_matricula as id, ref_cod_aluno as aluno_id, matricula.ano, | |
53 | + escola.ref_cod_instituicao as instituicao_id, matricula.ref_ref_cod_escola | |
54 | + as escola_id, matricula.ref_cod_curso as curso_id, matricula.ref_ref_cod_serie | |
55 | + as serie_id, matricula_turma.ref_cod_turma as turma_id from | |
56 | + pmieducar.matricula_turma, pmieducar.matricula, pmieducar.escola where escola.cod_escola = | |
57 | + matricula.ref_ref_cod_escola and ref_cod_matricula = cod_matricula and ref_cod_matricula = | |
58 | + $1 and matricula.ativo = matricula_turma.ativo and matricula_turma.ativo = 1 order by | |
59 | + matricula_turma.sequencial limit 1"; | |
60 | + | |
61 | + $dadosMatricula = $this->fetchPreparedQuery($sql, $matriculaId, false, 'first-row'); | |
62 | + | |
63 | + $attrs = array('id', 'aluno_id', 'ano', 'instituicao_id', 'escola_id', | |
64 | + 'curso_id', 'serie_id', 'turma_id'); | |
65 | + | |
66 | + return Portabilis_Array_Utils::filter($dadosMatricula, $attrs); | |
67 | + } | |
68 | + | |
69 | + // api | |
70 | + | |
71 | + protected function getBoletim() { | |
72 | + if ($this->canGetBoletim()) { | |
73 | + $dadosMatricula = $this->loadDadosForMatricula($this->getRequest()->matricula_id); | |
74 | + | |
75 | + $boletimReport = new BoletimReport(); | |
76 | + | |
77 | + $boletimReport->addArg('matricula', (int)$dadosMatricula['id']); | |
78 | + $boletimReport->addArg('ano', (int)$dadosMatricula['ano']); | |
79 | + $boletimReport->addArg('instituicao', (int)$dadosMatricula['instituicao_id']); | |
80 | + $boletimReport->addArg('escola', (int)$dadosMatricula['escola_id']); | |
81 | + $boletimReport->addArg('curso', (int)$dadosMatricula['curso_id']); | |
82 | + $boletimReport->addArg('serie', (int)$dadosMatricula['serie_id']); | |
83 | + $boletimReport->addArg('turma', (int)$dadosMatricula['turma_id']); | |
84 | + | |
85 | + $encoding = 'base64'; | |
86 | + | |
87 | + $dumpsOptions = array('options' => array('encoding' => $encoding)); | |
88 | + $encoded = $boletimReport->dumps($dumpsOptions); | |
89 | + | |
90 | + return array('matricula_id' => $this->getRequest()->matricula_id, | |
91 | + 'encoding' => $encoding, | |
92 | + 'encoded' => $encoded); | |
93 | + } | |
94 | + } | |
95 | + | |
96 | + public function Gerar() { | |
97 | + if ($this->isRequestFor('get', 'boletim')) | |
98 | + $this->appendResponse($this->getBoletim()); | |
99 | + else | |
100 | + $this->notImplementedOperationError(); | |
101 | + } | |
102 | +} | ... | ... |
... | ... | @@ -0,0 +1,84 @@ |
1 | +<?php | |
2 | + | |
3 | +#error_reporting(E_ALL); | |
4 | +#ini_set("display_errors", 1); | |
5 | + | |
6 | +/** | |
7 | + * i-Educar - Sistema de gestão escolar | |
8 | + * | |
9 | + * Copyright (C) 2006 Prefeitura Municipal de Itajaí | |
10 | + * <ctima@itajai.sc.gov.br> | |
11 | + * | |
12 | + * Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo | |
13 | + * sob os termos da Licença Pública Geral GNU conforme publicada pela Free | |
14 | + * Software Foundation; tanto a versão 2 da Licença, como (a seu critério) | |
15 | + * qualquer versão posterior. | |
16 | + * | |
17 | + * Este programa é distribuído na expectativa de que seja útil, porém, SEM | |
18 | + * NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU | |
19 | + * ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral | |
20 | + * do GNU para mais detalhes. | |
21 | + * | |
22 | + * Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto | |
23 | + * com este programa; se não, escreva para a Free Software Foundation, Inc., no | |
24 | + * endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA. | |
25 | + * | |
26 | + * @author Lucas D'Avila <lucasdavila@portabilis.com.br> | |
27 | + * @category i-Educar | |
28 | + * @license @@license@@ | |
29 | + * @package Api | |
30 | + * @subpackage Modules | |
31 | + * @since Arquivo disponível desde a versão ? | |
32 | + * @version $Id$ | |
33 | + */ | |
34 | + | |
35 | +require_once 'lib/Portabilis/Controller/ApiCoreController.php'; | |
36 | +require_once 'lib/Portabilis/Array/Utils.php'; | |
37 | +require_once 'lib/Portabilis/String/Utils.php'; | |
38 | +require_once 'Portabilis/Model/Report/TipoBoletim.php'; | |
39 | +require_once "App/Model/IedFinder.php"; | |
40 | + | |
41 | +class TurmaController extends ApiCoreController | |
42 | +{ | |
43 | + // validators | |
44 | + | |
45 | + protected function validatesTurmaId() { | |
46 | + return $this->validatesPresenceOf('id') && | |
47 | + $this->validatesExistenceOf('turma', $this->getRequest()->id); | |
48 | + } | |
49 | + | |
50 | + // validations | |
51 | + | |
52 | + protected function canGet() { | |
53 | + return $this->canAcceptRequest() && | |
54 | + $this->validatesTurmaId(); | |
55 | + } | |
56 | + | |
57 | + // api | |
58 | + | |
59 | + protected function getTipoBoletim() { | |
60 | + $tipo = App_Model_IedFinder::getTurma($codTurma = $this->getRequest()->id); | |
61 | + $tipo = $tipo['tipo_boletim']; | |
62 | + | |
63 | + $tiposBoletim = Portabilis_Model_Report_TipoBoletim; | |
64 | + | |
65 | + $tipos = array(null => 'indefinido', | |
66 | + $tiposBoletim::BIMESTRAL => 'portabilis_boletim', | |
67 | + $tiposBoletim::TRIMESTRAL => 'portabilis_boletim_trimestral', | |
68 | + $tiposBoletim::TRIMESTRAL_CONCEITUAL => 'portabilis_boletim_primeiro_ano_trimestral', | |
69 | + $tiposBoletim::SEMESTRAL => 'portabilis_boletim_semestral', | |
70 | + $tiposBoletim::SEMESTRAL_CONCEITUAL => 'portabilis_boletim_conceitual_semestral', | |
71 | + $tiposBoletim::SEMESTRAL_EDUCACAO_INFANTIL => 'portabilis_boletim_educ_infantil_semestral', | |
72 | + $tiposBoletim::PARECER_DESCRITIVO_COMPONENTE => 'portabilis_boletim_parecer', | |
73 | + $tiposBoletim::PARECER_DESCRITIVO_GERAL => 'portabilis_boletim_parecer_geral'); | |
74 | + | |
75 | + return array('tipo-boletim' => $tipos[$tipo]); | |
76 | + } | |
77 | + | |
78 | + public function Gerar() { | |
79 | + if ($this->isRequestFor('get', 'tipo-boletim')) | |
80 | + $this->appendResponse($this->getTipoBoletim()); | |
81 | + else | |
82 | + $this->notImplementedOperationError(); | |
83 | + } | |
84 | +} | ... | ... |