mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 09:05:53 +00:00
#1801 - search provides all results back, not a filtered search (merged from branches/2.2.0, r44867)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@44925 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
7eb2078d28
commit
b4fc0105e4
@ -1343,54 +1343,69 @@ JS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filterCache = array();
|
||||||
|
|
||||||
// TODO: Find way to put this in a class
|
// TODO: Find way to put this in a class
|
||||||
function cmsMainMarkingFilterFunction($node) {
|
function cmsMainMarkingFilterFunction($node) {
|
||||||
// Expand all nodes
|
// Expand all nodes
|
||||||
// $node->markingFinished();
|
// $node->markingFinished();
|
||||||
// Don't ever hide nodes with children, because otherwise if one of their children matches the search, it wouldn't be shown.
|
|
||||||
if($node->AllChildrenIncludingDeleted()->count() > 0) {
|
$failed_filter = false;
|
||||||
// Open all nodes with children so it is easy to see any children that match the search.
|
// First check for the generic search term in the URLSegment, Title, MenuTitle, & Content
|
||||||
$node->markOpened();
|
if (!empty($_REQUEST['SiteTreeSearchTerm'])) {
|
||||||
return true;
|
// For childless nodes, show only those matching the filter
|
||||||
} else {
|
$filter = strtolower($_REQUEST['SiteTreeSearchTerm']);
|
||||||
$failed_filter = false;
|
if ( strpos( strtolower($node->URLSegment) , $filter) === false
|
||||||
// First check for the generic search term in the URLSegment, Title, MenuTitle, & Content
|
&& strpos( strtolower($node->Title) , $filter) === false
|
||||||
if (!empty($_REQUEST['SiteTreeSearchTerm'])) {
|
&& strpos( strtolower($node->MenuTitle) , $filter) === false
|
||||||
// For childless nodes, show only those matching the filter
|
&& strpos( strtolower($node->Content) , $filter) === false) {
|
||||||
$filter = strtolower($_REQUEST['SiteTreeSearchTerm']);
|
$failed_filter = true;
|
||||||
if ( strpos( strtolower($node->URLSegment) , $filter) === false
|
}
|
||||||
&& strpos( strtolower($node->Title) , $filter) === false
|
}
|
||||||
&& strpos( strtolower($node->MenuTitle) , $filter) === false
|
// Check the 'Edited Since' date
|
||||||
&& strpos( strtolower($node->Content) , $filter) === false) {
|
if (!empty($_REQUEST['SiteTreeFilterDate'])) {
|
||||||
|
$edited_since = mktime(0, 0, 0, substr($_REQUEST['SiteTreeFilterDate'], 3, 2),
|
||||||
|
substr($_REQUEST['SiteTreeFilterDate'], 0, 2), substr($_REQUEST['SiteTreeFilterDate'], 6, 4));
|
||||||
|
if ( strtotime($node->LastEdited) < $edited_since ) {
|
||||||
|
$failed_filter = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Now check if a specified Criteria attribute matches
|
||||||
|
foreach (CMSMain::T_SiteTreeFilterOptions() as $key => $value)
|
||||||
|
{
|
||||||
|
if (!empty($_REQUEST[$key])) {
|
||||||
|
$parameterName = $key;
|
||||||
|
$filter = strtolower($_REQUEST[$key]);
|
||||||
|
// Show node only if the filter string exists anywere in the filter paramater (ignoring case)
|
||||||
|
if (strpos( strtolower($node->$parameterName) , $filter) === false) {
|
||||||
$failed_filter = true;
|
$failed_filter = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check the 'Edited Since' date
|
}
|
||||||
if (!empty($_REQUEST['SiteTreeFilterDate'])) {
|
// Each filter must match or it fails
|
||||||
$edited_since = mktime(0, 0, 0, substr($_REQUEST['SiteTreeFilterDate'], 3, 2),
|
if (true == $failed_filter) {
|
||||||
substr($_REQUEST['SiteTreeFilterDate'], 0, 2), substr($_REQUEST['SiteTreeFilterDate'], 6, 4));
|
// Don't ever hide nodes with children, because otherwise if one of their children matches the search, it wouldn't be shown.
|
||||||
if ( strtotime($node->LastEdited) < $edited_since ) {
|
if($node->AllChildrenIncludingDeleted()->count() > 0) {
|
||||||
$failed_filter = true;
|
// Open all nodes with children so it is easy to see any children that match the search.
|
||||||
}
|
|
||||||
}
|
foreach($node->AllChildrenIncludingDeleted() as $childNode) {
|
||||||
// Now check if a specified Criteria attribute matches
|
if(cmsMainMarkingFilterFunction($childNode)) {
|
||||||
foreach (CMSMain::T_SiteTreeFilterOptions() as $key => $value)
|
$node->markOpened();
|
||||||
{
|
$filterCache[$node->ID] = true;
|
||||||
if (!empty($_REQUEST[$key])) {
|
return true;
|
||||||
$parameterName = $key;
|
|
||||||
$filter = strtolower($_REQUEST[$key]);
|
|
||||||
// Show node only if the filter string exists anywere in the filter paramater (ignoring case)
|
|
||||||
if (strpos( strtolower($node->$parameterName) , $filter) === false) {
|
|
||||||
$failed_filter = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Each filter must match or it fails
|
|
||||||
if (true == $failed_filter) {
|
$filterCache[$node->ID] = false;
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
if($node->AllChildrenIncludingDeleted()->count() > 0) {
|
||||||
|
$node->markOpened();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$filterCache[$node->ID] = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user