add Paginator Service,fixed a issue about zf1 update to zf2 in Westdc/Reference/Reference.php

This commit is contained in:
Jianxuan Li 2014-12-26 00:53:46 +08:00
parent f6d4934410
commit a87b4b8d2a
4 changed files with 103 additions and 34 deletions

View File

@ -34,7 +34,9 @@ class Assist
$pagination = $ctl->getServiceLocator()->get('viewhelpermanager')->get('PaginationControl');
$renderer = $ctl->getServiceLocator()->get('Zend\View\Renderer\PhpRenderer');
$paginator->setView($renderer);
$pagination->setDefaultViewPartial($viewPartial);
$ctl->ViewModel->setVariable('paginator',$paginator);

View File

@ -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);
}
}

View File

@ -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))

View File

@ -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))
}
public function setServiceManager(ServiceManager $serviceManager)
{
$this->db = \Zend_Registry::get('db');
}else{
$this->db = $db;
$this->serviceManager = $serviceManager;
$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->events()->attachAggregate($Listener);
$this->table = new \Helpers\Table();
$this->table = new \stdClass();
$this->table->reference = "reference";
$this->table->reference_author = "ref_author";
$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)
{
@ -170,7 +169,7 @@ class Reference
}
//所有文献
public function fetchReferences()
public function fetchAll()
{
$wheresql = array();
if(!empty($this->keyword))