From b4bb8c327aaece7377871a068d22abd9ceb3588c Mon Sep 17 00:00:00 2001 From: Laetitia Fesselier Date: Mon, 16 Aug 2021 14:04:26 -0400 Subject: [PATCH] Displaying user projects and sites for filters --- .../php/conflict_resolver.class.inc | 43 ++++++------------- .../php/resolved_conflicts.class.inc | 41 ++++++------------ .../test/conflict_resolverTest.php | 21 +++++---- 3 files changed, 37 insertions(+), 68 deletions(-) diff --git a/modules/conflict_resolver/php/conflict_resolver.class.inc b/modules/conflict_resolver/php/conflict_resolver.class.inc index 9ba415a9838..950d7ce4e6e 100644 --- a/modules/conflict_resolver/php/conflict_resolver.class.inc +++ b/modules/conflict_resolver/php/conflict_resolver.class.inc @@ -24,7 +24,7 @@ namespace LORIS\conflict_resolver; * @license http://www.gnu.org/licenses/gpl-3.0.txt GPLv3 * @link https://github.com/aces/Loris */ -class Conflict_Resolver extends \NDB_Menu_Filter_Form +class Conflict_Resolver extends \NDB_Menu_Filter_Form, \DataFrameworkMenu { public $skipTemplate = true; @@ -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 = [ @@ -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( @@ -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) + ); } /** diff --git a/modules/conflict_resolver/php/resolved_conflicts.class.inc b/modules/conflict_resolver/php/resolved_conflicts.class.inc index 5cc5213d401..d6d4b30157e 100644 --- a/modules/conflict_resolver/php/resolved_conflicts.class.inc +++ b/modules/conflict_resolver/php/resolved_conflicts.class.inc @@ -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'; @@ -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( @@ -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) + ); } /** diff --git a/modules/conflict_resolver/test/conflict_resolverTest.php b/modules/conflict_resolver/test/conflict_resolverTest.php index 3e54f5679ea..856b2a08314 100644 --- a/modules/conflict_resolver/test/conflict_resolverTest.php +++ b/modules/conflict_resolver/test/conflict_resolverTest.php @@ -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 @@ -52,7 +52,6 @@ class ConflictResolverTestIntegrationTest extends LorisIntegrationTest function setUp(): void { parent::setUp(); - $this->setUpConfigSetting("useProjects", "true"); } /** * Delete testing data from database @@ -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 @@ -120,6 +118,7 @@ function testConflictResolverPermission() function testFiltersForUnresolvedConflicts() { $this->safeGet($this->url . "/conflict_resolver/"); + //testing data $this->_filterTest( self::$ForSite, @@ -133,7 +132,7 @@ function testFiltersForUnresolvedConflicts() self::$display, self::$clearFilter, 'V1', - "displayed of 576" + "displayed of 573" ); $this->_filterTest( self::$CandID, @@ -154,7 +153,7 @@ function testFiltersForUnresolvedConflicts() self::$display, self::$clearFilter, 'height_inches', - "displayed of 181" + "displayed of 180" ); $this->_filterTest( self::$Project, @@ -185,7 +184,7 @@ function testFiltersForResolvedConflicts() self::$display, self::$clearFilter, "V1", - "displayed of 33" + "displayed of 32" ); $this->_filterTest( self::$CandID, @@ -206,7 +205,7 @@ function testFiltersForResolvedConflicts() self::$display, self::$clearFilter, 'date_taken', - "9 rows" + "8 rows" ); $this->_filterTest( self::$Timestamp, @@ -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")) ); @@ -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); } }