Skip to content
Closed
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions modules/api/php/views/project.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ class Project
{
$meta = ['Project' => $this->_project->getName()];

$centerIDs = \User::singleton()->hasPermission('access_all_profiles')
? []
: \User::singleton()->getCenterIDs();

$obj = [
'Meta' => $meta,
'Candidates' => $this->_project->getCandidateIds(),
'Candidates' => $this->_project->getCandidateIds($centerIDs),
'Instruments' => array_keys(\Utility::getAllInstruments()),
'Visits' => $this->_getVisits(),
];
Expand Down Expand Up @@ -83,9 +87,13 @@ class Project
{
$meta = ['Project' => $this->_project->getName()];

$centerIDs = \User::singleton()->hasPermission('access_all_profiles')
? []
: \User::singleton()->getCenterIDs();

return [
'Meta' => $meta,
'Candidates' => $this->_project->getCandidateIds(),
'Candidates' => $this->_project->getCandidateIds($centerIDs),
];
}

Expand Down
20 changes: 17 additions & 3 deletions php/libraries/Project.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,26 @@ class Project implements \JsonSerializable
/**
* Get that project's participants
*
* @param array $centerIDs A list of center IDs that the candidate's
* registration center ID must be in.
*
* @return array A list of object representation of a basic candidates
*/
public function getCandidateIds(): array
public function getCandidateIds(array $centerIDs = []): array
{
$factory = \NDB_Factory::singleton();

$p = [$this->_projectId];
$args['v_project_id'] = implode(',', [$this->_projectId]);

// Compute clause restricting the candidate's center ID (if any)
// and its associated argument.
if (!empty($centerIDs)) {
$args['v_center_id'] = implode(',', $centerIDs);
}
$centerIDClause = empty($centerIDs)
? ''
: "AND FIND_IN_SET(IFNULL(RegistrationCenterID, '-1'), :v_center_id)";

$candidatesData = $factory->database()->pselect(
"
SELECT
Expand All @@ -405,8 +418,9 @@ class Project implements \JsonSerializable
WHERE
active = 'Y' AND
FIND_IN_SET(IFNULL(RegistrationProjectID, '-1'), :v_project_id)
$centerIDClause
",
['v_project_id' => implode(',', $p)]
$args
);
return array_map(
function ($row) {
Expand Down
Loading