mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02: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();
|
||||
$form->loadDataFrom($this->request->getVars());
|
||||
|
||||
$this->extend('updateSearchForm', $form);
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -173,46 +173,53 @@ class CMSSiteTreeFilter_Search extends CMSSiteTreeFilter {
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
function pagesIncluded() {
|
||||
public function pagesIncluded() {
|
||||
$sng = singleton('SiteTree');
|
||||
$ids = array();
|
||||
$q = new SQLQuery();
|
||||
$q->setSelect(array('"ID"','"ParentID"'))
|
||||
->setFrom('"SiteTree"');
|
||||
$where = array();
|
||||
|
||||
$SQL_params = Convert::raw2sql($this->params);
|
||||
foreach($SQL_params as $name => $val) {
|
||||
|
||||
$query = new DataQuery('SiteTree');
|
||||
$query->setQueriedColumns(array('ID', 'ParentID'));
|
||||
|
||||
foreach($this->params as $name => $val) {
|
||||
$SQL_val = Convert::raw2sql($val);
|
||||
|
||||
switch($name) {
|
||||
// Match against URLSegment, Title, MenuTitle & Content
|
||||
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;
|
||||
// Match against date
|
||||
|
||||
case 'LastEditedFrom':
|
||||
if($val) $where[] = "\"LastEdited\" >= '$val'";
|
||||
$query->where("\"LastEdited\" >= '$SQL_val'");
|
||||
break;
|
||||
|
||||
case 'LastEditedTo':
|
||||
if($val) $where[] = "\"LastEdited\" <= '$val'";
|
||||
$query->where("\"LastEdited\" <= '$SQL_val'");
|
||||
break;
|
||||
// Match against exact ClassName
|
||||
|
||||
case 'ClassName':
|
||||
if($val && $val != 'All') {
|
||||
$where[] = "\"ClassName\" = '$val'";
|
||||
$query->where("\"ClassName\" = '$SQL_val'");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Partial string match against a variety of fields
|
||||
if(!empty($val) && singleton("SiteTree")->hasDatabaseField($name)) {
|
||||
$where[] = "\"$name\" LIKE '%$val%'";
|
||||
if(!empty($val) && $sng->hasDatabaseField($name)) {
|
||||
$filter = $sng->dbObject($name)->defaultSearchFilter();
|
||||
$filter->setValue($val);
|
||||
$filter->apply($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
$q->setWhere(empty($where) ? '' : '(' . implode(') AND (',$where) . ')');
|
||||
|
||||
foreach($q->execute() as $row) {
|
||||
$ids[] = array('ID'=>$row['ID'],'ParentID'=>$row['ParentID']);
|
||||
foreach($query->execute() as $row) {
|
||||
$ids[] = array('ID' => $row['ID'], 'ParentID' => $row['ParentID']);
|
||||
}
|
||||
|
||||
|
||||
return $ids;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user