feat(helpdesk): add user-select field type to handover protocol schema
New schema field type 'user-select' renders a dropdown of active tenant users. Action files (create + edit) load tenant users when the schema contains at least one user-select field and pass them to _form.phtml. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
$schemaFields = is_array($schemaFields ?? null) ? $schemaFields : [];
|
$schemaFields = is_array($schemaFields ?? null) ? $schemaFields : [];
|
||||||
$fieldValues = is_array($fieldValues ?? null) ? $fieldValues : [];
|
$fieldValues = is_array($fieldValues ?? null) ? $fieldValues : [];
|
||||||
$fieldDiff = is_array($fieldDiff ?? null) ? $fieldDiff : [];
|
$fieldDiff = is_array($fieldDiff ?? null) ? $fieldDiff : [];
|
||||||
|
$tenantUsers = is_array($tenantUsers ?? null) ? $tenantUsers : [];
|
||||||
$readonly = !empty($readonly);
|
$readonly = !empty($readonly);
|
||||||
$hasDiff = $fieldDiff !== [];
|
$hasDiff = $fieldDiff !== [];
|
||||||
?>
|
?>
|
||||||
@@ -56,6 +57,35 @@ $hasDiff = $fieldDiff !== [];
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<?php elseif ($type === 'user-select'): ?>
|
||||||
|
<div class="handover-diff-field<?php e($diffClass); ?>">
|
||||||
|
<label for="<?php e($inputId); ?>">
|
||||||
|
<?php e($label); ?>
|
||||||
|
<?php if ($required): ?><span class="handover-form-required"> *</span><?php endif; ?>
|
||||||
|
</label>
|
||||||
|
<select
|
||||||
|
id="<?php e($inputId); ?>"
|
||||||
|
name="field_<?php e($key); ?>"
|
||||||
|
<?php if ($required): ?> aria-required="true"<?php endif; ?>
|
||||||
|
<?php if ($readonly): ?> disabled<?php endif; ?>
|
||||||
|
>
|
||||||
|
<option value=""><?php e(t('Please select...')); ?></option>
|
||||||
|
<?php foreach ($tenantUsers as $u):
|
||||||
|
$uId = (string) ($u['id'] ?? '');
|
||||||
|
$uName = trim((string) ($u['display_name'] ?? ''));
|
||||||
|
$uEmail = (string) ($u['email'] ?? '');
|
||||||
|
$uLabel = $uName !== '' ? $uName : $uEmail;
|
||||||
|
?>
|
||||||
|
<option value="<?php e($uId); ?>"<?php if ($value === $uId): ?> selected<?php endif; ?>>
|
||||||
|
<?php e($uLabel); ?>
|
||||||
|
</option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
<?php if ($diff !== null && $diff['type'] === 'changed'): ?>
|
||||||
|
<small class="app-muted handover-diff-indicator" aria-label="<?php e(t('Changed')); ?>"><?php e(t('was: %s', (string) ($diff['old'] ?? ''))); ?></small>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?php elseif ($type === 'select'): ?>
|
<?php elseif ($type === 'select'): ?>
|
||||||
<div class="handover-diff-field<?php e($diffClass); ?>">
|
<div class="handover-diff-field<?php e($diffClass); ?>">
|
||||||
<label for="<?php e($inputId); ?>">
|
<label for="<?php e($inputId); ?>">
|
||||||
|
|||||||
@@ -230,6 +230,21 @@ if ($step === $protocolStep) {
|
|||||||
? $product['name']
|
? $product['name']
|
||||||
: (string) ($product['bc_description'] ?? $wizardData['product_code']);
|
: (string) ($product['bc_description'] ?? $wizardData['product_code']);
|
||||||
|
|
||||||
|
// Load tenant users for user-select schema fields
|
||||||
|
$hasUserSelectField = !empty(array_filter($schemaFields, fn($f) => ($f['type'] ?? '') === 'user-select'));
|
||||||
|
$tenantUsers = [];
|
||||||
|
if ($hasUserSelectField) {
|
||||||
|
$rows = DB::select(
|
||||||
|
'SELECT u.id, u.display_name, u.email'
|
||||||
|
. ' FROM users u'
|
||||||
|
. ' JOIN user_tenants ut ON ut.user_id = u.id'
|
||||||
|
. ' WHERE ut.tenant_id = ? AND u.active = 1'
|
||||||
|
. ' ORDER BY u.display_name ASC',
|
||||||
|
(string) $currentTenantId
|
||||||
|
);
|
||||||
|
$tenantUsers = is_array($rows) ? $rows : [];
|
||||||
|
}
|
||||||
|
|
||||||
if ($request->isMethod('POST')) {
|
if ($request->isMethod('POST')) {
|
||||||
if (!Session::checkCsrfToken()) {
|
if (!Session::checkCsrfToken()) {
|
||||||
$modeParam = $canManage ? '&mode=' . ($wizardData['mode'] ?? 'self') : '';
|
$modeParam = $canManage ? '&mode=' . ($wizardData['mode'] ?? 'self') : '';
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use MintyPHP\Buffer;
|
use MintyPHP\Buffer;
|
||||||
|
use MintyPHP\DB;
|
||||||
use MintyPHP\Http\SessionStoreInterface;
|
use MintyPHP\Http\SessionStoreInterface;
|
||||||
use MintyPHP\Module\Helpdesk\HelpdeskAuthorizationPolicy;
|
use MintyPHP\Module\Helpdesk\HelpdeskAuthorizationPolicy;
|
||||||
use MintyPHP\Module\Helpdesk\Service\HandoverRevisionService;
|
use MintyPHP\Module\Helpdesk\Service\HandoverRevisionService;
|
||||||
@@ -201,6 +202,21 @@ if ($request->isMethod('POST') && $canEdit) {
|
|||||||
$validationSummaryErrors = $errorBag->toArray();
|
$validationSummaryErrors = $errorBag->toArray();
|
||||||
$errors = $errorBag->toFlatList();
|
$errors = $errorBag->toFlatList();
|
||||||
|
|
||||||
|
// Load tenant users for user-select schema fields
|
||||||
|
$hasUserSelectField = !empty(array_filter($schemaFields, fn($f) => ($f['type'] ?? '') === 'user-select'));
|
||||||
|
$tenantUsers = [];
|
||||||
|
if ($hasUserSelectField) {
|
||||||
|
$rows = DB::select(
|
||||||
|
'SELECT u.id, u.display_name, u.email'
|
||||||
|
. ' FROM users u'
|
||||||
|
. ' JOIN user_tenants ut ON ut.user_id = u.id'
|
||||||
|
. ' WHERE ut.tenant_id = ? AND u.active = 1'
|
||||||
|
. ' ORDER BY u.display_name ASC',
|
||||||
|
(string) $tenantId
|
||||||
|
);
|
||||||
|
$tenantUsers = is_array($rows) ? $rows : [];
|
||||||
|
}
|
||||||
|
|
||||||
// Load revision data
|
// Load revision data
|
||||||
$revisions = $revisionService->listByHandover($tenantId, $handoverId);
|
$revisions = $revisionService->listByHandover($tenantId, $handoverId);
|
||||||
$activeRevisionNumber = (int) $request->query('revision', 0);
|
$activeRevisionNumber = (int) $request->query('revision', 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user