<?php
/*
* This file is part of the pwp package.
* (c) 2009-2010 Victor Rad' <victor.v.rad[at]gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/**
* Search actions
*
* @package pwp
* @subpackage search
* @author Victor Rad'
*/
class searchActions extends sfActions
{
/**
* Forming of friendly URL from the POST query of search string
*/
public function preExecute()
{
// prepare data
$request = sfContext::getInstance()->getRequest();
$query = $request->getParameter('query');
// forming friendly URL and redirect
if ($request->isMethod('post') and strlen($query)){
$this->redirect('@search_query?query='.$query);
}
elseif ($request->isMethod('post') and !strlen($query)){
$this->redirect('@homepage');
}
}
/**
* Executes index action
*
* @param sfRequest $request A request object
*/
public function executeIndex(sfWebRequest $request)
{
// do search
$query = $request->getParameter('query');
$search = new Search_Composite(new Search_Resume(), new Search_Portfolio(), new Search_News());
$foundIds = $search->find($query);
// pager
$this->pager = new SearchPager('Search_Composite', sfConfig::get('app_search_per_page'));
$this->pager->setFoundIds($foundIds);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
// pager slice
$foundIdsSlice = $this->pager->getResults();
$search->setFoundIds($foundIdsSlice);
// get found data
$this->foundRendered = $search->render();
$this->foundData = $search->getFoundData();
// count items for current page
$this->countFoundSlice = 0;
foreach ($foundIdsSlice as $ids){
$this->countFoundSlice += count($ids);
}
// HTML meta tags
$this->getResponse()->setTitle('Search');
$this->getResponse()->addMeta('description', 'Results for "'. $query .'"');
}
/**
* First column on page
*/
public function postExecute()
{
$this->getResponse()->setSlot('colOne', $this->getPartial('colOne'));
}
}