157 lines
2.9 KiB
PHP
157 lines
2.9 KiB
PHP
<?php
|
|
class news
|
|
{
|
|
private $db; //传入PDO对象
|
|
public $ptype; //文档分类
|
|
public $tbl_archives; //文档表
|
|
public $tbl_categorys; //栏目表
|
|
public $tbl_catalog; //文档栏目关联表
|
|
public $tbl_tag; //关键字表
|
|
|
|
function __construct($db)
|
|
{
|
|
$this->db = $db;
|
|
$this->ptype();
|
|
$this->tbl_archives = "archive";
|
|
$this->tbl_categorys = "ar_category";
|
|
$this->tbl_catalog = "ar_catalog";
|
|
$this->tbl_tag = "ar_tag";
|
|
}
|
|
|
|
//文档分类
|
|
//在数组中设置档案分类
|
|
// "中文名称" => "数据库中标识"
|
|
function ptype (){
|
|
$this->ptype = array(
|
|
"新闻" => "news",
|
|
"数据新闻" => "datanews",
|
|
"说明文档" => "help",
|
|
"FAQ" => "faq"
|
|
);
|
|
}//ptype()
|
|
|
|
/*
|
|
递归获得所有栏目
|
|
*/
|
|
function getAllCategory($hide = true){
|
|
|
|
if($hide == -1)
|
|
{
|
|
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
|
|
ORDER BY displayorder asc";
|
|
}else{
|
|
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
|
|
WHERE is_pub = $hide
|
|
ORDER BY displayorder asc";
|
|
}
|
|
|
|
$re = $this->db->query($sql);
|
|
$categorys = $re->fetchAll();
|
|
|
|
return $categorys;
|
|
}
|
|
|
|
//取得最顶级的栏目
|
|
function getTopType(){
|
|
$sql = "SELECT c.* FROM ".$this->tbl_categorys." c
|
|
WHERE is_pub = true AND fid=0
|
|
ORDER BY displayorder asc";
|
|
$re = $this->db->query($sql);
|
|
$categorys = $re->fetchAll();
|
|
return $categorys;
|
|
}
|
|
|
|
//获得栏目
|
|
function getCategory($id)
|
|
{
|
|
$sql = "SELECT * FROM ".$this->tbl_categorys." WHERE id=?";
|
|
$sth = $this->db->prepare($sql);
|
|
$sth->execute(array($id));
|
|
$rows = $sth->fetch();
|
|
return $rows;
|
|
}
|
|
|
|
/*
|
|
写入关系表
|
|
*/
|
|
function ToCatalog($aid,$cid,$uuid='',$status=0){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(empty($cid) && empty($uuid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$data = array(
|
|
"aid" => $aid,
|
|
"cid" => $cid,
|
|
"status" => $status
|
|
);
|
|
|
|
if(!empty($uuid))
|
|
{
|
|
$data['uuid'] = $uuid;
|
|
}
|
|
|
|
if($this->db->insert($this->tbl_catalog,$data))
|
|
{
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
|
|
}//ToCatalog()
|
|
|
|
//写入标签关系
|
|
function MakeTags(){
|
|
|
|
return true;
|
|
|
|
}//MakeTags
|
|
|
|
//修改文档状态
|
|
function ChangeStatus($aid,$pub){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if(!is_bool($pub))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$data = array(
|
|
"is_pub" => $pub
|
|
);
|
|
|
|
if($this->db->update($this->tbl_archives,$data,"id=$aid"))
|
|
{
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}//修改文档状态
|
|
|
|
//删除文档
|
|
function DeleteArchives($aid){
|
|
|
|
if(empty($aid) || !is_numeric($aid))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$sql = "DELETE FROM ".$this->tbl_archives." WHERE id=$aid";
|
|
@$this->db->exec($sql);
|
|
|
|
$sql = "DELETE FROM ".$this->tbl_catalog." WHERE aid=$aid";
|
|
@$this->db->exec($sql);
|
|
|
|
return true;
|
|
}//DeleteArchives
|
|
} |