Location: PHPKode > projects > DIY Blog > diy-blog/classes/diy-blog/frontend/view/postList/PostListView.class.php
<?php

/**
 * Blog post listing view.
 * @package diy-blog.frontend.view.postList
 * @author	Martynas Jusevicius <hide@address.com>
 * @link	http://www.xml.lt
 */

class PostListView extends FrontEndView
{
	protected $criteria = null;
	
	public function __construct(Resource $resource = null)
	{
		parent::__construct($resource);

		$this->criteria = new Criteria();

		$this->template->load(APP_VIEW_DIR."postList/PostList.xsl");
	}

	function display(Request $request, Response $response)
	{
		$c = new Criteria();
		$criterion = $c->getNewCriterion(FrontEndResourcePeer::TYPE, FrontEndResourcePeer::CLASSKEY_MONTHLYPOSTLISTRESOURCE);
		$criterion->addOr($c->getNewCriterion(FrontEndResourcePeer::TYPE, FrontEndResourcePeer::CLASSKEY_YEARLYPOSTLISTRESOURCE));
		$c->add($criterion);
		$dateResources = FrontEndResourcePeer::doSelect($c);

		$pagingForm = new PagingForm($request);
		
		//QUIRKS!!!
		$offset = 0;
		if ($pagingForm->getOffset() != null) $offset = $pagingForm->getOffset();
		$limit = 10;
		if ($pagingForm->getLimit() != null) $limit = $pagingForm->getLimit();
		$desc = true;
		if ($pagingForm->getDesc() == "false") $desc = false;
		$orderBy = 1;

		$this->criteria->add(PagePeer::TYPE, PagePeer::CLASSKEY_POSTPAGE);

		$postCount = PagePeer::doCount($this->criteria);

		$this->criteria->setLimit($limit);
		$this->criteria->setOffset($offset);
		if ($desc)
		{
			$this->criteria->addDescendingOrderByColumn(PagePeer::DATETIME);
			$this->criteria->addDescendingOrderByColumn(PagePeer::TITLE);
		}
		else
		{
			$this->criteria->addAscendingOrderByColumn(PagePeer::DATETIME);
			$this->criteria->addAscendingOrderByColumn(PagePeer::TITLE);
		}

		$posts = PagePeer::doSelectJoinAllWithCount($this->criteria);

		$this->proc->setParameter("", "total-item-count", $postCount); // criteria
		$this->proc->setParameter("", "offset", $offset);
		$this->proc->setParameter("", "limit", $limit);
		$this->proc->setParameter("", "desc", $desc);

		$this->resolver->setArgument("posts", XMLSerializer::serialize($posts));
		$this->resolver->setArgument("date-resources", XMLSerializer::serialize($dateResources));

		parent::display($request, $response);

		$response->setStatus(Response::SC_OK);
	}

}

?>
Return current item: DIY Blog