2012-09-04 07:16:19 +00:00
|
|
|
<?php
|
|
|
|
class news
|
|
|
|
{
|
2012-11-23 09:54:37 +00:00
|
|
|
private $db; //传入PDO对象
|
|
|
|
public $ptype; //文档分类
|
|
|
|
public $tbl_archives; //文档表
|
|
|
|
public $tbl_categorys; //栏目表
|
|
|
|
public $tbl_catalog; //文档栏目关联表
|
|
|
|
public $tbl_tag; //关键字表
|
2012-09-04 07:16:19 +00:00
|
|
|
|
|
|
|
function __construct($db)
|
|
|
|
{
|
|
|
|
$this->db = $db;
|
2012-11-23 09:54:37 +00:00
|
|
|
$this->ptype();
|
|
|
|
$this->tbl_archives = "archive";
|
|
|
|
$this->tbl_categorys = "ar_category";
|
|
|
|
$this->tbl_catalog = "ar_catalog";
|
|
|
|
$this->tbl_tag = "ar_tag";
|
2012-09-04 07:16:19 +00:00
|
|
|
}
|
2012-11-23 09:54:37 +00:00
|
|
|
|
|
|
|
//文档分类
|
|
|
|
//在数组中设置档案分类
|
|
|
|
// "中文名称" => "数据库中标识"
|
|
|
|
function ptype (){
|
|
|
|
$this->ptype = array(
|
|
|
|
"新闻" => "news",
|
|
|
|
"数据新闻" => "datanews",
|
|
|
|
"说明文档" => "help",
|
|
|
|
"FAQ" => "faq"
|
|
|
|
);
|
|
|
|
}//ptype()
|
2012-09-04 07:16:19 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
递归获得所有栏目
|
|
|
|
*/
|
2012-11-23 09:54:37 +00:00
|
|
|
function getAllCategory($hide = true){
|
2012-09-04 07:16:19 +00:00
|
|
|
|
2012-11-23 09:54:37 +00:00
|
|
|
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
|
2012-09-04 07:16:19 +00:00
|
|
|
ORDER BY displayorder asc";
|
2012-11-23 09:54:37 +00:00
|
|
|
}
|
|
|
|
|
2012-09-04 07:16:19 +00:00
|
|
|
$re = $this->db->query($sql);
|
|
|
|
$categorys = $re->fetchAll();
|
|
|
|
|
|
|
|
return $categorys;
|
|
|
|
}
|
|
|
|
|
2012-11-23 09:54:37 +00:00
|
|
|
//取得最顶级的栏目
|
|
|
|
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
|
2012-09-04 07:16:19 +00:00
|
|
|
}
|