Navigation Menu

Skip to content

Commit

Permalink
fix: Fixed issue with SearchPanes and 3 leftjoins
Browse files Browse the repository at this point in the history
Jira Issue DD-1642
  • Loading branch information
SandyDatatables committed Sep 1, 2020
1 parent 10451f3 commit 63bdee4
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions Editor/SearchPaneOptions.php
Expand Up @@ -190,7 +190,6 @@ public function where ( $_=null )
*/
public function leftJoin ( $table, $field1, $operator, $field2 )
{
// echo("LEFT JOIN ".$table);
$this->_leftJoin[] = array(
"table" => $table,
"field1" => $field1,
Expand Down Expand Up @@ -233,7 +232,6 @@ private function _get_where ( $query )
*/
private function _perform_left_join ( $query )
{
// echo($this->_leftJoin." COUNT 236");
if ( count($this->_leftJoin) ) {
for ( $i=0, $ien=count($this->_leftJoin) ; $i<$ien ; $i++ ) {
$join = $this->_leftJoin[$i];
Expand All @@ -256,7 +254,6 @@ private function _perform_left_join ( $query )
*/
public function exec ( $field, $editor, $http, $fields, $leftJoinIn )
{
// echo($this->_value." ".$field->dbField()."\n");
// If the value is not yet set then set the variable to be the field name
if ( $this->_value == null) {
$value = $field->dbField();
Expand Down Expand Up @@ -294,19 +291,20 @@ public function exec ( $field, $editor, $http, $fields, $leftJoinIn )
}

// Set up the join variable so that it will fit nicely later
if(count($this->_leftJoin) > 0){
$leftJoin = $this->_leftJoin[0];
}
else {
$leftJoin = $this->_leftJoin;
}

// Set up the left join varaible so that it will fit nicely later
if(count($leftJoinIn) > 0 && count($leftJoin) === 0) {
$leftJoin = $leftJoinIn[0];
}
else if(count($leftJoin) === 0) {
$leftJoin = $leftJoinIn;
$leftJoin = gettype($this->_leftJoin) === 'array' ?
$this->_leftJoin :
[$this->_leftJoin];

foreach($leftJoinIn as $lj) {
$found = false;
foreach($leftJoin as $lje) {
if($lj['table'] === $lje['table']) {
$found = true;
}
}
if(!$found) {
array_push($leftJoin, $lj);
}
}

// Set the query to get the current counts for viewTotal
Expand All @@ -322,7 +320,9 @@ public function exec ( $field, $editor, $http, $fields, $leftJoinIn )
// If a join is required then we need to add the following to the query
// print_r($leftJoin);
if (count($leftJoin) > 0){
$query->join( $leftJoin['table'], $leftJoin['field1'].' '.$leftJoin['operator'].' '.$leftJoin['field2'], 'LEFT' );
foreach($leftJoin as $lj) {
$query->join( $lj['table'], $lj['field1'].' '.$lj['operator'].' '.$lj['field2'], 'LEFT' );
}
}

// Construct the where queries based upon the options selected by the user
Expand Down Expand Up @@ -354,7 +354,9 @@ public function exec ( $field, $editor, $http, $fields, $leftJoinIn )

// If a join is required then we need to add the following to the query
if (count($leftJoin) > 0){
$q->join( $leftJoin['table'], $leftJoin['field1'].' '.$leftJoin['operator'].' '.$leftJoin['field2'], 'LEFT' );
foreach($leftJoin as $lj) {
$q->join( $lj['table'], $lj['field1'].' '.$lj['operator'].' '.$lj['field2'], 'LEFT' );
}
}

if ( $this->_order ) {
Expand Down

0 comments on commit 63bdee4

Please sign in to comment.