mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 07:47:00 +02:00
Update for processwire/processwire-issues#1701
This commit is contained in:
@@ -195,11 +195,13 @@ class PageComparison {
|
|||||||
*
|
*
|
||||||
* @param Page $page
|
* @param Page $page
|
||||||
* @param string|array|Selectors $s
|
* @param string|array|Selectors $s
|
||||||
|
* @param array $options Options to modify behavior (3.0.225+ only):
|
||||||
|
* - `useDatabase` (bool|null): Use database for matching rather than in-memory? (default=false)
|
||||||
* @return bool
|
* @return bool
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function matches(Page $page, $s) {
|
public function matches(Page $page, $s, array $options = array()) {
|
||||||
|
|
||||||
$selectors = array();
|
$selectors = array();
|
||||||
|
|
||||||
if(is_string($s) || is_int($s)) {
|
if(is_string($s) || is_int($s)) {
|
||||||
@@ -238,13 +240,11 @@ class PageComparison {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$selectors->add(new SelectorEqual('id', $page->id))->add(new SelectorEqual('include', 'all'));
|
if(!empty($options['useDatabase'])) {
|
||||||
|
$selectors->add(new SelectorEqual('id', $page->id))->add(new SelectorEqual('include', 'all'));
|
||||||
return $page->wire()->pages->count($selectors) > 0;
|
return $page->wire()->pages->count($selectors) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* the following is for performing in-memory matches, left here for reference
|
|
||||||
*
|
|
||||||
$matches = false;
|
$matches = false;
|
||||||
|
|
||||||
foreach($selectors as $selector) {
|
foreach($selectors as $selector) {
|
||||||
@@ -276,7 +276,26 @@ class PageComparison {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $matches;
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user