diff --git a/modules/statistics/php/stats_behavioural.class.inc b/modules/statistics/php/stats_behavioural.class.inc index 8f32085db8f..36fefe35690 100644 --- a/modules/statistics/php/stats_behavioural.class.inc +++ b/modules/statistics/php/stats_behavioural.class.inc @@ -63,7 +63,17 @@ class Stats_Behavioural extends \NDB_Form { parent::setup(); - $DB =& \Database::singleton(); + $factory = \NDB_Factory::singleton(); + $DB = $factory->database(); + $user = $factory->user(); + + //SITES + if ($user->hasPermission('access_all_profiles')) { + $list_of_sites = \Utility::getSiteList(); + } else { + $list_of_sites = $user->getStudySites(); + } + $sitesString = implode(",", array_keys($list_of_sites)); $centers = $DB->pselect( "SELECT CONCAT('C', CenterID) as ID, @@ -72,7 +82,8 @@ class Stats_Behavioural extends \NDB_Form Name as ShortName FROM psc WHERE CenterID <> '1' - AND Study_site = 'Y'", + AND Study_site = 'Y' + AND CenterID IN (" . $sitesString . ")", array() ); @@ -142,6 +153,7 @@ class Stats_Behavioural extends \NDB_Form AND s.Current_stage <> 'Recycling Bin' AND f.CommentID NOT LIKE 'DDE%' AND s.CenterID <> '1' + AND s.CenterID IN (" . $sitesString . ") $suproject_query $Param_Project GROUP by s.ID, s.CenterID, VLabel, f.Data_Entry", @@ -199,20 +211,21 @@ class Stats_Behavioural extends \NDB_Form } // DDE STATS $result = $DB->pselect( - "SELECT s.CenterID, - f.Data_Entry as Data_Entry, - s.visit_label as VLabel, - COUNT(s.CandID) as val + "SELECT s.CenterID, + f.Data_Entry as Data_Entry, + s.visit_label as VLabel, + COUNT(s.CandID) as val FROM session as s - JOIN candidate as c ON (s.CandID=c.CandID) - JOIN flag as f ON (f.SessionID=s.ID) - WHERE s.Active='Y' - AND s.Current_stage <> 'Recycling Bin' - AND f.CommentID LIKE 'DDE%' - AND c.Active='Y' - AND s.CenterID <> '1' - $suproject_query - $Param_Project + JOIN candidate as c ON(s.CandID=c.CandID) + JOIN flag as f ON(f.SessionID=s.ID) + WHERE s.Active = 'Y' + AND s.Current_stage <> 'Recycling Bin' + AND f.CommentID LIKE 'DDE%' + AND c.Active = 'Y' + AND s.CenterID <> '1' + AND s.CenterID IN(" . $sitesString . ") + $suproject_query + $Param_Project GROUP BY s.CenterID, VLabel, f.Data_Entry", $this->params ?? array() );