<?php 



class DaoVideo extends conexao {

public function Atualizar(video $video) {

try {

if ($video->getVid_id() != '') {

$sql = " UPDATE video SET
vid_titulo = ?,
vid_imagem = ?,
vid_link = ?,
vid_status = ?
WHERE vid_id = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $video->getVid_titulo());
$stmt->bindValue(2, $video->getVid_imagem());
$stmt->bindValue(3, $video->getVid_link());
$stmt->bindValue(4, $video->getVid_status());
$stmt->bindValue(5, $video->getVid_id());


} else {

$sql = " INSERT INTO video (vid_titulo,vid_imagem,vid_link,vid_status)
VALUES (?,?,?,?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $video->getVid_titulo());
$stmt->bindValue(2, $video->getVid_imagem());
$stmt->bindValue(3, $video->getVid_link());
$stmt->bindValue(4, $video->getVid_status());


}
if ($stmt->execute()){
return true;
} else
return false;

} catch (Exception $e) {
print "Erro ao tentar atualizar: ".$e;
}

}

public function PesquisarVideo($codigo){
$sql = " SELECT * FROM video WHERE vid_id = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $codigo);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

public function ListarVideo(){
$sql = " SELECT * FROM video ORDER BY vid_id ";
$stmt = self::conectar()->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}



public function ListarVideoStatus(){
$sql = " SELECT * FROM video WHERE vid_status = 'ATIVO' ORDER BY vid_id ";
$stmt = self::conectar()->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

	
public function deletar($vid_id){		
$sql = " DELETE FROM video WHERE vid_id = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $vid_id); 
$stmt->execute();
}

 
}
