#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

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,11 @@
$this->breadcrumb('<a href="/">首页</a>');
$this->breadcrumb('<a href="/data">'.$this->config->title->data.'</a>');
$this->breadcrumb('离线申请');
$this->breadcrumb()->setSeparator(' > ');
$this->breadcrumb()->setSeparator(' > ');
$this->nav[] = array('link'=>"/data/order",'title'=>'数据蓝');
?>
<?= $this->render('breadcrumbs.phtml') ?>
<div class="row">
<?= $this->render('breadcrumbs.phtml') ?>
<div class="row">
<div class="span3">
<div class="well sidebar-nav">
@ -18,13 +18,13 @@ $this->nav[] = array('link'=>"/data/order",'title'=>'数据蓝');
</div><!--/.well -->
</div><!--/span-->
<div class="span9">
<h3>数据篮</h3>
<h3>数据篮</h3>
<hr />
<?php
if(!empty($this->msg))
{
echo $this->msg;
}
<?php
if(!empty($this->msg))
{
echo $this->msg;
}
?>
<ul class="nav nav-tabs">
@ -32,40 +32,40 @@ $this->nav[] = array('link'=>"/data/order",'title'=>'数据蓝');
<li id="Nav-order-offline2"><a href="/data/order/ac/offline2">正在提交的数据</a></li>
<li id="Nav-order-offline3"><a href="/data/order/ac/offline3">等待通过的申请</a></li>
<li id="Nav-order-offline4"><a href="/data/order/ac/offline4">已通过的申请</a></li>
<li id="Nav-order-online"><a href="/data/order/ac/online">在线数据</a></li>
<li id="Nav-order-online"><a href="/data/order/ac/online">在线数据</a></li>
</ul>
<!-- content -->
<!-- content -->
<?php if (!empty($this->paginator)) : ?>
<div class="pagenavi"><?= $this->paginator; ?></div>
<table class="table table-bordered table-striped">
<thead>
<th>时间</th>
<th>标题</th>
<th>
<?php if ($this->tabID=='order-offline1') {
echo '<a class="btn btn-primary" href="/data/order/apply/all">提交所有数据</a>一次最多5条';
} elseif ($this->tabID=='order-offline2') {
echo '<a class="btn btn-primary" href="/data/order/pdf/1">提交离线申请</a>';
} elseif ($this->tabID=='order-offline3') {
echo '申请状态';
} elseif ($this->tabID=='order-offline4') {
echo '通过时间';
}
?>
<th>标题</th>
<th>
<?php if ($this->tabID=='order-offline1') {
echo '<a class="btn btn-primary" href="/data/order/apply/all">提交所有数据</a>一次最多5条';
} elseif ($this->tabID=='order-offline2') {
echo '<a class="btn btn-primary" href="/data/order/pdf/1">提交离线申请</a>';
} elseif ($this->tabID=='order-offline3') {
echo '申请状态';
} elseif ($this->tabID=='order-offline4') {
echo '通过时间';
}
?>
</th>
</thead>
<tbody>
<?php foreach($this->paginator as $order) : ?>
<?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>
<?php
if ($this->tabID=='order-offline1') {
<td><a href="/data/<?php echo $order['uuid']; ?>"><?php echo $order['title']; ?></a></td>
<td>
<?php
if ($this->tabID=='order-offline1') {
echo '<a href="/data/order/apply/'.$order['id'].'" class="btn btn-primary">提交</a>
<a href="/data/order/cancel/'.$order['id'].'" class="btn">取消</a>';
} elseif ($this->tabID=='order-offline2') {
<a href="/data/order/cancel/'.$order['id'].'" class="btn">取消</a>';
} elseif ($this->tabID=='order-offline2') {
switch($order['status']) {
case 2:
echo "请生成PDF申请表";
@ -76,8 +76,8 @@ if ($this->tabID=='order-offline1') {
break;
default:
break;
}
} elseif ($this->tabID=='order-offline3') {
}
} elseif ($this->tabID=='order-offline3') {
switch($order['status']) {
case 3:
echo "请打印签字扫描为pdf并email或邮寄";
@ -90,18 +90,18 @@ if ($this->tabID=='order-offline1') {
break;
default:
break;
}
} elseif ($this->tabID=='order-offline4') {
echo date('Y-m-d',strtotime($order['ts_approved']));
}
?>
}
} elseif ($this->tabID=='order-offline4') {
echo date('Y-m-d',strtotime($order['ts_approved']));
}
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</table>
<?php endif; ?>
<!-- /content -->
</div><!--/span-->
</div><!--/row-->
</div><!--/row-->
<script>$('#Nav-<?= $this->tabID?>').addClass("active");</script>

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
}