#422 重新编写了数据新闻功能,文档类中优化若干操作,添加单文档字段调用方法。处理文档控制器中的文档时间判断bug,增加数据新闻相关内容的元数据标题和链接展示
This commit is contained in:
parent
6384c029cb
commit
8ae51fb0fb
|
@ -177,10 +177,10 @@ class ArchivesController extends Zend_Controller_Action
|
|||
|
||||
$this->view->deepField = $category->DeepTitle;
|
||||
|
||||
$time = date("Y-m-d",time());
|
||||
$time = date("Y-m-d H:i:s",time());
|
||||
|
||||
|
||||
$sql = "SELECT n.*,c.title as typename,c.code,u.realname as author FROM ".$News->tbl_archives." n
|
||||
$sql = "SELECT n.*,c.title as typename,c.code,u.realname as author,ct.uuid as mduuid FROM ".$News->tbl_archives." n
|
||||
left join ".$News->tbl_catalog." ct on ct.aid=n.id
|
||||
left join ".$News->tbl_categorys." c ON ct.cid=c.id
|
||||
LEFT JOIN users u ON n.userid=u.id
|
||||
|
@ -197,6 +197,14 @@ class ArchivesController extends Zend_Controller_Action
|
|||
|
||||
$this->view->infos = $row;
|
||||
|
||||
if(!empty($row['mduuid']))
|
||||
{
|
||||
$sql = "SELECT uuid,title FROM metadata WHERE uuid='{$row['mduuid']}'";
|
||||
$sth = $this->db->query($sql);
|
||||
$mdinfo = $sth->fetch();
|
||||
}
|
||||
$this->view->mdinfo = $mdinfo;
|
||||
|
||||
}
|
||||
|
||||
function searchAction()
|
||||
|
|
|
@ -15,7 +15,7 @@ class AuthorController extends Zend_Controller_Action
|
|||
// 调试模式中将显示全部错误细节,电子邮件将发往调试邮箱
|
||||
// 1 为开启
|
||||
// 0 为关闭
|
||||
public $debug = 0;
|
||||
public $debug = 1;
|
||||
|
||||
//调试模式邮箱地址
|
||||
public $debug_email = "wangliangxu@lzb.ac.cn";
|
||||
|
@ -1234,44 +1234,58 @@ class AuthorController extends Zend_Controller_Action
|
|||
$u_id = $user->id;
|
||||
}
|
||||
|
||||
$News = new Archive($this->db);
|
||||
$category = new ArchiveCategory($this->db);
|
||||
|
||||
//新闻列表
|
||||
if(empty($ac) || $ac=="list")
|
||||
{
|
||||
$keyword = $this->_request->getParam('q');
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
|
||||
$wheresql = "";
|
||||
$wheresql = array();
|
||||
$join = "";
|
||||
|
||||
if(!empty($keyword))
|
||||
{
|
||||
$this->view->q = $keyword;
|
||||
$search = new Search($keyword);
|
||||
$wheresql = $search->sql_expr(array("arc.title","arc.description"));
|
||||
}
|
||||
|
||||
if(!empty($wheresql))
|
||||
{
|
||||
$wheresql = " AND ".$wheresql;
|
||||
$wheresql[] = $search->sql_expr(array("arc.title","arc.description"));
|
||||
}
|
||||
|
||||
if(!empty($uuid) && preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
|
||||
{
|
||||
$join = "LEFT JOIN news_mdnews mdnews ON mdnews.aid=arc.id";
|
||||
$wheresql .= " AND mdnews.uuid='$uuid'";
|
||||
$wheresql[] = " ct.uuid='$uuid' ";
|
||||
}
|
||||
|
||||
$sql = "SELECT arc.id,arc.title,arc.ts_published,arc.description,u.realname FROM news_archives arc
|
||||
$wheresql[] = " c.code='".$category->DataNewsCode."' ";
|
||||
$wheresql[] = " ct.uuid IS NOT NULL ";
|
||||
$wheresql[] = " arc.userid=$u_id";
|
||||
|
||||
if(count($wheresql)>0)
|
||||
{
|
||||
$wheresql = " WHERE ".join(" AND ",$wheresql);
|
||||
}
|
||||
|
||||
$sql = "SELECT arc.*,c.id as cid,u.realname,md.title as mdtitle,md.uuid as mduuid FROM ".$News->tbl_archives." arc
|
||||
LEFT JOIN ".$News->tbl_catalog." ct ON arc.id=ct.aid
|
||||
LEFT JOIN ".$News->tbl_categorys." c ON ct.cid=c.id
|
||||
LEFT JOIN users u ON arc.userid=u.id
|
||||
$join
|
||||
WHERE arc.is_pub>0 AND arc.ts_published<'now()' $wheresql
|
||||
ORDER BY arc.ts_published";
|
||||
LEFT JOIN metadata md ON ct.uuid=md.uuid
|
||||
$wheresql
|
||||
ORDER BY arc.ts_published DESC";
|
||||
|
||||
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute();
|
||||
$rows = $sth->fetchAll();
|
||||
|
||||
foreach($rows as $k=>$v)
|
||||
{
|
||||
$arcinfo = $News->getArchiveUrlByCid($v['id'],$v['cid']);
|
||||
$rows[$k]['url'] = $arcinfo['archive_url'];
|
||||
}
|
||||
|
||||
$paginator = Zend_Paginator::factory($rows);
|
||||
$paginator->setCurrentPageNumber($this->_getParam('page'));
|
||||
$paginator->setItemCountPerPage(10);
|
||||
|
@ -1281,32 +1295,6 @@ class AuthorController extends Zend_Controller_Action
|
|||
|
||||
}
|
||||
|
||||
if($ac == "view")
|
||||
{
|
||||
|
||||
$this->_helper->viewRenderer('news-view');
|
||||
$aid = (int)$this->_request->getParam('aid');
|
||||
|
||||
if(empty($aid) || !is_numeric($aid))
|
||||
{
|
||||
$this->_redirect('/error/error');
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
$this->db->exec("UPDATE news_archives arc SET click=click+1 WHERE arc.id=$aid");
|
||||
$sql = "SELECT arc.*,u.realname FROM news_archives arc
|
||||
LEFT JOIN users u ON u.id=arc.userid
|
||||
WHERE arc.id=?";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth -> execute(array($aid));
|
||||
$row = $sth->fetch();
|
||||
$this->view->info = $row;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//新闻发布
|
||||
if($ac == "add")
|
||||
{
|
||||
|
@ -1329,21 +1317,41 @@ class AuthorController extends Zend_Controller_Action
|
|||
$this->_helper->viewRenderer('news-edit');
|
||||
|
||||
$aid = (int)$this->_request->getParam('aid');
|
||||
$uuid = $this->_request->getParam('uuid');
|
||||
|
||||
if(empty($aid) || !is_numeric($aid))
|
||||
{
|
||||
$this->_redirect('/error/error');
|
||||
}
|
||||
|
||||
$sql = "SELECT arc.*,mdarc.uuid FROM news_archives arc
|
||||
LEFT JOIN news_mdnews mdarc ON mdarc.aid = arc.id
|
||||
if(!preg_match("/^[0-9A-Za-z]{8}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{4}-[0-9A-Za-z]{12}$/",$uuid))
|
||||
{
|
||||
$this->_redirect('/error/error');
|
||||
}
|
||||
|
||||
$this->view->uuid = $uuid;
|
||||
|
||||
$sql = "SELECT arc.* FROM ".$News->tbl_archives." arc
|
||||
WHERE id=?";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($aid));
|
||||
$row = $sth->fetch();
|
||||
|
||||
$keywords = $News->GetTags($aid);
|
||||
$row['keywords'] = join(",",$keywords);
|
||||
|
||||
$this->view->info = $row;
|
||||
|
||||
$sql = "SELECT md.title,md.uuid FROM metadata md
|
||||
LEFT JOIN mdauthor a ON a.uuid = md.uuid
|
||||
WHERE a.userid=? AND a.status=1
|
||||
";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$sth->execute(array($u_id));
|
||||
$rows = $sth->fetchAll();
|
||||
|
||||
$this->view->md = $rows;
|
||||
|
||||
}//$ac == "edit"
|
||||
|
||||
//新闻发布的ajax动作
|
||||
|
@ -1436,47 +1444,28 @@ class AuthorController extends Zend_Controller_Action
|
|||
|
||||
//默认填充数据
|
||||
$data['source'] = "西部数据中心";
|
||||
$data['typeid'] = 0;
|
||||
$data['userid'] = $u_id;
|
||||
$data['keyword'] = str_replace(",",",",$data['keyword']);
|
||||
$keyword = str_replace(",",",",$data['keyword']);
|
||||
$data['ts_published'] = date("Y-m-d H:i:s",time());
|
||||
$data['is_pub'] = true;
|
||||
$data['image'] = "";
|
||||
|
||||
unset($data['keyword']);
|
||||
|
||||
$dataNewsCategory = $category->GetOne('datanews');
|
||||
$dataNewsCategoryID = $dataNewsCategory['id'];
|
||||
|
||||
//新闻添加
|
||||
if(empty($aid))
|
||||
{
|
||||
$sql = "INSERT INTO news_archives
|
||||
(userid,title,keywords,description,image,source,ts_published,is_pub,body)
|
||||
VALUES
|
||||
(?,?,?,?,?,?,?,?,?)
|
||||
RETURNING id
|
||||
";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$ex = $sth -> execute(array($data['userid'],$data['title'],$data['keyword'],$data['description'],'',$data['source'],'now()',1,$data['body']));
|
||||
|
||||
$newAid = $News->addArchive($data,$dataNewsCategoryID,$keyword,$uuid);
|
||||
//添加成功
|
||||
if($ex)
|
||||
{
|
||||
//写入文章ID对应UUID的表
|
||||
$archive = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$aid = $archive['id'];
|
||||
|
||||
$sql = "INSERT INTO news_mdnews (aid,uuid) VALUES (?,?)";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$uuidex = $sth->execute(array($aid,$uuid));
|
||||
|
||||
if($uuidex)
|
||||
if($newAid>0)
|
||||
{
|
||||
$msg['status'] = 1;
|
||||
$msg['outstring'] = "新闻添加成功";
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
|
||||
return true;
|
||||
}else{
|
||||
$sql = "DELETE FROM news_archives WHERE id=$aid";
|
||||
@$this->db->exec($sql); //如果新闻添加失败就删除原新闻,否则产生重复错误
|
||||
$msg['status'] = 0;
|
||||
$msg['error'] = "新闻添加失败,请重试";
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
|
||||
return true;
|
||||
}
|
||||
//添加失败
|
||||
}else{
|
||||
$msg['status'] = 0;
|
||||
|
@ -1489,11 +1478,15 @@ class AuthorController extends Zend_Controller_Action
|
|||
//新闻修改
|
||||
else
|
||||
{
|
||||
$sql = "UPDATE news_archives SET title=?,keywords=?,description=?,body=? WHERE id=? AND userid=?";
|
||||
$sth = $this->db->prepare($sql);
|
||||
$ex = $sth -> execute(array($data['title'],$data['keyword'],$data['description'],$data['body'],$aid,$data['userid']));
|
||||
|
||||
if($ex)
|
||||
if($u_id != $News->getArchiveField($aid,"userid"))
|
||||
{
|
||||
$msg['status'] = 0;
|
||||
$msg['outstring'] = "新闻编辑失败,您没有权限";
|
||||
$this->getResponse()->setHeader('Content-Type', 'application/json')->appendBody(Zend_Json::encode($msg));
|
||||
return true;
|
||||
}
|
||||
$updated = $News->updateArchive($aid,$data,$dataNewsCategoryID,$keyword,$uuid);
|
||||
if($updated)
|
||||
{
|
||||
$msg['status'] = 1;
|
||||
$msg['outstring'] = "新闻编辑成功";
|
||||
|
@ -1526,7 +1519,35 @@ class AuthorController extends Zend_Controller_Action
|
|||
}//catch end
|
||||
}//$ac = 'newsadd' endif;
|
||||
|
||||
if($ac == "del")
|
||||
{
|
||||
$this->_helper->layout->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender();
|
||||
|
||||
$aid = $this->_getParam('aid');
|
||||
if(!is_numeric($aid))
|
||||
{
|
||||
$this->jsonexit(array("error"=>"参数错误"));
|
||||
return true;
|
||||
}
|
||||
|
||||
$News = new Archive($this->db);
|
||||
|
||||
if($u_id != $News->getArchiveField($aid,"userid"))
|
||||
{
|
||||
$this->jsonexit(array("error"=>"您没有权限"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if($News->DeleteArchives($aid))
|
||||
{
|
||||
$this->jsonexit(array("deleted"=>$aid));
|
||||
return true;
|
||||
}else{
|
||||
$this->jsonexit(array("error"=>"删除失败",'aid'=>$aid));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}//newsAction() 数据新闻
|
||||
|
||||
function viewauthorsAction(){
|
||||
|
|
|
@ -40,6 +40,9 @@ $this->headMeta()->appendName('description', mb_substr($this->infos['description
|
|||
|
||||
<div class="title"><?php echo $this->infos['title'];?></div>
|
||||
<div class="info">时间 : <?php echo date("Y-m-d H:i",strtotime($this->infos['ts_published']));?> 作者 : <?php echo $this->infos['author'];?> 来源 : <?php echo $this->infos['source'];?></div>
|
||||
<?php if(!empty($this->mdinfo)){?>
|
||||
<div class="info">相关数据:《<a href="/data/<?= $this->mdinfo['uuid']?>"><?= $this->mdinfo['title']?></a>》</div>
|
||||
<?php } ?>
|
||||
<div class="archive_content">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
|
|
|
@ -38,6 +38,27 @@ $this->breadcrumb()->setSeparator(' > ');
|
|||
<input type="text" id="producttitle" class="half" value="<?php echo $this->info['title'];?>" name="title" maxlength="100"/>
|
||||
<small>请准确概况新闻内容</small>
|
||||
</p>
|
||||
<p>
|
||||
<label class="required" for="data">相关数据</label><br/>
|
||||
<select id="data" name="uuid">
|
||||
<option value="0">请选择相关数据</option>
|
||||
<?php
|
||||
if(!empty($this->md))
|
||||
{
|
||||
foreach($this->md as $v)
|
||||
{
|
||||
if($v['uuid'] == $this->uuid)
|
||||
{
|
||||
echo '<option value="'.$v['uuid'].'" selected="selected">'.$v['title'].'</option>';
|
||||
}else{
|
||||
echo '<option value="'.$v['uuid'].'">'.$v['title'].'</option>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
<small>从数据中选择一条</small>
|
||||
</p>
|
||||
<p>
|
||||
<label class="required" for="producttitle">标签</label><br/>
|
||||
<input type="text" id="keyword" class="half" value="<?php echo $this->info['keywords'];?>" name="keyword"/>
|
||||
|
|
|
@ -4,6 +4,8 @@ $this->headTitle($this->config->title->author);
|
|||
$this->headTitle()->setSeparator(' - ');
|
||||
$this->headScript()->appendFile('/js/jquery-1.7.min.js');
|
||||
$this->headLink()->appendStylesheet('/css/author.css');
|
||||
$this->headScript()->appendFile('/js/jquery.colorbox-min.js');
|
||||
$this->headLink()->appendStylesheet('/css/colorbox.css');
|
||||
$this->breadcrumb('<a href="/">首页</a>');
|
||||
$this->breadcrumb('<a href="/author">数据作者</a>');
|
||||
$this->breadcrumb('数据新闻');
|
||||
|
@ -37,9 +39,14 @@ $this->breadcrumb()->setSeparator(' > ');
|
|||
foreach ($this->paginator as $item):
|
||||
$autoindex++;
|
||||
?>
|
||||
<li>
|
||||
<p><a href="/author/news/ac/view/aid/<?php echo $item['id'];?>" class="title"><?php echo $item['title'];?></a></p>
|
||||
<p>作者:<?php echo $item['realname'];?> 发布时间:<?php echo date("Y-m-d",strtotime($item['ts_published']));?></p>
|
||||
<li id="item_<?= $item['id'] ?>">
|
||||
<p><a href="<?php echo $item['url'];?>" class="title"><?php echo $item['title'];?></a></p>
|
||||
<p>
|
||||
作者:<?php echo $item['realname'];?> |
|
||||
发布时间:<?php echo date("Y-m-d",strtotime($item['ts_published']));?> |
|
||||
关联数据:《<a href="/data/<?= $item['mduuid'] ?>"><?php echo $item['mdtitle'];?></a>》 |
|
||||
操作:<a href="/author/news/ac/edit/aid/<?= $item['id']?>/uuid/<?= $item['mduuid'] ?>">编辑</a> ·
|
||||
<a href="javascript:;" onclick="del(<?= $item['id'] ?>)" id="delBtn_<?= $item['id'] ?>">删除</a></p>
|
||||
<p><?php echo $item['description'];?></p>
|
||||
</li>
|
||||
<?php
|
||||
|
@ -52,5 +59,34 @@ $this->breadcrumb()->setSeparator(' > ');
|
|||
<!-- //页面内容 -->
|
||||
<script>
|
||||
$('#wapper').width($('body').width()-300);
|
||||
|
||||
function del(id){
|
||||
var dom = "#delBtn_"+id;
|
||||
var html = $(dom).html();
|
||||
$.ajax({
|
||||
'type':"POST",
|
||||
'url':'/author/news/ac/del',
|
||||
'data':'aid='+id,
|
||||
'success':function(data){
|
||||
if (typeof(data)=='object')
|
||||
{
|
||||
if(typeof(data.error)!='undefined')
|
||||
{Alert(data.error);return false;}
|
||||
if(typeof(data.msg)!='undefined')
|
||||
{Alert(data.msg);}
|
||||
if(typeof(data.deleted)!='undefined')
|
||||
{$('#item_'+id).fadeOut(function(){$(this).remove();});}
|
||||
}
|
||||
else{
|
||||
Alert('出现错误,请稍后再试');
|
||||
}
|
||||
},
|
||||
'timeout': 30000,
|
||||
'error': function(){Alert('处理中出现错误,请刷新页面后重试');},
|
||||
'beforeSend':function(){$(dom).html('<img src="/images/ajax-load-small.gif" />');$(dom).attr("disabled","disabled")},
|
||||
'complete':function(){$(dom).html(html);$(dom).removeAttr("disabled");dom = null;}
|
||||
});
|
||||
}
|
||||
function Alert(html){
|
||||
$.colorbox({'innerWidth':'50%','html':'<h4>'+html+'</h4>'});
|
||||
}
|
||||
</script>
|
|
@ -124,22 +124,32 @@ class Archive
|
|||
foreach($rows as $k=>$v)
|
||||
{
|
||||
$types[] = $v['cid'];
|
||||
if(is_array($typeid))
|
||||
{
|
||||
if(!in_array($v['cid'],$typeid))
|
||||
{
|
||||
//删除一个栏目
|
||||
$this->DeleteCatalog($v['id']);
|
||||
}
|
||||
}else{
|
||||
$this->DeleteCatalog($v['id']);
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($typeid))
|
||||
{
|
||||
foreach($typeid as $v)
|
||||
{
|
||||
|
||||
if(!in_array($v,$types))
|
||||
{
|
||||
//添加一个栏目
|
||||
$this->ToCatalog($aid,$v);
|
||||
$this->ToCatalog($aid,$v,$uuid,$status);
|
||||
}
|
||||
}
|
||||
}else{
|
||||
$this->ToCatalog($aid,$typeid,$uuid,$status);
|
||||
}
|
||||
return true;
|
||||
}catch(Exception $e){
|
||||
return $e->getMessage();
|
||||
|
@ -204,7 +214,7 @@ class Archive
|
|||
{
|
||||
$tag = explode(",",$keywords);
|
||||
}else{
|
||||
if($this->db->insert($this->tbl_tag,array("id"=>$aid,"tag"=>$tag)))
|
||||
if($this->db->insert($this->tbl_tag,array("id"=>$aid,"tag"=>$keywords)))
|
||||
{
|
||||
return true;
|
||||
}else{
|
||||
|
@ -275,7 +285,7 @@ class Archive
|
|||
*
|
||||
* @return int;
|
||||
*/
|
||||
function addArchive($data,$typeid,$keyword='')
|
||||
function addArchive($data,$typeid,$keyword='',$uuid='')
|
||||
{
|
||||
|
||||
$data = $this->scanField($data);
|
||||
|
@ -303,7 +313,7 @@ class Archive
|
|||
{
|
||||
$temp = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
$newAid = $temp['id'];
|
||||
$this->AddToCatalog($newAid,$typeid);
|
||||
$this->AddToCatalog($newAid,$typeid,$uuid);
|
||||
if(!empty($keyword))
|
||||
{
|
||||
$this->MakeTags($newAid,$keyword);
|
||||
|
@ -325,7 +335,7 @@ class Archive
|
|||
*
|
||||
* @return int
|
||||
*/
|
||||
function updateArchive($aid,$data,$typeid,$keyword='')
|
||||
function updateArchive($aid,$data,$typeid,$keyword='',$uuid='')
|
||||
{
|
||||
if(!is_numeric($aid))
|
||||
{
|
||||
|
@ -356,7 +366,7 @@ class Archive
|
|||
$this->DeleteTags($aid);
|
||||
$this->MakeTags($aid,$keyword);
|
||||
}
|
||||
$this->ChangeCatalog($aid,$typeid);
|
||||
$this->ChangeCatalog($aid,$typeid,$uuid);
|
||||
return $aid;
|
||||
}else{
|
||||
return 0;
|
||||
|
@ -503,4 +513,25 @@ class Archive
|
|||
$rows=$sth->fetch();
|
||||
return $rows;
|
||||
}
|
||||
|
||||
/*
|
||||
* getArchiveField() 读取某个文档的某个字段
|
||||
*
|
||||
* @param int $aid
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function getArchiveField($aid,$field)
|
||||
{
|
||||
if(!is_numeric($aid))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$sql = "SELECT $field as output_string FROM ".$this->tbl_archives." WHERE id=$aid";
|
||||
$sth = $this->db->query($sql);
|
||||
$row = $sth->fetch();
|
||||
|
||||
return $row['output_string'];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -241,12 +241,12 @@ class ArchiveCategory
|
|||
|
||||
if(is_numeric($tid))
|
||||
{
|
||||
$wehresql = "id=$tid";
|
||||
$wheresql = "id=$tid";
|
||||
}else{
|
||||
$wheresql = "code='$tid'";
|
||||
}
|
||||
|
||||
$sql = "SELECT * FROM ".$this->CategoryTable." WHERE id=$tid";
|
||||
$sql = "SELECT * FROM ".$this->CategoryTable." WHERE $wheresql";
|
||||
$sth = $this->db->query($sql);
|
||||
return $sth->fetch();
|
||||
|
||||
|
|
Loading…
Reference in New Issue