Completed
Push — master ( 10e479...8ee696 )
by Reginaldo
32:57
created
app/Controller/ApiController.php 2 patches
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -15,19 +15,19 @@  discard block
 block discarded – undo
15 15
 	public function client($id_cliente = null)
16 16
 	{
17 17
 		$api = 'cliente';
18
-	    $this->loadModel('Cliente');
18
+		$this->loadModel('Cliente');
19 19
 		$this->autoRender = false;
20 20
 		$this->response->type('json');
21 21
 		
22 22
 		$type = $this->request;
23 23
 
24
-	    if (!$this->validate_use_api($type, $api)) {
25
-	    	echo '{message: Você não tem permissão para usar nosso modulo}';
26
-	    	return;
27
-	    }
24
+		if (!$this->validate_use_api($type, $api)) {
25
+			echo '{message: Você não tem permissão para usar nosso modulo}';
26
+			return;
27
+		}
28 28
 
29
-	    if ($type->is('get')) {
30
-	    	$conditions = array(
29
+		if ($type->is('get')) {
30
+			$conditions = array(
31 31
 				'ativo' => 1,
32 32
 				'id_usuario' => $this->getIdUser(),
33 33
 			);
@@ -36,70 +36,70 @@  discard block
 block discarded – undo
36 36
 			 	$conditions['id'] = $id_cliente;
37 37
 
38 38
 
39
-		    $cliente = $this->Cliente->find('all', 
39
+			$cliente = $this->Cliente->find('all', 
40 40
 				array('conditions' => 
41 41
 					$conditions
42 42
 				)
43 43
 			);
44 44
 
45 45
 			$this->response->body(json_encode($cliente));
46
-	    } else if ($type->is('post')) {
47
-	    	$dados = $this->request->data;
46
+		} else if ($type->is('post')) {
47
+			$dados = $this->request->data;
48 48
 	    	
49
-	    	if (empty($dados)) {
49
+			if (empty($dados)) {
50 50
 				$this->response->body(json_encode(array('message' => 'Ocorreu algum erro com os parametros passados')));
51 51
 				return;
52
-	    	}
52
+			}
53 53
 
54
-	    	if (!empty($dados['nome1']) && !empty($dados['nome2']) && !empty($dados['email']) && !empty($dados['senha'])) {
55
-	    		$this->postClient($dados);
56
-	    	} 
54
+			if (!empty($dados['nome1']) && !empty($dados['nome2']) && !empty($dados['email']) && !empty($dados['senha'])) {
55
+				$this->postClient($dados);
56
+			} 
57 57
 
58
-	    	$this->loginClient($dados);
59
-	    } else if ($type->is('put')) {
58
+			$this->loginClient($dados);
59
+		} else if ($type->is('put')) {
60 60
 
61
-	    	$dados = $this->request->data;
61
+			$dados = $this->request->data;
62 62
 	    	
63 63
 			if (empty($dados)) {
64 64
 				$this->response->body(json_encode(array('message' => 'Ocorreu algum erro com os parametros passados')));
65 65
 				return;
66
-	    	}
66
+			}
67 67
 
68
-	    	if ($id_cliente == null) {
69
-	    		$this->response->body(json_encode(array('message' => 'Você não passou o id do usuario')));
70
-	    		return;
71
-	    	}
68
+			if ($id_cliente == null) {
69
+				$this->response->body(json_encode(array('message' => 'Você não passou o id do usuario')));
70
+				return;
71
+			}
72 72
 
73
-	    	$this->putClient($dados, $id_cliente);
74
-	    } else if ($type->is('delete')) {
73
+			$this->putClient($dados, $id_cliente);
74
+		} else if ($type->is('delete')) {
75 75
 	    	
76
-	    	if ($id_cliente == null) {
77
-	    		$this->response->body(json_encode(array('message' => 'Você não passou o id do usuario')));
78
-	    		return;
79
-	    	}
76
+			if ($id_cliente == null) {
77
+				$this->response->body(json_encode(array('message' => 'Você não passou o id do usuario')));
78
+				return;
79
+			}
80 80
 
81
-	    	$this->inactiveClient($id_cliente);
82
-	    }
81
+			$this->inactiveClient($id_cliente);
82
+		}
83 83
 	}
84 84
 
85 85
 	public function parent($id_cliente = null, $id_parente = null)
86 86
 	{
87 87
 		$api = 'parente';
88 88
 
89
-	    $this->loadModel('Parente');
89
+		$this->loadModel('Parente');
90 90
 
91 91
 		$this->autoRender = false;
92 92
 		$this->response->type('json');
93 93
 		
94 94
 		$type = $this->request;
95 95
 
96
-	    if (!$this->validate_use_api($type, $api)) {
97
-	    	echo '{message: Você não tem permissão para usar nosso modulo}';
98
-	    	return;
99
-	    }
96
+		if (!$this->validate_use_api($type, $api)) {
97
+			echo '{message: Você não tem permissão para usar nosso modulo}';
98
+			return;
99
+		}
100 100
 
101
-	    if ($type->is('get')) {
102
-	    	$conditions = array(
101
+		if ($type->is('get')) {
102
+			$conditions = array(
103 103
 				'ativo' => 1,
104 104
 				'usuario_id' => $this->getIdUser(),
105 105
 			);
@@ -110,50 +110,50 @@  discard block
 block discarded – undo
110 110
 				$conditions['id'] = $id_parente;
111 111
 			}
112 112
 
113
-		    $parentes = $this->Parente->find('all', 
113
+			$parentes = $this->Parente->find('all', 
114 114
 				array('conditions' => 
115 115
 					$conditions
116 116
 				)
117 117
 			);
118 118
 
119 119
 			$this->response->body(json_encode($parentes));
120
-	    } else if ($type->is('post')) {
121
-	    	$dados = $this->request->data;
120
+		} else if ($type->is('post')) {
121
+			$dados = $this->request->data;
122 122
 	    	
123
-	    	if (empty($dados)) {
123
+			if (empty($dados)) {
124 124
 				$this->response->body(json_encode(array('message' => 'Ocorreu algum erro com os parametros passados')));
125 125
 				return;
126
-	    	}
126
+			}
127 127
 
128
-	    	if (!empty($dados['cliente_id'])) {
129
-	    		$this->postParent($dados);
130
-	    	} 
128
+			if (!empty($dados['cliente_id'])) {
129
+				$this->postParent($dados);
130
+			} 
131 131
 
132
-	    	$this->loginParent($dados);
133
-	    } else if ($type->is('put')) {
132
+			$this->loginParent($dados);
133
+		} else if ($type->is('put')) {
134 134
 
135
-	    	$dados = $this->request->data;
135
+			$dados = $this->request->data;
136 136
 	    	
137 137
 			if (empty($dados)) {
138 138
 				$this->response->body(json_encode(array('message' => 'Ocorreu algum erro com os parametros passados')));
139 139
 				return;
140
-	    	}
140
+			}
141 141
 
142
-	    	if ($id_parente == null) {
143
-	    		$this->response->body(json_encode(array('message' => 'Você não passou o id do usuario')));
144
-	    		return;
145
-	    	}
142
+			if ($id_parente == null) {
143
+				$this->response->body(json_encode(array('message' => 'Você não passou o id do usuario')));
144
+				return;
145
+			}
146 146
 
147
-	    	$this->putParent($dados, $id_parente);
148
-	    } else if ($type->is('delete')) {
147
+			$this->putParent($dados, $id_parente);
148
+		} else if ($type->is('delete')) {
149 149
 	    	
150
-	    	if ($id_parente == null) {
151
-	    		$this->response->body(json_encode(array('message' => 'Você não passou o id do usuario')));
152
-	    		return;
153
-	    	}
150
+			if ($id_parente == null) {
151
+				$this->response->body(json_encode(array('message' => 'Você não passou o id do usuario')));
152
+				return;
153
+			}
154 154
 
155
-	    	$this->inactiveClient($id_parente);
156
-	    }
155
+			$this->inactiveClient($id_parente);
156
+		}
157 157
 	}
158 158
 
159 159
 	public function occurrences($id_cliente = null) 
@@ -166,23 +166,23 @@  discard block
 block discarded – undo
166 166
 
167 167
 		$type = $this->request;
168 168
 
169
-	    if ($type->is('get'))
170
-	    {
171
-	    	$conditions = array(
169
+		if ($type->is('get'))
170
+		{
171
+			$conditions = array(
172 172
 				'ativo' => 1,
173 173
 				'cliente_id' => $id_cliente,
174 174
 			);
175 175
 
176 176
 			$conditions['cliente_id'] = $id_cliente;
177 177
 
178
-		    $ocorrencias = $this->Ocorrencias->find('all', 
178
+			$ocorrencias = $this->Ocorrencias->find('all', 
179 179
 				array('conditions' => 
180 180
 					$conditions
181 181
 				)
182 182
 			);
183 183
 
184 184
 			$this->response->body(json_encode($ocorrencias));	    	
185
-	    }
185
+		}
186 186
 	}
187 187
 
188 188
 	public function newsletter()
@@ -196,17 +196,17 @@  discard block
 block discarded – undo
196 196
 		
197 197
 		$type = $this->request;
198 198
 
199
-	    if (!$this->validate_use_api($type, $api)) {
200
-	    	echo '{message: Você não tem permissão para usar nosso modulo}';
201
-	    	return;
202
-	    }
199
+		if (!$this->validate_use_api($type, $api)) {
200
+			echo '{message: Você não tem permissão para usar nosso modulo}';
201
+			return;
202
+		}
203 203
 
204
-    	$request = $this->request->data;
204
+		$request = $this->request->data;
205 205
     	
206
-    	if (empty($request)) {
206
+		if (empty($request)) {
207 207
 			$this->response->body(json_encode(array('message' => 'Ocorreu algum erro com os parametros passados')));
208 208
 			return;
209
-    	}
209
+		}
210 210
 
211 211
 		$dados = array(
212 212
 			'email'  => $request['email'],
@@ -233,25 +233,25 @@  discard block
 block discarded – undo
233 233
 		$type = $this->request;
234 234
 
235 235
 		if (!$this->validate_use_api($type, $api)) {
236
-	    	echo '{message: Você não tem permissão para usar nosso modulo}';
237
-	    	return;
238
-	    }
236
+			echo '{message: Você não tem permissão para usar nosso modulo}';
237
+			return;
238
+		}
239 239
 
240
-    	$conditions = array(
240
+		$conditions = array(
241 241
 			'ativo' => 1,
242 242
 			'usuario_id' => $this->getIdUser()
243 243
 		);
244 244
 
245
-	    $banner = $this->Banner->find('all', 
245
+		$banner = $this->Banner->find('all', 
246 246
 			array('conditions' => 
247 247
 				$conditions
248 248
 			)
249 249
 		);
250 250
 
251
-	    if (!empty($banner)) {
251
+		if (!empty($banner)) {
252 252
 			$this->response->body('{"message": "success", "result":'.json_encode($banner).'}');
253 253
 			return;
254
-	    }
254
+		}
255 255
 		
256 256
 		$this->response->body('{"message": "error"}');
257 257
 		return;	
@@ -269,39 +269,39 @@  discard block
 block discarded – undo
269 269
 		$type = $this->request;
270 270
 
271 271
 		if (!$this->validate_use_api($type, $api)) {
272
-	    	echo '{message: Você não tem permissão para usar nosso modulo}';
273
-	    	return;
274
-	    }
272
+			echo '{message: Você não tem permissão para usar nosso modulo}';
273
+			return;
274
+		}
275 275
 
276 276
 
277
-	    if ($type->is('get')) {
278
-	    	$conditions = array(
277
+		if ($type->is('get')) {
278
+			$conditions = array(
279 279
 				'ativo' => 1,
280 280
 				'id_usuario' => $this->getIdUser()
281 281
 			);
282 282
 
283
-		    $consulta = $this->Consulta->find('all', 
283
+			$consulta = $this->Consulta->find('all', 
284 284
 				array('conditions' => 
285 285
 					$conditions
286 286
 				)
287 287
 			);
288 288
 
289
-		    if (!empty($consulta)) {
289
+			if (!empty($consulta)) {
290 290
 				$this->response->body('{"message": "success", "result":'.json_encode($consulta).'}');
291 291
 				return;
292
-		    }
292
+			}
293 293
 		}
294 294
 
295 295
 		if ($type->is('post'))
296 296
 		{
297
-	    	$dados = $this->request->data;
297
+			$dados = $this->request->data;
298 298
 	    	
299
-	    	if (empty($dados)) {
299
+			if (empty($dados)) {
300 300
 				$this->response->body(json_encode(array('message' => 'Ocorreu algum erro com os parametros passados')));
301 301
 				return;
302
-	    	}
302
+			}
303 303
 
304
-	    	return $this->postConsulta($dados);			
304
+			return $this->postConsulta($dados);			
305 305
 		}
306 306
 
307 307
 		$this->response->body('{"message": "error"}');
@@ -311,23 +311,23 @@  discard block
 block discarded – undo
311 311
 	public function loginClient($dados)
312 312
 	{
313 313
 
314
-    	$conditions = array(
314
+		$conditions = array(
315 315
 			'ativo' => 1,
316 316
 			'id_usuario' => $this->getIdUser(),
317 317
 			'email' => $dados['email'],
318 318
 			'senha' => sha1($dados['senha'])
319 319
 		);
320 320
 
321
-	    $cliente = $this->Cliente->find('all', 
321
+		$cliente = $this->Cliente->find('all', 
322 322
 			array('conditions' => 
323 323
 				$conditions
324 324
 			)
325 325
 		);
326 326
 
327
-	    if (!empty($cliente)) {
327
+		if (!empty($cliente)) {
328 328
 			$this->response->body('{"message": "success", "result":'.json_encode($cliente).'}');
329 329
 			return;
330
-	    }
330
+		}
331 331
 		
332 332
 		$this->response->body('{"message": "error"}');
333 333
 		return;	    
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 	{
338 338
 		$this->loadModel('Cliente');
339 339
 
340
-    	$dados['senha'] = sha1($dados['senha']);
340
+		$dados['senha'] = sha1($dados['senha']);
341 341
 		$dados['ativo'] = 1;
342 342
 		$dados['id_usuario'] = $this->instancia;
343 343
 		
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 
387 387
 	public function postParent($dados)
388 388
 	{
389
-    	$dados = array(
389
+		$dados = array(
390 390
 			'senha'      => sha1($dados['senha']),
391 391
 			'usuario_id' => $this->getIdUser(),
392 392
 			'cliente_id' => $dados['cliente_id'],
@@ -405,23 +405,23 @@  discard block
 block discarded – undo
405 405
 
406 406
 	public function loginParent($dados) 
407 407
 	{
408
-    	$conditions = array(
408
+		$conditions = array(
409 409
 			'ativo' => 1,
410 410
 			'usuario_id' => $this->getIdUser(),
411 411
 			'login' => $dados['login'],
412 412
 			'senha' => sha1($dados['senha'])
413 413
 		);
414 414
 
415
-	    $parente = $this->Parente->find('all', 
415
+		$parente = $this->Parente->find('all', 
416 416
 			array('conditions' => 
417 417
 				$conditions
418 418
 			)
419 419
 		);
420 420
 
421
-	    if (!empty($parente)) {
421
+		if (!empty($parente)) {
422 422
 			$this->response->body('{"message": "success", "result":'.json_encode($parente).'}');
423 423
 			return;
424
-	    }
424
+		}
425 425
 		
426 426
 		$this->response->body('{"message": "error"}');
427 427
 		return;	
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 
463 463
 	public function postConsulta($dados)
464 464
 	{
465
-    	$dados = array(
465
+		$dados = array(
466 466
 			'nome'       => $dados['nome'],
467 467
 			'email'      => $dados['email'],
468 468
 			'data'       => $dados['date'],
@@ -481,8 +481,8 @@  discard block
 block discarded – undo
481 481
 	}
482 482
 
483 483
 	/**
484
-	* Valida o usuario que está tentando usar a api
485
-	*/
484
+	 * Valida o usuario que está tentando usar a api
485
+	 */
486 486
 	public function validate_use_api($req, $api)
487 487
 	{
488 488
 		$this->loadModel('Usuario');
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 		
22 22
 		$type = $this->request;
23 23
 
24
-	    if (!$this->validate_use_api($type, $api)) {
24
+	    if ( ! $this->validate_use_api($type, $api)) {
25 25
 	    	echo '{message: Você não tem permissão para usar nosso modulo}';
26 26
 	    	return;
27 27
 	    }
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 				return;
52 52
 	    	}
53 53
 
54
-	    	if (!empty($dados['nome1']) && !empty($dados['nome2']) && !empty($dados['email']) && !empty($dados['senha'])) {
54
+	    	if ( ! empty($dados['nome1']) && ! empty($dados['nome2']) && ! empty($dados['email']) && ! empty($dados['senha'])) {
55 55
 	    		$this->postClient($dados);
56 56
 	    	} 
57 57
 
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		
94 94
 		$type = $this->request;
95 95
 
96
-	    if (!$this->validate_use_api($type, $api)) {
96
+	    if ( ! $this->validate_use_api($type, $api)) {
97 97
 	    	echo '{message: Você não tem permissão para usar nosso modulo}';
98 98
 	    	return;
99 99
 	    }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 				return;
126 126
 	    	}
127 127
 
128
-	    	if (!empty($dados['cliente_id'])) {
128
+	    	if ( ! empty($dados['cliente_id'])) {
129 129
 	    		$this->postParent($dados);
130 130
 	    	} 
131 131
 
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		
197 197
 		$type = $this->request;
198 198
 
199
-	    if (!$this->validate_use_api($type, $api)) {
199
+	    if ( ! $this->validate_use_api($type, $api)) {
200 200
 	    	echo '{message: Você não tem permissão para usar nosso modulo}';
201 201
 	    	return;
202 202
 	    }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 
233 233
 		$type = $this->request;
234 234
 
235
-		if (!$this->validate_use_api($type, $api)) {
235
+		if ( ! $this->validate_use_api($type, $api)) {
236 236
 	    	echo '{message: Você não tem permissão para usar nosso modulo}';
237 237
 	    	return;
238 238
 	    }
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 			)
249 249
 		);
250 250
 
251
-	    if (!empty($banner)) {
251
+	    if ( ! empty($banner)) {
252 252
 			$this->response->body('{"message": "success", "result":'.json_encode($banner).'}');
253 253
 			return;
254 254
 	    }
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 
269 269
 		$type = $this->request;
270 270
 
271
-		if (!$this->validate_use_api($type, $api)) {
271
+		if ( ! $this->validate_use_api($type, $api)) {
272 272
 	    	echo '{message: Você não tem permissão para usar nosso modulo}';
273 273
 	    	return;
274 274
 	    }
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 				)
287 287
 			);
288 288
 
289
-		    if (!empty($consulta)) {
289
+		    if ( ! empty($consulta)) {
290 290
 				$this->response->body('{"message": "success", "result":'.json_encode($consulta).'}');
291 291
 				return;
292 292
 		    }
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 			)
325 325
 		);
326 326
 
327
-	    if (!empty($cliente)) {
327
+	    if ( ! empty($cliente)) {
328 328
 			$this->response->body('{"message": "success", "result":'.json_encode($cliente).'}');
329 329
 			return;
330 330
 	    }
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 		$this->Cliente->id_usuario = $this->getIdUser();
361 361
 
362 362
 		if ($this->Cliente->save($dados)) {
363
-			$this->response->body('{"message": "success", "result": '. json_encode($dados) .'}');
363
+			$this->response->body('{"message": "success", "result": '.json_encode($dados).'}');
364 364
 			return;
365 365
 		}
366 366
 
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 			)
419 419
 		);
420 420
 
421
-	    if (!empty($parente)) {
421
+	    if ( ! empty($parente)) {
422 422
 			$this->response->body('{"message": "success", "result":'.json_encode($parente).'}');
423 423
 			return;
424 424
 	    }
@@ -437,7 +437,7 @@  discard block
 block discarded – undo
437 437
 		$this->Parente->id_usuario = $this->getIdUser();
438 438
 
439 439
 		if ($this->Parente->save($dados)) {
440
-			$this->response->body('{"message": "success", "result": '. json_encode($dados) .'}');
440
+			$this->response->body('{"message": "success", "result": '.json_encode($dados).'}');
441 441
 			return;
442 442
 		}
443 443
 
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 		);
473 473
 		
474 474
 		if ($this->Consulta->save($dados)) {
475
-			$this->response->body('{"message": "success", "result":' . json_encode($dados) . '}');
475
+			$this->response->body('{"message": "success", "result":'.json_encode($dados).'}');
476 476
 			return;
477 477
 		}
478 478
 
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 
505 505
 		$this->setIdUser($resposta['Usuario']['id']);
506 506
 
507
-		if (!$this->verifyUseApi($api)) 
507
+		if ( ! $this->verifyUseApi($api)) 
508 508
 		{
509 509
 			return false;
510 510
 		}
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 
542 542
 	public function getIdUser()
543 543
 	{
544
-		if (!is_numeric($this->instancia))
544
+		if ( ! is_numeric($this->instancia))
545 545
 		{
546 546
 			return false;
547 547
 		}
Please login to merge, or discard this patch.
app/Test/Case/Controller/LojaControllerTest.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-require(APP . 'Controller/AppController.php');
4
-require(APP . 'Controller/LojaController.php');
3
+require(APP.'Controller/AppController.php');
4
+require(APP.'Controller/LojaController.php');
5 5
 
6 6
 /**
7 7
 * 
Please login to merge, or discard this patch.