Created
January 9, 2020 22:01
-
-
Save andre-mz/8980fa03b4a2b0d33beec90bdfabc98d to your computer and use it in GitHub Desktop.
Models
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Evento{ | |
private $db; | |
public function __construct(){ | |
$this->db = new Database; | |
} | |
public function getEventos(){ | |
$this->db->query('SELECT *, | |
eventos.id as eventosId, | |
usuario.id as usuarioId, | |
eventos.data_criacao as eventoCriacao, | |
usuario.data_criacao as usuarioCriacao, | |
eventos.img1 as eventoImg, | |
eventos.img2 as eventoImg2 | |
FROM eventos | |
INNER JOIN usuario | |
ON eventos.usuario_id = usuario.id | |
ORDER BY eventos.data_criacao DESC'); | |
$resultado = $this->db->resultaSet(); | |
return $resultado; | |
} | |
public function getEventos2(){ | |
$this->db->query('SELECT *, | |
eventos.id as eventosId, | |
usuario.id as usuarioId, | |
eventos.data_criacao as eventoCriacao, | |
usuario.data_criacao as usuarioCriacao, | |
eventos.img1 as eventoImg, | |
eventos.img2 as eventoImg2 | |
FROM eventos | |
INNER JOIN usuario | |
ON eventos.usuario_id = usuario.id | |
ORDER BY eventos.data_criacao DESC LIMIT 6'); | |
$resultado = $this->db->resultaSet(); | |
return $resultado; | |
} | |
/** | |
* public function getImagem(){ | |
$this->db->query('SELECT * FROM galeria'); | |
$resultado = $this->db->resultaSet(); | |
return $resultado; | |
}*/ | |
//ADD EVENTO | |
public function addEvento($dados){ | |
$this->db->query('INSERT INTO eventos(usuario_id, titulo, cat, data,img1, img2,corpo)VALUES (:usuario_id,:titulo, :cat, :data,:img1, :img2,:corpo)'); | |
$this->db->bind(':usuario_id', $dados['usuario_id']); | |
$this->db->bind(':titulo', $dados['titulo']); | |
$this->db->bind(':cat', $dados['cat']); | |
$this->db->bind(':data', $dados['data']); | |
$this->db->bind(':img1', $dados['img1']); | |
$this->db->bind(':img2', $dados['img2']); | |
$this->db->bind(':corpo', $dados['corpo']); | |
if ($this->db->execute()){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
//PEGA EVENTO PELO ID | |
public function pegaEventoId($id){ | |
$this->db->query('SELECT * FROM eventos WHERE id = :id'); | |
$this->db->bind(':id', $id); | |
$row = $this->db->unico(); | |
return $row; | |
} | |
//ACTUALIZAR EVENTOS | |
public function updateEvento($dados){ | |
$this->db->query('UPDATE eventos SET titulo = :titulo, cat =:cat, data =:data, img1=:img1, img2=:img2,corpo = :corpo WHERE id = :id'); | |
$this->db->bind(':id', $dados['id']); | |
$this->db->bind(':titulo', $dados['titulo']); | |
$this->db->bind(':corpo', $dados['corpo']); | |
$this->db->bind(':cat', $dados['cat']); | |
$this->db->bind(':data', $dados['data']); | |
$this->db->bind(':img1', $dados['img1']); | |
$this->db->bind(':img2', $dados['img2']); | |
$this->db->bind(':corpo', $dados['corpo']); | |
if($this->db->execute()){ | |
return true; | |
} | |
else{ | |
return false; | |
} | |
} | |
//APAGAR EVENTOS | |
public function apagaEvento($id){ | |
$this->db->query('DELETE FROM eventos WHERE id = :id'); | |
$this->db->bind(':id', $id); | |
if ($this->db->execute()){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Usuario{ | |
private $db; | |
public function __construct(){ | |
$this->db = new Database; | |
} | |
/** | |
* Registrar um novo usuario | |
*/ | |
public function registro($dados){ | |
$this->db->query('INSERT INTO usuario(nome, apelido, email, password) VALUES(:nome, :apelido, :email, :password)'); | |
$this->db->bind(':nome', $dados['nome']); | |
$this->db->bind(':apelido', $dados['apelido']); | |
$this->db->bind(':email', $dados['email']); | |
$this->db->bind(':password', $dados['password']); | |
if ($this->db->execute()){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
/** | |
* encontra o usuario pelo email | |
*/ | |
public function econtraUsuarioPorEmail($email){ | |
$this->db->query('SELECT * FROM usuario WHERE email = :email'); | |
$this->db->bind(':email', $email); | |
$row = $this->db->unico(); | |
if ($this->db->rowCount() > 0){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
/** | |
* Login | |
*/ | |
public function login($email, $password){ | |
$this->db->query('SELECT * FROM usuario where email = :email'); | |
$this->db->bind(':email', $email); | |
$row = $this->db->unico(); | |
$hash_password = $row->password; | |
if(password_verify($password, $hash_password)){ | |
return $row; | |
}else{ | |
return false; | |
} | |
} | |
/** | |
* Pega usuarios pelo id | |
*/ | |
public function pegaUsuarioId($id){ | |
$this->db->query('SELECT * FROM usuario WHERE id = :id'); | |
$this->db->bind(':id', $id); | |
$row = $this->db->unico(); | |
return $row; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment