diff --git a/modules/dataquery/php/query.class.inc b/modules/dataquery/php/query.class.inc index ac32b1984c..c4cb2fc82f 100644 --- a/modules/dataquery/php/query.class.inc +++ b/modules/dataquery/php/query.class.inc @@ -761,11 +761,7 @@ class Query implements \LORIS\StudyEntities\AccessibleResource, throw new \Exception("Unhandled operator: " . $crit['op']); } - // FIXME: Verify visits, test was done with candidate scope data - $visitlist = null; - if (isset($crit['visits'])) { - $visitlist = $crit['visits']; - } + $visitlist = $crit['visits'] ?? null; \Profiler::checkpoint("Calling engine get matches"); $matches = $engine->getCandidateMatches($term, $visitlist); diff --git a/modules/imaging_browser/php/queryengine.class.inc b/modules/imaging_browser/php/queryengine.class.inc index 2b39b1cf2d..7ec70a7fb0 100644 --- a/modules/imaging_browser/php/queryengine.class.inc +++ b/modules/imaging_browser/php/queryengine.class.inc @@ -375,7 +375,10 @@ class QueryEngine extends \LORIS\Data\Query\SQLQueryEngine \LORIS\Data\Dictionary\DictionaryItem $item ): string { if ($item->getName() == 'ScanDone') { - $this->addTable('LEFT JOIN session s ON (s.CandidateID=c.ID)'); + $this->addTable( + "LEFT JOIN session s " + . "ON (s.CandidateID=c.ID AND s.Active='Y')" + ); return "CASE WHEN s.Scan_Done='Y' THEN true WHEN s.Scan_Done='N' THEN false ELSE NULL END"; @@ -392,7 +395,10 @@ class QueryEngine extends \LORIS\Data\Query\SQLQueryEngine // $field = whatever's after the first underscore $field = substr($item->getName(), strpos($item->getName(), '_') + 1); - $this->addTable('LEFT JOIN session s ON (s.CandidateID=c.ID)'); + $this->addTable( + "LEFT JOIN session s " + . "ON (s.CandidateID=c.ID AND s.Active='Y')" + ); $this->addTable("LEFT JOIN files ON (s.ID=files.SessionID)"); if ($item instanceof LocationDictionaryItem) { @@ -544,7 +550,10 @@ class QueryEngine extends \LORIS\Data\Query\SQLQueryEngine || $item instanceof MRICommentDictionaryItem || $item instanceof MRIPredefinedCommentDictionaryItem ) { - $this->addTable('LEFT JOIN session s ON (s.CandidateID=c.ID)'); + $this->addTable( + "LEFT JOIN session s " + . "ON (s.CandidateID=c.ID AND s.Active='Y')" + ); $this->addTable("LEFT JOIN files ON (s.ID=files.SessionID)"); return "SUBSTRING_INDEX(files.File, '/', -1)"; } diff --git a/src/Data/Query/SQLQueryEngine.php b/src/Data/Query/SQLQueryEngine.php index c2c32eb917..7947237e32 100644 --- a/src/Data/Query/SQLQueryEngine.php +++ b/src/Data/Query/SQLQueryEngine.php @@ -116,7 +116,7 @@ public function getCandidateMatches( $this->addWhereClause("c.Active='Y'"); $prepbindings = []; - $this->buildQueryFromCriteria($term, $prepbindings); + $this->buildQueryFromCriteria($term, $prepbindings, $visitlist); $query = 'SELECT DISTINCT c.CandID FROM';