2010-10-04 06:32:48 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Extension to provide a search interface when applied to ContentController
|
2010-10-19 05:54:51 +02:00
|
|
|
*
|
2010-10-13 05:53:12 +02:00
|
|
|
* @package sapphire
|
|
|
|
* @subpackage search
|
2010-10-04 06:32:48 +02:00
|
|
|
*/
|
2010-10-19 05:54:51 +02:00
|
|
|
class ContentControllerSearchExtension extends Extension {
|
2010-10-13 03:14:27 +02:00
|
|
|
static $allowed_actions = array(
|
|
|
|
'SearchForm',
|
|
|
|
'results',
|
|
|
|
);
|
2010-10-19 05:54:51 +02:00
|
|
|
|
2010-10-04 06:32:48 +02:00
|
|
|
/**
|
|
|
|
* Site search form
|
|
|
|
*/
|
|
|
|
function SearchForm() {
|
2010-10-15 02:31:26 +02:00
|
|
|
$searchText = _t('SearchForm.SEARCH', 'Search');
|
2010-10-19 05:54:51 +02:00
|
|
|
|
2010-10-15 02:31:26 +02:00
|
|
|
if($this->owner->request) {
|
|
|
|
$searchText = $this->owner->request->getVar('Search');
|
|
|
|
}
|
2010-10-19 05:54:51 +02:00
|
|
|
|
2010-10-04 06:32:48 +02:00
|
|
|
$fields = new FieldSet(
|
2010-10-15 02:30:30 +02:00
|
|
|
new TextField('Search', false, $searchText)
|
2010-10-04 06:32:48 +02:00
|
|
|
);
|
|
|
|
$actions = new FieldSet(
|
2010-10-15 02:30:30 +02:00
|
|
|
new FormAction('results', _t('SearchForm.GO', 'Go'))
|
2010-10-04 06:32:48 +02:00
|
|
|
);
|
2010-10-19 05:54:51 +02:00
|
|
|
$form = new SearchForm($this->owner, 'SearchForm', $fields, $actions);
|
2010-10-19 06:53:36 +02:00
|
|
|
$form->classesToSearch(FulltextSearchable::get_searchable_classes());
|
2010-10-19 05:54:51 +02:00
|
|
|
return $form;
|
2010-10-04 06:32:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process and render search results.
|
2010-10-19 05:54:51 +02:00
|
|
|
*
|
2010-10-04 06:32:48 +02:00
|
|
|
* @param array $data The raw request data submitted by user
|
|
|
|
* @param SearchForm $form The form instance that was submitted
|
|
|
|
* @param SS_HTTPRequest $request Request generated for this action
|
|
|
|
*/
|
|
|
|
function results($data, $form, $request) {
|
|
|
|
$data = array(
|
|
|
|
'Results' => $form->getResults(),
|
|
|
|
'Query' => $form->getSearchQuery(),
|
2010-10-15 02:30:30 +02:00
|
|
|
'Title' => _t('SearchForm.SearchResults', 'Search Results')
|
2010-10-04 06:32:48 +02:00
|
|
|
);
|
|
|
|
return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
|
|
|
|
}
|
|
|
|
}
|