mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
ENHANCEMENT: Made the tree search form more extensible.
- Use DataQuery for generating the search query. - For custom field matching, use searchcontext rather than a LIKE query. - Added an extension hook for updating the search form.
This commit is contained in:
parent
97d678b258
commit
21bcc01878
@ -303,6 +303,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
|
|||||||
->unsetValidator();
|
->unsetValidator();
|
||||||
$form->loadDataFrom($this->request->getVars());
|
$form->loadDataFrom($this->request->getVars());
|
||||||
|
|
||||||
|
$this->extend('updateSearchForm', $form);
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,43 +173,50 @@ class CMSSiteTreeFilter_Search extends CMSSiteTreeFilter {
|
|||||||
*
|
*
|
||||||
* @return Array
|
* @return Array
|
||||||
*/
|
*/
|
||||||
function pagesIncluded() {
|
public function pagesIncluded() {
|
||||||
|
$sng = singleton('SiteTree');
|
||||||
$ids = array();
|
$ids = array();
|
||||||
$q = new SQLQuery();
|
|
||||||
$q->setSelect(array('"ID"','"ParentID"'))
|
|
||||||
->setFrom('"SiteTree"');
|
|
||||||
$where = array();
|
|
||||||
|
|
||||||
$SQL_params = Convert::raw2sql($this->params);
|
$query = new DataQuery('SiteTree');
|
||||||
foreach($SQL_params as $name => $val) {
|
$query->setQueriedColumns(array('ID', 'ParentID'));
|
||||||
|
|
||||||
|
foreach($this->params as $name => $val) {
|
||||||
|
$SQL_val = Convert::raw2sql($val);
|
||||||
|
|
||||||
switch($name) {
|
switch($name) {
|
||||||
// Match against URLSegment, Title, MenuTitle & Content
|
|
||||||
case 'Term':
|
case 'Term':
|
||||||
if($val) $where[] = "\"URLSegment\" LIKE '%$val%' OR \"Title\" LIKE '%$val%' OR \"MenuTitle\" LIKE '%$val%' OR \"Content\" LIKE '%$val%'";
|
$query->whereAny(array(
|
||||||
|
"\"URLSegment\" LIKE '%$SQL_val%'",
|
||||||
|
"\"Title\" LIKE '%$SQL_val%'",
|
||||||
|
"\"MenuTitle\" LIKE '%$SQL_val%'",
|
||||||
|
"\"Content\" LIKE '%$SQL_val%'"
|
||||||
|
));
|
||||||
break;
|
break;
|
||||||
// Match against date
|
|
||||||
case 'LastEditedFrom':
|
case 'LastEditedFrom':
|
||||||
if($val) $where[] = "\"LastEdited\" >= '$val'";
|
$query->where("\"LastEdited\" >= '$SQL_val'");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'LastEditedTo':
|
case 'LastEditedTo':
|
||||||
if($val) $where[] = "\"LastEdited\" <= '$val'";
|
$query->where("\"LastEdited\" <= '$SQL_val'");
|
||||||
break;
|
break;
|
||||||
// Match against exact ClassName
|
|
||||||
case 'ClassName':
|
case 'ClassName':
|
||||||
if($val && $val != 'All') {
|
if($val && $val != 'All') {
|
||||||
$where[] = "\"ClassName\" = '$val'";
|
$query->where("\"ClassName\" = '$SQL_val'");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
// Partial string match against a variety of fields
|
|
||||||
if(!empty($val) && singleton("SiteTree")->hasDatabaseField($name)) {
|
|
||||||
$where[] = "\"$name\" LIKE '%$val%'";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$q->setWhere(empty($where) ? '' : '(' . implode(') AND (',$where) . ')');
|
|
||||||
|
|
||||||
foreach($q->execute() as $row) {
|
default:
|
||||||
|
if(!empty($val) && $sng->hasDatabaseField($name)) {
|
||||||
|
$filter = $sng->dbObject($name)->defaultSearchFilter();
|
||||||
|
$filter->setValue($val);
|
||||||
|
$filter->apply($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach($query->execute() as $row) {
|
||||||
$ids[] = array('ID' => $row['ID'], 'ParentID' => $row['ParentID']);
|
$ids[] = array('ID' => $row['ID'], 'ParentID' => $row['ParentID']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user