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();
|
$request = $ctl->getRequest();
|
||||||
$page = $ctl->params()->fromRoute('page');
|
$page = $ctl->params()->fromRoute('page');
|
||||||
|
@ -34,7 +34,9 @@ class Assist
|
||||||
|
|
||||||
$pagination = $ctl->getServiceLocator()->get('viewhelpermanager')->get('PaginationControl');
|
$pagination = $ctl->getServiceLocator()->get('viewhelpermanager')->get('PaginationControl');
|
||||||
$renderer = $ctl->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
|
$renderer = $ctl->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
|
||||||
|
|
||||||
$paginator->setView($renderer);
|
$paginator->setView($renderer);
|
||||||
|
|
||||||
$pagination->setDefaultViewPartial($viewPartial);
|
$pagination->setDefaultViewPartial($viewPartial);
|
||||||
|
|
||||||
$ctl->ViewModel->setVariable('paginator',$paginator);
|
$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\Message;
|
||||||
use Zend\Mail\Transport\Smtp as SmtpTransport;
|
use Zend\Mail\Transport\Smtp as SmtpTransport;
|
||||||
use Zend\Mail\Transport\SmtpOptions;
|
use Zend\Mail\Transport\SmtpOptions;
|
||||||
use Zend\Mime\Mime;
|
|
||||||
use Zend\Mime\Message as MimeMessage;
|
use Zend\Mime\Message as MimeMessage;
|
||||||
use Zend\Mime\Part as MimePart;
|
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)
|
public function preSend($from = NULL)
|
||||||
{
|
{
|
||||||
if(empty($this->subject) || empty($this->body))
|
if(empty($this->subject) || empty($this->body))
|
||||||
|
@ -168,6 +171,9 @@ class Mail extends AbstractEventManager implements ServiceManagerAwareInterface{
|
||||||
|
|
||||||
//使用loadTemplate 的结果发送邮件
|
//使用loadTemplate 的结果发送邮件
|
||||||
//在此之前需要使用 $this->mail->addTo()添加收件人
|
//在此之前需要使用 $this->mail->addTo()添加收件人
|
||||||
|
/**
|
||||||
|
* @param null $from
|
||||||
|
*/
|
||||||
public function send($from = NULL){
|
public function send($from = NULL){
|
||||||
|
|
||||||
if(!$status = $this->preSend($from))
|
if(!$status = $this->preSend($from))
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Westdc\Reference;
|
namespace Westdc\Reference;
|
||||||
|
|
||||||
use Westdc\Helpers\Assist as view;
|
use Zend\ServiceManager\ServiceManager;
|
||||||
use Westdc\Db\Dbh as dbh;
|
use Zend\ServiceManager\ServiceManagerAwareInterface;
|
||||||
|
use Westdc\EventModel\AbstractEventManager;
|
||||||
use Westdc\Reference\Listener\ReferenceListener;
|
use Westdc\Reference\Listener\ReferenceListener;
|
||||||
use Westdc\Files\Files;
|
|
||||||
|
|
||||||
class Reference
|
class Reference extends AbstractEventManager implements ServiceManagerAwareInterface{
|
||||||
{
|
|
||||||
|
protected $serviceManager;
|
||||||
private $db; //传入PDO对象.
|
private $db; //传入PDO对象.
|
||||||
private $config; //站点设置
|
|
||||||
|
|
||||||
protected $events = NULL;
|
protected $events = NULL;
|
||||||
public $table;
|
public $table;
|
||||||
|
@ -22,30 +22,29 @@ class Reference
|
||||||
|
|
||||||
function __construct($db = NULL,$mail = NULL)
|
function __construct($db = NULL,$mail = NULL)
|
||||||
{
|
{
|
||||||
if(empty($db))
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setServiceManager(ServiceManager $serviceManager)
|
||||||
{
|
{
|
||||||
$this->db = \Zend_Registry::get('db');
|
$this->serviceManager = $serviceManager;
|
||||||
}else{
|
|
||||||
$this->db = $db;
|
$this->init();
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->config = \Zend_Registry::get('config');
|
private function init(){
|
||||||
|
$dbService = $this->serviceManager->get('Db');
|
||||||
|
$this->db = $dbService->getPdo();
|
||||||
|
unset($dbService);
|
||||||
|
|
||||||
$Listener = new ReferenceListener();
|
$this->table = new \stdClass();
|
||||||
@$this->events()->attachAggregate($Listener);
|
$this->table->reference = "reference";
|
||||||
|
$this->table->reference_author = "ref_author";
|
||||||
$this->table = new \Helpers\Table();
|
$this->table->source = "source";
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function reference($id = 0)
|
public function reference($id = 0)
|
||||||
{
|
{
|
||||||
|
@ -170,7 +169,7 @@ class Reference
|
||||||
}
|
}
|
||||||
|
|
||||||
//所有文献
|
//所有文献
|
||||||
public function fetchReferences()
|
public function fetchAll()
|
||||||
{
|
{
|
||||||
$wheresql = array();
|
$wheresql = array();
|
||||||
if(!empty($this->keyword))
|
if(!empty($this->keyword))
|
||||||
|
|
Loading…
Reference in New Issue