mirror of
https://github.com/AzuraCast/AzuraCast.git
synced 2024-06-15 05:36:37 +00:00
New paginator using Doctrine's onboard pagination tool.
This commit is contained in:
parent
6426c8cba7
commit
4749ba8e4e
52
app/library/DF/Paginator/Adapter/DoctrinePaginator.php
Normal file
52
app/library/DF/Paginator/Adapter/DoctrinePaginator.php
Normal file
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
namespace DF\Paginator\Adapter;
|
||||
|
||||
use \Doctrine\ORM\Query;
|
||||
use \Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
|
||||
class DoctrinePaginator implements \Zend_Paginator_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* Paginator
|
||||
* @var Paginator
|
||||
*/
|
||||
protected $paginator = null;
|
||||
|
||||
/**
|
||||
* Item count
|
||||
* @var integer
|
||||
*/
|
||||
protected $count = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param Paginator $paginator
|
||||
*/
|
||||
public function __construct(Query $query)
|
||||
{
|
||||
$this->paginator = new Paginator($query);
|
||||
$this->count = count($this->paginator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of items for a page.
|
||||
*
|
||||
* @param integer $offset Page offset
|
||||
* @param integer $itemCountPerPage Number of items per page
|
||||
* @return array
|
||||
*/
|
||||
public function getItems($offset, $itemCountPerPage)
|
||||
{
|
||||
return $this->paginator->getIterator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the total number of rows in the array.
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function count()
|
||||
{
|
||||
return $this->count;
|
||||
}
|
||||
}
|
|
@ -4,8 +4,13 @@ class Doctrine extends \Zend_Paginator
|
|||
{
|
||||
public function __construct($query, $page = 1, $limit = 10)
|
||||
{
|
||||
parent::__construct(new Adapter\DoctrineQuery($query));
|
||||
if ($query instanceof QueryBuilder)
|
||||
$query = $query->getQuery();
|
||||
|
||||
$query->setMaxResults($limit);
|
||||
$query->setFirstResult(($page - 1) * $limit);
|
||||
|
||||
parent::__construct(new Adapter\DoctrinePaginator($query));
|
||||
$this->setItemCountPerPage($limit);
|
||||
$this->setCurrentPageNumber($page);
|
||||
}
|
||||
|
|
|
@ -13,12 +13,12 @@ class Admin_UsersController extends \DF\Controller\Action
|
|||
if ($_GET)
|
||||
$this->redirectFromHere($_GET);
|
||||
|
||||
if ($this->_hasParam('q'))
|
||||
if ($this->hasParam('q'))
|
||||
{
|
||||
$this->view->q = $q = trim($this->_getParam('q'));
|
||||
$this->view->q = $q = trim($this->getParam('q'));
|
||||
|
||||
$query = $this->em->createQuery('SELECT u FROM Entity\User u WHERE (u.name LIKE :q OR u.email LIKE :q) ORDER BY u.name ASC')
|
||||
->setParameter('q', '%'.$q.'%');
|
||||
$query = $this->em->createQuery('SELECT u FROM Entity\User u WHERE (u.name LIKE :query OR u.email LIKE :query) ORDER BY u.name ASC')
|
||||
->setParameter('query', '%'.$q.'%');
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ class Admin_UsersController extends \DF\Controller\Action
|
|||
{
|
||||
$form = new \DF\Form($this->current_module_config->forms->user_edit->form);
|
||||
|
||||
if ($this->_hasParam('id'))
|
||||
if ($this->hasParam('id'))
|
||||
{
|
||||
$record = User::find($this->_getParam('id'));
|
||||
$form->setDefaults($record->toArray());
|
||||
|
@ -59,7 +59,7 @@ class Admin_UsersController extends \DF\Controller\Action
|
|||
|
||||
public function deleteAction()
|
||||
{
|
||||
$id = (int)$this->_getParam('id');
|
||||
$id = (int)$this->getParam('id');
|
||||
$user = User::find($id);
|
||||
|
||||
if ($user instanceof User)
|
||||
|
@ -71,7 +71,7 @@ class Admin_UsersController extends \DF\Controller\Action
|
|||
|
||||
public function impersonateAction()
|
||||
{
|
||||
$id = (int)$this->_getParam('id');
|
||||
$id = (int)$this->getParam('id');
|
||||
$user = User::find($id);
|
||||
|
||||
if (!($user instanceof User))
|
||||
|
|
Loading…
Reference in New Issue
Block a user