Skip to content

Commit

Permalink
LIMS-1514: Dont join to data collections if not specifying proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Williams committed Dec 3, 2024
1 parent 7e85c23 commit c2daeb3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions api/src/Page/Proposal.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@ function _get_visits($visit = null, $output = true)

if ($this->has_arg('all')) {
$args = array();
$where = 'WHERE 1=1';
// 'All' is used for the main summary view (Next, Last, Commissioning)
// Ignore session zero for this summary view - they should be included if a proposal is selected
$where .= " AND s.visit_number > 0";
$where = "WHERE s.visit_number > 0";
$select = '';
$join = '';
} else {
if (!$this->has_arg('prop'))
$this->_error('No proposal specified');
Expand All @@ -343,6 +344,9 @@ function _get_visits($visit = null, $output = true)

$args = array($p);
$where = 'WHERE s.proposalid = :1';
$select = 'COUNT(distinct dc.datacollectionid) AS dccount,';
$join = 'LEFT OUTER JOIN datacollectiongroup dcg ON dcg.sessionid = s.sessionid
LEFT OUTER JOIN datacollection dc ON dcg.datacollectiongroupid = dc.datacollectiongroupid';
}

if ($this->has_arg('notnull')) {
Expand Down Expand Up @@ -472,16 +476,15 @@ function _get_visits($visit = null, $output = true)
s.beamcalendarid,
CONCAT(p.proposalcode, p.proposalnumber) AS proposal,
COUNT(shp.personid) AS persons,
COUNT(distinct dc.datacollectionid) AS dccount,
$select
s.proposalid
FROM BLSession s
INNER JOIN proposal p ON p.proposalid = s.proposalid
LEFT OUTER JOIN sessiontype st ON st.sessionid = s.sessionid
LEFT OUTER JOIN session_has_person shp ON shp.sessionid = s.sessionid
LEFT OUTER JOIN beamlinesetup bls on bls.beamlinesetupid = s.beamlinesetupid
LEFT OUTER JOIN beamcalendar bc ON bc.beamcalendarid = s.beamcalendarid
LEFT OUTER JOIN datacollectiongroup dcg ON dcg.sessionid = s.sessionid
LEFT OUTER JOIN datacollection dc ON dcg.datacollectiongroupid = dc.datacollectiongroupid
$join
$where
GROUP BY s.sessionid
ORDER BY $order", $args);
Expand Down

0 comments on commit c2daeb3

Please sign in to comment.