Skip to content

Commit

Permalink
Displaying user projects and sites for filters
Browse files Browse the repository at this point in the history
  • Loading branch information
laemtl committed Aug 16, 2021
1 parent c955b88 commit 1a067ea
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 67 deletions.
41 changes: 13 additions & 28 deletions modules/conflict_resolver/php/conflict_resolver.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class Conflict_Resolver extends \NDB_Menu_Filter_Form
$this->query .= ' AND session.CenterID IN (' . $site_arr . ')';
}

$proj_arr = implode(",", $user->getProjectIDs());
$this->query .= " AND session.ProjectID IN ($proj_arr)";

$this->group_by = '';
$this->order_by = 'conflicts_unresolved.TableName, session.Visit_label';
$this->headers = [
Expand Down Expand Up @@ -266,34 +269,17 @@ class Conflict_Resolver extends \NDB_Menu_Filter_Form
$visits = \Utility::getVisitList();
$visits = array_merge(['' => 'All'], $visits);

// Get sites
if ($user->hasPermission('access_all_profiles')) {
// get the list of study sites - to be replaced by the Site object
$sites = \Utility::getSiteList();
foreach ($sites as $key => $site) {
unset($sites[$key]);
$sites[$site] = $site;
}
if (is_array($sites)) {
$sites = ['' => 'All'] + $sites;
}
} else {
// allow only to view own site data
$sites = $user->getStudySites();
foreach ($sites as $key => $site) {
unset($sites[$key]);
$sites[$site] = $site;
}
$sites = ['' => 'All User Sites'] + $sites;
}

$labelOptions = [
'addEmptyOption' => true,
'emptyOptionValue' => '',
];

// Add form elements
$this->addSelect('site', 'For Site:', $sites);
$this->addSelect(
'site',
'For Site:',
['' => 'All'] + $this->getSiteOptions($user, false)
);
$this->addSelect('instrument', 'Instrument:', $instruments, $labelOptions);
$this->addSelect('visitLabel', 'Visit label:', $visits);
$this->addBasicText(
Expand All @@ -317,12 +303,11 @@ class Conflict_Resolver extends \NDB_Menu_Filter_Form
$this->addBasicText('question', 'Question:');

// Project list, if applicable
$list_of_projects = [];
$projectList = \Utility::getProjectList();
foreach (array_values($projectList) as $value) {
$list_of_projects[$value] = $value;
}
$this->addSelect('project', 'Project: ', $list_of_projects);
$this->addSelect(
'project',
'Project: ',
$this->getProjectOptions($user, false)
);
}

/**
Expand Down
41 changes: 13 additions & 28 deletions modules/conflict_resolver/php/resolved_conflicts.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ class Resolved_Conflicts extends \NDB_Menu_Filter
$this->query .= ' AND session.CenterID IN (' . $site_arr . ')';
}

$proj_arr = implode(",", $user->getProjectIDs());
$this->query .= " AND session.ProjectID IN ($proj_arr)";

$this->group_by = '';
$this->order_by = 'conflicts_resolved.TableName, session.Visit_label';

Expand Down Expand Up @@ -117,34 +120,17 @@ class Resolved_Conflicts extends \NDB_Menu_Filter
$visits = \Utility::getVisitList();
$visits = array_merge(['' => 'All'], $visits);

// Get sites
if ($user->hasPermission('access_all_profiles')) {
// get the list of study sites - to be replaced by the Site object
$sites = \Utility::getSiteList();
foreach ($sites as $key => $site) {
unset($sites[$key]);
$sites[$site] = $site;
}
if (is_array($sites)) {
$sites = ['' => 'All'] + $sites;
}
} else {
// allow only to view own site data
$sites = $user->getStudySites();
foreach ($sites as $key => $site) {
unset($sites[$key]);
$sites[$site] = $site;
}
$sites = ['' => 'All User Sites'] + $sites;
}

$labelOptions = [
'addEmptyOption' => true,
'emptyOptionValue' => '',
];

// Add form elements
$this->addSelect('site', 'For Site:', $sites);
$this->addSelect(
'site',
'For Site:',
['' => 'All'] + $this->getSiteOptions($user, false)
);
$this->addSelect('instrument', 'Instrument:', $instruments, $labelOptions);
$this->addSelect('visitLabel', 'Visit label:', $visits);
$this->addBasicText(
Expand All @@ -169,12 +155,11 @@ class Resolved_Conflicts extends \NDB_Menu_Filter
$this->addBasicText('resolutionTimestamp', 'Resolution Timestamp:');

// Project list, if applicable
$list_of_projects = [];
$projectList = \Utility::getProjectList();
foreach (array_values($projectList) as $value) {
$list_of_projects[$value] = $value;
}
$this->addSelect('project', 'Project: ', $list_of_projects);
$this->addSelect(
'project',
'Project: ',
$this->getProjectOptions($user, false)
);
}

/**
Expand Down
21 changes: 10 additions & 11 deletions modules/conflict_resolver/test/conflict_resolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
use Facebook\WebDriver\WebDriverSelect;
use Facebook\WebDriver\WebDriverBy;
require_once __DIR__
require_once __DIR__
. "/../../../test/integrationtests/LorisIntegrationTest.class.inc";
/**
* Implements tests for conflict resolver
Expand Down Expand Up @@ -52,7 +52,6 @@ class ConflictResolverTestIntegrationTest extends LorisIntegrationTest
function setUp(): void
{
parent::setUp();
$this->setUpConfigSetting("useProjects", "true");
}
/**
* Delete testing data from database
Expand All @@ -63,7 +62,6 @@ function setUp(): void
function tearDown(): void
{
parent::tearDown();
$this->restoreConfigSetting("useProjects");
// if data not exist then insert the origin test data
$CommentId1 = $this->DB->pselectOne(
'SELECT CommentId1 FROM conflicts_unresolved
Expand Down Expand Up @@ -120,6 +118,7 @@ function testConflictResolverPermission()
function testFiltersForUnresolvedConflicts()
{
$this->safeGet($this->url . "/conflict_resolver/");

//testing data
$this->_filterTest(
self::$ForSite,
Expand All @@ -133,7 +132,7 @@ function testFiltersForUnresolvedConflicts()
self::$display,
self::$clearFilter,
'V1',
"displayed of 576"
"displayed of 573"
);
$this->_filterTest(
self::$CandID,
Expand All @@ -154,7 +153,7 @@ function testFiltersForUnresolvedConflicts()
self::$display,
self::$clearFilter,
'height_inches',
"displayed of 181"
"displayed of 180"
);
$this->_filterTest(
self::$Project,
Expand Down Expand Up @@ -185,7 +184,7 @@ function testFiltersForResolvedConflicts()
self::$display,
self::$clearFilter,
"V1",
"displayed of 33"
"displayed of 32"
);
$this->_filterTest(
self::$CandID,
Expand All @@ -206,7 +205,7 @@ function testFiltersForResolvedConflicts()
self::$display,
self::$clearFilter,
'date_taken',
"9 rows"
"8 rows"
);
$this->_filterTest(
self::$Timestamp,
Expand All @@ -230,9 +229,9 @@ function testSaveUnresolvedToResolved()
$this->url .
"/conflict_resolver/?candidateID=475906&instrument=radiology_review"
);
$element = "tr:nth-child(1) .form-control";
$btn = self::$saveBtn;
$row = self::$display;
$element = "tr:nth-child(1) .form-control";
$btn = self::$saveBtn;
$row = self::$display;
$el_dropdown = new WebDriverSelect(
$this->safeFindElement(WebDriverBy::cssSelector("$element"))
);
Expand All @@ -243,6 +242,6 @@ function testSaveUnresolvedToResolved()
WebDriverBy::cssSelector($row)
)->getText();
// 4 means there are 4 records under this site.
$this->assertStringContainsString("of 575", $bodyText);
$this->assertStringContainsString("of 572", $bodyText);
}
}

0 comments on commit 1a067ea

Please sign in to comment.