PontoController.php
6.12 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
<?php
#error_reporting(E_ALL);
#ini_set("display_errors", 1);
/**
* 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 Api
* @subpackage Modules
* @since Arquivo disponível desde a versão ?
* @version $Id$
*/
require_once 'include/modules/clsModulesPessoaTransporte.inc.php';
require_once 'include/modules/clsModulesItinerarioTransporteEscolar.inc.php';
require_once 'include/modules/clsModulesPontoTransporteEscolar.inc.php';
require_once 'Portabilis/Controller/ApiCoreController.php';
require_once 'Portabilis/Array/Utils.php';
require_once 'Portabilis/String/Utils.php';
require_once 'Portabilis/Date/Utils.php';
class PontoController extends ApiCoreController
{
protected $_processoAp = 578; //verificar
protected $_nivelAcessoOption = App_Model_NivelAcesso::SOMENTE_ESCOLA; // verificar
protected function createOrUpdatePonto($id = null){
$ponto = new clsModulesPontoTransporteEscolar();
$ponto->cod_ponto_transporte_escolar = $id;
// após cadastro não muda mais id pessoa
$ponto->descricao = Portabilis_String_Utils::toLatin1($this->getRequest()->desc);
return (is_null($id) ? $ponto->cadastra() : $ponto->edita());
}
protected function get() {
$id = $this->getRequest()->id;
$ponto = new clsModulesPontoTransporteEscolar();
$ponto->cod_ponto_transporte_escolar = $id;
$ponto = $ponto->detalhe();
$attrs = array(
'cod_ponto_transporte_escolar' => 'id',
);
$pt = Portabilis_Array_Utils::filter($ponto, $attrs);
$pt['desc'] = Portabilis_String_Utils::toUtf8($ponto['descricao']);
return $pt;
}
protected function validateIfPontoIsNotInUse(){
$itinerario = new clsModulesItinerarioTransporteEscolar();
$lista = $itinerario->lista(NULL,NULL,NULL,NULL,NULL,$this->getRequest()->id);
if(is_array($lista) && count($lista)>0){
$this->messenger->append('Não é possível excluir um ponto que está vinculado a um itinerário.',
'error', false, 'error');
return false;
}else{
return true;
}
}
protected function post() {
$id = $this->createOrUpdatePonto();
if (is_numeric($id)) {
$this->messenger->append('Cadastro realizado com sucesso', 'success', false, 'error');
}
else
$this->messenger->append('Aparentemente o ponto não pode ser cadastrada, por favor, verifique.');
return array('id' => $id);
}
protected function sqlsForNumericSearch() {
$sqls[] = "select distinct cod_ponto_transporte_escolar as id, descricao as name from
modules.ponto_transporte_escolar where cod_ponto_transporte_escolar like $1||'%'";
return $sqls;
}
protected function sqlsForStringSearch() {
$sqls[] = "select distinct cod_ponto_transporte_escolar as id, descricao as name from
modules.ponto_transporte_escolar where lower(to_ascii(descricao)) like '%'||lower(to_ascii($1))||'%'";
return $sqls;
}
protected function put() {
$id = $this->getRequest()->id;
$editou = $this->createOrUpdatePonto($id);
if ($editou) {
$this->messenger->append('Alteração realizada com sucesso', 'success', false, 'error');
}
else
$this->messenger->append('Aparentemente o ponto não pode ser alterado, por favor, verifique.');
return array('id' => $id);
}
protected function delete() {
$id = $this->getRequest()->id;
$pessoas = new clsModulesPessoaTransporte();
$lista = $pessoas->lista(NULL,NULL,NULL,$id);
foreach($lista as $registro){
$editaPessoa = new clsModulesPessoaTransporte($registro['cod_pessoa_transporte'],
$registro['ref_cod_rota_transporte_escolar'],$registro['ref_idpes'],
null,$registro['ref_idpes_destino'],$registro['observacao']);
$editaPessoa->edita();
}
$ponto = new clsModulesPontoTransporteEscolar();
$ponto->cod_ponto_transporte_escolar = $id;
if($ponto->excluir()){
$this->messenger->append('Cadastro removido com sucesso', 'success', false, 'error');
}else
$this->messenger->append('Aparentemente o cadastro não pode ser removido, por favor, verifique.',
'error', false, 'error');
return array('id' => $id);
}
public function Gerar() {
if ($this->isRequestFor('get', 'ponto'))
$this->appendResponse($this->get());
elseif ($this->isRequestFor('get', 'ponto-search'))
$this->appendResponse($this->search());
// create
elseif ($this->isRequestFor('post', 'ponto'))
$this->appendResponse($this->post());
// update
elseif ($this->isRequestFor('put', 'ponto'))
$this->appendResponse($this->put());
elseif ($this->isRequestFor('delete', 'ponto')){
if($this->validateIfPontoIsNotInUse()){
$this->appendResponse($this->delete());
echo "<script language= \"JavaScript\">
location.href=\"intranet/transporte_ponto_lst.php\";
</script>";
die();
}
}else
$this->notImplementedOperationError();
}
}