Skip to content

Improve display of unresolved requests #40

Merged
merged 1 commit into from
Oct 27, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions app/templates/Matchgrids/reconcile.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,40 @@

use \App\Lib\Util\ArrayUtil;

// extract the attribute field names into a simple array
// Ensure that the candidates array is sorted by referenceid so we can easily match up identical adjacent referenceids.
// Note that this will retain the "New" record in first position (because the referenceid is empty).
array_multisort(array_column($vv_candidates, 'referenceid'), SORT_ASC, $vv_candidates);

// Generate the referenceid label output by creating a simple array that contains the unique referenceid values
// along with the count of how many occurrences each has in the $vv_candidates structure (for colspan).
// Note that we must assign an empty string when encountering a NULL referenceid because array_count_values
// can only work on integers or strings.
$refIds = array();
foreach ($vv_candidates as $candidate) {
$refIds[] = !empty($candidate['referenceid']) ? $candidate['referenceid'] : '';
}
$refIds = array_count_values($refIds);

// Extract the attribute field names into a simple array.
$fieldNames = array();
foreach ($vv_candidates as $candidate) {
$fieldNames = array_keys($candidate);
break;
}

// remove "referenceid" - it is given special treatment and should not be included in our structure
// Remove "referenceid" from the field names - it is given special treatment and should not be included in our
// attributes structure.
array_splice($fieldNames, array_search('referenceid',$fieldNames), 1);

// build the data for the candidates into a structure for generating the view:
// Build the data for the candidates into a structure for generating the view:
// attribute field name | attribute values | do the values match?
$canAttr = array();
for($i = 0; $i < count($fieldNames); $i++) {

// put the field name in the first column
// Put the field name in the first column.
$canAttr[$i][0] = $fieldNames[$i];

// put all the values for the current attribute into the second column
// Put all the values for the current attribute into the second column.
$canAttr[$i][1] = array();
foreach($vv_candidates as $c) {
foreach($c as $key => $val) {
Expand Down Expand Up @@ -75,10 +90,10 @@
<thead>
<tr>
<td class="empty"></td>
<?php $i = 0; // note that we'll skip the first, "new" record. ?>
<?php foreach($vv_candidates as $c): ?>
<th class="col-names" scope="col">
<?= !empty($c['referenceid']) ? __('match.fd.suggestion.a',[$i]) : __('match.fd.new_record'); ?>
<?php $i = 0; // used to print the suggestion number in the output. ?>
<?php foreach($refIds as $refId => $refIdCount): ?>
<th class="col-names" scope="col" colspan="<?= $refIdCount; ?>">
<?= !empty($refId) ? __('match.fd.suggestion.a',[$i]) : __('match.fd.new_record'); ?>
<?php $i++; ?>
</th>
<?php endforeach; ?>
Expand All @@ -90,9 +105,9 @@
<th class="attr-title" scope="row">
<?= __('match.fd.referenceid', [99]); ?>
</th>
<?php foreach($vv_candidates as $c): ?>
<td class="reference-ids">
<?= !empty($c['referenceid']) ? $c['referenceid'] : __('match.op.new'); ?>
<?php foreach($refIds as $refId => $refIdCount): ?>
<td class="reference-ids" colspan="<?= $refIdCount; ?>">
<?= !empty($refId) ? $refId : __('match.op.new'); ?>
</td>
<?php endforeach; ?>
</tr>
Expand All @@ -101,16 +116,16 @@
<th class="attr-title" scope="row">
<?= __('match.fd.action'); ?>
</th>
<?php foreach($vv_candidates as $c): ?>
<td class="reconcile-actions">
<?php foreach($refIds as $refId => $refIdCount): ?>
<td class="reconcile-actions" colspan="<?= $refIdCount; ?>">
<?=
$this->Form->postLink(__('match.op.reconcile.' . (!empty($c['referenceid']) ? 'assign' : 'generate')),
$this->Form->postLink(__('match.op.reconcile.' . (!empty($refId) ? 'assign' : 'generate')),
['action' => 'reconcile',
$vv_cur_mg->id],
['data' => [
'rowid' => $vv_request['id'],
// Default value needs to be the literal string "new" and not a localized text string
'referenceid' => (!empty($c['referenceid']) ? $c['referenceid'] : 'new')
'referenceid' => (!empty($refId) ? $refId : 'new')
],
'confirm' => __('match.op.assign.confirm'),
'class' => 'btn btn-primary nospin']);
Expand Down