From be20fee5e07679a392efa6f0d72617fc71d7fd78 Mon Sep 17 00:00:00 2001 From: Saagar Arya Date: Fri, 4 Oct 2024 13:07:00 -0400 Subject: [PATCH 1/6] [dictionary] Cohort Filter --- modules/datadict/jsx/dataDictIndex.js | 9 +++++++++ .../datadict/php/datadictrowprovisioner.class.inc | 5 ++++- modules/datadict/php/fields.class.inc | 8 +++++++- modules/dictionary/jsx/dataDictIndex.js | 9 +++++++++ modules/dictionary/php/datadictrow.class.inc | 5 +++++ .../dictionary/php/datadictrowprovisioner.class.inc | 13 ++++++++++++- modules/dictionary/php/dictionary.class.inc | 7 +++++++ 7 files changed, 53 insertions(+), 3 deletions(-) diff --git a/modules/datadict/jsx/dataDictIndex.js b/modules/datadict/jsx/dataDictIndex.js index 9116f80ab92..5904fc544ef 100644 --- a/modules/datadict/jsx/dataDictIndex.js +++ b/modules/datadict/jsx/dataDictIndex.js @@ -199,6 +199,15 @@ class DataDictIndex extends Component { }, }, }, + { + label: 'Cohorts', + show: true, + filter: { + name: 'Cohorts', + type: 'multiselect', + options: options.cohorts, + }, + }, ]; return ( user(); + $projects = $user->getProjectIDs(); + $cohorts = []; + foreach ($projects AS $projectID) { + $cohorts = $cohorts + \Utility::getCohortList($projectID); + } return new \LORIS\Http\Response\JSON\OK( - ['sourceFrom' => \Utility::getAllInstruments()] + ['sourceFrom' => \Utility::getAllInstruments(), 'cohorts' => $cohorts] ); } } diff --git a/modules/dictionary/jsx/dataDictIndex.js b/modules/dictionary/jsx/dataDictIndex.js index 8de4855d5ed..7e00138c566 100644 --- a/modules/dictionary/jsx/dataDictIndex.js +++ b/modules/dictionary/jsx/dataDictIndex.js @@ -317,6 +317,15 @@ class DataDictIndex extends Component { show: false, filter: null, }, + { + label: 'Cohorts', + show: false, + filter: { + name: 'Cohorts', + type: 'multiselect', + options: options.cohorts, + }, + }, ]; return ( itemmodule = $itemmodule; $this->itemcategory = $cat; @@ -46,6 +49,7 @@ class DataDictRow implements \LORIS\Data\DataInstance, $this->desc = $desc; $this->status = $descstatus; $this->visits = $visits; + $this->cohorts = $cohorts; } /** @@ -73,6 +77,7 @@ class DataDictRow implements \LORIS\Data\DataInstance, } if ($scope->__toString() == "session") { $val['visits'] = $this->visits; + $val['cohorts'] = $this->cohorts; } return $val; diff --git a/modules/dictionary/php/datadictrowprovisioner.class.inc b/modules/dictionary/php/datadictrowprovisioner.class.inc index 1ad37c42a3e..2fe133fe69b 100644 --- a/modules/dictionary/php/datadictrowprovisioner.class.inc +++ b/modules/dictionary/php/datadictrowprovisioner.class.inc @@ -69,6 +69,14 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance $status = 'Empty'; } + $cohorts = $DB->pselectCol( + "SELECT DISTINCT tb.CohortID FROM test_names tn + JOIN test_battery tb ON tn.Test_name=tb.Test_name + WHERE tn.Test_name=:tn + ORDER BY tb.CohortID", + ['tn' => $cat->getName()] + ); + $visits = $qe->getVisitList($cat, $item); $dict[] = $this->getInstance( $module, @@ -77,6 +85,7 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance $desc, $status, $visits, + $cohorts, ); } } @@ -96,6 +105,7 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance * @param string $desc The overridden description of the item * @param string $descstatus The status of the description override * @param ?[]string $visits The visits for session scoped variables + * @param ?[]string $cohorts The cohorts for session scoped variables * * @return \LORIS\Data\DataInstance An instance representing this row. */ @@ -106,7 +116,8 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance string $desc, string $descstatus, array $visits, + array $cohorts, ) : \LORIS\Data\DataInstance { - return new DataDictRow($module, $cat, $item, $desc, $descstatus, $visits); + return new DataDictRow($module, $cat, $item, $desc, $descstatus, $visits, $cohorts); } } diff --git a/modules/dictionary/php/dictionary.class.inc b/modules/dictionary/php/dictionary.class.inc index e3fe835bf30..c5846791b8e 100644 --- a/modules/dictionary/php/dictionary.class.inc +++ b/modules/dictionary/php/dictionary.class.inc @@ -52,9 +52,16 @@ class Dictionary extends \DataFrameworkMenu foreach ($this->modules as $module) { $amodules[$module->getName()] = $module->getLongName(); } + $user = \NDB_Factory::singleton()->user(); + $projects = $user->getProjectIDs(); + $cohorts = []; + foreach ($projects AS $projectID) { + $cohorts = $cohorts + \Utility::getCohortList($projectID); + } return [ 'modules' => $amodules, 'categories' => $this->categories, + 'cohorts' => $cohorts ]; } From 01c1285074cc6cc96840471430f909854053b9ba Mon Sep 17 00:00:00 2001 From: Saagar Arya Date: Fri, 4 Oct 2024 13:19:26 -0400 Subject: [PATCH 2/6] Update for php lint --- .../datadict/php/datadictrowprovisioner.class.inc | 4 ++-- modules/dictionary/php/datadictrow.class.inc | 2 +- .../dictionary/php/datadictrowprovisioner.class.inc | 12 ++++++++++-- modules/dictionary/php/dictionary.class.inc | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/datadict/php/datadictrowprovisioner.class.inc b/modules/datadict/php/datadictrowprovisioner.class.inc index 56434dfdb9e..b8ce641026d 100644 --- a/modules/datadict/php/datadictrowprovisioner.class.inc +++ b/modules/datadict/php/datadictrowprovisioner.class.inc @@ -53,8 +53,8 @@ class DataDictRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisioner LEFT JOIN parameter_type_override pto USING (Name) LEFT JOIN test_battery tb ON pt.sourceFrom=tb.Test_name WHERE pt.Queryable=1 - GROUP BY pt.sourceFrom, pt.name, pt.sourceField, description, description_status - ", + GROUP BY pt.sourceFrom, pt.name, pt.sourceField, + description, description_status", [] ); } diff --git a/modules/dictionary/php/datadictrow.class.inc b/modules/dictionary/php/datadictrow.class.inc index 1af3b422368..71c6739c3be 100644 --- a/modules/dictionary/php/datadictrow.class.inc +++ b/modules/dictionary/php/datadictrow.class.inc @@ -76,7 +76,7 @@ class DataDictRow implements \LORIS\Data\DataInstance, $val['options'] = $itype->getOptions(); } if ($scope->__toString() == "session") { - $val['visits'] = $this->visits; + $val['visits'] = $this->visits; $val['cohorts'] = $this->cohorts; } diff --git a/modules/dictionary/php/datadictrowprovisioner.class.inc b/modules/dictionary/php/datadictrowprovisioner.class.inc index 2fe133fe69b..d749ac9ade8 100644 --- a/modules/dictionary/php/datadictrowprovisioner.class.inc +++ b/modules/dictionary/php/datadictrowprovisioner.class.inc @@ -76,7 +76,7 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance ORDER BY tb.CohortID", ['tn' => $cat->getName()] ); - + $visits = $qe->getVisitList($cat, $item); $dict[] = $this->getInstance( $module, @@ -118,6 +118,14 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance array $visits, array $cohorts, ) : \LORIS\Data\DataInstance { - return new DataDictRow($module, $cat, $item, $desc, $descstatus, $visits, $cohorts); + return new DataDictRow( + $module, + $cat, + $item, + $desc, + $descstatus, + $visits, + $cohorts, + ); } } diff --git a/modules/dictionary/php/dictionary.class.inc b/modules/dictionary/php/dictionary.class.inc index c5846791b8e..35c1a2e3d90 100644 --- a/modules/dictionary/php/dictionary.class.inc +++ b/modules/dictionary/php/dictionary.class.inc @@ -54,7 +54,7 @@ class Dictionary extends \DataFrameworkMenu } $user = \NDB_Factory::singleton()->user(); $projects = $user->getProjectIDs(); - $cohorts = []; + $cohorts = []; foreach ($projects AS $projectID) { $cohorts = $cohorts + \Utility::getCohortList($projectID); } From c5c7f154d19e6114827402dd489a0f99f8159f6c Mon Sep 17 00:00:00 2001 From: Saagar Arya Date: Fri, 18 Oct 2024 14:32:25 -0400 Subject: [PATCH 3/6] Rewrite to match candidate_list syntax --- modules/datadict/jsx/dataDictIndex.js | 2 +- modules/datadict/php/datadictrowprovisioner.class.inc | 3 ++- modules/datadict/php/fields.class.inc | 10 +++++++--- modules/dictionary/jsx/dataDictIndex.js | 2 +- modules/dictionary/php/datadictrow.class.inc | 2 +- .../dictionary/php/datadictrowprovisioner.class.inc | 7 ++++--- modules/dictionary/php/dictionary.class.inc | 10 +++++++--- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/modules/datadict/jsx/dataDictIndex.js b/modules/datadict/jsx/dataDictIndex.js index 5904fc544ef..c6ebe6418bd 100644 --- a/modules/datadict/jsx/dataDictIndex.js +++ b/modules/datadict/jsx/dataDictIndex.js @@ -205,7 +205,7 @@ class DataDictIndex extends Component { filter: { name: 'Cohorts', type: 'multiselect', - options: options.cohorts, + options: options.cohort, }, }, ]; diff --git a/modules/datadict/php/datadictrowprovisioner.class.inc b/modules/datadict/php/datadictrowprovisioner.class.inc index b8ce641026d..9ac6ac7b854 100644 --- a/modules/datadict/php/datadictrowprovisioner.class.inc +++ b/modules/datadict/php/datadictrowprovisioner.class.inc @@ -48,10 +48,11 @@ class DataDictRowProvisioner extends \LORIS\Data\Provisioners\DBRowProvisioner WHEN pto.name IS NOT NULL THEN 'Modified' WHEN pto.name IS NULL THEN 'Unchanged' END as description_status, - GROUP_CONCAT(DISTINCT tb.CohortID) AS cohorts + GROUP_CONCAT(DISTINCT c.title) AS Cohort FROM parameter_type pt LEFT JOIN parameter_type_override pto USING (Name) LEFT JOIN test_battery tb ON pt.sourceFrom=tb.Test_name + LEFT JOIN cohort c ON tb.CohortID=c.CohortID WHERE pt.Queryable=1 GROUP BY pt.sourceFrom, pt.name, pt.sourceField, description, description_status", diff --git a/modules/datadict/php/fields.class.inc b/modules/datadict/php/fields.class.inc index e8481006842..500c35f95ab 100644 --- a/modules/datadict/php/fields.class.inc +++ b/modules/datadict/php/fields.class.inc @@ -25,12 +25,16 @@ class Fields extends \NDB_Page { $user = \NDB_Factory::singleton()->user(); $projects = $user->getProjectIDs(); - $cohorts = []; + $list_of_cohorts = []; foreach ($projects AS $projectID) { - $cohorts = $cohorts + \Utility::getCohortList($projectID); + $list_of_cohorts = $list_of_cohorts + \Utility::getCohortList($projectID); + } + $cohort_options=[]; + foreach (array_values($list_of_cohorts) as $name) { + $cohort_options[$name] = $name; } return new \LORIS\Http\Response\JSON\OK( - ['sourceFrom' => \Utility::getAllInstruments(), 'cohorts' => $cohorts] + ['sourceFrom' => \Utility::getAllInstruments(), 'cohort' => $cohort_options] ); } } diff --git a/modules/dictionary/jsx/dataDictIndex.js b/modules/dictionary/jsx/dataDictIndex.js index 7e00138c566..18edaea338c 100644 --- a/modules/dictionary/jsx/dataDictIndex.js +++ b/modules/dictionary/jsx/dataDictIndex.js @@ -319,7 +319,7 @@ class DataDictIndex extends Component { }, { label: 'Cohorts', - show: false, + show: true, filter: { name: 'Cohorts', type: 'multiselect', diff --git a/modules/dictionary/php/datadictrow.class.inc b/modules/dictionary/php/datadictrow.class.inc index 71c6739c3be..8ad1ef626b0 100644 --- a/modules/dictionary/php/datadictrow.class.inc +++ b/modules/dictionary/php/datadictrow.class.inc @@ -32,7 +32,7 @@ class DataDictRow implements \LORIS\Data\DataInstance, * @param string $desc The (possibly overridden) description * @param string $descstatus The status of the description override * @param ?string[] $visits List of visits for the item. - * @param ?string[] $cohorts List of cohorts for the item. + * @param ?string[] $cohorts List of cohorts for the item. */ public function __construct( \Module $itemmodule, diff --git a/modules/dictionary/php/datadictrowprovisioner.class.inc b/modules/dictionary/php/datadictrowprovisioner.class.inc index d749ac9ade8..e3e28eab855 100644 --- a/modules/dictionary/php/datadictrowprovisioner.class.inc +++ b/modules/dictionary/php/datadictrowprovisioner.class.inc @@ -70,10 +70,11 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance } $cohorts = $DB->pselectCol( - "SELECT DISTINCT tb.CohortID FROM test_names tn + "SELECT GROUP_CONCAT(DISTINCT c.title) FROM test_names tn JOIN test_battery tb ON tn.Test_name=tb.Test_name + JOIN cohort c ON tb.CohortID=c.CohortID WHERE tn.Test_name=:tn - ORDER BY tb.CohortID", + ORDER BY c.title", ['tn' => $cat->getName()] ); @@ -105,7 +106,7 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance * @param string $desc The overridden description of the item * @param string $descstatus The status of the description override * @param ?[]string $visits The visits for session scoped variables - * @param ?[]string $cohorts The cohorts for session scoped variables + * @param ?[]int $cohorts The cohorts for session scoped variables * * @return \LORIS\Data\DataInstance An instance representing this row. */ diff --git a/modules/dictionary/php/dictionary.class.inc b/modules/dictionary/php/dictionary.class.inc index 35c1a2e3d90..320bcd043ab 100644 --- a/modules/dictionary/php/dictionary.class.inc +++ b/modules/dictionary/php/dictionary.class.inc @@ -54,14 +54,18 @@ class Dictionary extends \DataFrameworkMenu } $user = \NDB_Factory::singleton()->user(); $projects = $user->getProjectIDs(); - $cohorts = []; + $list_of_cohorts = []; foreach ($projects AS $projectID) { - $cohorts = $cohorts + \Utility::getCohortList($projectID); + $list_of_cohorts = $list_of_cohorts + \Utility::getCohortList($projectID); + } + $cohort_options=[]; + foreach (array_values($list_of_cohorts) as $name) { + $cohort_options[$name] = $name; } return [ 'modules' => $amodules, 'categories' => $this->categories, - 'cohorts' => $cohorts + 'cohorts' => $cohort_options ]; } From ad5ee748d2a503b52791e923ac158717035fcc0d Mon Sep 17 00:00:00 2001 From: Saagar Arya Date: Fri, 18 Oct 2024 16:15:23 -0400 Subject: [PATCH 4/6] Redo php doc and variable names --- modules/datadict/php/fields.class.inc | 13 ++++++++----- modules/dictionary/php/datadictrow.class.inc | 2 +- .../dictionary/php/datadictrowprovisioner.class.inc | 2 +- modules/dictionary/php/dictionary.class.inc | 8 ++++---- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/modules/datadict/php/fields.class.inc b/modules/datadict/php/fields.class.inc index 500c35f95ab..9258dc55233 100644 --- a/modules/datadict/php/fields.class.inc +++ b/modules/datadict/php/fields.class.inc @@ -25,16 +25,19 @@ class Fields extends \NDB_Page { $user = \NDB_Factory::singleton()->user(); $projects = $user->getProjectIDs(); - $list_of_cohorts = []; + $cohorts = []; foreach ($projects AS $projectID) { - $list_of_cohorts = $list_of_cohorts + \Utility::getCohortList($projectID); + $cohorts = $cohorts + \Utility::getCohortList($projectID); } - $cohort_options=[]; - foreach (array_values($list_of_cohorts) as $name) { + $cohort_options = []; + foreach (array_values($cohorts) as $name) { $cohort_options[$name] = $name; } return new \LORIS\Http\Response\JSON\OK( - ['sourceFrom' => \Utility::getAllInstruments(), 'cohort' => $cohort_options] + [ + 'sourceFrom' => \Utility::getAllInstruments(), + 'cohort' => $cohort_options + ] ); } } diff --git a/modules/dictionary/php/datadictrow.class.inc b/modules/dictionary/php/datadictrow.class.inc index 8ad1ef626b0..71c6739c3be 100644 --- a/modules/dictionary/php/datadictrow.class.inc +++ b/modules/dictionary/php/datadictrow.class.inc @@ -32,7 +32,7 @@ class DataDictRow implements \LORIS\Data\DataInstance, * @param string $desc The (possibly overridden) description * @param string $descstatus The status of the description override * @param ?string[] $visits List of visits for the item. - * @param ?string[] $cohorts List of cohorts for the item. + * @param ?string[] $cohorts List of cohorts for the item. */ public function __construct( \Module $itemmodule, diff --git a/modules/dictionary/php/datadictrowprovisioner.class.inc b/modules/dictionary/php/datadictrowprovisioner.class.inc index e3e28eab855..0f99b82381e 100644 --- a/modules/dictionary/php/datadictrowprovisioner.class.inc +++ b/modules/dictionary/php/datadictrowprovisioner.class.inc @@ -106,7 +106,7 @@ class DataDictRowProvisioner extends \LORIS\Data\ProvisionerInstance * @param string $desc The overridden description of the item * @param string $descstatus The status of the description override * @param ?[]string $visits The visits for session scoped variables - * @param ?[]int $cohorts The cohorts for session scoped variables + * @param ?[]string $cohorts The cohorts for session scoped variables * * @return \LORIS\Data\DataInstance An instance representing this row. */ diff --git a/modules/dictionary/php/dictionary.class.inc b/modules/dictionary/php/dictionary.class.inc index 320bcd043ab..37811ba002f 100644 --- a/modules/dictionary/php/dictionary.class.inc +++ b/modules/dictionary/php/dictionary.class.inc @@ -54,12 +54,12 @@ class Dictionary extends \DataFrameworkMenu } $user = \NDB_Factory::singleton()->user(); $projects = $user->getProjectIDs(); - $list_of_cohorts = []; + $cohorts = []; foreach ($projects AS $projectID) { - $list_of_cohorts = $list_of_cohorts + \Utility::getCohortList($projectID); + $cohorts = $cohorts + \Utility::getCohortList($projectID); } - $cohort_options=[]; - foreach (array_values($list_of_cohorts) as $name) { + $cohort_options = []; + foreach (array_values($cohorts) as $name) { $cohort_options[$name] = $name; } return [ From 9447650090f2a28ed16646eff3e9431a087f64d8 Mon Sep 17 00:00:00 2001 From: Maxime Mulder Date: Tue, 22 Oct 2024 15:59:09 -0400 Subject: [PATCH 5/6] Update modules/datadict/php/fields.class.inc --- modules/datadict/php/fields.class.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/datadict/php/fields.class.inc b/modules/datadict/php/fields.class.inc index 9258dc55233..49a871fdb9f 100644 --- a/modules/datadict/php/fields.class.inc +++ b/modules/datadict/php/fields.class.inc @@ -36,7 +36,7 @@ class Fields extends \NDB_Page return new \LORIS\Http\Response\JSON\OK( [ 'sourceFrom' => \Utility::getAllInstruments(), - 'cohort' => $cohort_options + 'cohort' => $cohort_options ] ); } From 89a24a897cc0674908d1733daa0dbc77a380e49d Mon Sep 17 00:00:00 2001 From: Saagar Arya Date: Thu, 31 Oct 2024 10:19:30 -0400 Subject: [PATCH 6/6] Fix for lint changes --- modules/datadict/jsx/dataDictIndex.js | 17 +++++++++-------- modules/dictionary/jsx/dataDictIndex.js | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/modules/datadict/jsx/dataDictIndex.js b/modules/datadict/jsx/dataDictIndex.js index dda8f915105..4c74e22d1bc 100644 --- a/modules/datadict/jsx/dataDictIndex.js +++ b/modules/datadict/jsx/dataDictIndex.js @@ -198,14 +198,15 @@ class DataDictIndex extends Component { 'unchanged': 'Unchanged', }, }, - { - label: 'Cohorts', - show: true, - filter: { - name: 'Cohorts', - type: 'multiselect', - options: options.cohort, - }, + }, + { + label: 'Cohorts', + show: true, + filter: { + name: 'Cohorts', + type: 'multiselect', + options: options.cohort, + }, }, ]; return ( diff --git a/modules/dictionary/jsx/dataDictIndex.js b/modules/dictionary/jsx/dataDictIndex.js index 2409a4d3aef..44418c5eb16 100644 --- a/modules/dictionary/jsx/dataDictIndex.js +++ b/modules/dictionary/jsx/dataDictIndex.js @@ -307,15 +307,16 @@ class DataDictIndex extends Component { 'many': 'Many', }, }, - { - label: 'Cohorts', - show: true, - filter: { - name: 'Cohorts', - type: 'multiselect', - options: options.cohorts, - }, + }, + { + label: 'Cohorts', + show: true, + filter: { + name: 'Cohorts', + type: 'multiselect', + options: options.cohorts, }, + }, ]; return (