Skip to content

Commit

Permalink
adding paginator
Browse files Browse the repository at this point in the history
  • Loading branch information
tawfekov committed Apr 5, 2013
1 parent eab854b commit aa187d7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/ZF2EntityAudit/Audit/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ public function findRevisions($className, $id)

return $revisions;
}

public function countRevisions()
{
$conn = $this->em->getConnection();
$this->platform = $conn->getDatabasePlatform();
$query = "SELECT COUNT(*) as `total` FROM " . $this->config->getRevisionTableName() ;
$number = $conn->fetchAll($query);
return $number[0]["total"] ;
}

protected function getEntityPersister($entity)
{
Expand Down
8 changes: 4 additions & 4 deletions src/ZF2EntityAudit/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Zend\View\Model\ViewModel;
use ZF2EntityAudit\Utils\ArrayDiff;
use Doctrine\ORM\Mapping\ClassMetadata;

use ZF2EntityAudit\Paginator\Dbal as DBALPaginator ;
class IndexController extends AbstractActionController
{

Expand All @@ -31,10 +31,10 @@ public function indexAction()
$config = $sm->get("Config");
$ZF2AuditConfig = $config["zf2-entity-audit"];
$page = (int) $this->getEvent()->getRouteMatch()->getParam('page');
$revisions = $auditReader->findRevisionHistory($ZF2AuditConfig['ui']['page.limit'], 20 * ($page - 1));

$paginator = new DBALPaginator($auditReader);
$paginator->getItems(20 * ($page - 1), $ZF2AuditConfig['ui']['page.limit']);
return new ViewModel(array(
'revisions' => $revisions,
'paginator' => $paginator ,
'auditReader' => $auditReader,
));
}
Expand Down
27 changes: 27 additions & 0 deletions src/ZF2EntityAudit/Paginator/Dbal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace ZF2EntityAudit\Paginator;


use Zend\Paginator\Paginator;
use Zend\Paginator\Adapter\Null as NullAdapter ;
use ZF2EntityAudit\Audit\Reader ;

class Dbal extends Paginator
{
protected $reader ;
public function __construct( Reader $reader ) {
$this->reader = $reader ;
parent::__construct(new NullAdapter());
}

public function getItems($offset, $itemCountPerPage)
{
return $this->reader->findRevisionHistory($itemCountPerPage, $offset);
}

public function count()
{
return $this->reader->countRevisions();
}

}
52 changes: 50 additions & 2 deletions view/zf2-entity-audit/index/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<tbody>
<?php
$i = 1 ;
foreach ($revisions as $revision) {
foreach ($this->paginator as $revision) {
?>
<tr>
<td><?php echo $this->escapeHtml($i);?></td>
Expand Down Expand Up @@ -108,7 +108,55 @@
</tbody>
</table>
</div>
<div class="span6">
<div class="span12">
<?php if ($this->pageCount): ?>
<div class="pagination pagination-centered">
<ul>
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<li>
<a href="<?php echo $this->url($this->route); ?>?page=<?php echo $this->previous; ?>">
<<
</a>
</li>
<?php else: ?>
<li class="disabled">
<a href="#">
<<
</a>
</li>
<?php endif; ?>
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<li>
<a href="<?php echo $this->url($this->route);?>?page=<?php echo $page; ?>">
<?php echo $page; ?>
</a>
</li>
<?php else: ?>
<li class="active">
<a href="#"><?php echo $page; ?></a>
</li>
<?php endif; ?>
<?php endforeach; ?>

<!-- Next page link -->
<?php if (isset($this->next)): ?>
<li>
<a href="<?php echo $this->url($this->route); ?>?page=<?php echo $this->next; ?>">
>>
</a>
</li>
<?php else: ?>
<li class="disabled">
<a href="#">
>>
</a>
</li>
<?php endif; ?>
</ul>
</div>
<?php endif; ?>
</div>
</div>

0 comments on commit aa187d7

Please sign in to comment.