Source

zf-form-builder / www / system / modules / blog / library / Service / Entry.php

Full commit
<?php
class Blog_Service_Entry extends Neno_Service_Doctrine
{
    protected $pageQuery = null;

    public function setPageQuery(Doctrine_Query $query)
    {
        $this->pageQuery = $query;
    }

    public function getPageQuery()
    {
        if (null === $this->pageQuery) {
            $this->pageQuery = $this->createQuery('e');
        }
        return $this->pageQuery;
    }

    public function get($title_slug)
    {
        return $this->createQuery('e')
                ->addWhere('e.title_slug = ?')
                ->fetchOne();
    }

    public function getPage($currentPage, $itemsPerPage = 15, $pageRange = 5)
    {
        $query = $this->getPageQuery()
                ->select('e.*, t.*')
                ->leftJoin('e.Tags as t')
                ->orderBy('e.created_at DESC');
        $entries = new Zend_Paginator(new ZendY_Doctrine_Paginator_Adapter($query));
        $entries
                ->setItemCountPerPage($itemsPerPage)
                ->setPageRange($pageRange)
                ->setCurrentPageNumber($currentPage);
        return $entries;
    }
}