educar_disciplina_dependencia_cad.php
14.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<?php
/**
* i-Educar - Sistema de gestão escolar
*
* Copyright (C) 2006 Prefeitura Municipal de ItajaÃ
* <ctima@itajai.sc.gov.br>
*
* Este programa é software livre; você pode redistribuÃ-lo e/ou modificá-lo
* sob os termos da Licença Pública Geral GNU conforme publicada pela Free
* Software Foundation; tanto a versão 2 da Licença, como (a seu critério)
* qualquer versão posterior.
*
* Este programa é distribuÃÂdo na expectativa de que seja útil, porém, SEM
* NENHUMA GARANTIA; nem mesmo a garantia implÃÂcita de COMERCIABILIDADE OU
* ADEQUAÃÃO A UMA FINALIDADE ESPECÃFICA. Consulte a Licença Pública Geral
* do GNU para mais detalhes.
*
* Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto
* com este programa; se não, escreva para a Free Software Foundation, Inc., no
* endereço 59 Temple Street, Suite 330, Boston, MA 02111-1307 USA.
*
* @author Lucas Schmoeller da Silva <lucas@portabilis.com.br>
* @category i-Educar
* @license @@license@@
* @package iEd_Pmieducar
* @since Arquivo disponÃvel desde a versão 1.0.0
* @version $Id$
*/
require_once 'include/clsBase.inc.php';
require_once 'include/clsCadastro.inc.php';
require_once 'include/clsBanco.inc.php';
require_once 'include/pmieducar/geral.inc.php';
require_once 'ComponenteCurricular/Model/ComponenteDataMapper.php';
/**
* clsIndexBase class.
*
* @author Lucas Schmoeller da Silva <lucas@portabilis.com.br>
* @category i-Educar
* @license @@license@@
* @package iEd_Pmieducar
* @since Classe disponÃvel desde a versão 1.0.0
* @version @@package_version@@
*/
class clsIndexBase extends clsBase
{
function Formular()
{
$this->SetTitulo($this->_instituicao . ' i-Educar - Dispensa Componente Curricular');
$this->processoAp = 578;
}
}
/**
* indice class.
*
* @author Lucas Schmoeller da Silva <lucas@portabilis.com.br>
* @category i-Educar
* @license @@license@@
* @package iEd_Pmieducar
* @since Classe disponÃvel desde a versão 1.0.0
* @version @@package_version@@
*/
class indice extends clsCadastro
{
var $pessoa_logada;
var $observacao;
var $ref_cod_matricula;
var $ref_cod_turma;
var $ref_cod_serie;
var $ref_cod_disciplina;
var $ref_sequencial;
var $ref_cod_instituicao;
var $ref_cod_escola;
function Inicializar()
{
$retorno = 'Novo';
$this->ref_cod_disciplina = $_GET['ref_cod_disciplina'];
$this->ref_cod_matricula = $_GET['ref_cod_matricula'];
$obj_permissoes = new clsPermissoes();
$obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7,
'educar_disciplina_dependencia_lst.php?ref_ref_cod_matricula=' . $this->ref_cod_matricula);
if (is_numeric($this->ref_cod_matricula)) {
$obj_matricula = new clsPmieducarMatricula($this->ref_cod_matricula, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1);
$det_matricula = $obj_matricula->detalhe();
if (!$det_matricula) {
$this->simpleRedirect("educar_matricula_lst.php");
}
$this->ref_cod_escola = $det_matricula['ref_ref_cod_escola'];
$this->ref_cod_serie = $det_matricula['ref_ref_cod_serie'];
} else {
$this->simpleRedirect("educar_matricula_lst.php");
}
if (is_numeric($this->ref_cod_matricula) && is_numeric($this->ref_cod_serie) &&
is_numeric($this->ref_cod_escola) && is_numeric($this->ref_cod_disciplina)
) {
$obj = new clsPmieducarDisciplinaDependencia($this->ref_cod_matricula,
$this->ref_cod_serie, $this->ref_cod_escola, $this->ref_cod_disciplina);
$registro = $obj->detalhe();
if ($registro) {
// passa todos os valores obtidos no registro para atributos do objeto
foreach ($registro as $campo => $val) {
$this->$campo = $val;
}
$obj_permissoes = new clsPermissoes();
if ($obj_permissoes->permissao_excluir(578, $this->pessoa_logada, 7)) {
$this->fexcluir = TRUE;
}
$retorno = 'Editar';
}
}
$this->url_cancelar = $retorno == 'Editar' ?
sprintf('educar_disciplina_dependencia_det.php?ref_cod_matricula=%d&ref_cod_serie=%d&ref_cod_escola=%d&ref_cod_disciplina=%d',
$registro['ref_cod_matricula'], $registro['ref_cod_serie'],
$registro['ref_cod_escola'], $registro['ref_cod_disciplina']) :
'educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula;
$this->nome_url_cancelar = 'Cancelar';
$this->breadcrumb('Disciplinas de dependência', [
url('intranet/educar_index.php') => 'Escola',
]);
return $retorno;
}
function Gerar()
{
/**
* Busca dados da matricula
*/
$obj_ref_cod_matricula = new clsPmieducarMatricula();
$detalhe_aluno = array_shift($obj_ref_cod_matricula->lista($this->ref_cod_matricula));
$obj_aluno = new clsPmieducarAluno();
$det_aluno = array_shift($det_aluno = $obj_aluno->lista($detalhe_aluno['ref_cod_aluno'],
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1));
$obj_escola = new clsPmieducarEscola($this->ref_cod_escola, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, 1);
$det_escola = $obj_escola->detalhe();
$this->ref_cod_instituicao = $det_escola['ref_cod_instituicao'];
$obj_matricula_turma = new clsPmieducarMatriculaTurma();
$lst_matricula_turma = $obj_matricula_turma->lista($this->ref_cod_matricula,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1, $this->ref_cod_serie, NULL,
$this->ref_cod_escola);
if (is_array($lst_matricula_turma)) {
$det = array_shift($lst_matricula_turma);
$this->ref_cod_turma = $det['ref_cod_turma'];
$this->ref_sequencial = $det['sequencial'];
}
$this->campoRotulo('nm_aluno', 'Nome do Aluno', $det_aluno['nome_aluno']);
if (!isset($this->ref_cod_turma)) {
$this->mensagem = 'Para cadastrar uma disciplina de dependência de um aluno, é necessário que este esteja enturmado.';
return;
}
// primary keys
$this->campoOculto('ref_cod_matricula', $this->ref_cod_matricula);
$this->campoOculto('ref_cod_serie', $this->ref_cod_serie);
$this->campoOculto('ref_cod_escola', $this->ref_cod_escola);
$opcoes = array('' => 'Selecione');
// Seleciona os componentes curriculares da turma
try {
$componentes = App_Model_IedFinder::getComponentesTurma($this->ref_cod_serie,
$this->ref_cod_escola, $this->ref_cod_turma);
} catch (App_Model_Exception $e) {
$this->mensagem = $e->getMessage();
return;
}
foreach ($componentes as $componente) {
$opcoes[$componente->id] = $componente->nome;
}
if ($this->ref_cod_disciplina) {
$this->campoRotulo('nm_disciplina', 'Disciplina', $opcoes[$this->ref_cod_disciplina]);
$this->campoOculto('ref_cod_disciplina', $this->ref_cod_disciplina);
} else {
$this->campoLista('ref_cod_disciplina', 'Disciplina', $opcoes,
$this->ref_cod_disciplina);
}
$this->campoMemo('observacao', 'Observação', $this->observacao, 60, 10, FALSE);
}
function existeComponenteSerie()
{
$db = new clsBanco();
$sql = "SELECT EXISTS (SELECT 1
FROM pmieducar.escola_serie_disciplina
WHERE ref_ref_cod_serie = {$this->ref_cod_serie}
AND ref_ref_cod_escola = {$this->ref_cod_escola}
AND ref_cod_disciplina = {$this->ref_cod_disciplina}
AND escola_serie_disciplina.ativo = 1)";
return dbBool($db->campoUnico($sql));
}
function validaQuantidadeDisciplinasDependencia()
{
$query = <<<'SQL'
SELECT t.ano
FROM pmieducar.matricula AS m
INNER JOIN pmieducar.matricula_turma AS mt ON mt.ref_cod_matricula = m.cod_matricula
INNER JOIN pmieducar.turma AS t ON t.cod_turma = mt.ref_cod_turma
WHERE m.cod_matricula = $1
SQL;
$ano = Portabilis_Utils_Database::selectField($query, [$this->ref_cod_matricula]);
$db = new clsBanco();
$db->consulta("SELECT (CASE
WHEN escola.utiliza_regra_diferenciada AND serie.regra_avaliacao_diferenciada_id IS NOT NULL
THEN regra_avaliacao_diferenciada.qtd_disciplinas_dependencia
ELSE regra_avaliacao.qtd_disciplinas_dependencia
END) AS qtd_disciplinas_dependencia
FROM pmieducar.escola,
pmieducar.serie
LEFT JOIN modules.regra_avaliacao_serie_ano AS rasa ON (rasa.serie_id = serie.cod_serie AND rasa.ano_letivo = {$ano})
LEFT JOIN modules.regra_avaliacao ON (rasa.regra_avaliacao_id = regra_avaliacao.id)
LEFT JOIN modules.regra_avaliacao AS regra_avaliacao_diferenciada ON (rasa.regra_avaliacao_diferenciada_id = regra_avaliacao_diferenciada.id)
WHERE serie.cod_serie = {$this->ref_cod_serie}
AND escola.cod_escola = {$this->ref_cod_escola}");
$db->ProximoRegistro();
$m = $db->Tupla();
$qtdDisciplinasLimite = $m['qtd_disciplinas_dependencia'];
$db->consulta("SELECT COUNT(1) as qtd
FROM pmieducar.disciplina_dependencia
WHERE ref_cod_matricula = {$this->ref_cod_matricula} ");
$db->ProximoRegistro();
$m = $db->Tupla();
$qtdDisciplinas = $m['qtd'];
$valid = $qtdDisciplinas < $qtdDisciplinasLimite;
if (!$valid) {
$this->mensagem .= "A regra desta série limita a quantidade de disciplinas de dependência para {$qtdDisciplinasLimite}. <br/>";
}
return $valid;
}
function Novo()
{
$obj_permissoes = new clsPermissoes();
$obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7,
'educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula);
if (!$this->validaQuantidadeDisciplinasDependencia()) {
return false;
}
if (!$this->existeComponenteSerie()) {
$this->mensagem = 'O componente não está habilitado na série da escola.';
$this->url_cancelar = 'educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula;
$this->nome_url_cancelar = 'Cancelar';
return false;
}
$sql = 'SELECT MAX(cod_disciplina_dependencia) + 1 FROM pmieducar.disciplina_dependencia';
$db = new clsBanco();
$max_cod_disciplina_dependencia = $db->CampoUnico($sql);
// Caso não exista nenhuma dispensa, atribui o código 1, tabela não utiliza sequences
$max_cod_disciplina_dependencia = $max_cod_disciplina_dependencia > 0 ? $max_cod_disciplina_dependencia : 1;
$obj = new clsPmieducarDisciplinaDependencia($this->ref_cod_matricula,
$this->ref_cod_serie, $this->ref_cod_escola, $this->ref_cod_disciplina,
$this->observacao, $max_cod_disciplina_dependencia);
if ($obj->existe()) {
$obj = new clsPmieducarDisciplinaDependencia($this->ref_cod_matricula,
$this->ref_cod_serie, $this->ref_cod_escola, $this->ref_cod_disciplina,
$this->observacao);
$obj->edita();
$this->simpleRedirect('educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula);
}
$cadastrou = $obj->cadastra();
if ($cadastrou) {
$this->mensagem .= 'Cadastro efetuado com sucesso.<br />';
$this->simpleRedirect('educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula);
}
$this->mensagem = 'Cadastro não realizado.<br />';
return FALSE;
}
function Editar()
{
$obj_permissoes = new clsPermissoes();
$obj_permissoes->permissao_cadastra(578, $this->pessoa_logada, 7,
'educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula);
$obj = new clsPmieducarDisciplinaDependencia($this->ref_cod_matricula,
$this->ref_cod_serie, $this->ref_cod_escola, $this->ref_cod_disciplina,
$this->observacao);
$editou = $obj->edita();
if ($editou) {
$this->mensagem .= 'Edição efetuada com sucesso.<br />';
$this->simpleRedirect('educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula);
}
$this->mensagem = 'Edição não realizada.<br />';
return FALSE;
}
function Excluir()
{
$obj_permissoes = new clsPermissoes();
$obj_permissoes->permissao_excluir(578, $this->pessoa_logada, 7,
'educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula);
$obj = new clsPmieducarDisciplinaDependencia($this->ref_cod_matricula,
$this->ref_cod_serie, $this->ref_cod_escola, $this->ref_cod_disciplina,
$this->observacao);
$excluiu = $obj->excluir();
if ($excluiu) {
$this->mensagem .= 'Exclusão efetuada com sucesso.<br />';
$this->simpleRedirect('educar_disciplina_dependencia_lst.php?ref_cod_matricula=' . $this->ref_cod_matricula);
}
$this->mensagem = 'Exclusão não realizada.<br />';
return FALSE;
}
}
// Instancia objeto de página
$pagina = new clsIndexBase();
// Instancia objeto de conteúdo
$miolo = new indice();
// Atribui o conteúdo à página
$pagina->addForm($miolo);
// Gera o código HTML
$pagina->MakeAll();