AviseMeController::excluir_cadastro()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 16
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
App::uses('AppController', 'Controller');
4
5
class AviseMeController extends AppController
6
{
7
	
8
	public function listar_cadastros()
9
	{
10
		$this->loadModel('AviseMe');
11
12
		$query = array (
13
			'joins' => array(
14
			    array(
15
			        'table' => 'produtos',
16
			        'alias' => 'Produto',
17
			        'type' => 'LEFT',
18
			        'conditions' => array(
19
			            'AviseMe.produto_id = Produto.id',
20
			        ),
21
			    )
22
			),
23
	        'conditions' => array('AviseMe.ativo' => 1, 'AviseMe.usuario_id' => $this->instancia),
24
	        'fields' => array('Produto.nome, AviseMe.email, AviseMe.id, Produto.id'),
25
		);
26
27
		$cadastros = $this->AviseMe->find('all', $query);
28
		$this->set('cadastros', $cadastros);
29
30
		$this->layout = 'wadmin';
31
	}
32
33 View Code Duplication
	public function excluir_cadastro($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
34
	{
35
		$this->loadModel('AviseMe');
36
		$this->layout = 'ajax';
37
38
		$id = $this->request->data('id');
39
40
		$dados = array ('ativo' => '0');
41
		$parametros = array ('id' => $id);
42
43
		if ($this->AviseMe->updateAll($dados, $parametros)) {
44
			echo json_encode(true);
45
		} else {
46
			echo json_encode(false);
47
		}
48
	}
49
50
	/**
51
	* @return boolean
52
	* Cadastra as informações
53
	**/
54
	public function cadastrar_avise_me()
55
	{	
56
		try 
57
		{
58
			$this->loadModel('AviseMe');
59
60
			$this->AviseMe->set($this->request->data);
61
62
			if (!$this->AviseMe->validates())
63
			{
64
				return $this->AviseMe->validationErrors;
65
			}
66
67
			if (!$this->AviseMe->save($this->request->data))
68
			{
69
				return false;
70
			}
71
72
			return true;
73
		} 
74
		catch (Exception $e) 
75
		{
76
			throw new Exception("Error Processing Request", 1);
77
		}
78
79
		return false;
0 ignored issues
show
Unused Code introduced by
return false; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
80
	}
81
82
	public function enviar_email_aviseme($produto_id, $email)
0 ignored issues
show
Unused Code introduced by
The parameter $email is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
	{
84
		try {
85
			$this->loadModel('Produto');
86
87
			$produto = $this->Produto->find('all',
88
				array('conditions' => 
89
					array('Produto.id' => $produto_id
90
					)
91
				)
92
			);
93
94
			App::uses('CakeEmail', 'Network/Email');
95
96
			$email = new CakeEmail('default');
97
			$email->from('[email protected]', 'reginaldo')
98
				->to('[email protected]')
99
				->subject('Produto Aviso');
100
			
101
			$mensagem = '
102
						<p><strong>Nome</strong>: '. $produto[0]['Produto']['nome'] .'</p>
103
					    ';
104
			
105
			if ($email->send($mensagem)) {
106
				return true;
107
			}
108
			
109
			return false;
110
		} catch (Exception $e) {
111
			throw new Exception($e->getMessage(), 1);
112
		}
113
	}
114
115
}