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:
@@ -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.
|
||||
*
|
||||
@@ -3205,13 +3207,33 @@ class Page extends WireData implements \Countable, WireMatchable {
|
||||
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?
|
||||
*
|
||||
* 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 {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -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)
|
||||
*
|
||||
|
Reference in New Issue
Block a user