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

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

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

		$this->template->load(APP_VIEW_DIR."search/Search.xsl");
	}

	function display(Request $request, Response $response)
	{
		$searchForm = new SearchForm($request);
		$search = strip_tags($searchForm->getSearch());

//print_r(urldecode($request->getAttribute("search-form")->getSearch()));

		$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;

		$c = new Criteria();
		$criterion = $c->getNewCriterion(PagePeer::TITLE, "%".$search."%", Criteria::LIKE);
		$criterion->addOr($c->getNewCriterion(PagePeer::CONTENT, "%".$search."%", Criteria::LIKE));
		$c->add($criterion);

		$pageCount = PagePeer::doCount($c);

		$c->setLimit($limit);
		$c->setOffset($offset);
		if ($desc)
		{
			$c->addDescendingOrderByColumn(PagePeer::DATETIME);
			$c->addDescendingOrderByColumn(PagePeer::TITLE);
		}
		else
		{
			$c->addAscendingOrderByColumn(PagePeer::DATETIME);
			$c->addAscendingOrderByColumn(PagePeer::TITLE);
		}
		
		$pages = PagePeer::doSelectJoinAll($c);

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

		//$this->proc->setParameter("", "search-result", $request->getAttribute("search-result"));
		$this->proc->setParameter("", "search-result", "success");
		$this->resolver->setArgument("search-form", XMLSerializer::serialize($searchForm));

		$this->resolver->setArgument("pages", XMLSerializer::serialize($pages));

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

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

}

?>
Return current item: DIY Blog