Skip to content

Commit

Permalink
6.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
scottjpearson committed Nov 26, 2024
1 parent a98022f commit 11cacc2
Show file tree
Hide file tree
Showing 21 changed files with 560 additions and 260 deletions.
11 changes: 8 additions & 3 deletions Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,19 @@ public static function getRelevantChoices() {
}

public static function getJQueryURL(): string {
$module = self::getModule();
$fileOrder = [
APP_PATH_DOCROOT."Resources/webpack/js/bundle.js" => APP_PATH_WEBROOT."Resources/webpack/js/bundle.js",
__DIR__."/js/jquery.min.js" => $module->getUrl("js/jquery.min.js"),
__DIR__."/js/jquery.min.js" => "getUrl",
];
foreach ($fileOrder as $file => $url) {
if (file_exists($file)) {
return $url;
if ($url == "getUrl") {
# this should only rarely be called => save CPU cycles by lazy instantiation
$module = self::getModule();
return $module->getUrl("js/jquery.min.js");
} else {
return $url;
}
}
}
return "";
Expand Down
2 changes: 1 addition & 1 deletion CareerDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CareerDev {
public static $passedModule = NULL;

public static function getVersion() {
return "6.18.2";
return "6.19.0";
}

public static function getLocalhostPluginPid() {
Expand Down
2 changes: 1 addition & 1 deletion classes/Altmetric.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function makeClickText($thisLink) {
$clickStatus = "on";
}
$title = 'Sourced from the Web, altmetrics can tell you a lot about how often journal articles and other scholarly outputs like datasets are discussed and used around the world.';
return "<h4><a href='$url' title='$title'>Turn $clickStatus Altmetrics</a></h4><p class='centered max-width'>$title</p>";
return "<div class='centered'><a href='$url' title='$title'>Turn $clickStatus Altmetrics</a></div><div class='centered max-width smaller'>$title</div>";
}

public function getVariable($var) {
Expand Down
11 changes: 8 additions & 3 deletions classes/Citation.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ private function changeTextColorOfLink($str, $color) {
return $str;
}

public function hasMESHTerm(string $term): bool {
return in_array($term, $this->getMESHTerms());
}

private function makeTooltip() {
$html = "";

Expand Down Expand Up @@ -482,9 +486,10 @@ public function getVariables() {
return json_encode($this->data);
}

public static function explodeList($str) {
public static function explodeList(string $str): array {
if ($str) {
return explode("; ", $str);
# PREG_SPLIT_NO_EMPTY avoids blank entries in an array in case of bad data
return preg_split("/\s*;\s*/", $str, -1, PREG_SPLIT_NO_EMPTY);
} else {
return [];
}
Expand All @@ -501,7 +506,7 @@ public function getPubTypes() {
return [];
}

public function getMESHTerms() {
public function getMESHTerms(): array {
$str = $this->getVariable("mesh_terms");
return self::explodeList($str);
}
Expand Down
39 changes: 39 additions & 0 deletions classes/CitationCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,45 @@ public function getCitationsAsString($hasLink = FALSE) {
return $str;
}

public function filterForMeSHTerms(array $terms, string $combiner): void {
$combiner = strtolower($combiner);
if (!in_array($combiner, ["and", "or"]) && (count($terms) >= 2)) {
throw new \Exception("Invalid combine term '$combiner'!");
}
if (count($terms) == 0) {
return;
}
$newCitations = [];
foreach ($this->getCitations() as $citation) {
if (count($terms) == 1) {
$term = $terms[0];
if ($citation->hasMESHTerm($term)) {
$newCitations[] = $citation;
}
} else if ($combiner == "and") {
$hasAll = TRUE;
foreach ($terms as $term) {
if (!$citation->hasMESHTerm($term)) {
$hasAll = FALSE;
}
}
if ($hasAll) {
$newCitations[] = $citation;
}
} else if ($combiner == "or") {
foreach ($terms as $term) {
if ($citation->hasMeSHTerm($term)) {
$newCitations[] = $citation;
break;
}
}
} else {
throw new \Exception("Invalid citation state! This should never happen.");
}
}
$this->citations = $newCitations;
}

public function filterForAuthorPositions($positions, $name) {
$methods = [];
if (in_array("first", $positions)) {
Expand Down
1 change: 1 addition & 0 deletions classes/ClassicalREDCapRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function __construct(\ExternalModules\AbstractExternalModule $module, int
$this->pid = $pid;
$this->pk = $this->getPrimaryKey();
$this->redcapDataTable = method_exists("\REDCap", "getDataTable") ? \REDCap::getDataTable($this->pid) : "redcap_data";

}

private function getPidForSQL() {
Expand Down
70 changes: 55 additions & 15 deletions classes/MMAHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Vanderbilt\CareerDevLibrary;

use Couchbase\MutateArrayAppendSpec;
use \Vanderbilt\FlightTrackerExternalModule\CareerDev;

require_once(__DIR__ . '/ClassLoader.php');
Expand All @@ -17,6 +18,7 @@ class MMAHelper {
public const EVAL_INSTRUMENT = "mentoring_agreement_evaluations";
public const STEPS_KEY = "mma_steps";
public const METADATA_KEY = "mma_metadata";
public const SESSION_EMULATOR = "mma_session";

public static function createHash($token, $server) {
$newHash = REDCapManagement::makeHash(self::getHashLength());
Expand Down Expand Up @@ -758,6 +760,24 @@ public static function getMentees($menteeRecordId, $userid, $token, $server) {
}
}

public static function getCurrentDatabaseSession(string $recordId, $pid): array {
$field = self::SESSION_EMULATOR."___".$recordId;
$session = Application::getSetting($field, $pid) ?: [];
$interval = 12 * 3600;
if ($session["timestamp"] + $interval > time()) {
# expired
Application::saveSetting($field, [], $pid);
return [];
}
return $session;
}

public static function saveCurrentDatabaseSession(string $recordId, $pid, array $session): void {
$field = self::SESSION_EMULATOR."___".$recordId;
$session["timestamp"] = time();
Application::saveSetting($field, $session, $pid);
}

public static function getMenteesAndMentors($menteeRecordId, $userid, $token, $server) {
if (self::isValidHash($userid)) {
if (isset($_GET['test'])) {
Expand Down Expand Up @@ -1239,10 +1259,25 @@ private static function makeStepsHTML($selectedSteps, $currStep) {
return "<div class='max-width smaller centered'>".implode(" &rarr; ", $stepHTML)."</div>";
}

public static function doesMentoringStartExist(string $recordId, int $instance, $pid): bool {
$module = Application::getModule();
$redcapDataTable = Application::getDataTable($pid);
$params = [$recordId, $pid, "mentoring_start"];
if ($instance == 1) {
$trail = " IS NULL";
} else {
$trail = " = ?";
$params[] = $instance;
}
$sql = "SELECT value FROM $redcapDataTable WHERE record = ? AND project_id = ? AND field_name = ? AND instance ".$trail;
$result = $module->query($sql, $params);
return ($result->num_rows > 0);
}

public static function makeStepHTML($metadata, $step, $redcapData, $menteeRecordId, $currInstance, $phase, $notesFields, $userid2, $thisUrl, $token, $server, $pid) {
$choices = DataDictionaryManagement::getChoices($metadata);
$secHeaders = self::getSectionHeadersWithMenteeQuestions($metadata);
$steps = $_SESSION[self::STEPS_KEY];
$steps = $_SESSION[self::STEPS_KEY] ?? self::getCurrentDatabaseSession($menteeRecordId, $pid)[self::STEPS_KEY] ?? "";
if (in_array($step, $steps)) {
$index = array_search($step, $steps);
$recordInformation = "&menteeRecord=".urlencode($menteeRecordId)."&instance=$currInstance";
Expand All @@ -1267,9 +1302,13 @@ public static function makeStepHTML($metadata, $step, $redcapData, $menteeRecord
}
$stepsHTML = self::makeStepsHTML($steps, $step);

$mentoringStartHTML = "";
if (!self::doesMentoringStartExist($menteeRecordId, $currInstance, $pid)) {
$mentoringStartHTML = "<input type='hidden' class='form-hidden-data' name='mentoring_start' id='mentoring_start' value='" . date("Y-m-d H:i:s") . "' />";
}
$html = "<form id='tsurvey' name='tsurvey'>
<input type='hidden' class='form-hidden-data' name='mentoring_phase' id='mentoring_phase' value='$phase'>
<input type='hidden' class='form-hidden-data' name='mentoring_start' id='mentoring_start' value='".date("Y-m-d H:i:s")."'>
$mentoringStartHTML
<section class='bg-light'>
$stepsHTML
<div class='container'>
Expand Down Expand Up @@ -1466,7 +1505,8 @@ function setupAgreement(url) {
});
const postdata = {
redcap_csrf_token: '".Application::generateCSRFToken()."',
sectionsToShow: sections
sectionsToShow: sections,
recordId: '$menteeRecord',
};
if (sections.length > 0) {
$.post(url, postdata, (json) => {
Expand Down Expand Up @@ -2013,8 +2053,8 @@ function() {
return $html;
}

private static function getTableCSS($step) {
$enqueuedSections = $_SESSION[self::STEPS_KEY] ?? [];
private static function getTableCSS(string $step, string $recordId, $pid): string {
$enqueuedSections = $_SESSION[self::STEPS_KEY] ?? self::getCurrentDatabaseSession($recordId, $pid)[self::STEPS_KEY] ?? [];
$index = array_search($step, $enqueuedSections);
$colors = [
"#41a9de14",
Expand All @@ -2032,7 +2072,7 @@ private static function getTableCSS($step) {
return ".tabledquestions { padding: 1em; background-color: $color; }";
}

public static function getMenteeHead($hash, $menteeRecordId, $currInstance, $uidString, $userid2, $commentJS) {
public static function getMenteeHead($hash, $menteeRecordId, $currInstance, $uidString, $userid2, $commentJS, $pid) {
$hashStr = $hash ? '&hash=$hash' : '';
if (isset($_REQUEST['uid'])) {
$uid = Sanitizer::sanitize($_REQUEST['uid']);
Expand All @@ -2042,7 +2082,7 @@ public static function getMenteeHead($hash, $menteeRecordId, $currInstance, $uid
}
$branchingJS = self::getBranchingJS();
$percCompleteJS = self::makePercentCompleteJS();
$tableCSS = self::getTableCSS($_GET['step'] ?? "initial");
$tableCSS = self::getTableCSS($_GET['step'] ?? "initial", $menteeRecordId, $pid);
return "
<link rel='stylesheet' type='text/css' href='".Application::link("mentor/css/simptip.css")."' media='screen,projection' />
<link rel='stylesheet' href='".Application::link("mentor/css/jquery.sweet-modal.min.css")."' />
Expand Down Expand Up @@ -2270,12 +2310,12 @@ function updateData(ob) {
";
}

private static function getPercentCompleteBySections() {
private static function getPercentCompleteBySections(string $recordId, $pid): int {
$step = $_GET['step'] ?? "initial";
if ($step == "initial") {
return 0;
}
$enqueuedSections = $_SESSION[self::STEPS_KEY] ?? [];
$enqueuedSections = $_SESSION[self::STEPS_KEY] ?? self::getCurrentDatabaseSession($recordId, $pid)[self::STEPS_KEY] ?? [];
if (empty($enqueuedSections)) {
return 0;
}
Expand All @@ -2287,11 +2327,11 @@ private static function getPercentCompleteBySections() {
}
}

public static function makeSurveyHTML($partners, $partnerRelationship, $row, $metadata) {
public static function makeSurveyHTML(string $partners, string $partnerRelationship, string $menteeRecordId, $pid): string {
$html = "";
$imageLink = Application::link("mentor/img/temp_image.jpg");
$scriptLink = Application::link("mentor/js/jquery.easypiechart.min.js");
$percComplete = self::getPercentCompleteBySections();
$percComplete = self::getPercentCompleteBySections($menteeRecordId, $pid);

$html .= "
<p><div>
Expand Down Expand Up @@ -2491,8 +2531,8 @@ public static function getSectionsToShow($username, $secHeaders, $redcapData, $m
return $sectionsToShow;
}

public static function isLastStep($step) {
$enqueuedSteps = $_SESSION[self::STEPS_KEY] ?: [];
public static function isLastStep(string $step, string $recordId, $pid): bool {
$enqueuedSteps = $_SESSION[self::STEPS_KEY] ?? self::getCurrentDatabaseSession($recordId, $pid)[self::STEPS_KEY] ?: [];
$index = array_search($step, $enqueuedSteps);
if ($index === FALSE) {
return FALSE;
Expand Down Expand Up @@ -2524,7 +2564,7 @@ public static function makeCommentJS($username, $menteeRecordId, $menteeInstance
}

if ($isMenteePage) {
if (self::isLastStep($_GET['step'] ?? "initial")) {
if (self::isLastStep($_GET['step'] ?? "initial", $menteeRecordId, $pid)) {
$functionToCall = "scheduleMentorEmail";
} else {
$functionToCall = "";
Expand Down Expand Up @@ -3344,4 +3384,4 @@ public static function setMMADebug($b) {
}

protected static $isDebug = FALSE;
}
}
Loading

0 comments on commit 11cacc2

Please sign in to comment.