Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 21bcc01878c94605e2ac251e01a8dd6726290640 1 parent 97d678b
@ajshort ajshort authored wilr committed
View
1  code/controllers/CMSMain.php
@@ -303,6 +303,7 @@ function SearchForm() {
->unsetValidator();
$form->loadDataFrom($this->request->getVars());
+ $this->extend('updateSearchForm', $form);
return $form;
}
View
51 code/controllers/CMSSiteTreeFilter.php
@@ -173,46 +173,53 @@ static function title() {
*
* @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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.