add Paginator Service,fixed a issue about zf1 update to zf2 in Westdc/Reference/Reference.php
This commit is contained in:
parent
f6d4934410
commit
a87b4b8d2a
|
@ -14,7 +14,7 @@ class Assist
|
|||
|
||||
}
|
||||
|
||||
static function addPaginator($data,$ctl,$limit = 10,$viewPartial = "layout/manager/pagination")
|
||||
static function addPaginator($data,$ctl,$limit = 10,$viewPartial = "layout/manager/pagination" )
|
||||
{
|
||||
$request = $ctl->getRequest();
|
||||
$page = $ctl->params()->fromRoute('page');
|
||||
|
@ -33,8 +33,10 @@ class Assist
|
|||
$paginator->setDefaultScrollingStyle('Sliding');
|
||||
|
||||
$pagination = $ctl->getServiceLocator()->get('viewhelpermanager')->get('PaginationControl');
|
||||
$renderer = $ctl->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
|
||||
$paginator->setView($renderer);
|
||||
$renderer = $ctl->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
|
||||
|
||||
$paginator->setView($renderer);
|
||||
|
||||
$pagination->setDefaultViewPartial($viewPartial);
|
||||
|
||||
$ctl->ViewModel->setVariable('paginator',$paginator);
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: liujin834
|
||||
* Date: 14/12/25
|
||||
* Time: 下午5:29
|
||||
*/
|
||||
|
||||
namespace Westdc\Helpers;
|
||||
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
||||
use Zend\Paginator\Adapter\ArrayAdapter;
|
||||
use Zend\Paginator\Adapter\DbSelect;
|
||||
use Zend\Paginator\Adapter\DbTableGateway;
|
||||
use Zend\Paginator\Paginator as Zend_Paginator;
|
||||
use Zend\Db\Sql\Select;
|
||||
use Zend\Db\TableGateway\TableGateway;
|
||||
|
||||
class Paginator implements ServiceManagerAwareInterface{
|
||||
|
||||
protected $serviceManager;
|
||||
|
||||
public $sqlQuery,$sqlOrder,$sqlGroup,$sqlHaving;
|
||||
|
||||
public function setServiceManager(ServiceManager $serviceManager)
|
||||
{
|
||||
$this->serviceManager = $serviceManager;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function add($data,$ctl,$limit = 10,$route = "",$viewPartial = "layout/manager/pagination")
|
||||
{
|
||||
$page = $ctl->params()->fromRoute('page');
|
||||
|
||||
if(is_array($data))
|
||||
$data = new ArrayAdapter($data);
|
||||
|
||||
if($data instanceof Select)
|
||||
{
|
||||
$dbService = $this->serviceManager->get('Db');
|
||||
$zendDb = $dbService->getZendDb();
|
||||
$data = new DbSelect($data,$zendDb);
|
||||
}
|
||||
|
||||
if($data instanceof TableGateway)
|
||||
$data = new DbTableGateway($data,$this->sqlQuery,$this->sqlOrder,$this->sqlGroup,$this->sqlHaving);
|
||||
|
||||
$paginator = new Zend_Paginator($data);
|
||||
$paginator->setCurrentPageNumber($page)
|
||||
->setItemCountPerPage($limit)
|
||||
->setPageRange(6);
|
||||
|
||||
$pagination = $ctl->getServiceLocator()->get('viewhelpermanager')->get('PaginationControl');
|
||||
$pageSliding = $pagination($paginator,'Sliding',$viewPartial,array('route'=>$route));
|
||||
|
||||
$ctl->ViewModel->setVariable('pagination',$pageSliding);
|
||||
$ctl->ViewModel->setVariable('paginator',$paginator);
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,6 @@ use Westdc\Service\ServiceManager as WestdcServiceManager;
|
|||
use Zend\Mail\Message;
|
||||
use Zend\Mail\Transport\Smtp as SmtpTransport;
|
||||
use Zend\Mail\Transport\SmtpOptions;
|
||||
use Zend\Mime\Mime;
|
||||
use Zend\Mime\Message as MimeMessage;
|
||||
use Zend\Mime\Part as MimePart;
|
||||
|
||||
|
@ -130,6 +129,10 @@ class Mail extends AbstractEventManager implements ServiceManagerAwareInterface{
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param null $from
|
||||
* @return bool
|
||||
*/
|
||||
public function preSend($from = NULL)
|
||||
{
|
||||
if(empty($this->subject) || empty($this->body))
|
||||
|
@ -168,6 +171,9 @@ class Mail extends AbstractEventManager implements ServiceManagerAwareInterface{
|
|||
|
||||
//使用loadTemplate 的结果发送邮件
|
||||
//在此之前需要使用 $this->mail->addTo()添加收件人
|
||||
/**
|
||||
* @param null $from
|
||||
*/
|
||||
public function send($from = NULL){
|
||||
|
||||
if(!$status = $this->preSend($from))
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
<?php
|
||||
namespace Westdc\Reference;
|
||||
|
||||
use Westdc\Helpers\Assist as view;
|
||||
use Westdc\Db\Dbh as dbh;
|
||||
use Zend\ServiceManager\ServiceManager;
|
||||
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
||||
use Westdc\EventModel\AbstractEventManager;
|
||||
use Westdc\Reference\Listener\ReferenceListener;
|
||||
use Westdc\Files\Files;
|
||||
|
||||
class Reference
|
||||
{
|
||||
class Reference extends AbstractEventManager implements ServiceManagerAwareInterface{
|
||||
|
||||
protected $serviceManager;
|
||||
private $db; //传入PDO对象.
|
||||
private $config; //站点设置
|
||||
|
||||
protected $events = NULL;
|
||||
public $table;
|
||||
|
@ -22,30 +22,29 @@ class Reference
|
|||
|
||||
function __construct($db = NULL,$mail = NULL)
|
||||
{
|
||||
if(empty($db))
|
||||
{
|
||||
$this->db = \Zend_Registry::get('db');
|
||||
}else{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
$this->config = \Zend_Registry::get('config');
|
||||
|
||||
$Listener = new ReferenceListener();
|
||||
@$this->events()->attachAggregate($Listener);
|
||||
|
||||
$this->table = new \Helpers\Table();
|
||||
|
||||
}
|
||||
|
||||
public function events(\Zend_EventManager_EventCollection $events = NULL)
|
||||
|
||||
public function setServiceManager(ServiceManager $serviceManager)
|
||||
{
|
||||
if ($events !== NULL) {
|
||||
$this->events = $events;
|
||||
} elseif ($this->events === NULL) {
|
||||
$this->events = new \Zend_EventManager_EventManager(__CLASS__);
|
||||
}
|
||||
return $this->events;
|
||||
$this->serviceManager = $serviceManager;
|
||||
|
||||
$this->init();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function init(){
|
||||
$dbService = $this->serviceManager->get('Db');
|
||||
$this->db = $dbService->getPdo();
|
||||
unset($dbService);
|
||||
|
||||
$this->table = new \stdClass();
|
||||
$this->table->reference = "reference";
|
||||
$this->table->reference_author = "ref_author";
|
||||
$this->table->source = "source";
|
||||
}
|
||||
|
||||
|
||||
public function reference($id = 0)
|
||||
{
|
||||
|
@ -170,7 +169,7 @@ class Reference
|
|||
}
|
||||
|
||||
//所有文献
|
||||
public function fetchReferences()
|
||||
public function fetchAll()
|
||||
{
|
||||
$wheresql = array();
|
||||
if(!empty($this->keyword))
|
||||
|
@ -209,7 +208,7 @@ class Reference
|
|||
$order = "{$this->table->reference}.{$this->order}";
|
||||
}
|
||||
|
||||
$sql = "SELECT {$this->table->reference}.* FROM
|
||||
$sql = "SELECT {$this->table->reference}.* FROM
|
||||
{$this->table->reference}
|
||||
$wheresql
|
||||
ORDER BY $order {$this->sort}";
|
||||
|
@ -240,7 +239,7 @@ class Reference
|
|||
$order = "ref.{$this->order} {$this->sort}";
|
||||
}
|
||||
|
||||
$sql="select distinct ref.* from {$this->table->reference} ref where ref.id in (select r.refid from mdref r
|
||||
$sql="select distinct ref.* from {$this->table->reference} ref where ref.id in (select r.refid from mdref r
|
||||
left join datasource ds on r.uuid=ds.uuid left join {$this->table->source} s on s.id=ds.sourceid
|
||||
where s.code='$code')
|
||||
$wheresql
|
||||
|
|
Loading…
Reference in New Issue