Viewing file: blog_textos_class.php (5.51 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
class BlogTextos {
var $id, $data, $titulo, $texto, $qtd_leituras, $ativo, $deletado;
var $conexao, $tabela;
function BlogTextos() {
$this->id = Null;
$this->data = Null;
$this->titulo = Null;
$this->texto = Null;
$this->autor = Null;
$this->qtd_leituras = Null;
$this->deletado = Null;
$this->tabela = "blog_textos";
global $conexao;
$this->conexao = $conexao;
}
function get($nome) {
return stripslashes($this->$nome);
}
function set($nome,$valor) {
$this->$nome = $valor;
}
function carrega($dados) {
$this->id = $dados['BTX_RowID'];
$this->data = formata_data($dados['BTX_Data']);
$this->titulo = $dados['BTX_Titulo'];
$this->texto = $dados['BTX_Texto'];
$this->autor = $dados['BTX_Autor'];
$this->qtd_leituras = $dados['BTX_QtdLeituras'];
$this->ativo = $dados['BTX_AtivoSN'];
$this->deletado = $dados['BTX_DeletadoSN'];
}
function verNotNull() {
if (strlen($this->get("qtd_leituras"))==0)
$this->set("qtd_leituras","0");
if (strlen($this->get("data"))==0)
$this->set("data",date("d/m/Y H:i:s"));
if (strlen($this->get("ativo"))==0)
$this->set("ativo","S");
if (strlen($this->get("deletado"))==0)
$this->set("deletado","N");
if (
(strlen($this->get("data"))==0) or
(strlen($this->get("titulo"))==0) or
(strlen($this->get("texto"))==0) or
(strlen($this->get("autor"))==0) or
(strlen($this->get("qtd_leituras"))==0) or
(strlen($this->get("deletado"))==0) or
(strlen($this->get("ativo"))==0)
) {
return false;
}
else
return true;
}
function inserir() {
if (!$this->verNotNull())
return false;
$data = "'".prepara_data($this->get("data"))."'";
$titulo = "'".$this->get("titulo")."'";
$texto = "'".$this->get("texto")."'";
$autor = "'".$this->get("autor")."'";
$qtd_leituras = "'".$this->get("qtd_leituras")."'";
$ativo = "'".$this->get("ativo")."'";
$deletado = "'".$this->get("deletado")."'";
$sql = "INSERT INTO $this->tabela (BTX_Data, BTX_Titulo, BTX_Texto, BTX_Autor, BTX_QtdLeituras, BTX_AtivoSN, BTX_DeletadoSN) VALUES ($data, $titulo, $texto, $autor, $qtd_leituras, $ativo, $deletado)";
if ($this->conexao->Executar($sql)) {
$this->set("id",mysql_insert_id($this->conexao->conexao));
return true;
}
else {
$this->set("id","");
return false;
}
}
function alterar($id) {
if (!is_numeric($id)) return false;
if (!$this->verNotNUll())
return false;
$this->set("id",$id);
$data = "'".prepara_data($this->get("data"))."'";
$titulo = "'".$this->get("titulo")."'";
$texto = "'".$this->get("texto")."'";
$autor = "'".$this->get("autor")."'";
$ativo = "'".$this->get("ativo")."'";
$sql = "UPDATE $this->tabela SET BTX_Data = $data, BTX_Titulo = $titulo, BTX_Texto = $texto, BTX_Autor = $autor, BTX_AtivoSN = $ativo WHERE BTX_RowID = $id";
if ($this->conexao->Executar($sql))
return true;
else
return false;
}
function deletar($id) {
if (!$this->buscar($id)) return false;
return $this->conexao->Executar("UPDATE $this->tabela SET BTX_AtivoSN = 'N', BTX_DeletadoSN = 'S' WHERE BTX_RowID=".$this->get("id"));
}
function buscar($id) {
if (!is_numeric($id)) return false;
$dados = $this->conexao->UmFetch("SELECT * FROM $this->tabela WHERE BTX_RowID=$id");
if (is_array($dados)) {
$this->carrega($dados);
return true;
}
else
return false;
}
function listar($where="",$orderby="",$inicio="",$qtd="") {
$sql = "SELECT * FROM $this->tabela";
if ($where) $where = "($where) AND BTX_DeletadoSN = 'N'";
else $where = "BTX_DeletadoSN = 'N'";
$sql = $sql." WHERE ".$where;
if ($orderby) $sql = $sql." ORDER BY ".$orderby;
if (is_numeric($inicio) and is_numeric($qtd))
$sql = $sql." LIMIT $inicio,$qtd";
return $this->conexao->Executar($sql);
}
function listar_ativos($where="",$orderby="BTX_Data DESC",$inicio="",$qtd="") {
if ($where) $where = "($where) AND BTX_AtivoSN = 'S'";
else $where = "BTX_AtivoSN = 'S'";
return $this->listar($where,$orderby,$inicio,$qtd);
}
function buscar_ultimo_ativo() {
$this->Fetch($this->listar_ativos("","BTX_Data DESC","0","1"));
return is_numeric($this->get('id'));
}
function Fetch($resultado) {
$dados = $this->conexao->Fetch($resultado);
if ($dados) {
$this->carrega($dados);
return true;
}
else
return false;
}
function ativar($id) {
if (!is_numeric($id)) return false;
return $this->conexao->Executar("UPDATE $this->tabela SET BTX_AtivoSN = 'S' WHERE BTX_RowID = $id");
}
function desativar($id) {
if (!is_numeric($id)) return false;
return $this->conexao->Executar("UPDATE $this->tabela SET BTX_AtivoSN = 'N' WHERE BTX_RowID = $id");
}
function ativar_desativar($id) {
if (!is_numeric($id)) return false;
$this->buscar($id);
if ($this->get("ativo")=='S')
return $this->desativar($id);
else
return $this->ativar($id);
}
function informa_leitura($id="") {
if (!is_numeric($id))
$id = $this->get('id');
if (!is_numeric($id))
return false;
return $this->conexao->Executar("UPDATE $this->tabela SET BTX_QtdLeituras = BTX_QtdLeituras + 1 WHERE BTX_RowID = $id");
}
}
?>
|