From d3a1a1fceac597ae9ea7bf9aba4c78c67195d70f Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Fri, 18 Oct 2024 15:33:34 -0400 Subject: [PATCH 01/17] LEAF 4455 data.metadata read for forms and report builder cells --- LEAF-Automated-Tests | 1 + LEAF_Request_Portal/sources/Form.php | 40 ++++++++++++++-------------- 2 files changed, 21 insertions(+), 20 deletions(-) create mode 160000 LEAF-Automated-Tests diff --git a/LEAF-Automated-Tests b/LEAF-Automated-Tests new file mode 160000 index 000000000..32f13e0a7 --- /dev/null +++ b/LEAF-Automated-Tests @@ -0,0 +1 @@ +Subproject commit 32f13e0a7331fd9135dd398abdbe5272d3cdcd57 diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index 4945a1f5d..8ff67ef40 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -573,13 +573,13 @@ public function getIndicator($indicatorID, $series, $recordID = null, $parseTemp $form[$idx]['value'] = $this->fileToArray($data[0]['data']); $form[$idx]['raw'] = $data[0]['data']; } - // special handling for org chart data types + // special handling for org chart data types (request header questions, edited report builder cells) else if ($data[0]['format'] == 'orgchart_employee' && !empty($data[0]['data'])) { - $empRes = $this->employee->lookupEmpUID($data[0]['data']); - if (!empty($empRes)) { - $form[$idx]['displayedValue'] = "{$empRes[0]['firstName']} {$empRes[0]['lastName']}"; + if (isset($data[0]['metadata'])) { + $orgchartInfo = json_decode($data[0]['metadata'], true); + $form[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; } else { $form[$idx]['displayedValue'] = ''; } @@ -2605,16 +2605,14 @@ public function getCustomData(array $recordID_list, string|null $indicatorID_lis } } break; - case 'orgchart_employee': - $empRes = $this->employee->lookupEmpUID($item['data']); - if (isset($empRes[0])) - { - $item['data'] = "{$empRes[0]['firstName']} {$empRes[0]['lastName']}"; - $item['dataOrgchart'] = $empRes[0]; - } - else - { - $item['data'] = ''; + case 'orgchart_employee': //report builder cells + $item['data'] = ''; + if (isset($item['metadata'])) { + $orgchartInfo = json_decode($item['metadata'], true); + if(!empty($orgchartInfo['userName'])) { + $item['data'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; + $item['dataOrgchart'] = $orgchartInfo; + } } break; case 'orgchart_position': @@ -4308,7 +4306,7 @@ private function buildFormTree($id, $series = null, $recordID = null, $parseTemp { $var = array(':series' => (int)$series, ':recordID' => (int)$recordID, ); - $res2 = $this->db->prepared_query('SELECT data, timestamp, indicatorID, groupID, userID FROM data + $res2 = $this->db->prepared_query('SELECT data, metadata, timestamp, indicatorID, groupID, userID FROM data LEFT JOIN indicator_mask USING (indicatorID) WHERE indicatorID IN (' . $indicatorList . ') AND series=:series AND recordID=:recordID', $var); @@ -4316,6 +4314,7 @@ private function buildFormTree($id, $series = null, $recordID = null, $parseTemp { $idx = $resIn['indicatorID']; $data[$idx]['data'] = isset($resIn['data']) ? $resIn['data'] : ''; + $data[$idx]['metadata'] = isset($resIn['metadata']) ? $resIn['metadata'] : null; $data[$idx]['timestamp'] = isset($resIn['timestamp']) ? $resIn['timestamp'] : 0; $data[$idx]['groupID'] = isset($resIn['groupID']) ? $resIn['groupID'] : null; $data[$idx]['userID'] = isset($resIn['userID']) ? $resIn['userID'] : ''; @@ -4382,14 +4381,15 @@ private function buildFormTree($id, $series = null, $recordID = null, $parseTemp $child[$idx]['value'] = $this->fileToArray($data[$idx]['data']); } - // special handling for org chart data types + // special handling for org chart data types (request subquestions / child) if ($field['format'] == 'orgchart_employee') { - $empRes = $this->employee->lookupEmpUID($data[$idx]['data']); $child[$idx]['displayedValue'] = ''; - if (isset($empRes[0])) - { - $child[$idx]['displayedValue'] = ($child[$idx]['isMasked']) ? '[protected data]' : "{$empRes[0]['firstName']} {$empRes[0]['lastName']}"; + if (isset($data[$idx]['metadata'])) { + $orgchartInfo = json_decode($data[$idx]['metadata'], true); + if(!empty($orgchartInfo['userName'])) { + $child[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; + } } } if ($field['format'] == 'orgchart_position') From 37614a980aad4999dd711daa1a1552f5df196dc7 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Wed, 30 Oct 2024 14:21:47 -0400 Subject: [PATCH 02/17] LEAF 4455 action_history table read metadata --- LEAF-Automated-Tests | 2 +- LEAF_Request_Portal/sources/View.php | 14 +++++++++----- LEAF_Request_Portal/templates/view_status.tpl | 7 ++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/LEAF-Automated-Tests b/LEAF-Automated-Tests index 32f13e0a7..e14fa0952 160000 --- a/LEAF-Automated-Tests +++ b/LEAF-Automated-Tests @@ -1 +1 @@ -Subproject commit 32f13e0a7331fd9135dd398abdbe5272d3cdcd57 +Subproject commit e14fa09524c35ed4ae17c9edc25f2ecd91c073b7 diff --git a/LEAF_Request_Portal/sources/View.php b/LEAF_Request_Portal/sources/View.php index a31dc25f2..2a4ec937e 100644 --- a/LEAF_Request_Portal/sources/View.php +++ b/LEAF_Request_Portal/sources/View.php @@ -61,7 +61,7 @@ public function buildViewStatus(int $recordID): array $vars = array(':recordID' => $recordID); $sql1 = 'SELECT time, description, actionText, stepTitle, - dependencyID, comment, userID + dependencyID, comment, userID, userMetadata FROM action_history LEFT JOIN dependencies USING (dependencyID) LEFT JOIN workflow_steps USING (stepID) @@ -69,13 +69,13 @@ public function buildViewStatus(int $recordID): array WHERE recordID=:recordID UNION SELECT timestamp, "Note Added", "N/A", "N/A", - "N/A", note, userID + "N/A", note, userID, userMetadata FROM notes WHERE recordID = :recordID AND deleted IS NULL UNION SELECT `timestamp`, "Email Sent", "N/A", "N/A", - "N/A", concat(`recipients`, "
", `subject`), "" + "N/A", concat(`recipients`, "
", `subject`), "", "" FROM `email_tracker` WHERE recordID = :recordID ORDER BY time ASC'; @@ -102,8 +102,12 @@ public function buildViewStatus(int $recordID): array $packet['comment'] = $tmp['comment']; if (!empty($tmp['userID'])) { - $user = $dir->lookupLogin($tmp['userID']); - $name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $tmp['userID']; + $name = $tmp['userID']; + if(isset($tmp['userMetadata'])) { + $umd = json_decode($tmp['userMetadata'], true); + $display = trim($umd['firstName'] . " " . $umd['lastName']); + $name = !empty($display) ? $display : $name; + } $packet['userName'] = $name; } diff --git a/LEAF_Request_Portal/templates/view_status.tpl b/LEAF_Request_Portal/templates/view_status.tpl index bf2455c3b..1ea210cd7 100644 --- a/LEAF_Request_Portal/templates/view_status.tpl +++ b/LEAF_Request_Portal/templates/view_status.tpl @@ -26,12 +26,13 @@ Title of request: - by + + by -
Comment:
+
Comment: -
+
From f015626cac78924905855ef6b3674794f6169538 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Mon, 2 Dec 2024 09:19:32 -0500 Subject: [PATCH 03/17] LEAF 4455 records and notes userMetadata read --- LEAF_Request_Portal/sources/Form.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index 8ff67ef40..afe7b5c6f 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -1008,9 +1008,9 @@ public function getRecordInfo($recordID) ); } - $dir = new VAMC_Directory; - $user = $dir->lookupLogin($res[0]['userID']); - $name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $res[0]['userID']; + $userMetadata = json_decode($res[0]['userMetadata'], true); + $name = isset($userMetadata) && trim("{$userMetadata['firstName']} {$userMetadata['lastName']}") !== "" ? + "{$userMetadata['firstName']} {$userMetadata['lastName']}" : $res[0]['userID']; $data = array('name' => $name, 'service' => $res[0]['service'], @@ -2730,14 +2730,14 @@ public function getActionComments(int $recordID): array } else { $vars = array(':recordID' => $recordID); - $sql = 'SELECT actionTextPasttense, comment, time, userID + $sql = 'SELECT actionTextPasttense, comment, time, userID, userMetadata FROM action_history LEFT JOIN dependencies USING (dependencyID) LEFT JOIN actions USING (actionType) WHERE recordID = :recordID AND comment != "" UNION - SELECT "Note Added", note, timestamp, userID + SELECT "Note Added", note, timestamp, userID, userMetadata FROM notes WHERE recordID = :recordID AND deleted IS NULL @@ -2745,13 +2745,12 @@ public function getActionComments(int $recordID): array $res = $this->db->prepared_query($sql, $vars); - $dir = new VAMC_Directory; - $total = count($res); - for ($i = 0; $i < $total; $i++) { - $user = $dir->lookupLogin($res[$i]['userID']); - $name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $res[$i]['userID']; + $userMetadata = json_decode($res[$i]['userMetadata'], true); + $name = isset($userMetadata) && trim("{$userMetadata['firstName']} {$userMetadata['lastName']}") !== "" ? + "{$userMetadata['firstName']} {$userMetadata['lastName']}" : $res[$i]['userID']; + $res[$i]['name'] = $name; } From e1ea6a5c97ed9ee6f613aa43120eab7b81e15585 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Mon, 2 Dec 2024 10:32:22 -0500 Subject: [PATCH 04/17] LEAF 4455 display val logic consistency, read approverName, fix approverName userID --- LEAF_Request_Portal/sources/Form.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index afe7b5c6f..a99949d37 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -577,11 +577,12 @@ public function getIndicator($indicatorID, $series, $recordID = null, $parseTemp else if ($data[0]['format'] == 'orgchart_employee' && !empty($data[0]['data'])) { + $form[$idx]['displayedValue'] = ''; if (isset($data[0]['metadata'])) { $orgchartInfo = json_decode($data[0]['metadata'], true); - $form[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; - } else { - $form[$idx]['displayedValue'] = ''; + if(trim("{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}") !== "") { + $form[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; + } } } else if ($data[0]['format'] == 'orgchart_position' @@ -2609,7 +2610,7 @@ public function getCustomData(array $recordID_list, string|null $indicatorID_lis $item['data'] = ''; if (isset($item['metadata'])) { $orgchartInfo = json_decode($item['metadata'], true); - if(!empty($orgchartInfo['userName'])) { + if(trim("{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}") !== "") { $item['data'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; $item['dataOrgchart'] = $orgchartInfo; } @@ -3819,14 +3820,14 @@ public function query(string $inQuery): mixed $dir = new VAMC_Directory; $actionHistorySQL = - 'SELECT recordID, stepID, userID, time, description, + 'SELECT recordID, stepID, userID, userMetadata, time, description, actionTextPasttense, actionType, comment FROM action_history LEFT JOIN dependencies USING (dependencyID) LEFT JOIN actions USING (actionType) WHERE recordID IN (' . $recordIDs . ') UNION - SELECT recordID, "-5", userID, timestamp, "Note Added", + SELECT recordID, "-5", userID, userMetadata, timestamp, "Note Added", "Note Added", "LEAF_note", note FROM notes WHERE recordID IN (' . $recordIDs . ') @@ -3836,8 +3837,10 @@ public function query(string $inQuery): mixed $res2 = $this->db->prepared_query($actionHistorySQL, array()); foreach ($res2 as $item) { - $user = $dir->lookupLogin($item['userID'], true); - $name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $res[0]['userID']; + $userMetadata = json_decode($item['userMetadata'], true); + $name = isset($userMetadata) && trim("{$userMetadata['firstName']} {$userMetadata['lastName']}") !== "" ? + "{$userMetadata['firstName']} {$userMetadata['lastName']}" : $item['userID']; + $item['approverName'] = $name; $data[$item['recordID']]['action_history'][] = $item; @@ -4386,7 +4389,7 @@ private function buildFormTree($id, $series = null, $recordID = null, $parseTemp $child[$idx]['displayedValue'] = ''; if (isset($data[$idx]['metadata'])) { $orgchartInfo = json_decode($data[$idx]['metadata'], true); - if(!empty($orgchartInfo['userName'])) { + if(trim("{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}") !== "") { $child[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; } } From b19771036ae40b920beff0031f777ac5fd2f22fb Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Mon, 2 Dec 2024 10:58:20 -0500 Subject: [PATCH 05/17] LEAF 4455 read metadata for resolvedBy, remove VAMC init for that lookup --- LEAF_Request_Portal/sources/Form.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index a99949d37..b8e1c7c2b 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -3817,8 +3817,6 @@ public function query(string $inQuery): mixed if ($joinActionHistory) { - $dir = new VAMC_Directory; - $actionHistorySQL = 'SELECT recordID, stepID, userID, userMetadata, time, description, actionTextPasttense, actionType, comment @@ -3878,9 +3876,7 @@ public function query(string $inQuery): mixed } if ($joinRecordResolutionBy === true) { - $dir = new VAMC_Directory; - - $recordResolutionBySQL = "SELECT recordID, action_history.userID as resolvedBy, action_history.stepID, action_history.actionType + $recordResolutionBySQL = "SELECT recordID, action_history.userID as resolvedBy, action_history.userMetadata, action_history.stepID, action_history.actionType FROM action_history LEFT JOIN records USING (recordID) INNER JOIN workflow_routes USING (stepID) @@ -3895,8 +3891,9 @@ public function query(string $inQuery): mixed $res2 = $this->db->prepared_query($recordResolutionBySQL, array()); foreach ($res2 as $item) { - $user = $dir->lookupLogin($item['resolvedBy'], true); - $nameResolved = isset($user[0]) ? "{$user[0]['Lname']}, {$user[0]['Fname']} " : $item['resolvedBy']; + $userMetadata = json_decode($item['userMetadata'], true); + $nameResolved = isset($userMetadata) && trim("{$userMetadata['firstName']} {$userMetadata['lastName']}") !== "" ? + "{$userMetadata['firstName']} {$userMetadata['lastName']} " : $item['resolvedBy']; $data[$item['recordID']]['recordResolutionBy']['resolvedBy'] = $nameResolved; } } From f2cec1b09ddfe5dea0687fe4a1007cc763902c91 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Mon, 2 Dec 2024 12:28:48 -0500 Subject: [PATCH 06/17] LEAF 4455 metadata read, dep -2 requestor followup steps --- LEAF_Request_Portal/sources/FormWorkflow.php | 31 +++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/LEAF_Request_Portal/sources/FormWorkflow.php b/LEAF_Request_Portal/sources/FormWorkflow.php index 48603d0a0..7d8de4156 100644 --- a/LEAF_Request_Portal/sources/FormWorkflow.php +++ b/LEAF_Request_Portal/sources/FormWorkflow.php @@ -447,7 +447,7 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $strSQL = ""; if(!$selectUnfilled) { - $strSQL = "SELECT dependencyID, recordID, stepID, stepTitle, blockingStepID, workflowID, serviceID, filled, stepBgColor, stepFontColor, stepBorder, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, jsSrc, userID, requiresDigitalSignature FROM records_workflow_state + $strSQL = "SELECT dependencyID, recordID, stepID, stepTitle, blockingStepID, workflowID, serviceID, filled, stepBgColor, stepFontColor, stepBorder, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, jsSrc, userID, userMetadata, requiresDigitalSignature FROM records_workflow_state LEFT JOIN records USING (recordID) LEFT JOIN workflow_steps USING (stepID) LEFT JOIN step_dependencies USING (stepID) @@ -456,7 +456,7 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel WHERE recordID IN ({$recordIDs})"; } else { - $strSQL = "SELECT dependencyID, recordID, stepTitle, serviceID, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, userID FROM records_workflow_state + $strSQL = "SELECT dependencyID, recordID, stepTitle, serviceID, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, userID, userMetadata FROM records_workflow_state LEFT JOIN records USING (recordID) LEFT JOIN workflow_steps USING (stepID) LEFT JOIN step_dependencies USING (stepID) @@ -490,18 +490,19 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $personDesignatedIndicators[$res[$i]['indicatorID_for_assigned_empUID']] = 1; break; case -2: // dependencyID -2 is for requestor followup - $dir = $this->getDirectory(); - $approver = $dir->lookupLogin($res[$i]['userID']); + $approver = json_decode($res[$i]['userMetadata'], true); - if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { + if (!isset($approver) || + (empty($approver['firstName']) && empty($approver['lastName'])) + ) { $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; $res[$i]['approverName'] = '(Requestor followup)'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (' . $approver[0]['Fname'] . ' ' . $approver[0]['Lname'] . ')'; - $res[$i]['approverName'] = $approver[0]['Fname'] . ' ' . $approver[0]['Lname']; - $res[$i]['approverUID'] = $approver[0]['Email']; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (' . $approver['firstName'] . ' ' . $approver['lastName'] . ')'; + $res[$i]['approverName'] = $approver['firstName'] . ' ' . $approver['lastName']; + $res[$i]['approverUID'] = $approver['email']; } break; case -3: // dependencyID -3 is for a group designated by the requestor @@ -540,17 +541,19 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $res[$i]['isActionable'] = $isActionable; - $dir = $this->getDirectory(); - $approver = $dir->lookupLogin($res[$i]['userID']); - if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { + $approver = json_decode($res[$i]['userMetadata'], true); + + if (!isset($approver) || + (empty($approver['firstName']) && empty($approver['lastName'])) + ) { $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; $res[$i]['approverName'] = '(Requestor followup)'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (' . $approver[0]['Fname'] . ' ' . $approver[0]['Lname'] . ')'; - $res[$i]['approverName'] = $approver[0]['Fname'] . ' ' . $approver[0]['Lname']; - $res[$i]['approverUID'] = $approver[0]['Email']; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (' . $approver['firstName'] . ' ' . $approver['lastName'] . ')'; + $res[$i]['approverName'] = $approver['firstName'] . ' ' . $approver['lastName']; + $res[$i]['approverUID'] = $approver['email']; } break; From 1911d7aeea30edcafbf0dfc4cb07265c18dcaadc Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Wed, 4 Dec 2024 09:53:49 -0500 Subject: [PATCH 07/17] Revert "LEAF 4455 metadata read, dep -2 requestor followup steps" This reverts commit f2cec1b09ddfe5dea0687fe4a1007cc763902c91. Keep lookup so that display will reflect current account status --- LEAF_Request_Portal/sources/FormWorkflow.php | 31 +++++++++----------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/LEAF_Request_Portal/sources/FormWorkflow.php b/LEAF_Request_Portal/sources/FormWorkflow.php index 7d8de4156..48603d0a0 100644 --- a/LEAF_Request_Portal/sources/FormWorkflow.php +++ b/LEAF_Request_Portal/sources/FormWorkflow.php @@ -447,7 +447,7 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $strSQL = ""; if(!$selectUnfilled) { - $strSQL = "SELECT dependencyID, recordID, stepID, stepTitle, blockingStepID, workflowID, serviceID, filled, stepBgColor, stepFontColor, stepBorder, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, jsSrc, userID, userMetadata, requiresDigitalSignature FROM records_workflow_state + $strSQL = "SELECT dependencyID, recordID, stepID, stepTitle, blockingStepID, workflowID, serviceID, filled, stepBgColor, stepFontColor, stepBorder, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, jsSrc, userID, requiresDigitalSignature FROM records_workflow_state LEFT JOIN records USING (recordID) LEFT JOIN workflow_steps USING (stepID) LEFT JOIN step_dependencies USING (stepID) @@ -456,7 +456,7 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel WHERE recordID IN ({$recordIDs})"; } else { - $strSQL = "SELECT dependencyID, recordID, stepTitle, serviceID, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, userID, userMetadata FROM records_workflow_state + $strSQL = "SELECT dependencyID, recordID, stepTitle, serviceID, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, userID FROM records_workflow_state LEFT JOIN records USING (recordID) LEFT JOIN workflow_steps USING (stepID) LEFT JOIN step_dependencies USING (stepID) @@ -490,19 +490,18 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $personDesignatedIndicators[$res[$i]['indicatorID_for_assigned_empUID']] = 1; break; case -2: // dependencyID -2 is for requestor followup - $approver = json_decode($res[$i]['userMetadata'], true); + $dir = $this->getDirectory(); + $approver = $dir->lookupLogin($res[$i]['userID']); - if (!isset($approver) || - (empty($approver['firstName']) && empty($approver['lastName'])) - ) { + if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; $res[$i]['approverName'] = '(Requestor followup)'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (' . $approver['firstName'] . ' ' . $approver['lastName'] . ')'; - $res[$i]['approverName'] = $approver['firstName'] . ' ' . $approver['lastName']; - $res[$i]['approverUID'] = $approver['email']; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (' . $approver[0]['Fname'] . ' ' . $approver[0]['Lname'] . ')'; + $res[$i]['approverName'] = $approver[0]['Fname'] . ' ' . $approver[0]['Lname']; + $res[$i]['approverUID'] = $approver[0]['Email']; } break; case -3: // dependencyID -3 is for a group designated by the requestor @@ -541,19 +540,17 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $res[$i]['isActionable'] = $isActionable; - $approver = json_decode($res[$i]['userMetadata'], true); - - if (!isset($approver) || - (empty($approver['firstName']) && empty($approver['lastName'])) - ) { + $dir = $this->getDirectory(); + $approver = $dir->lookupLogin($res[$i]['userID']); + if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; $res[$i]['approverName'] = '(Requestor followup)'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (' . $approver['firstName'] . ' ' . $approver['lastName'] . ')'; - $res[$i]['approverName'] = $approver['firstName'] . ' ' . $approver['lastName']; - $res[$i]['approverUID'] = $approver['email']; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (' . $approver[0]['Fname'] . ' ' . $approver[0]['Lname'] . ')'; + $res[$i]['approverName'] = $approver[0]['Fname'] . ' ' . $approver[0]['Lname']; + $res[$i]['approverUID'] = $approver[0]['Email']; } break; From 39b09e3937d6d1a85c2c08c4eb7e5ab569b74693 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Wed, 4 Dec 2024 12:18:04 -0500 Subject: [PATCH 08/17] LEAF 4455 keep lookup if pending action, use metadata if avail for more info for disabled accts --- LEAF_Request_Portal/sources/FormWorkflow.php | 26 ++++++++++++-------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/LEAF_Request_Portal/sources/FormWorkflow.php b/LEAF_Request_Portal/sources/FormWorkflow.php index 48603d0a0..5ced50e7e 100644 --- a/LEAF_Request_Portal/sources/FormWorkflow.php +++ b/LEAF_Request_Portal/sources/FormWorkflow.php @@ -447,7 +447,7 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $strSQL = ""; if(!$selectUnfilled) { - $strSQL = "SELECT dependencyID, recordID, stepID, stepTitle, blockingStepID, workflowID, serviceID, filled, stepBgColor, stepFontColor, stepBorder, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, jsSrc, userID, requiresDigitalSignature FROM records_workflow_state + $strSQL = "SELECT dependencyID, recordID, stepID, stepTitle, blockingStepID, workflowID, serviceID, filled, stepBgColor, stepFontColor, stepBorder, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, jsSrc, userID, userMetadata, requiresDigitalSignature FROM records_workflow_state LEFT JOIN records USING (recordID) LEFT JOIN workflow_steps USING (stepID) LEFT JOIN step_dependencies USING (stepID) @@ -456,7 +456,7 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel WHERE recordID IN ({$recordIDs})"; } else { - $strSQL = "SELECT dependencyID, recordID, stepTitle, serviceID, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, userID FROM records_workflow_state + $strSQL = "SELECT dependencyID, recordID, stepTitle, serviceID, `description`, indicatorID_for_assigned_empUID, indicatorID_for_assigned_groupID, userID, userMetadata FROM records_workflow_state LEFT JOIN records USING (recordID) LEFT JOIN workflow_steps USING (stepID) LEFT JOIN step_dependencies USING (stepID) @@ -494,8 +494,11 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $approver = $dir->lookupLogin($res[$i]['userID']); if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; - $res[$i]['approverName'] = '(Requestor followup)'; + $approverMetadata = json_decode($res[$i]['userMetadata'], true); + $nameInfo = isset($approverMetadata) && trim($approverMetadata['firstName'] . " " . $approverMetadata['lastName'] ) !== '' ? + " - " . $approverMetadata['firstName'] . " " . $approverMetadata['lastName'] : ''; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup' . $nameInfo . ')'; + $res[$i]['approverName'] = '(Requestor followup' . $nameInfo . ')'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { @@ -543,8 +546,11 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $dir = $this->getDirectory(); $approver = $dir->lookupLogin($res[$i]['userID']); if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; - $res[$i]['approverName'] = '(Requestor followup)'; + $approverMetadata = json_decode($res[$i]['userMetadata'], true); + $nameInfo = isset($approverMetadata) && trim($approverMetadata['firstName'] . " " . $approverMetadata['lastName'] ) !== '' ? + " - " . $approverMetadata['firstName'] . " " . $approverMetadata['lastName'] : ''; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup' . $nameInfo . ')'; + $res[$i]['approverName'] = '(Requestor followup' . $nameInfo . ')'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { @@ -716,11 +722,11 @@ public function getLastAction(): array|null|int if (isset($res[0]) && $res[0]['dependencyID'] == -1) { - $dir = $this->getDirectory(); - - $approver = $dir->lookupLogin($res[0]['userID']); + $approverMetadata = json_decode($res[0]['userMetadata'], true); + $display = isset($approverMetadata) && trim($approverMetadata['firstName'] . " " . $approverMetadata['lastName'] ) !== '' ? + $approverMetadata['firstName'] . " " . $approverMetadata['lastName'] : $res[0]['userID']; - $res[0]['description'] = "{$approver[0]['firstName']} {$approver[0]['lastName']}"; + $res[0]['description'] = $display; } // dependencyID -3 is for a group designated by the requestor if (isset($res[0]) From a60a75aa23f815b520d07893b38846664c5c8dbe Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Thu, 5 Dec 2024 11:21:40 -0500 Subject: [PATCH 09/17] LEAF 4455 update q to use record usermetadata instead of join --- LEAF_Request_Portal/sources/Form.php | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index b8e1c7c2b..c78066685 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -3578,7 +3578,6 @@ public function query(string $inQuery): mixed $joinActionHistory = false; $joinRecordResolutionData = false; $joinRecordResolutionBy = false; - $joinInitiatorNames = false; $joinUnfilledDependencies = false; if (isset($query['joins'])) { @@ -3625,10 +3624,6 @@ public function query(string $inQuery): mixed case 'recordResolutionBy': $joinRecordResolutionBy = true; - break; - case 'initiatorName': - $joinInitiatorNames = true; - break; case 'destructionDate': $joinRecordResolutionData = true; @@ -3710,14 +3705,14 @@ public function query(string $inQuery): mixed WHERE format = 'orgchart_employee') rj_OCEmployeeData ON (lj_data.indicatorID = rj_OCEmployeeData.indicatorID) "; } - if ($joinInitiatorNames) - { - $joins .= "LEFT JOIN (SELECT userName, lastName, firstName FROM {$this->oc_dbName}.employee) lj_OCinitiatorNames ON records.userID = lj_OCinitiatorNames.userName "; - } + $resSQL = 'SELECT *, + TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.firstName")) AS `firstName`, + TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.lastName")) AS `lastName` + FROM `records` ' . $joins . ' WHERE ' . $conditions . $sort . $limit; if(isset($_GET['debugQuery'])) { if($this->login->checkGroup(1)) { - $debugQuery = str_replace(["\r", "\n","\t", "%0d","%0a","%09","%20", ";"], ' ', 'SELECT * FROM records ' . $joins . 'WHERE ' . $conditions . $sort . $limit); + $debugQuery = str_replace(["\r", "\n","\t", "%0d","%0a","%09","%20", ";"], ' ', $resSQL); $debugVars = []; foreach($vars as $key => $value) { if(strpos($key, ':data') !== false @@ -3731,17 +3726,14 @@ public function query(string $inQuery): mixed header('X-LEAF-Query: '. str_replace(array_keys($debugVars), $debugVars, $debugQuery)); - return $res = $this->db->prepared_query('EXPLAIN SELECT * FROM records - ' . $joins . ' - WHERE ' . $conditions . $sort . $limit, $vars); + return $res = $this->db->prepared_query('EXPLAIN ' . $resSQL, $vars); } else { return XSSHelpers::scrubObjectOrArray(json_decode(html_entity_decode(html_entity_decode($_GET['q'])), true)); } } - $res = $this->db->prepared_query('SELECT * FROM records - ' . $joins . ' - WHERE ' . $conditions . $sort . $limit, $vars); + + $res = $this->db->prepared_query($resSQL, $vars); $data = array(); $recordIDs = ''; From f9b7b155821b32e89ca5c5b0b364036e2e40a587 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Thu, 5 Dec 2024 12:11:16 -0500 Subject: [PATCH 10/17] LEAF 4455 use metadata info for comment when setting initiator --- LEAF_Request_Portal/sources/Form.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index c78066685..ad9470e76 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -2903,11 +2903,9 @@ public function setInitiator($recordID, $userID) userID=:userID, userMetadata=:userMetadata WHERE recordID=:recordID', $vars); - // write log entry - $dir = new VAMC_Directory; - $user = $dir->lookupLogin($userID); - $name = isset($user[0]) ? "{$user[0]['Fname']} {$user[0]['Lname']}" : $userID; + $newInitiatorInfo = json_decode($newInitiatorMetadata, true); + $name = "{$newInitiatorInfo['firstName']} {$newInitiatorInfo['lastName']}"; $actionUserID = $this->login->getUserID(); $actionUserMetadata = $this->employee->getInfoForUserMetadata($actionUserID, false); From 56140cef7233d07665ff34a54ca38b882f8ce6fe Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Thu, 5 Dec 2024 14:17:20 -0500 Subject: [PATCH 11/17] LEAF 4455 Report Builder, userID instead of null for inactive accounts --- LEAF_Request_Portal/templates/view_reports.tpl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/LEAF_Request_Portal/templates/view_reports.tpl b/LEAF_Request_Portal/templates/view_reports.tpl index 61b91ef80..c113950f6 100644 --- a/LEAF_Request_Portal/templates/view_reports.tpl +++ b/LEAF_Request_Portal/templates/view_reports.tpl @@ -131,10 +131,12 @@ function addHeader(column) { case 'initiator': filterData['lastName'] = 1; filterData['firstName'] = 1; - leafSearch.getLeafFormQuery().join('initiatorName'); + filterData['userID'] = 1; headers.push({ name: 'Initiator', indicatorID: 'initiator', editable: false, callback: function(data, blob) { - document.querySelector(`#${data.cellContainerID}`).innerHTML = blob[data.recordID].lastName + ', ' + blob[data.recordID].firstName; + const textContent = blob[data.recordID]?.lastName || "" !== "" ? + `${blob[data.recordID].lastName}, ${blob[data.recordID].firstName}` : blob[data.recordID].userID; + document.querySelector(`#${data.cellContainerID}`).innerHTML = textContent; }}); break; case 'dateCancelled': From 4955503b31a0ed4bf0230f798042d7268b0bce7a Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Thu, 5 Dec 2024 16:06:08 -0500 Subject: [PATCH 12/17] LEAF 4455 add actionType to filterData for cancelled by display, userID for site search initiator --- .../templates/reports/LEAF_Sitemap_Search.tpl | 7 +++++-- LEAF_Request_Portal/templates/view_reports.tpl | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl b/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl index f48ed746f..d9f158d89 100644 --- a/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl +++ b/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl @@ -188,16 +188,19 @@ function addHeader(column) { case 'initiator': filterData['lastName'] = 1; filterData['firstName'] = 1; - leafSearch.getLeafFormQuery().join('initiatorName'); + filterData['userID'] = 1; headers.push({ name: 'Initiator', indicatorID: 'initiator', editable: false, callback: function(data, blob) { let d = grid.getDataByIndex(data.index); - $('#'+data.cellContainerID).html(d.lastName + ', ' + d.firstName); + const textContent = d?.lastName || "" !== "" ? + d.lastName + ', ' + d.firstName : d.userID; + $('#'+data.cellContainerID).html(textContent); }}); break; case 'dateCancelled': filterData['deleted'] = 1; filterData['action_history.approverName'] = 1; + filterData['action_history.actionType'] = 1; leafSearch.getLeafFormQuery().join('action_history'); headers.push({ name: 'Date Cancelled', indicatorID: 'dateCancelled', editable: false, callback: function(data, blob) { diff --git a/LEAF_Request_Portal/templates/view_reports.tpl b/LEAF_Request_Portal/templates/view_reports.tpl index c113950f6..a6be81f42 100644 --- a/LEAF_Request_Portal/templates/view_reports.tpl +++ b/LEAF_Request_Portal/templates/view_reports.tpl @@ -142,6 +142,7 @@ function addHeader(column) { case 'dateCancelled': filterData['deleted'] = 1; filterData['action_history.approverName'] = 1; + filterData['action_history.actionType'] = 1; leafSearch.getLeafFormQuery().join('action_history'); headers.push({ name: 'Date Cancelled', indicatorID: 'dateCancelled', editable: false, callback: function(data, blob) { From 4b0b014ded0d8c7ba7cb066d250c26917cab3ab7 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Fri, 6 Dec 2024 12:06:13 -0500 Subject: [PATCH 13/17] LEAF 4455 revert view reports change except for join call, handle display on backend --- LEAF_Request_Portal/sources/Form.php | 13 +++++++++++-- .../templates/reports/LEAF_Sitemap_Search.tpl | 5 +---- LEAF_Request_Portal/templates/view_reports.tpl | 5 +---- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index ad9470e76..9389d7d31 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -3703,9 +3703,18 @@ public function query(string $inQuery): mixed WHERE format = 'orgchart_employee') rj_OCEmployeeData ON (lj_data.indicatorID = rj_OCEmployeeData.indicatorID) "; } + //backwards compat: userMetadata properties are empty for accounts that were inactive when prior md values were updated. + //userMetadata alternatives here prevent the initiator field from displaying 'null, null' if metadata is empty. + //Handled here due to high customization of view_reports, view_search and other reports $resSQL = 'SELECT *, - TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.firstName")) AS `firstName`, - TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.lastName")) AS `lastName` + IF( + TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.userName")) != "", + TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.firstName")), "(inactive account)" + ) AS `firstName`, + IF( + TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.userName")) != "", + TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.lastName")), `userID` + ) AS `lastName` FROM `records` ' . $joins . ' WHERE ' . $conditions . $sort . $limit; if(isset($_GET['debugQuery'])) { diff --git a/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl b/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl index d9f158d89..a1d3ae6c8 100644 --- a/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl +++ b/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl @@ -188,13 +188,10 @@ function addHeader(column) { case 'initiator': filterData['lastName'] = 1; filterData['firstName'] = 1; - filterData['userID'] = 1; headers.push({ name: 'Initiator', indicatorID: 'initiator', editable: false, callback: function(data, blob) { let d = grid.getDataByIndex(data.index); - const textContent = d?.lastName || "" !== "" ? - d.lastName + ', ' + d.firstName : d.userID; - $('#'+data.cellContainerID).html(textContent); + $('#'+data.cellContainerID).html(d.lastName + ', ' + d.firstName); }}); break; case 'dateCancelled': diff --git a/LEAF_Request_Portal/templates/view_reports.tpl b/LEAF_Request_Portal/templates/view_reports.tpl index a6be81f42..b8fcacdc7 100644 --- a/LEAF_Request_Portal/templates/view_reports.tpl +++ b/LEAF_Request_Portal/templates/view_reports.tpl @@ -131,12 +131,9 @@ function addHeader(column) { case 'initiator': filterData['lastName'] = 1; filterData['firstName'] = 1; - filterData['userID'] = 1; headers.push({ name: 'Initiator', indicatorID: 'initiator', editable: false, callback: function(data, blob) { - const textContent = blob[data.recordID]?.lastName || "" !== "" ? - `${blob[data.recordID].lastName}, ${blob[data.recordID].firstName}` : blob[data.recordID].userID; - document.querySelector(`#${data.cellContainerID}`).innerHTML = textContent; + document.querySelector(`#${data.cellContainerID}`).innerHTML = blob[data.recordID].lastName + ', ' + blob[data.recordID].firstName; }}); break; case 'dateCancelled': From f3cfc8a01c45f0003a1efc71dfc1c1767e6277a1 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Fri, 6 Dec 2024 14:58:44 -0500 Subject: [PATCH 14/17] LEAF 4455 remove unneeded sql trim for comparison --- LEAF_Request_Portal/sources/Form.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index 9389d7d31..7d40a4808 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -3708,11 +3708,11 @@ public function query(string $inQuery): mixed //Handled here due to high customization of view_reports, view_search and other reports $resSQL = 'SELECT *, IF( - TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.userName")) != "", + JSON_EXTRACT(`userMetadata`, "$.userName") != "", TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.firstName")), "(inactive account)" ) AS `firstName`, IF( - TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.userName")) != "", + JSON_EXTRACT(`userMetadata`, "$.userName") != "", TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.lastName")), `userID` ) AS `lastName` FROM `records` ' . $joins . ' WHERE ' . $conditions . $sort . $limit; From a5ac942451c7d86fa423528fcc3c99e9a9cb2820 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Mon, 9 Dec 2024 08:17:55 -0500 Subject: [PATCH 15/17] LEAF 4455 revert -2 text update since this info is already elsewhere --- LEAF_Request_Portal/sources/FormWorkflow.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/LEAF_Request_Portal/sources/FormWorkflow.php b/LEAF_Request_Portal/sources/FormWorkflow.php index 5ced50e7e..f54bed92c 100644 --- a/LEAF_Request_Portal/sources/FormWorkflow.php +++ b/LEAF_Request_Portal/sources/FormWorkflow.php @@ -494,11 +494,8 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $approver = $dir->lookupLogin($res[$i]['userID']); if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { - $approverMetadata = json_decode($res[$i]['userMetadata'], true); - $nameInfo = isset($approverMetadata) && trim($approverMetadata['firstName'] . " " . $approverMetadata['lastName'] ) !== '' ? - " - " . $approverMetadata['firstName'] . " " . $approverMetadata['lastName'] : ''; - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup' . $nameInfo . ')'; - $res[$i]['approverName'] = '(Requestor followup' . $nameInfo . ')'; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; + $res[$i]['approverName'] = '(Requestor followup)'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { @@ -546,11 +543,8 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $dir = $this->getDirectory(); $approver = $dir->lookupLogin($res[$i]['userID']); if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { - $approverMetadata = json_decode($res[$i]['userMetadata'], true); - $nameInfo = isset($approverMetadata) && trim($approverMetadata['firstName'] . " " . $approverMetadata['lastName'] ) !== '' ? - " - " . $approverMetadata['firstName'] . " " . $approverMetadata['lastName'] : ''; - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup' . $nameInfo . ')'; - $res[$i]['approverName'] = '(Requestor followup' . $nameInfo . ')'; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; + $res[$i]['approverName'] = '(Requestor followup)'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { From a6ea2613942825b47027eae232a486ce66aff53e Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Mon, 9 Dec 2024 16:29:49 -0500 Subject: [PATCH 16/17] LEAF 4455 keep initiatorName query distinct from general records query --- LEAF_Request_Portal/sources/Form.php | 33 ++++++++++++------- .../templates/reports/LEAF_Sitemap_Search.tpl | 1 + .../templates/view_reports.tpl | 1 + 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index 7d40a4808..d049cc003 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -3576,6 +3576,7 @@ public function query(string $inQuery): mixed $joinActionHistory = false; $joinRecordResolutionData = false; $joinRecordResolutionBy = false; + $joinInitiatorNames = false; $joinUnfilledDependencies = false; if (isset($query['joins'])) { @@ -3622,6 +3623,10 @@ public function query(string $inQuery): mixed case 'recordResolutionBy': $joinRecordResolutionBy = true; + break; + case 'initiatorName': + $joinInitiatorNames = true; + break; case 'destructionDate': $joinRecordResolutionData = true; @@ -3703,19 +3708,23 @@ public function query(string $inQuery): mixed WHERE format = 'orgchart_employee') rj_OCEmployeeData ON (lj_data.indicatorID = rj_OCEmployeeData.indicatorID) "; } - //backwards compat: userMetadata properties are empty for accounts that were inactive when prior md values were updated. - //userMetadata alternatives here prevent the initiator field from displaying 'null, null' if metadata is empty. + + //joinInitiatorNames backwards compat. userMetadata properties are empty for accounts that were inactive when prior metadata + //values were updated. Alternatives here prevent the initiator field from displaying 'null, null' if metadata is empty. //Handled here due to high customization of view_reports, view_search and other reports - $resSQL = 'SELECT *, - IF( - JSON_EXTRACT(`userMetadata`, "$.userName") != "", - TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.firstName")), "(inactive account)" - ) AS `firstName`, - IF( - JSON_EXTRACT(`userMetadata`, "$.userName") != "", - TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.lastName")), `userID` - ) AS `lastName` - FROM `records` ' . $joins . ' WHERE ' . $conditions . $sort . $limit; + $initiatorNamesSQL = ''; + if ($joinInitiatorNames) { + $initiatorNamesSQL = ', + IF( + JSON_EXTRACT(`userMetadata`, "$.userName") != "", + TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.firstName")), "(inactive account)" + ) AS `firstName`, + IF( + JSON_EXTRACT(`userMetadata`, "$.userName") != "", + TRIM(BOTH \'\"\' FROM JSON_EXTRACT(`userMetadata`, "$.lastName")), `userID` + ) AS `lastName`'; + } + $resSQL = 'SELECT * ' . $initiatorNamesSQL . ' FROM `records` ' . $joins . ' WHERE ' . $conditions . $sort . $limit; if(isset($_GET['debugQuery'])) { if($this->login->checkGroup(1)) { diff --git a/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl b/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl index a1d3ae6c8..445aff1df 100644 --- a/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl +++ b/LEAF_Request_Portal/templates/reports/LEAF_Sitemap_Search.tpl @@ -188,6 +188,7 @@ function addHeader(column) { case 'initiator': filterData['lastName'] = 1; filterData['firstName'] = 1; + leafSearch.getLeafFormQuery().join('initiatorName'); headers.push({ name: 'Initiator', indicatorID: 'initiator', editable: false, callback: function(data, blob) { let d = grid.getDataByIndex(data.index); diff --git a/LEAF_Request_Portal/templates/view_reports.tpl b/LEAF_Request_Portal/templates/view_reports.tpl index b8fcacdc7..6ac37fac9 100644 --- a/LEAF_Request_Portal/templates/view_reports.tpl +++ b/LEAF_Request_Portal/templates/view_reports.tpl @@ -131,6 +131,7 @@ function addHeader(column) { case 'initiator': filterData['lastName'] = 1; filterData['firstName'] = 1; + leafSearch.getLeafFormQuery().join('initiatorName'); headers.push({ name: 'Initiator', indicatorID: 'initiator', editable: false, callback: function(data, blob) { document.querySelector(`#${data.cellContainerID}`).innerHTML = blob[data.recordID].lastName + ', ' + blob[data.recordID].firstName; From f8c11b725b8b98b3ef50e9e6a0bc041af7ea6f08 Mon Sep 17 00:00:00 2001 From: Carrie Hanscom Date: Tue, 10 Dec 2024 09:04:47 -0500 Subject: [PATCH 17/17] LEAF 4455 inactive user verbiage, simplify empty metadata check --- LEAF_Request_Portal/sources/Form.php | 16 ++++++++-------- LEAF_Request_Portal/sources/FormWorkflow.php | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/LEAF_Request_Portal/sources/Form.php b/LEAF_Request_Portal/sources/Form.php index d049cc003..de810ccd1 100644 --- a/LEAF_Request_Portal/sources/Form.php +++ b/LEAF_Request_Portal/sources/Form.php @@ -580,7 +580,7 @@ public function getIndicator($indicatorID, $series, $recordID = null, $parseTemp $form[$idx]['displayedValue'] = ''; if (isset($data[0]['metadata'])) { $orgchartInfo = json_decode($data[0]['metadata'], true); - if(trim("{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}") !== "") { + if(!empty(trim($orgchartInfo['lastName']))) { $form[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; } } @@ -1010,7 +1010,7 @@ public function getRecordInfo($recordID) } $userMetadata = json_decode($res[0]['userMetadata'], true); - $name = isset($userMetadata) && trim("{$userMetadata['firstName']} {$userMetadata['lastName']}") !== "" ? + $name = isset($userMetadata) && !empty(trim($userMetadata['lastName'])) ? "{$userMetadata['firstName']} {$userMetadata['lastName']}" : $res[0]['userID']; $data = array('name' => $name, @@ -2610,7 +2610,7 @@ public function getCustomData(array $recordID_list, string|null $indicatorID_lis $item['data'] = ''; if (isset($item['metadata'])) { $orgchartInfo = json_decode($item['metadata'], true); - if(trim("{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}") !== "") { + if(!empty(trim($orgchartInfo['lastName']))) { $item['data'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; $item['dataOrgchart'] = $orgchartInfo; } @@ -2749,7 +2749,7 @@ public function getActionComments(int $recordID): array $total = count($res); for ($i = 0; $i < $total; $i++) { $userMetadata = json_decode($res[$i]['userMetadata'], true); - $name = isset($userMetadata) && trim("{$userMetadata['firstName']} {$userMetadata['lastName']}") !== "" ? + $name = isset($userMetadata) && !empty(trim($userMetadata['lastName'])) ? "{$userMetadata['firstName']} {$userMetadata['lastName']}" : $res[$i]['userID']; $res[$i]['name'] = $name; @@ -3709,9 +3709,9 @@ public function query(string $inQuery): mixed } - //joinInitiatorNames backwards compat. userMetadata properties are empty for accounts that were inactive when prior metadata - //values were updated. Alternatives here prevent the initiator field from displaying 'null, null' if metadata is empty. - //Handled here due to high customization of view_reports, view_search and other reports + //joinInitiatorNames backwards compat - additional SQL for records.userMetadata replaces previous join with orgchart.employee. + //userMetadata properties are empty for accounts that were inactive when prior metadata values were updated. + //Alternatives here display 'userID (inactive account)' instead of 'null, null' if metadata is empty. $initiatorNamesSQL = ''; if ($joinInitiatorNames) { $initiatorNamesSQL = ', @@ -4394,7 +4394,7 @@ private function buildFormTree($id, $series = null, $recordID = null, $parseTemp $child[$idx]['displayedValue'] = ''; if (isset($data[$idx]['metadata'])) { $orgchartInfo = json_decode($data[$idx]['metadata'], true); - if(trim("{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}") !== "") { + if(!empty(trim($orgchartInfo['lastName']))) { $child[$idx]['displayedValue'] = "{$orgchartInfo['firstName']} {$orgchartInfo['lastName']}"; } } diff --git a/LEAF_Request_Portal/sources/FormWorkflow.php b/LEAF_Request_Portal/sources/FormWorkflow.php index f54bed92c..42142e947 100644 --- a/LEAF_Request_Portal/sources/FormWorkflow.php +++ b/LEAF_Request_Portal/sources/FormWorkflow.php @@ -494,8 +494,8 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $approver = $dir->lookupLogin($res[$i]['userID']); if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; - $res[$i]['approverName'] = '(Requestor followup)'; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Inactive User)'; + $res[$i]['approverName'] = '(Inactive User)'; $res[$i]['approverUID'] = $res[$i]['userID']; } else { @@ -543,8 +543,8 @@ public function getRecordsDependencyData(object $form, array $records, bool $sel $dir = $this->getDirectory(); $approver = $dir->lookupLogin($res[$i]['userID']); if (empty($approver[0]['Fname']) && empty($approver[0]['Lname'])) { - $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Requestor followup)'; - $res[$i]['approverName'] = '(Requestor followup)'; + $res[$i]['description'] = $res[$i]['stepTitle'] . ' (Inactive User)'; + $res[$i]['approverName'] = '(Inactive User)'; $res[$i]['approverUID'] = $res[$i]['userID']; } else {