From 77c95fde761ad47123fabc3c238451883c461663 Mon Sep 17 00:00:00 2001 From: Li Jianxuan Date: Fri, 19 Jul 2013 10:19:59 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A6=BB=E7=BA=BF=E7=94=B3?= =?UTF-8?q?=E8=AF=B7=E8=A1=A8=EF=BC=8C=E5=A2=9E=E5=8A=A0wsn=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=9D=A5=E6=BA=90=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../default/controllers/DataController.php | 307 ++++++++++-------- .../default/views/scripts/data/pdf.phtml | 90 ++++- application/models/order/Order.php | 122 ++++++- .../models/order/listener/OrderEvents.php | 9 +- .../models/order/listener/OrderListener.php | 1 + .../models/order/mount/OrderOperate.php | 21 +- 6 files changed, 407 insertions(+), 143 deletions(-) diff --git a/application/default/controllers/DataController.php b/application/default/controllers/DataController.php index 82bb0627..2fab7e87 100755 --- a/application/default/controllers/DataController.php +++ b/application/default/controllers/DataController.php @@ -1459,11 +1459,13 @@ class DataController extends Zend_Controller_Action $apply = $this->_request->getParam('apply'); $finish = $this->_request->getParam('finish'); $cancel = $this->_request->getParam('cancel'); + $wsn = $this->_request->getParam('wsn'); $pdf = $this->_request->getParam('pdf'); //if (empty($uuid)) $this->_redirect('/data'); $userid = view::User('id'); + //添加到数据篮 if ($uuid) { //存在历史遗留问题,原来的数据并不能保证唯一 @@ -1475,28 +1477,57 @@ class DataController extends Zend_Controller_Action if($state !== true) { - $this->view->msg = \view::Msg('alert-error',$state); + if(!is_array($state)) + { + $this->view->msg = \view::Msg('alert-error',$state); + }else{ + if($state['datetype'] == "wsn") + { + \view::Post($this,"此数据提供下载选择功能,请等待页面跳转至数据选择页面","/data/order/wsn/$uuid"); + }else{ + $this->view->msg = \view::Msg('alert-error',"无法申请:此元数据的数据类型未知"); + } + } }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); - $this->db->query($sql); + } + + //删除申请 + elseif ($del) { + $order = new order\Order(); + $state = $order->del($del); + if($state !== true) + { + $this->view->msg = \view::Msg('alert-error',$state); + }else{ + $this->view->msg = \view::Msg('alert-success',"数据申请取消成功"); + } $this->_redirect('/data/order'); - } elseif ($apply) { - if ($apply=='all') { - $sql=$this->db->quoteInto("update dataorder set status=2 where status=1 and userid=?",$userid); - $this->db->query($sql); - } else { - $sql="update dataorder set status=2 where status=1 and userid=? and id=?"; - $this->db->query($sql,array($userid,(int)$apply)); - } + } + + //提交申请 + elseif ($apply) { + if($apply == "all" || !is_numeric($apply)) + { + $apply = -1; + } + $order = new order\Order(); + $state = $order->apply($apply); + if($state !== true) + { + $this->view->msg = \view::Msg('alert-error',$state); + }else{ + $this->view->msg = \view::Msg('alert-success',"提交成功,您可以点击“提交离线申请”来生成PDF申请表"); + } if (empty($ac)) $ac='offline2'; - } elseif ($finish) { + } + + //完成 + elseif ($finish) { if ($finish=='all') { $sql=$this->db->quoteInto("update dataorder set ts_approved=now() where status=0 and userid=?",$userid); $this->db->query($sql); @@ -1504,11 +1535,20 @@ class DataController extends Zend_Controller_Action $this->db->query($sql,array($userid)); } else { $sql="update dataorder set ts_approved=now() where status=0 and userid=? and id=?"; - $this->db->query($sql,array($userid,(int)$finish)); + $this->db->query($sql,array($userid,(int)$finish)); $sql="update ftpuser set datacount=datacount-1 where userid=? and datacount>0"; $this->db->query($sql,array($userid)); } - } elseif ($cancel) { + } + + elseif($wsn) + { + $this->_helper->viewRenderer('order-wsn'); + + return true; + } + + elseif ($cancel) { if ($cancel=='all') { $sql=$this->db->quoteInto("update dataorder set ts_approved=now(),status=-1 where status=0 and userid=?",$userid); $this->db->query($sql); @@ -1521,128 +1561,131 @@ class DataController extends Zend_Controller_Action $this->db->query($sql,array($userid)); } if (empty($ac)) $ac='offline2'; - } elseif ($pdf) { - //生成PDF离线申请文件 + } + + //生成PDF离线申请文件 + elseif ($pdf) { + //用户信息可以从SESSION中读取?离线申请信息 //$sql="select * from users where id=?"; - $sql="select m.title||'('||m.filesize::text||'MB)' as title,m.ts_published,date_part('year',doi.ts_published) as publish_year,m.citation,m.suppinfo, -array_to_string(ARRAY( -select r.reference from mdref mr left join reference r on mr.refid=r.id -where mr.reftype=3 and mr.uuid=d.uuid order by mr.place),'\n'::text) as reference, -array_to_string(array( -select fund.fund_type||':'||fund.title||'(编号:'||fund.fund_id||')' -from fund left join mdfund on fund.id=mdfund.fid where mdfund.uuid=d.uuid),'\n'::text) as fund, -doi.doi as datadoi,doi.authors,doi.publisher,doi.title as doititle,doi.author_en,doi.publisher_en,doi.title_en -from dataorder d left join metadata m on d.uuid=m.uuid left join datadoi doi on doi.uuid=d.uuid -where d.status=2 and d.userid=? order by d.ts_created desc -"; - $rows=$this->db->fetchAll($sql,array($userid)); + $order = new order\Order(); + $rows = $order->getOrderItemForPdf(); + $this->view->projectType = $order->projectType; + if ($rows) { - $this->view->data2=$rows; - $this->view->form=new OfflinePdfForm(); - - $this->_helper->viewRenderer('pdf'); + $this->_helper->viewRenderer('pdf'); + + $this->view->data2 = $rows; + if ($this->_request->isPost()) { - $formData = $this->_request->getPost(); + + $this->view->formData = $formData = $this->_request->getPost(); + + if(empty($formData['title'])) + { + $this->view->error = \view::Msg('alert-error',""); + return true; + } + + $datalist=''; foreach($rows as $i=>$row) $datalist.=($i+1).". ".$row['title'].";"; - $formData['datalist']=$datalist; - if ($this->view->form->isValid($formData)) { - if (@$formData['save']) { - //保存 - //根据pdflink字段,以判断是否已经提交 - //在数据库中创建rules,在更新offlineapp表时同时更新users表中对应的信息 - $sql="select id from offlineapp where userid=? and (pdflink is null or pdflink='') and (ts_approved is null)"; - $row=$this->db->fetchRow($sql,array($userid)); - if ($row) { - $sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now(),project_type=?,project_id=?,project_title=? where id=?"; - $this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$formData['project_type'],$formData['project_id'],$formData['project_title'],$row['id'])); - } else { - $sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist,project_type,project_id,project_title) values(?,?,?,?,?,?,?,?,?,?,?,?)"; - $this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$formData['project_type'],$formData['project_id'],$formData['project_title'])); - } - $this->_helper->layout->disableLayout(); - $this->_helper->viewRenderer->setNoRender(); - //生成PDF - $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join heihemetadata m on d.uuid=m.uuid where d.status=2 and d.userid=?"; - $list=$this->db->fetchAll($sql,array($userid)); - foreach($list as $i=>$row) @$formData['heihelist'].=($i+1).". ".$row['title'].";"; - $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join normalmetadata m on d.uuid=m.uuid where d.uuid not in (select uuid from heihemetadata) and d.status=2 and d.userid=?"; - $list=$this->db->fetchAll($sql,array($userid)); - foreach($list as $i=>$row) @$formData['westdclist'].=($i+1).". ".$row['title'].";"; - $pdf = new ApplicantPDF(); - $pdf->template=$this->view->config->offline->template; - $pdf->heihetemplate=$this->view->config->offline->heihetemplate; - $formData['project'].='['.$formData['project_title'].' | '.$formData['project_type'].' | '.$formData['project_id'].']'; - $pdf->data = $formData; - if (isset($formData['westdclist'])) $pdf->drawWestdc(); - if (isset($formData['heihelist'])) $pdf->drawHeihe(); - $pdf->addRef($rows); - $pdf->addSecurity($this->view->config->offline->security); - header("Content-Disposition: inline; filename=westdc-data-apply.pdf"); - header("Content-Type:application/pdf"); - //header("Content-Length: " . strlen($pdfstring)); - echo $pdf->Output('westdc-data-apply.pdf','S'); - die(); - //exit; - } elseif ($formData['submit']) { - //提交 - //生成PDF - $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join heihemetadata m on d.uuid=m.uuid where d.status=2 and d.userid=?"; - $list=$this->db->fetchAll($sql,array($userid)); - foreach($list as $i=>$row) @$formData['heihelist'].=($i+1).". ".$row['title'].";"; - $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join normalmetadata m on d.uuid=m.uuid where d.uuid not in (select uuid from heihemetadata) and d.status=2 and d.userid=?"; - $list=$this->db->fetchAll($sql,array($userid)); - foreach($list as $i=>$row) @$formData['westdclist'].=($i+1).". ".$row['title'].";"; - $pdf = new ApplicantPDF(); - $pdf->template=$this->view->config->offline->template; - $pdf->heihetemplate=$this->view->config->offline->heihetemplate; - $pdf->data = $formData; - $pdf->data['project'].='['.$formData['project_title'].' | '.$formData['project_type'].' | '.$formData['project_id'].']'; - if (isset($formData['westdclist'])) $pdf->drawWestdc(); - if (isset($formData['heihelist'])) $pdf->drawHeihe(); - $pdf->addRef($rows); - $pdf->addSecurity($this->view->config->offline->security); - $fn=$formData['realname'].date('YmdHis').".pdf"; - $pdf->Output($this->view->config->offline->savepath."/".$fn, 'F'); - - //保存到数据库 - $sql="select id from offlineapp where userid=? and pdflink is null and (ts_approved is null)"; - $row=$this->db->fetchRow($sql,array($userid)); - if ($row) { - $sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now(),pdflink=?,project_type=?,project_id=?,project_title=? where id=?"; - $this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn,$formData['project_type'],$formData['project_id'],$formData['project_title'],$row['id'])); - } else { - $sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist,pdflink,project_type,project_id,project_title) values(?,?,?,?,?,?,?,?,?,?,?,?,?)"; - $this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn,$formData['project_type'],$formData['project_id'],$formData['project_title'])); - $sql="select id from offlineapp where userid=? and pdflink=?"; - $row=$this->db->fetchRow($sql,array($userid,$fn)); - } - $sql="update dataorder set status=3, offlineappid=? where status=2 and userid=?"; - $this->db->query($sql,array($row['id'],$userid)); - - //发送用户邮件进行信息提示和说明 - //$mail = new Zend_Mail('utf-8'); - $data = array( - "user"=>$formData['realname'], - "datalist"=>str_replace(";","\n",$datalist) - ); - $mailtp=new EmailText($this->db,'offline-email',$data); - $mail = new WestdcMailer($this->view->config->smtp); - $mail->setBodyText($mailtp->getBody()); - $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); - $mail->addTo($formData['email']); - $mail->setSubject($mailtp->getSubject()); - $attach=$mail->createAttachment($pdf->Output('applicant','S')); - $attach->filename='数据申请-'.$formData['realname'].'.pdf'; - $mail->send(); - $this->_helper->viewRenderer('order'); - - //跳转到/data/order,并提示帮助信息,告知用户已经发送EMAIL - $this->view->msg=view::Msg('alert-success',"提示信息:您的离线申请已经提交,系统已经发送一封邮件给您,请打印出申请表、签字后扫描为pdf并email给数据中心服务组(仍可以采用邮寄方式),具体信息请参考邮件说明。",0); - if (empty($ac)) $ac='offline3'; - //$this->_redirect('/data/order'); + $formData['datalist'] = $datalist; + + if (@$formData['save']) { + //保存 + //根据pdflink字段,以判断是否已经提交 + //在数据库中创建rules,在更新offlineapp表时同时更新users表中对应的信息 + $sql="select id from offlineapp where userid=? and (pdflink is null or pdflink='') and (ts_approved is null)"; + $row=$this->db->fetchRow($sql,array($userid)); + if ($row) { + $sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now(),project_type=?,project_id=?,project_title=? where id=?"; + $this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$formData['project_type'],$formData['project_id'],$formData['project_title'],$row['id'])); + } else { + $sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist,project_type,project_id,project_title) values(?,?,?,?,?,?,?,?,?,?,?,?)"; + $this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$formData['project_type'],$formData['project_id'],$formData['project_title'])); } + $this->_helper->layout->disableLayout(); + $this->_helper->viewRenderer->setNoRender(); + //生成PDF + $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join heihemetadata m on d.uuid=m.uuid where d.status=2 and d.userid=?"; + $list=$this->db->fetchAll($sql,array($userid)); + foreach($list as $i=>$row) @$formData['heihelist'].=($i+1).". ".$row['title'].";"; + $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join normalmetadata m on d.uuid=m.uuid where d.uuid not in (select uuid from heihemetadata) and d.status=2 and d.userid=?"; + $list=$this->db->fetchAll($sql,array($userid)); + foreach($list as $i=>$row) @$formData['westdclist'].=($i+1).". ".$row['title'].";"; + $pdf = new ApplicantPDF(); + $pdf->template=$this->view->config->offline->template; + $pdf->heihetemplate=$this->view->config->offline->heihetemplate; + $formData['project'].='['.$formData['project_title'].' | '.$formData['project_type'].' | '.$formData['project_id'].']'; + $pdf->data = $formData; + if (isset($formData['westdclist'])) $pdf->drawWestdc(); + if (isset($formData['heihelist'])) $pdf->drawHeihe(); + $pdf->addRef($rows); + $pdf->addSecurity($this->view->config->offline->security); + header("Content-Disposition: inline; filename=westdc-data-apply.pdf"); + header("Content-Type:application/pdf"); + //header("Content-Length: " . strlen($pdfstring)); + echo $pdf->Output('westdc-data-apply.pdf','S'); + die(); + //exit; + } elseif ($formData['submit']) { + //提交 + //生成PDF + $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join heihemetadata m on d.uuid=m.uuid where d.status=2 and d.userid=?"; + $list=$this->db->fetchAll($sql,array($userid)); + foreach($list as $i=>$row) @$formData['heihelist'].=($i+1).". ".$row['title'].";"; + $sql="select m.title||'('||m.filesize::text||'MB)' as title from dataorder d right join normalmetadata m on d.uuid=m.uuid where d.uuid not in (select uuid from heihemetadata) and d.status=2 and d.userid=?"; + $list=$this->db->fetchAll($sql,array($userid)); + foreach($list as $i=>$row) @$formData['westdclist'].=($i+1).". ".$row['title'].";"; + $pdf = new ApplicantPDF(); + $pdf->template=$this->view->config->offline->template; + $pdf->heihetemplate=$this->view->config->offline->heihetemplate; + $pdf->data = $formData; + $pdf->data['project'].='['.$formData['project_title'].' | '.$formData['project_type'].' | '.$formData['project_id'].']'; + if (isset($formData['westdclist'])) $pdf->drawWestdc(); + if (isset($formData['heihelist'])) $pdf->drawHeihe(); + $pdf->addRef($rows); + $pdf->addSecurity($this->view->config->offline->security); + $fn=$formData['realname'].date('YmdHis').".pdf"; + $pdf->Output($this->view->config->offline->savepath."/".$fn, 'F'); + + //保存到数据库 + $sql="select id from offlineapp where userid=? and pdflink is null and (ts_approved is null)"; + $row=$this->db->fetchRow($sql,array($userid)); + if ($row) { + $sql="update offlineapp set username=?,email=?,phone=?,address=?,postcode=?,project=?,unit=?,datalist=?,ts_created=now(),pdflink=?,project_type=?,project_id=?,project_title=? where id=?"; + $this->db->query($sql,array($formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn,$formData['project_type'],$formData['project_id'],$formData['project_title'],$row['id'])); + } else { + $sql="insert into offlineapp (userid,username,email,phone,address,postcode,project,unit,datalist,pdflink,project_type,project_id,project_title) values(?,?,?,?,?,?,?,?,?,?,?,?,?)"; + $this->db->query($sql,array($userid,$formData['realname'],$formData['email'],$formData['phone'],$formData['address'],$formData['postcode'],$formData['project'],$formData['unit'],$datalist,$fn,$formData['project_type'],$formData['project_id'],$formData['project_title'])); + $sql="select id from offlineapp where userid=? and pdflink=?"; + $row=$this->db->fetchRow($sql,array($userid,$fn)); + } + $sql="update dataorder set status=3, offlineappid=? where status=2 and userid=?"; + $this->db->query($sql,array($row['id'],$userid)); + + //发送用户邮件进行信息提示和说明 + //$mail = new Zend_Mail('utf-8'); + $data = array( + "user"=>$formData['realname'], + "datalist"=>str_replace(";","\n",$datalist) + ); + $mailtp=new EmailText($this->db,'offline-email',$data); + $mail = new WestdcMailer($this->view->config->smtp); + $mail->setBodyText($mailtp->getBody()); + $mail->setFrom($this->view->config->service->email,'西部数据中心服务组'); + $mail->addTo($formData['email']); + $mail->setSubject($mailtp->getSubject()); + $attach=$mail->createAttachment($pdf->Output('applicant','S')); + $attach->filename='数据申请-'.$formData['realname'].'.pdf'; + $mail->send(); + $this->_helper->viewRenderer('order'); + + //跳转到/data/order,并提示帮助信息,告知用户已经发送EMAIL + $this->view->msg=view::Msg('alert-success',"提示信息:您的离线申请已经提交,系统已经发送一封邮件给您,请打印出申请表、签字后扫描为pdf并email给数据中心服务组(仍可以采用邮寄方式),具体信息请参考邮件说明。",0); + if (empty($ac)) $ac='offline3'; + //$this->_redirect('/data/order'); } } else { $sql="select u.* from users u left join offlineapp o on u.id=o.userid where u.id=?"; @@ -1655,7 +1698,7 @@ where d.status=2 and d.userid=? order by d.ts_created desc $formData['address']=$row->address; $formData['purpose']=$row->project; $formData['id']=$row->id;*/ - $this->view->form->populate($row); + $this->view->formData = $row; } } else $this->view->msg=view::Msg('alert-error',"错误:您还没有提交任何离线申请的数据,或您的数据申请已经提交(等待处理过程中)!",0); diff --git a/application/default/views/scripts/data/pdf.phtml b/application/default/views/scripts/data/pdf.phtml index 0df0eedc..7a76003e 100644 --- a/application/default/views/scripts/data/pdf.phtml +++ b/application/default/views/scripts/data/pdf.phtml @@ -17,17 +17,17 @@

离线申请提交

-

数据清单

+

数据清单

    data2 as $i=>$md) : ?>
-
-

申请表填写说明

+
+

申请表填写说明

-

其中用途部分,请填写您的详细使用目的;项目类型请从列表中选择,若无对应的项目支持,请选择其他项目工程;如项目无编号信息,则填写“无”;硕博论文请在用途中注明。

+

其中用途部分,请填写您的详细使用目的;项目类型请从列表中选择,若无对应的项目支持,请选择其他项目工程;如项目无编号信息,则填写“无”;硕博论文请在用途中注明。

详细准确的信息能使您更快通过申请。(数据提供者会根据您提供的信息来进行决策判断)

申请表(请务必填写真实信息以便审核通过)

messages): foreach($this->messages as $msg): ?> @@ -36,6 +36,84 @@ msg) : ?>

msg; ?>

- form;?> +
+
+ +
+ formData['realname']?>" helper="formText">
+
+ +
+ +
+ formData['email']?>" helper="formText">
+
+ +
+ +
+ formData['phone']?>" helper="formText">
+
+ +
+ +
+ formData['unit']?>" helper="formText">
+
+ +
+ +
+ formData['address']?>" helper="formText">
+
+ +
+ +
+ formData['postcode']?>" helper="formText">
+
+ +
+ +
+ formData['project_id']?>" helper="formText">
+
+ +
+ +
+ +
+
+ +
+ +
+ formData['project_title']?>" helper="formText" class="input-block-level">
+
+ +
+ +
+
+
+ +
+
+ + + + + +
+
+
- \ No newline at end of file + diff --git a/application/models/order/Order.php b/application/models/order/Order.php index a0ca62b1..003cbcf2 100644 --- a/application/models/order/Order.php +++ b/application/models/order/Order.php @@ -9,6 +9,18 @@ class Order private $config; protected $events = NULL; + public $projectType = array( + "国家973计划项目课题" => "国家973计划项目课题", + "国家863计划课题"=>"国家863计划课题", + "国家级科技支撑课题" => "国家级科技支撑课题", + "国家级科技重大专项" => "国家级科技重大专项", + "国家级国家重大工程" => "国家级国家重大工程", + "国家级国家自然科学基金" => "国家级国家自然科学基金", + "国际合作项目"=>"国际合作项目", + "省部级项目" => "省部级项目", + "其他项目工程" => "其他项目工程", + ); //申请中的项目类型 + function __construct($db = NULL) { if(empty($db)) @@ -53,6 +65,11 @@ class Order $uid = \view::User('id'); } + if(!is_numeric($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 "参数错误"; @@ -66,6 +83,14 @@ class Order return $data; } + $results = $this->events()->trigger('checksource', $this, compact('uuid')); + $data = $results->bottom(); + + if($data !== true) + { + return array("datetype"=>$data,"uuid"=>$uuid); + } + if($this->pushToDataorder($uuid,$uid) === true) { return true; @@ -73,7 +98,7 @@ class Order return "操作中出现错误,请重试"; } - } + }//addOrder //放到数据篮中 public function pushToDataorder($uuid,$uid = 0) @@ -92,8 +117,101 @@ class Order }else{ return false; } + }//pushToDataorder + + //提交 + public function apply($id,$uid = 0) + { + if(!is_numeric($id) || !is_numeric($uid)) + { + return "参数错误"; + } + + if(empty($uid)) + { + $uid = \view::User('id'); + } + + if($id == -1) + { + $sql = $this->db->quoteInto("update dataorder set status=2 where status=1 and userid=?",$uid); + if($this->db->exec($sql)) + { + return true; + }else{ + return "处理中遇到问题,请重试"; + } + } + + if($id > 0) + { + $sql = $this->db->quoteInto("update dataorder set status=2 where status=1 and userid=$uid and id=?",$id); + if($this->db->exec($sql)) + { + return true; + }else{ + return "处理中遇到问题,请重试"; + } + } + + return "参数错误"; + }//apply() + + //删除 + public function del($id,$uid = 0) + { + if(!is_numeric($id) || !is_numeric($uid)) + { + return "参数错误"; + } + + if(empty($uid)) + { + $uid = \view::User('id'); + } + + if($id > 0) + { + $sql = $this->db->quoteInto("delete from dataorder where userid=$uid and status in (1,2) and id=?",$id); + if($this->db->exec($sql)) + { + return true; + }else{ + return "处理中遇到错误,请重试"; + } + } + + return "参数错误"; } + //生成pdf + public function pdf($uid = 0) + { + + + } - + //获得要生成pdf的信息 + public function getOrderItemForPdf($uid = 0) + { + if(empty($uid)) + { + $uid = \view::User('id'); + } + + $sql = "select m.title||'('||m.filesize::text||'MB)' as title,m.ts_published,date_part('year',doi.ts_published) as publish_year,m.citation,m.suppinfo, + array_to_string(ARRAY( + select r.reference from mdref mr left join reference r on mr.refid=r.id + where mr.reftype=3 and mr.uuid=d.uuid order by mr.place),'\n'::text) as reference, + array_to_string(array( + select fund.fund_type||':'||fund.title||'(编号:'||fund.fund_id||')' + from fund left join mdfund on fund.id=mdfund.fid where mdfund.uuid=d.uuid),'\n'::text) as fund, + doi.doi as datadoi,doi.authors,doi.publisher,doi.title as doititle,doi.author_en,doi.publisher_en,doi.title_en + from dataorder d left join metadata m on d.uuid=m.uuid left join datadoi doi on doi.uuid=d.uuid + where d.status=2 and d.userid=? order by d.ts_created desc + "; + $rows = $this->db->fetchAll($sql,array($uid)); + + return $rows; + } } \ No newline at end of file diff --git a/application/models/order/listener/OrderEvents.php b/application/models/order/listener/OrderEvents.php index 3c78445f..033a9be0 100644 --- a/application/models/order/listener/OrderEvents.php +++ b/application/models/order/listener/OrderEvents.php @@ -3,5 +3,12 @@ namespace order\listener; //接口 ,需要实现的Listener中的方法 interface OrderEvents { - public function submit($e); + //申请提交事件 + public function submit(\Zend_EventManager_Event $e); + + //检查数据来源事件 + //区别是直接下载的数据或是wsn来源的数据 + //wsn来源的数据需要用户在提交申请的时候选择要下载的内容 + public function checksource(\Zend_EventManager_Event $e); + } \ No newline at end of file diff --git a/application/models/order/listener/OrderListener.php b/application/models/order/listener/OrderListener.php index 84b9411f..d72e314b 100644 --- a/application/models/order/listener/OrderListener.php +++ b/application/models/order/listener/OrderListener.php @@ -31,6 +31,7 @@ class OrderListener implements \Zend_EventManager_ListenerAggregate { $mountedClass = new \order\mount\OrderOperate(); $events->attach('submit', array($mountedClass, 'submit'), 100); + $events->attach('checksource',array($mountedClass,'checksource'),100); } } \ No newline at end of file diff --git a/application/models/order/mount/OrderOperate.php b/application/models/order/mount/OrderOperate.php index 35f27ece..46a60397 100644 --- a/application/models/order/mount/OrderOperate.php +++ b/application/models/order/mount/OrderOperate.php @@ -26,7 +26,7 @@ class OrderOperate implements \order\listener\OrderEvents } //提交申请 - public function submit($e) + public function submit(\Zend_EventManager_Event $e) { $uuid = $e->getParam('uuid'); $uid = $e->getParam('uid'); @@ -112,6 +112,23 @@ class OrderOperate implements \order\listener\OrderEvents } }//checkOrderNum - + //检查数据来源 + public function checksource(\Zend_EventManager_Event $e) + { + $uuid = $e->getParam('uuid'); + + $sql = "SELECT * FROM wsn_metadata WHERE uuid='$uuid'"; + + $rs = $this->db->query($sql); + + $row = $rs->fetch(); + + if(isset($row['uuid']) && !empty($row['uuid'])) + { + return "wsn"; + }else{ + return true; + } + } } \ No newline at end of file