#546 添加数据篮操作的相关类,初步模块化数据篮功能,修改视图中链接bug

This commit is contained in:
Li Jianxuan 2013-07-17 09:53:44 +00:00
parent 8eee6b352a
commit a7462e4921
6 changed files with 2384 additions and 2140 deletions

View File

@ -1450,53 +1450,38 @@ class DataController extends Zend_Controller_Action
function orderAction()
{
$this->view->pageID = "account-dataorder";
$uuid=$this->_request->getParam('uuid');
$ac = $this->_request->getParam('ac');
include_once("helper/view.php");
$uuid = $this->_request->getParam('uuid');
$del = $this->_request->getParam('del');
$apply = $this->_request->getParam('apply');
$finish = $this->_request->getParam('finish');
$cancel = $this->_request->getParam('cancel');
$pdf = $this->_request->getParam('pdf');
$ac = $this->_request->getParam('ac');
//if (empty($uuid)) $this->_redirect('/data');
$userid=Zend_Auth::getInstance()->getIdentity()->id;
include_once("helper/view.php");
$userid = view::User('id');
if ($uuid)
{
//处理数据入库
//离线申请的数据不应该重复因此需要在数据库限制还是在WEB端限制
//在数据库中控制只保证uuid,userid,status唯一就可以?
//存在历史遗留问题,原来的数据并不能保证唯一
//status: 1 开始进入离线申请申请程序中
// 2 填写并提交离线申请表
// 3 邮寄离线申请表
// 4 收到离线申请表
// 5 处理离线申请表
// 10:离线申请完成?
// -1: 取消了在线下载进程
//首先判断离线申请的数据数量是否超过系统限制
$sql="select count(*) as datacount from dataorder where (ts_approved is null) and userid=? and status>0 and status<3";
$r=$this->db->fetchRow($this->db->quoteInto($sql,$userid));
//保证添加的离线数据申请未申请
$sql="select count(*) as datacount from dataorder where (ts_approved is null) and userid='$userid' and uuid=? and status in (1,2,3,4)";
$r1=$this->db->fetchRow($this->db->quoteInto($sql,$uuid));
//保证添加的离线数据是正式发布的数据
$sql="select count(*) as mdcount from heihemetadata where uuid=?";
$r2=$this->db->fetchRow($this->db->quoteInto($sql,$uuid));
if ($r['datacount']<$this->view->config->download->max && $r1['datacount']<1 && $r2['mdcount']>0) {
$sql="insert into dataorder (uuid,ts_created,userid,status) values(?,now(),?,?)";
$this->db->query($sql,array($uuid,$userid,1));
//成功信息提示
$sql=$this->db->quoteInto("select title,uuid from metadata where uuid=?",$uuid);
$this->view->md=$this->db->fetchRow($sql);
} else {
if ($r1['datacount']>=1)
$this->view->msg=view::Msg('alert-error',"错误:您申请的数据已经在数据蓝中!",0);
elseif ($r2['mdcount']==0)
$this->view->msg=view::Msg('alert-error',"错误:您申请的数据不存在。",0);
else
$this->view->msg=view::Msg('alert-error',"错误:您正在进行的离线申请的数据数已经超过系统允许的最大值,请在完成本次离线申请后再进行操作!",0);
$order = new order\Order();
$orderListener = new order\listener\OrderListener();
@$order->events()->attachAggregate($orderListener);
$state = $order->addOrder($uuid);
if($state !== true)
{
$this->view->msg = \view::Msg('alert-error',$state);
}else{
$this->view->msg = \view::Msg('alert-success',"添加成功!您可以继续浏览数据或是继续提交申请表");
}
if (empty($ac)) $ac='offline1';
} elseif ($del) {
//删除数据申请
$sql=$this->db->quoteInto("delete from dataorder where userid=".$userid." and status in (1,2) and id=?",$del);

View File

@ -59,7 +59,7 @@ echo '通过时间';
<?php foreach($this->paginator as $order) : ?>
<tr>
<td><?php echo date('Y-m-d H:i:s',strtotime($order['ts_created'])); ?></td>
<td><a href="<?php echo $order['uuid']; ?>"><?php echo $order['title']; ?></a></td>
<td><a href="/data/<?php echo $order['uuid']; ?>"><?php echo $order['title']; ?></a></td>
<td>
<?php
if ($this->tabID=='order-offline1') {

View File

@ -0,0 +1,99 @@
<?php
namespace order;
include_once("helper/view.php");
class Order
{
private $db;
private $config;
protected $events = NULL;
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
}
public function events(\Zend_EventManager_EventCollection $events = NULL)
{
if ($events !== NULL) {
$this->events = $events;
} elseif ($this->events === NULL) {
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
}
return $this->events;
}
/*************
status:
1 开始进入离线申请申请程序中
2 填写并提交离线申请表
3 邮寄离线申请表
4 收到离线申请表
5 处理离线申请表
10:离线申请完成?
-1: 取消了在线下载进程
**************/
//添加到数据篮
public function addOrder($uuid,$uid = 0){
if(empty($uid))
{
$uid = \view::User('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))
{
return "参数错误";
}
$results = $this->events()->trigger('submit', $this, compact('uuid','uid'));
$data = $results->bottom();
if($data !== true)
{
return $data;
}
if($this->pushToDataorder($uuid,$uid) === true)
{
return true;
}else{
return "操作中出现错误,请重试";
}
}
//放到数据篮中
public function pushToDataorder($uuid,$uid = 0)
{
if(empty($uid))
{
$uid = \view::User('id');
}
$sql="insert into dataorder (uuid,ts_created,userid,status) values(?,now(),?,?)";
$rs = $this->db->query($sql,array($uuid,$uid,1));
if($rs)
{
return true;
}else{
return false;
}
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace order\listener;
//接口 需要实现的Listener中的方法
interface OrderEvents
{
public function submit($e);
}

View File

@ -0,0 +1,36 @@
<?php
namespace order\listener;
//侦听
class OrderListener implements \Zend_EventManager_ListenerAggregate
{
private $db;
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
}
public function attach(\Zend_EventManager_EventCollection $events)
{
$this->attachOnOrder($events);
}
public function detach(\Zend_EventManager_EventCollection $events)
{
}
public function attachOnOrder(\Zend_EventManager_EventCollection $events)
{
$mountedClass = new \order\mount\OrderOperate();
$events->attach('submit', array($mountedClass, 'submit'), 100);
}
}

View File

@ -0,0 +1,117 @@
<?php
namespace order\mount;
include_once("helper/view.php");
//事件中存在的操作
class OrderOperate implements \order\listener\OrderEvents
{
private $db;
private $config;
//!!!!!!important!!!!!
//不同项目使用时是否要修改此项??
public $tbl_metadata = "heihemetadata";
public $tbl_dataorder = "dataorder";
function __construct($db = NULL)
{
if(empty($db))
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
}
$this->config = \Zend_Registry::get('config');
}
//提交申请
public function submit($e)
{
$uuid = $e->getParam('uuid');
$uid = $e->getParam('uid');
try{
if($this->checkOrderUUID($uuid) !== false)
{
return "此数据尚未正式发布,还不能申请";
}
if($this->checkOrderNum(true,$uid) === false)
{
return "您的数据篮中存放的数据已达到可申请的数量";
}
if($this->checkOrderHas($uuid,$uid))
{
return "此数据已经在数据篮中";
}
}catch(Exception $e)
{
\view::Dump($e->getMessage());
}
return true;
}
//检查元数据是否已发布(存在于metadata表中)
public function checkOrderUUID($uuid)
{
$sql = "select count(*) as mdcount from {$this->tbl_metadata} where uuid=?";
$rs = $this->db->fetchRow($this->db->quoteInto($sql,$uuid));
if($rs['mdcount'] == 0)
{
return true;
}else{
return false;
}
}
//检查用户是否已经提交了该数据的申请
public function checkOrderHas($uuid,$uid = 0)
{
if(empty($uid))
{
$uid = \view::User('id');
}
$sql = "select count(*) as datacount from {$this->tbl_dataorder} where (ts_approved is null) and userid=$uid and uuid=? and status in (1,2,3,4)";
$rs = $this->db->fetchRow($this->db->quoteInto($sql,$uuid));
if($rs['datacount']>=1)
{
return true;
}else{
return false;
}
}//CheckOrderHas()
//检查用户已经在数据篮中的申请的数量
// 已经超过返回 true
public function checkOrderNum($bool = true,$uid = 0)
{
if(empty($uid))
{
$uid = \view::User('id');
}
$sql = "select count(*) as datacount from {$this->tbl_dataorder} where (ts_approved is null) and userid=? and status>0 and status<3";
$rs = $this->db->fetchRow($this->db->quoteInto($sql,$uid));
if($bool === true)
{
if($rs['datacount'] <= $this->config->download->max - 1)
{
return true;
}else{
return false;
}
}else{
return $rs['datacount'];
}
}//checkOrderNum
}