2011-03-18 04:05:23 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Extension to provide a search interface when applied to ContentController
|
|
|
|
*
|
|
|
|
* @package cms
|
|
|
|
* @subpackage search
|
|
|
|
*/
|
|
|
|
class ContentControllerSearchExtension extends Extension {
|
2013-03-18 11:47:15 +01:00
|
|
|
private static $allowed_actions = array(
|
2011-03-18 04:05:23 +01:00
|
|
|
'SearchForm',
|
|
|
|
'results',
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Site search form
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function SearchForm() {
|
2011-03-18 04:05:23 +01:00
|
|
|
$searchText = _t('SearchForm.SEARCH', 'Search');
|
|
|
|
|
2015-04-30 01:04:02 +02:00
|
|
|
if($this->owner->getRequest() && $this->owner->getRequest()->getVar('Search')) {
|
|
|
|
$searchText = $this->owner->getRequest()->getVar('Search');
|
2011-03-18 04:05:23 +01:00
|
|
|
}
|
|
|
|
|
2011-10-26 07:35:51 +02:00
|
|
|
$fields = new FieldList(
|
2011-03-18 04:05:23 +01:00
|
|
|
new TextField('Search', false, $searchText)
|
|
|
|
);
|
2011-10-26 07:35:51 +02:00
|
|
|
$actions = new FieldList(
|
2011-03-18 04:05:23 +01:00
|
|
|
new FormAction('results', _t('SearchForm.GO', 'Go'))
|
|
|
|
);
|
2015-03-31 18:03:17 +02:00
|
|
|
$form = SearchForm::create($this->owner, 'SearchForm', $fields, $actions);
|
2011-03-18 04:05:23 +01:00
|
|
|
$form->classesToSearch(FulltextSearchable::get_searchable_classes());
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process and render search results.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2012-09-19 12:07:46 +02:00
|
|
|
public function results($data, $form, $request) {
|
2011-03-18 04:05:23 +01:00
|
|
|
$data = array(
|
|
|
|
'Results' => $form->getResults(),
|
2014-04-30 01:05:25 +02:00
|
|
|
'Query' => DBField::create_field('Text', $form->getSearchQuery()),
|
2011-03-18 04:05:23 +01:00
|
|
|
'Title' => _t('SearchForm.SearchResults', 'Search Results')
|
|
|
|
);
|
|
|
|
return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
|
|
|
|
}
|
2012-04-12 09:23:20 +02:00
|
|
|
}
|