mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-08-26 20:45:47 +02:00
FEATURE New DateField and TimeField form classes with more consistent API and easier localization API CHANGE Date/time parsing in DateField, TimeField and DatetimeField defaults to i18n::get_locale() ('en_US') instead of using en_NZ/en_GB specific parsing. Use i18n::set_locale('en_NZ') in mysite/_config.php to revert to old behaviour. API CHANGE constructor parameter in TimeField needs to be in ISO date notation (not PHP's date()) API CHANGE TimeField, DateField and related subclasses use Zend_Date for date parsing, meaning they're stricer than the previously used strtotime() API CHANGE Removed DMYCalendarDateField and CalendarDateField, use DateField with setConfig('showcalendar') API CHANGE Removed CompositeDateField, DMYDateField, use DateField with setConfig('dmyfields') API CHANGE Removed DropdownTimeField, use TimeField with setConfig('showdropdown') API CHANGE Removed PopupDateTimeField, use DatetimeField API CHANGE Changed 'date', 'month' and 'year' HTML field names to lowercase in DMYDateField API CHANGE Removed support for ambiguous date formats in DateField, e.g. '06/03/03'. Use DateField->setConfig('dateformat', '<format>') to revert to this behaviour. API CHANGE Removed flag from DateField, CalendarDateField etc., use DateField->setConfig('min') and DateField->setConfig('max') ENHANCEMENT Using Zend_Date for DateField and TimeField, with more robust date handling, starting localization support. Set globally via i18n::set_locale(), or for a field instance through setLocale(). Note: Javascript validation is not localized yet. (from r99360) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102859 467b73ca-7a2a-4603-9d3b-597d59a354a9
137 lines
4.6 KiB
PHP
Executable File
137 lines
4.6 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* More advanced search form
|
|
* @package sapphire
|
|
* @subpackage search
|
|
*/
|
|
class AdvancedSearchForm extends SearchForm {
|
|
|
|
/**
|
|
* the constructor of a Simple/basic SearchForm
|
|
*/
|
|
function __construct($controller, $name, $fields = null, $actions = null) {
|
|
if(!$fields) {
|
|
$fields = new FieldSet(
|
|
$searchBy = new CompositeField(
|
|
new HeaderField('SearchByHeader',_t('AdvancedSearchForm.SEARCHBY', 'SEARCH BY')),
|
|
new TextField("+", _t('AdvancedSearchForm.ALLWORDS', 'All Words')),
|
|
new TextField("quote", _t('AdvancedSearchForm.EXACT', 'Exact Phrase')),
|
|
new TextField("any", _t('AdvancedSearchForm.ATLEAST', 'At Least One Of the Words')),
|
|
new TextField("-", _t('AdvancedSearchForm.WITHOUT', 'Without the Words'))
|
|
),
|
|
$sortBy = new CompositeField(
|
|
new HeaderField('SortByHeader',_t('AdvancedSearchForm.SORTBY', 'SORT RESULTS BY')),
|
|
new OptionsetField("sortby", "",
|
|
array(
|
|
'Relevance' => _t('AdvancedSearchForm.RELEVANCE', 'Relevance'),
|
|
'LastUpdated' => _t('AdvancedSearchForm.LASTUPDATED', 'Last Updated'),
|
|
'PageTitle' => _t('AdvancedSearchForm.PAGETITLE', 'Page Title'),
|
|
),
|
|
'Relevance'
|
|
)
|
|
),
|
|
$chooseDate = new CompositeField(
|
|
new HeaderField('LastUpdatedHeader',_t('AdvancedSearchForm.LASTUPDATEDHEADER', 'LAST UPDATED')),
|
|
new DateField("From", _t('AdvancedSearchForm.FROM', 'From')),
|
|
new DateField("To", _t('AdvancedSearchForm.TO', 'To'))
|
|
)
|
|
);
|
|
|
|
$searchBy->ID = "AdvancedSearchForm_SearchBy";
|
|
$searchOnly->ID = "AdvancedSearchForm_SearchOnly";
|
|
$sortBy->ID = "AdvancedSearchForm_SortBy";
|
|
$chooseDate->ID = "AdvancedSearchForm_ChooseDate";
|
|
}
|
|
|
|
if(!$actions) {
|
|
$actions = new FieldSet(
|
|
new FormAction("results", _t('AdvancedSearchForm.GO', 'Go'))
|
|
);
|
|
}
|
|
parent::__construct($controller, $name, $fields, $actions);
|
|
}
|
|
|
|
public function forTemplate(){
|
|
return $this->renderWith(array("AdvancedSearchForm","Form"));
|
|
}
|
|
|
|
/* Return dataObjectSet of the results, using the form data.
|
|
*/
|
|
public function getResults($numPerPage = 10) {
|
|
$data = $this->getData();
|
|
|
|
if($data['+']) $keywords .= " +" . ereg_replace(" +", " +", trim($data['+']));
|
|
if($data['quote']) $keywords .= ' "' . $data['quote'] . '"';
|
|
if($data['any']) $keywords .= ' ' . $data['any'];
|
|
if($data['-']) $keywords .= " -" . ereg_replace(" +", " -", trim($data['-']));
|
|
$keywords = trim($keywords);
|
|
|
|
// This means that they want to just find pages where there's *no* match
|
|
|
|
if($keywords[0] == '-') {
|
|
$keywords = $data['-'];
|
|
$invertedMatch = true;
|
|
}
|
|
|
|
|
|
// Limit search to various sections
|
|
if($_REQUEST['OnlyShow']) {
|
|
$pageList = array();
|
|
|
|
// Find the associated pages
|
|
foreach($_REQUEST['OnlyShow'] as $section => $checked) {
|
|
$items = explode(",", $section);
|
|
foreach($items as $item) {
|
|
$page = DataObject::get_one('SiteTree', "\"URLSegment\" = '" . DB::getConn()->addslashes($item) . "'");
|
|
$pageList[] = $page->ID;
|
|
if(!$page) user_error("Can't find a page called '$item'", E_USER_WARNING);
|
|
$page->loadDescendantIDListInto($pageList);
|
|
}
|
|
}
|
|
$contentFilter = "\"ID\" IN (" . implode(",", $pageList) . ")";
|
|
|
|
// Find the files associated with those pages
|
|
$fileList = DB::query("SELECT \"FileID\" FROM \"Page_ImageTracking\" WHERE \"PageID\" IN (" . implode(",", $pageList) . ")")->column();
|
|
if($fileList) $fileFilter = "\"ID\" IN (" . implode(",", $fileList) . ")";
|
|
else $fileFilter = " 1 = 2 ";
|
|
}
|
|
|
|
if($data['From']) {
|
|
$filter .= ($filter?" AND":"") . " \"LastEdited\" >= '$data[From]'";
|
|
}
|
|
if($data['To']) {
|
|
$filter .= ($filter?" AND":"") . " \"LastEdited\" <= '$data[To]'";
|
|
}
|
|
|
|
if($filter) {
|
|
$contentFilter .= ($contentFilter?" AND":"") . $filter;
|
|
$fileFilter .= ($fileFilter?" AND":"") . $filter;
|
|
}
|
|
|
|
if($data['sortby']) {
|
|
$sorts = array(
|
|
'LastUpdated' => '"LastEdited" DESC',
|
|
'PageTitle' => '"Title" ASC',
|
|
'Relevance' => '"Relevance" DESC',
|
|
);
|
|
$sortBy = $sorts[$data['sortby']] ? $sorts[$data['sortby']] : $sorts['Relevance'];
|
|
}
|
|
|
|
$keywords = $this->addStarsToKeywords($keywords);
|
|
|
|
return $this->searchEngine($keywords, $numPerPage, $sortBy, $contentFilter, true, $fileFilter, $invertedMatch);
|
|
}
|
|
|
|
function getSearchQuery() {
|
|
$data = $_REQUEST;
|
|
if($data['+']) $keywords .= " +" . ereg_replace(" +", " +", trim($data['+']));
|
|
if($data['quote']) $keywords .= ' "' . $data['quote'] . '"';
|
|
if($data['any']) $keywords .= ' ' . $data['any'];
|
|
if($data['-']) $keywords .= " -" . ereg_replace(" +", " -", trim($data['-']));
|
|
|
|
return trim($keywords);
|
|
}
|
|
|
|
}
|
|
|
|
?>
|