<?php 


class DaoCarrossel extends conexao {

public function Atualizar(carrossel $carrossel) {

try {

if ($carrossel->getCar_id() != '') {

$sql = " UPDATE carrossel SET
car_imagem = ?,
car_titulo = ?,
car_situacao = ?
WHERE car_id = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $carrossel->getCar_imagem());
$stmt->bindValue(2, $carrossel->getCar_titulo());
$stmt->bindValue(3, $carrossel->getCar_situacao());
$stmt->bindValue(4, $carrossel->getCar_id());


} else {

$sql = " INSERT INTO carrossel (car_imagem,car_titulo,car_situacao)
VALUES (?,?,?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $carrossel->getCar_imagem());
$stmt->bindValue(2, $carrossel->getCar_titulo());
$stmt->bindValue(3, $carrossel->getCar_situacao());


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

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

}

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

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

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

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

public function retornarCarrosselQuatroUltimos(){	
		$sql  = " SELECT car_imagem, car_titulo FROM carrossel WHERE car_situacao='ATIVO' ORDER BY car_id DESC LIMIT 4 ";
		$stmt = self::conectar()->prepare($sql);
		$stmt->execute();
		$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
		return $result;
	}

 
}
