Skip to content

Commit

Permalink
6.17.3
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjpearson committed Nov 12, 2024
1 parent d6dcf6a commit 4f38881
Show file tree
Hide file tree
Showing 90 changed files with 1,359 additions and 906 deletions.
43 changes: 3 additions & 40 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,30 +284,8 @@ public static function getPatentFields($metadata) {
return REDCapManagement::filterOutInvalidFields($metadata, $possibleFields);
}

public static function isPluginProject($project_id = "") {
if (!$project_id) {
$project_id = CareerDev::getPID();
}
$isCopiedPluginProject = FALSE;
global $info;
if (isset($info)) {
foreach (array_values($info) as $row) {
if ($project_id == $row['pid']) {
if (isset($row['copied'])) {
if ($row['copied']) {
$isCopiedPluginProject = TRUE;
}
}
}
}
}

return (
(self::isVanderbilt() && ($project_id == NEWMAN_SOCIETY_PROJECT))
|| (self::isVanderbilt() && $isCopiedPluginProject)
|| (self::isLocalhost() && ($project_id == LOCALHOST_TEST_PROJECT))
|| (self::isServer(FlightTrackerExternalModule::VANDERBILT_TEST_SERVER) && ($project_id == REDCAPTEST_TEST_PROJECT))
);
public static function isPluginProject() {
return FALSE;
}

public static function log($mssg, $pid = FALSE) {
Expand Down Expand Up @@ -535,15 +513,7 @@ public static function getTable1Token() {

# gets the project-id for NIH Training Table 1
public static function getTable1PID() {
if (
isset($_GET['pid'])
&& self::isVanderbilt()
&& self::isPluginProject($_GET['pid'])
) {
$table1Pid = self::getSetting("table1Pid", self::isLocalhost() ? LOCALHOST_TEST_PROJECT : NEWMAN_SOCIETY_PROJECT);
} else {
$table1Pid = self::getSystemSetting("table1Pid");
}
$table1Pid = self::getSystemSetting("table1Pid");
if ($table1Pid && REDCapManagement::isActiveProject($table1Pid)) {
return $table1Pid;
} else {
Expand Down Expand Up @@ -608,13 +578,6 @@ public static function getPids() {
}
}
}
if (self::isLocalhost()) {
array_unshift($pids, LOCALHOST_TEST_PROJECT);
} else if (self::isServer("redcap.vanderbilt.edu") || self::isServer("redcap.vumc.org")) {
array_unshift($pids, NEWMAN_SOCIETY_PROJECT);
} else if (self::isServer(FlightTrackerExternalModule::VANDERBILT_TEST_SERVER)) {
# TODO Add test projects with plugin
}
} else {
$module = self::getModule();
$pids = $module->getPids();
Expand Down
51 changes: 3 additions & 48 deletions CareerDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,11 @@
use Vanderbilt\CareerDevLibrary\Sanitizer;
use Vanderbilt\CareerDevLibrary\Publications;

# test projects
define("LOCALHOST_TEST_PROJECT", CareerDev::getLocalhostPluginPID());
define("NEWMAN_SOCIETY_PROJECT", 66635);
define("REDCAPTEST_TEST_PROJECT", 761);

class CareerDev {
public static $passedModule = NULL;

public static function getVersion() {
return "6.17.2";
return "6.17.3";
}

public static function getLocalhostPluginPid() {
Expand Down Expand Up @@ -902,36 +897,6 @@ public static function getAllSettings($pid = "") {
}

public static function getSetting($field, $pid = NULL) {
if (
self::isVanderbilt()
&& ((Application::isServer("redcap.vumc.org") && ($pid == NEWMAN_SOCIETY_PROJECT))
|| ((Application::isLocalhost() && ($pid == LOCALHOST_TEST_PROJECT))))
) {
# TODO add redcaptest.vumc.org
$module = ExternalModules::getModuleInstance("vanderbilt_plugin-settings");
$items = [$field];
if (!preg_match("/\/plugins\//", $_SERVER['REQUEST_URI'] ?? "")) {
$items[] = "career_dev_".$field;
}
foreach ($items as $item) {
$value = $module->getProjectSetting($item, $pid);
if ($value) {
return $value;
}
}
if (file_exists(self::getCredentialsFile())) {
include(self::getCredentialsFile());
if (isset($info['prod'][$field]) && ($pid == NEWMAN_SOCIETY_PROJECT)) {
return $info['prod'][$field];
} else if (isset($info['localhost'][$field]) && ($pid == LOCALHOST_TEST_PROJECT)) {
return $info['localhost'][$field];
}
}
if (($field == "admin_email") || ($field == "adminEmail")) {
return "[email protected]";
}
return "";
}
if (($field == "pubmed_api_key") && Application::isVanderbilt() && file_exists(self::getCredentialsFile())) {
include(self::getCredentialsFile());
if (isset($pubmedAPIKey) && $pubmedAPIKey) {
Expand Down Expand Up @@ -1089,17 +1054,6 @@ public static function getRelevantChoices() {
"ldap" => "University Directory",
"vera" => "VERA (online database)",
]);
if (self::getPid() == NEWMAN_SOCIETY_PROJECT) {
$itemChoices = array_merge($itemChoices, [
"data" => "Newman Data (spreadsheet)",
"sheet2" => "Newman Sheet2 (spreadsheet)",
"demographics" => "Newman Demographics (spreadsheet)",
"expertise" => "Expertise Survey (self-survey)",
"new2017" => "2017 New Scholars (spreadsheet)",
"k12", "K12 List (spreadsheet)",
"nonrespondents" => "Nonrespondents (spreadsheet)",
]);
}
} else {
$itemChoices = array_merge($itemChoices, [
"local_gms" => "Institutional Grants Management System",
Expand Down Expand Up @@ -1248,7 +1202,8 @@ public static function getMenu($menuName, $pid = NULL) {
$ary["Who Has Responded to Surveys?"] = self::link("/emailMgmt/surveySubmissions.php");
$ary["Import General Data"] = self::link("/import.php");
$ary["Import Positions"] = self::link("/bulkImport.php") . "&positions";
if (self::isVanderbilt() && ($pid == 145767)) {
if (self::isVanderbilt() && in_array($pid,[145767, 66635])) {
# special EFS projects
$ary["LDAP Lookup"] = "https://redcap.vumc.org/plugins/career_dev/LDAP/ldapLookup.php";
}

Expand Down
3 changes: 0 additions & 3 deletions FlightTrackerExternalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1444,9 +1444,6 @@ function executeCron() {
$activePids = [Sanitizer::sanitizePid($_GET['pid'])];
} else {
$activePids = $this->framework->getProjectsWithModuleEnabled();
if (Application::isVanderbilt() && Application::isServer("redcap.vanderbilt.edu")) {
$activePids[] = NEWMAN_SOCIETY_PROJECT;
}
}
Application::log($this->getName()." running for pids ".json_encode($activePids));
foreach ($activePids as $pid) {
Expand Down
8 changes: 2 additions & 6 deletions classes/CelebrationsEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,12 +738,8 @@ public function getEmailHTML($frequency, $thresholdDate = NULL) {
$this->process();
$ftLogoBase64 = FileManagement::getBase64OfFile(__DIR__."/../img/flight_tracker_logo_medium_white_bg.png", "image/png");
$projectInfo = Links::makeProjectHomeLink($this->pid, Download::projectTitle($this->pid));
if (!Application::isVanderbilt() || ($this->pid !== NEWMAN_SOCIETY_PROJECT)) {
$configureLink = Application::link("index.php", $this->pid)."#Celebrations_Email";
$configureInfo = "<br/>".Links::makeLink($configureLink, "Configure Celebrations Email");
} else {
$configureInfo = "";
}
$configureLink = Application::link("index.php", $this->pid)."#Celebrations_Email";
$configureInfo = "<br/>".Links::makeLink($configureLink, "Configure Celebrations Email");

$html = "<style>
.redtext { color: #f0565d; }
Expand Down
42 changes: 40 additions & 2 deletions classes/DataDictionaryManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ class DataDictionaryManagement {
const NONE = "NONE";
const ALUMNI_OTHER_VALUE = "999999";
const HONORACTIVITY_OTHER_VALUE = '999999';
const CUSTOM_SECTION_HEADER_SETTING = "custom_survey_text";
const CUSTOM_SECTION_HEADER_FIELDS = [
"check_d1",
"check_residency1",
"check_fellowship",
"check_d15a",
"followup_d0",
"followup_d15a",
];
const FUNDING_SECTION_HEADER_SETTING = "custom_funding_text";
const FUNDING_SECTION_HEADER_FIELDS = [
"check_grant1_d",
"followup_grant1_d",
];
const HONORACTIVITY_SPECIAL_FIELDS = [
"activityhonor_committee_name_other" => [
"activityhonor_committee_name",
Expand Down Expand Up @@ -728,6 +742,7 @@ public static function findChangedFieldsInMetadata($projectMetadata, $files, $de
if (MMAHelper::canConfigureCustomAgreement($pid)) {
$metadata['file'] = self::filterOutForms($metadata['file'], ["mentoring_agreement"]);
}
self::alterSectionHeaders($metadata['file'], $pid);

$choices = [];
foreach ($metadata as $type => $md) {
Expand Down Expand Up @@ -1213,15 +1228,38 @@ public static function mergeMetadataAndUploadNew($originalMetadata, $fileMetadat
self::alterResourcesFields($mergedMetadata, $pid);
self::alterInstitutionFields($mergedMetadata, $pid);
self::alterDepartmentsFields($mergedMetadata, $pid);
self::alterSectionHeaders($mergedMetadata, $pid);
self::updateAlumniAssociations($mergedMetadata, $originalMetadata, $pid);
unset($_SESSION['metadata'.$pid]);
$feedback = Upload::metadata($mergedMetadata, $token, $server);
$feedback = Upload::metadataNoAPI($mergedMetadata, $pid);
if (!empty($upload)) {
Upload::rowsByPid($upload, $pid);
}
return $feedback;
}

private static function alterSectionHeaders(&$metadata, $pid) {
$customSurveyText = Application::getSetting(self::CUSTOM_SECTION_HEADER_SETTING, $pid);
$customFundingText = Application::getSetting(self::FUNDING_SECTION_HEADER_SETTING, $pid);
if ($customSurveyText || $customFundingText) {
foreach ($metadata as $i => $row) {
if (
$customSurveyText
&& in_array($row['field_name'], self::CUSTOM_SECTION_HEADER_FIELDS)
&& (strpos($row['section_header'], $customSurveyText) !== FALSE)
) {
$metadata[$i]["section_header"] .= "<p><i>$customSurveyText</i></p>";
} else if (
$customFundingText
&& in_array($row['field_name'], self::FUNDING_SECTION_HEADER_FIELDS)
&& (strpos($row['section_header'], $customFundingText) !== FALSE)
) {
$metadata[$i]["section_header"] .= "<p><i>$customFundingText</i></p>";
}
}
}
}

# strategy: use original forms as much as possible
private static function makeNewFormOrder(array $originalForms, array $currentForms, $pid): array {
$validFirstForms = ["identifiers", "sign_up"];
Expand All @@ -1247,7 +1285,7 @@ private static function makeNewFormOrder(array $originalForms, array $currentFor
# Strategy: Put $form in front of the next item in $currentForms that is also in $forms
# first, we must find the next form that's in $forms: place in $nextCurrentFormInForms
$nextCurrentFormInForms = "";
for ($j = $i + 1; $j < count($currentForms); $j++) {
for ($j = (int) $i + 1; $j < count($currentForms); $j++) {
$formJ = $currentForms[$j];
if (in_array($formJ, $forms)) {
$nextCurrentFormInForms = $formJ;
Expand Down
28 changes: 8 additions & 20 deletions classes/Grants.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ public static function getFAndA($awardNo, $date) {

public function setRows($rows) {
if ($rows) {
$newmanSources = ($this->pid == NEWMAN_SOCIETY_PROJECT) ? self::getNewmanSources() : [];
$thresholdTs = strtotime("2023-05-10 00:00:00");
$this->rows = $rows;
$this->recordId = 0;
Expand Down Expand Up @@ -594,25 +593,14 @@ public function setRows($rows) {

foreach ($gs as $g) {
# combine all grants into one unordered list
if (
empty($newmanSources)
|| (
($this->pid == NEWMAN_SOCIETY_PROJECT)
&& (!in_array($g->getVariable("source"), $newmanSources)
|| !preg_match("/VCTRS/", $g->getNumber())
)
)
|| (time() < $thresholdTs)
) {
if (self::getShowDebug()) { Application::log("Prospective grant ".json_encode($g->toArray())); }
$this->setupAbstracts($g);
if ($variable == "nativeGrants") {
$this->nativeGrants[] = $g;
} else if ($variable == "grantSubmissions") {
$this->grantSubmissions[] = $g;
} else {
throw new \Exception("Invalid variable $variable");
}
if (self::getShowDebug()) { Application::log("Prospective grant ".json_encode($g->toArray())); }
$this->setupAbstracts($g);
if ($variable == "nativeGrants") {
$this->nativeGrants[] = $g;
} else if ($variable == "grantSubmissions") {
$this->grantSubmissions[] = $g;
} else {
throw new \Exception("Invalid variable $variable");
}
}
}
Expand Down
20 changes: 0 additions & 20 deletions classes/NIHTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,6 @@ public static function getFeedbackData($headers, $matches, $emailsByPid, $table,
$countKey = self::makeCountKey($table, $recordId, $pid);
$countKeyOld = str_replace("$pid:", "", $countKey);
$possibleKeys = [$countKey, $countKeyOld];
if (in_array($pid, [LOCALHOST_TEST_PROJECT, NEWMAN_SOCIETY_PROJECT])) {
$prefix = "career_dev_";
$possibleKeys[] = $prefix.$countKey;
$possibleKeys[] = $prefix.$countKeyOld;
}
foreach ($possibleKeys as $myKey) {
$settingsFromSavePid = Application::getSetting($myKey, $savePid) ?: [];
$settingsFromPid = Application::getSetting($myKey, $pid) ?: [];
Expand Down Expand Up @@ -1789,21 +1784,6 @@ private function getAllDegreeFieldsIndexed($year = TRUE, $institution = FALSE) {
if ($year) { $ary[] = "vfrs_degree1_year"; }
if ($institution) { $ary[] = "vfrs_degree1_institution"; }
$fields[$field] = $ary;
} else if (preg_match("/^newman_new_degree/", $field)) {
$fields[$field] = $ary;
} else if (preg_match("/^newman_data_degree/", $field)) {
$fields[$field] = $ary;
} else if (preg_match("/^newman_sheet2_degree/", $field)) {
$fields[$field] = $ary;
} else if ($field == "newman_demographics_degrees") {
if ($year) {
$ary[] = "newman_demographics_last_degree_year";
$ary[] = "newman_demographics_degrees_years";
}
if ($institution) {
$ary[] = "newman_demographics_last_degree_institution";
}
$fields[$field] = $ary;
}
}
}
Expand Down
25 changes: 14 additions & 11 deletions classes/ORCID.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public static function fetchORCIDEndpointData($orcid, $endpoint, $pid) {
$xpath = self::initializeXPath($output);
$parsedData = self::parseEndpointData($xpath, $endpoint);
return [TRUE, $parsedData];
} catch (Exception $e) {
} catch (\Exception $e) {
Application::log("Error parsing XML for $endpoint: " . $e->getMessage(), $pid);
return [FALSE, []];
}
Expand Down Expand Up @@ -403,26 +403,29 @@ private static function parseEndpointData($xpath, $endpoint) {
];
break;
default:
throw new Exception("Unsupported endpoint: $endpoint");
throw new \Exception("Unsupported endpoint: $endpoint");
}
return self::genericParseData($xpath, $relativeUrl, $fields);
}

private static function genericParseData(\DOMXPath $xpath, string $relativeUrl, array $fields): array {
$results = [];
$nodes = $xpath->query($relativeUrl);
$nodeList = $xpath->query($relativeUrl);

foreach ($nodes as $node) {
$orcidPath = $node->getAttribute('path');
for ($i = 0; $i < $nodeList->count(); $i++) {
$node = $nodeList->item($i);
if (method_exists($node, 'getAttribute')) {
$orcidPath = $node->getAttribute('path');

$orcidParts = explode('/', ltrim($orcidPath, '/'));
$orcidId = $orcidParts[0];
$orcidParts = explode('/', ltrim($orcidPath, '/'));
$orcidId = $orcidParts[0];

$resultRow = ['id' => $orcidId];
foreach ($fields as $field => $query) {
$resultRow[$field] = self::getNodeValue($xpath, $query, $node);
$resultRow = ['id' => $orcidId];
foreach ($fields as $field => $query) {
$resultRow[$field] = self::getNodeValue($xpath, $query, $node);
}
$results[] = $resultRow;
}
$results[] = $resultRow;
}

return $results;
Expand Down
2 changes: 1 addition & 1 deletion classes/Portal.php
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ private static function isValidStoredDate($date) {
# Regardless, Newman data will be the cleanest, and the user does not need to be confused
private static function filterOutNonNewmanProject(&$matches) {
$nonNewmanProjectPid = 145767;
if (isset($matches[NEWMAN_SOCIETY_PROJECT]) && isset($matches[$nonNewmanProjectPid])) {
if (isset($matches[$nonNewmanProjectPid])) {
unset($matches[$nonNewmanProjectPid]);
}
}
Expand Down
Loading

0 comments on commit 4f38881

Please sign in to comment.