Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions includes/db-queries/query-conditions-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Query_Conditions_Builder {
private $conditions = array();

private $relation_type = 'AND';
private $inherit_view_only = false;

/**
* @var array
Expand Down Expand Up @@ -138,6 +139,10 @@ public function set_conditions( array $conditions ): Query_Conditions_Builder {
}

public function after_set_view() {
if ( $this->inherit_view_only ) {
return;
}

try {
$view = $this->view();
} catch ( Query_Builder_Exception $exception ) {
Expand All @@ -147,6 +152,18 @@ public function after_set_view() {
$this->set_conditions( $view->conditions() );
}

private function inherit_view( Views\View_Base $view ): Query_Conditions_Builder {
if ( $this->view ) {
return $this;
}

$this->inherit_view_only = true;
$this->set_view( $view );
$this->inherit_view_only = false;

return $this;
}

/**
* @return string
*/
Expand Down Expand Up @@ -182,6 +199,10 @@ public function prepare() {
$condition = $this->generator->current();

if ( $condition instanceof Query_Conditions_Builder ) {
if ( $this->view ) {
$condition->inherit_view( $this->view );
}

return sprintf( "(\r\n%s\r\n)", $condition->prepare_conditions() );
}

Expand Down
Loading