1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 08:17:12 +02:00

Add Page::matchesDatabase() method to accompany existing matches() method but query the database rather than in memory

This commit is contained in:
Ryan Cramer
2023-08-17 12:09:01 -04:00
parent 1ff6f147f8
commit 754fb2b1fd
2 changed files with 24 additions and 23 deletions

View File

@@ -3188,7 +3188,7 @@ class Page extends WireData implements \Countable, WireMatchable {
}
/**
* Given a selector, return whether or not this Page matches it
* Given a selector, return whether or not this Page matches using runtime/memory comparison
*
* ~~~~~
* if($page->matches("created>=" . strtotime("today"))) {
@@ -3196,6 +3196,8 @@ class Page extends WireData implements \Countable, WireMatchable {
* }
* ~~~~~
*
* #pw-group-traversal
*
* @param string|Selectors|array $s Selector to compare against (string, Selectors object, or array).
* @return bool Returns true if this page matches, or false if it doesn't.
*
@@ -3204,6 +3206,26 @@ class Page extends WireData implements \Countable, WireMatchable {
// This method implements the WireMatchable interface
return $this->comparison()->matches($this, $s);
}
/**
* Given a selector, return whether or not this Page matches by querying the database
*
* ~~~~~
* if($page->matchesDatabase("created>=today")) {
* echo "This page was created today";
* }
* ~~~~~
*
* #pw-group-traversal
*
* @param string|Selectors|array $s Selector to compare against (string, Selectors object, or array).
* @return bool Returns true if this page matches, or false if it doesn't.
* @since 3.0.225
*
*/
public function matchesDatabase($s) {
return $this->comparison()->matches($this, $s, array('useDatabase' => true));
}
/**
* Does this page have the specified status number or template name?
@@ -3211,7 +3233,7 @@ class Page extends WireData implements \Countable, WireMatchable {
* See status flag constants at top of Page class.
* You may also use status names: hidden, locked, unpublished, system, systemID
*
* #pw-internal
* #pw-group-status
*
* @param int|string|Selectors $status Status number, status name, or Template name or selector string/object
* @return bool
@@ -4178,4 +4200,3 @@ class Page extends WireData implements \Countable, WireMatchable {
}
}

View File

@@ -278,26 +278,6 @@ class PageComparison {
return $matches;
}
/**
* Same as matches() method but forces use of the database only for matching
*
* ~~~~~
* $selector = "created>=" . strtotime("today");
* if($page->comparison()->matchesDatabase($selector) {
* echo "This page was created today";
* }
* ~~~~~
*
* @param Page $page
* @param string|array|Selectors $s
* @return bool
* @since 3.0.225
*
*/
public function matchesDatabase(Page $page, $s) {
return $this->matches($page, $s, array('useDatabase' => true));
}
/**
* Given an object, return the value(s) it represents (optionally from a property in the object)
*