Changes for personalisation
Specific Folder FTP Upload / ftp-deploy (push) Successful in 1m43s
Details
Specific Folder FTP Upload / ftp-deploy (push) Successful in 1m43s
Details
This commit is contained in:
parent
58df87f186
commit
a8bb633553
|
|
@ -9056,7 +9056,11 @@ class FormController extends Controller
|
||||||
return redirect('/form/show');
|
return redirect('/form/show');
|
||||||
}
|
}
|
||||||
//echo '<pre>'; print_r($formdata); exit;
|
//echo '<pre>'; print_r($formdata); exit;
|
||||||
$history = LambdaRequest::postrequest('form', 'formentity/getformhistory', ['form_id' => $form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition ]);
|
$historyParams = ['form_id' => $form_id, 'user_id' => $formdata->user_id, 'partition' => $formdata->partition];
|
||||||
|
if ($request->input('export', false)) {
|
||||||
|
$historyParams['designer_flag'] = 'show_in_export';
|
||||||
|
}
|
||||||
|
$history = LambdaRequest::postrequest('form', 'formentity/getformhistory', $historyParams);
|
||||||
//echo '<pre>'; print_r($history); print_r($formdata); exit;
|
//echo '<pre>'; print_r($history); print_r($formdata); exit;
|
||||||
//Log::debug(print_r($history, true));
|
//Log::debug(print_r($history, true));
|
||||||
$canDeleteSubmission = $this->sessionFlag($formdata, 'delete_submission');
|
$canDeleteSubmission = $this->sessionFlag($formdata, 'delete_submission');
|
||||||
|
|
@ -9082,62 +9086,94 @@ class FormController extends Controller
|
||||||
$exceldata = [];
|
$exceldata = [];
|
||||||
$exceldata[] = [$formdata->title];
|
$exceldata[] = [$formdata->title];
|
||||||
$exceldata[] = [''];
|
$exceldata[] = [''];
|
||||||
$headers = ['Submission Date', 'Submitted By'];
|
$dataDesignerExport = $this->hasDataDesignerExport($history->data->form ?? null);
|
||||||
foreach ($userAttrs as $attr) {
|
$headers = [];
|
||||||
$headers[] = $userAttrLabels[$attr] ?? ucwords(str_replace('_', ' ', (string) $attr));
|
if ($dataDesignerExport) {
|
||||||
}
|
foreach ($history->data->questions as $code => $question) {
|
||||||
$headers[] = 'Approval Status';
|
if (isset($question->type) && $question->type == 'hidden') {
|
||||||
foreach($history->data->questions as $question) {
|
continue;
|
||||||
if (isset($question->type) && $question->type == 'hidden') {
|
}
|
||||||
continue;
|
$headers[] = $question->label ?? (is_object($question) && isset($question->code) ? $question->code : $code);
|
||||||
}
|
}
|
||||||
if (isset($question->type) && $question->type == 'multitextbox' && !empty($question->options)) {
|
} else {
|
||||||
foreach ($question->options as $k => $v) {
|
$headers = ['Submission Date', 'Submitted By'];
|
||||||
$optLabel = is_object($v) ? ($v->display ?? $v->label ?? $k) : $v;
|
foreach ($userAttrs as $attr) {
|
||||||
$headers[] = $optLabel.' ('.$question->label.')';
|
$headers[] = $userAttrLabels[$attr] ?? ucwords(str_replace('_', ' ', (string) $attr));
|
||||||
|
}
|
||||||
|
$headers[] = 'Approval Status';
|
||||||
|
foreach($history->data->questions as $question) {
|
||||||
|
if (isset($question->type) && $question->type == 'hidden') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isset($question->type) && $question->type == 'multitextbox' && !empty($question->options)) {
|
||||||
|
foreach ($question->options as $k => $v) {
|
||||||
|
$optLabel = is_object($v) ? ($v->display ?? $v->label ?? $k) : $v;
|
||||||
|
$headers[] = $optLabel.' ('.$question->label.')';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$headers[] = $question->label;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$headers[] = $question->label;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$exceldata[] = $headers;
|
$exceldata[] = $headers;
|
||||||
foreach($history->data->submissions as $submission) {
|
foreach($history->data->submissions as $submission) {
|
||||||
$row = [];
|
$row = [];
|
||||||
$row[] = $submission->createdAt;
|
if ($dataDesignerExport) {
|
||||||
$row[] = isset($submission->user_info->name) ? $submission->user_info->name : '';
|
foreach ($history->data->questions as $code => $question) {
|
||||||
foreach ($userAttrs as $attr) {
|
if (isset($question->type) && $question->type == 'hidden') {
|
||||||
$row[] = $this->userAttributeValue($submission->user_info ?? null, $attr);
|
continue;
|
||||||
}
|
|
||||||
$row[] = isset($submission->workflow_status) ? $submission->workflow_status : '';
|
|
||||||
foreach($history->data->questions as $q => $v) {
|
|
||||||
if (isset($v->type) && $v->type == 'hidden') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (isset($v->type) && $v->type == 'multitextbox' && !empty($v->options)) {
|
|
||||||
foreach ($v->options as $optKey => $optMeta) {
|
|
||||||
$fieldKey = is_object($optMeta) ? ($optMeta->value ?? $optKey) : $optKey;
|
|
||||||
if (isset($submission->formdata->{$fieldKey})) {
|
|
||||||
$raw = $submission->formdata->{$fieldKey};
|
|
||||||
$row[] = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
|
||||||
} elseif (isset($submission->formdata->{$q}) && (is_object($submission->formdata->{$q}) || is_array($submission->formdata->{$q}))) {
|
|
||||||
$box = (array) $submission->formdata->{$q};
|
|
||||||
$raw = $box[$fieldKey] ?? '-';
|
|
||||||
$row[] = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
|
||||||
} else {
|
|
||||||
$row[] = '-';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
$col = is_object($question) && isset($question->code) ? $question->code : $code;
|
||||||
if (!isset($submission->formdata->{$q})) {
|
if (!isset($submission->formdata->{$col})) {
|
||||||
$row[] = '-';
|
$row[] = '-';
|
||||||
} elseif (is_array($submission->formdata->{$q})) {
|
} elseif (is_array($submission->formdata->{$col})) {
|
||||||
$row[] = implode(', ', $submission->formdata->{$q});
|
$row[] = implode(', ', $submission->formdata->{$col});
|
||||||
} elseif (is_object($submission->formdata->{$q})) {
|
} elseif (is_object($submission->formdata->{$col})) {
|
||||||
$row[] = collect((array) $submission->formdata->{$q})->map(function ($val, $key) {
|
$row[] = collect((array) $submission->formdata->{$col})->map(function ($val, $key) {
|
||||||
return $key.': '.$val;
|
return $key.': '.$val;
|
||||||
})->implode(', ');
|
})->implode(', ');
|
||||||
} else {
|
} else {
|
||||||
$row[] = $submission->formdata->{$q};
|
$row[] = $submission->formdata->{$col};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$row[] = $submission->createdAt;
|
||||||
|
$row[] = isset($submission->user_info->name) ? $submission->user_info->name : '';
|
||||||
|
foreach ($userAttrs as $attr) {
|
||||||
|
$row[] = $this->userAttributeValue($submission->user_info ?? null, $attr);
|
||||||
|
}
|
||||||
|
$row[] = isset($submission->workflow_status) ? $submission->workflow_status : '';
|
||||||
|
foreach($history->data->questions as $q => $v) {
|
||||||
|
if (isset($v->type) && $v->type == 'hidden') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$col = is_object($v) && isset($v->code) ? $v->code : $q;
|
||||||
|
if (isset($v->type) && $v->type == 'multitextbox' && !empty($v->options)) {
|
||||||
|
foreach ($v->options as $optKey => $optMeta) {
|
||||||
|
$fieldKey = is_object($optMeta) ? ($optMeta->value ?? $optKey) : $optKey;
|
||||||
|
if (isset($submission->formdata->{$fieldKey})) {
|
||||||
|
$raw = $submission->formdata->{$fieldKey};
|
||||||
|
$row[] = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
||||||
|
} elseif (isset($submission->formdata->{$col}) && (is_object($submission->formdata->{$col}) || is_array($submission->formdata->{$col}))) {
|
||||||
|
$box = (array) $submission->formdata->{$col};
|
||||||
|
$raw = $box[$fieldKey] ?? '-';
|
||||||
|
$row[] = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
||||||
|
} else {
|
||||||
|
$row[] = '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!isset($submission->formdata->{$col})) {
|
||||||
|
$row[] = '-';
|
||||||
|
} elseif (is_array($submission->formdata->{$col})) {
|
||||||
|
$row[] = implode(', ', $submission->formdata->{$col});
|
||||||
|
} elseif (is_object($submission->formdata->{$col})) {
|
||||||
|
$row[] = collect((array) $submission->formdata->{$col})->map(function ($val, $key) {
|
||||||
|
return $key.': '.$val;
|
||||||
|
})->implode(', ');
|
||||||
|
} else {
|
||||||
|
$row[] = $submission->formdata->{$col};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11291,7 +11327,8 @@ class FormController extends Controller
|
||||||
'user_id' => $formdata->user_id,
|
'user_id' => $formdata->user_id,
|
||||||
'partition' => $formdata->partition,
|
'partition' => $formdata->partition,
|
||||||
'team_report' => 1,
|
'team_report' => 1,
|
||||||
'json_file' => 1
|
'json_file' => 1,
|
||||||
|
'designer_flag' => 'show_in_export',
|
||||||
];
|
];
|
||||||
if (isset($formdata->all_data_access) && $formdata->all_data_access == true) {
|
if (isset($formdata->all_data_access) && $formdata->all_data_access == true) {
|
||||||
$serviceParams['alldata'] = 1;
|
$serviceParams['alldata'] = 1;
|
||||||
|
|
@ -11310,87 +11347,122 @@ class FormController extends Controller
|
||||||
$exceldata[] = [$formdata->title];
|
$exceldata[] = [$formdata->title];
|
||||||
|
|
||||||
$exceldata[] = [''];
|
$exceldata[] = [''];
|
||||||
$headers = ['Submission Date', 'Submitted By', 'Employee Code', 'Approval Status'];
|
$dataDesignerExport = $this->hasDataDesignerExport($history->data->form ?? null);
|
||||||
$userAttrs = $this->userAttributeCodes($history->data->form ?? null);
|
$headers = [];
|
||||||
$userAttrLabels = $this->resolveUserAttributeLabels($userAttrs);
|
$userAttrs = [];
|
||||||
foreach ($userAttrs as $attr) {
|
$userAttrLabels = [];
|
||||||
$headers[] = $userAttrLabels[$attr] ?? ucwords(str_replace('_', ' ', (string) $attr));
|
$exportPositionColumns = [];
|
||||||
}
|
if ($dataDesignerExport) {
|
||||||
$exportShowPositions = $history->data->form->show_positions ?? $history->data->form->show_position ?? 'no';
|
foreach ($history->data->questions as $code => $question) {
|
||||||
$exportPositionColumns = $this->getAvailablePositionColumns($history->data->submissions ?? [], $exportShowPositions);
|
if (isset($question->type) && $question->type == 'hidden') {
|
||||||
$positionLabels = [
|
continue;
|
||||||
'territory' => 'Territory',
|
}
|
||||||
'area' => 'Area',
|
$headers[] = $question->label ?? (is_object($question) && isset($question->code) ? $question->code : $code);
|
||||||
'region' => 'Region',
|
}
|
||||||
'zone' => 'Zone',
|
} else {
|
||||||
];
|
$headers = ['Submission Date', 'Submitted By', 'Employee Code', 'Approval Status'];
|
||||||
foreach ($exportPositionColumns as $positionField) {
|
$userAttrs = $this->userAttributeCodes($history->data->form ?? null);
|
||||||
$headers[] = $positionLabels[$positionField] ?? ucfirst($positionField);
|
$userAttrLabels = $this->resolveUserAttributeLabels($userAttrs);
|
||||||
}
|
foreach ($userAttrs as $attr) {
|
||||||
if(isset($history->data) && isset($history->data->form) && isset($history->data->form->show_manager_details) && $history->data->form->show_manager_details === 'yes'){
|
$headers[] = $userAttrLabels[$attr] ?? ucwords(str_replace('_', ' ', (string) $attr));
|
||||||
$headers = array_merge( $headers, ['L1 Manager', 'L1 Employee Code', 'L2 Manager', 'L2 Employee Code'] );
|
}
|
||||||
}
|
$exportShowPositions = $history->data->form->show_positions ?? $history->data->form->show_position ?? 'no';
|
||||||
foreach($history->data->questions as $question) {
|
$exportPositionColumns = $this->getAvailablePositionColumns($history->data->submissions ?? [], $exportShowPositions);
|
||||||
if (isset($question->type) && $question->type == 'hidden') {
|
$positionLabels = [
|
||||||
continue;
|
'territory' => 'Territory',
|
||||||
}
|
'area' => 'Area',
|
||||||
if (isset($question->type) && $question->type == 'multitextbox' && !empty($question->options)) {
|
'region' => 'Region',
|
||||||
foreach ($question->options as $k => $v) {
|
'zone' => 'Zone',
|
||||||
$optLabel = is_object($v) ? ($v->display ?? $v->label ?? $k) : $v;
|
];
|
||||||
$headers[] = $optLabel.' ('.$question->label.')';
|
foreach ($exportPositionColumns as $positionField) {
|
||||||
|
$headers[] = $positionLabels[$positionField] ?? ucfirst($positionField);
|
||||||
|
}
|
||||||
|
if(isset($history->data) && isset($history->data->form) && isset($history->data->form->show_manager_details) && $history->data->form->show_manager_details === 'yes'){
|
||||||
|
$headers = array_merge( $headers, ['L1 Manager', 'L1 Employee Code', 'L2 Manager', 'L2 Employee Code'] );
|
||||||
|
}
|
||||||
|
foreach($history->data->questions as $question) {
|
||||||
|
if (isset($question->type) && $question->type == 'hidden') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isset($question->type) && $question->type == 'multitextbox' && !empty($question->options)) {
|
||||||
|
foreach ($question->options as $k => $v) {
|
||||||
|
$optLabel = is_object($v) ? ($v->display ?? $v->label ?? $k) : $v;
|
||||||
|
$headers[] = $optLabel.' ('.$question->label.')';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$headers[] = $question->label;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$headers[] = $question->label;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$exceldata[] = $headers;
|
$exceldata[] = $headers;
|
||||||
foreach($history->data->submissions as $submission) {
|
foreach($history->data->submissions as $submission) {
|
||||||
$row = [];
|
$row = [];
|
||||||
$row[] = $submission->createdAt;
|
if ($dataDesignerExport) {
|
||||||
$row[] = isset($submission->user_info->name) ? $submission->user_info->name : '';
|
foreach ($history->data->questions as $code => $question) {
|
||||||
$row[] = isset($submission->user_info->employee_code) ? $submission->user_info->employee_code : '';
|
if (isset($question->type) && $question->type == 'hidden') {
|
||||||
$row[] = isset($submission->workflow_status) ? $submission->workflow_status : '';
|
continue;
|
||||||
foreach ($userAttrs as $attr) {
|
|
||||||
$row[] = $this->userAttributeValue($submission->user_info ?? null, $attr);
|
|
||||||
}
|
|
||||||
foreach ($exportPositionColumns as $positionField) {
|
|
||||||
$row[] = isset($submission->{$positionField}) ? $submission->{$positionField} : '';
|
|
||||||
}
|
|
||||||
if(isset($history->data) && isset($history->data->form) && isset($history->data->form->show_manager_details) && $history->data->form->show_manager_details === 'yes'){
|
|
||||||
$row[] = isset($submission->manager1_name) ? $submission->manager1_name : '';
|
|
||||||
$row[] = isset($submission->manager1_code) ? $submission->manager1_code : '';
|
|
||||||
$row[] = isset($submission->manager2_name) ? $submission->manager2_name : '';
|
|
||||||
$row[] = isset($submission->manager2_code) ? $submission->manager2_code : '';
|
|
||||||
}
|
|
||||||
foreach($history->data->questions as $q => $v) {
|
|
||||||
if (isset($v->type) && $v->type == 'hidden') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (isset($v->type) && $v->type == 'multitextbox' && !empty($v->options)) {
|
|
||||||
foreach ($v->options as $optKey => $optMeta) {
|
|
||||||
$fieldKey = is_object($optMeta) ? ($optMeta->value ?? $optKey) : $optKey;
|
|
||||||
if (isset($submission->formdata->{$fieldKey})) {
|
|
||||||
$raw = $submission->formdata->{$fieldKey};
|
|
||||||
$row[] = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
|
||||||
} elseif (isset($submission->formdata->{$q}) && (is_object($submission->formdata->{$q}) || is_array($submission->formdata->{$q}))) {
|
|
||||||
$box = (array) $submission->formdata->{$q};
|
|
||||||
$raw = $box[$fieldKey] ?? '-';
|
|
||||||
$row[] = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
|
||||||
} else {
|
|
||||||
$row[] = '-';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
$col = is_object($question) && isset($question->code) ? $question->code : $code;
|
||||||
if (!isset($submission->formdata->{$q})) {
|
if (!isset($submission->formdata->{$col})) {
|
||||||
$row[] = '-';
|
$row[] = '-';
|
||||||
} elseif (is_array($submission->formdata->{$q})) {
|
} elseif (is_array($submission->formdata->{$col})) {
|
||||||
$row[] = implode(', ', $submission->formdata->{$q});
|
$row[] = implode(', ', $submission->formdata->{$col});
|
||||||
} elseif (is_object($submission->formdata->{$q})) {
|
} elseif (is_object($submission->formdata->{$col})) {
|
||||||
$row[] = collect((array) $submission->formdata->{$q})->map(function ($val, $key) {
|
$row[] = collect((array) $submission->formdata->{$col})->map(function ($val, $key) {
|
||||||
return $key.': '.$val;
|
return $key.': '.$val;
|
||||||
})->implode(', ');
|
})->implode(', ');
|
||||||
} else {
|
} else {
|
||||||
$row[] = $submission->formdata->{$q};
|
$row[] = $submission->formdata->{$col};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$row[] = $submission->createdAt;
|
||||||
|
$row[] = isset($submission->user_info->name) ? $submission->user_info->name : '';
|
||||||
|
$row[] = isset($submission->user_info->employee_code) ? $submission->user_info->employee_code : '';
|
||||||
|
$row[] = isset($submission->workflow_status) ? $submission->workflow_status : '';
|
||||||
|
foreach ($userAttrs as $attr) {
|
||||||
|
$row[] = $this->userAttributeValue($submission->user_info ?? null, $attr);
|
||||||
|
}
|
||||||
|
foreach ($exportPositionColumns as $positionField) {
|
||||||
|
$row[] = isset($submission->{$positionField}) ? $submission->{$positionField} : '';
|
||||||
|
}
|
||||||
|
if(isset($history->data) && isset($history->data->form) && isset($history->data->form->show_manager_details) && $history->data->form->show_manager_details === 'yes'){
|
||||||
|
$row[] = isset($submission->manager1_name) ? $submission->manager1_name : '';
|
||||||
|
$row[] = isset($submission->manager1_code) ? $submission->manager1_code : '';
|
||||||
|
$row[] = isset($submission->manager2_name) ? $submission->manager2_name : '';
|
||||||
|
$row[] = isset($submission->manager2_code) ? $submission->manager2_code : '';
|
||||||
|
}
|
||||||
|
foreach($history->data->questions as $q => $v) {
|
||||||
|
if (isset($v->type) && $v->type == 'hidden') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$col = is_object($v) && isset($v->code) ? $v->code : $q;
|
||||||
|
if (isset($v->type) && $v->type == 'multitextbox' && !empty($v->options)) {
|
||||||
|
foreach ($v->options as $optKey => $optMeta) {
|
||||||
|
$fieldKey = is_object($optMeta) ? ($optMeta->value ?? $optKey) : $optKey;
|
||||||
|
if (isset($submission->formdata->{$fieldKey})) {
|
||||||
|
$raw = $submission->formdata->{$fieldKey};
|
||||||
|
$row[] = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
||||||
|
} elseif (isset($submission->formdata->{$col}) && (is_object($submission->formdata->{$col}) || is_array($submission->formdata->{$col}))) {
|
||||||
|
$box = (array) $submission->formdata->{$col};
|
||||||
|
$raw = $box[$fieldKey] ?? '-';
|
||||||
|
$row[] = is_array($raw) ? implode(', ', $raw) : (is_object($raw) ? json_encode($raw) : $raw);
|
||||||
|
} else {
|
||||||
|
$row[] = '-';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!isset($submission->formdata->{$col})) {
|
||||||
|
$row[] = '-';
|
||||||
|
} elseif (is_array($submission->formdata->{$col})) {
|
||||||
|
$row[] = implode(', ', $submission->formdata->{$col});
|
||||||
|
} elseif (is_object($submission->formdata->{$col})) {
|
||||||
|
$row[] = collect((array) $submission->formdata->{$col})->map(function ($val, $key) {
|
||||||
|
return $key.': '.$val;
|
||||||
|
})->implode(', ');
|
||||||
|
} else {
|
||||||
|
$row[] = $submission->formdata->{$col};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13375,6 +13447,117 @@ class FormController extends Controller
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve left edge + max draw width from personalization position.
|
||||||
|
* Supports max_width, width, or x range "left-right" (used for center boxes).
|
||||||
|
*
|
||||||
|
* @return array{0:int,1:int}|null [left, maxWidth]
|
||||||
|
*/
|
||||||
|
protected function resolvePersonalizationTextBounds(object $pos): ?array
|
||||||
|
{
|
||||||
|
$x = $pos->x ?? 0;
|
||||||
|
$left = null;
|
||||||
|
$maxWidth = 0;
|
||||||
|
|
||||||
|
if (is_string($x) && strpos($x, '-') !== false) {
|
||||||
|
$parts = explode('-', $x, 2);
|
||||||
|
if (count($parts) === 2 && is_numeric($parts[0]) && is_numeric($parts[1])) {
|
||||||
|
$x1 = (int) $parts[0];
|
||||||
|
$x2 = (int) $parts[1];
|
||||||
|
$left = min($x1, $x2);
|
||||||
|
$maxWidth = abs($x2 - $x1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$left = (int) $x;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($pos->max_width) && (float) $pos->max_width > 0) {
|
||||||
|
$maxWidth = (int) $pos->max_width;
|
||||||
|
} elseif (isset($pos->width) && (float) $pos->width > 0) {
|
||||||
|
$maxWidth = (int) $pos->width;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($maxWidth <= 0 || $left === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [$left, $maxWidth];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function measurePersonalizationTextWidth(float $size, float $angle, string $font, string $text): float
|
||||||
|
{
|
||||||
|
$box = imagettfbbox($size, $angle, $font, $text);
|
||||||
|
if ($box === false) {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (float) abs($box[2] - $box[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function fitPersonalizationFontSize(
|
||||||
|
float $size,
|
||||||
|
float $angle,
|
||||||
|
string $font,
|
||||||
|
string $text,
|
||||||
|
int $maxWidth,
|
||||||
|
float $minSize = 5.0
|
||||||
|
): float {
|
||||||
|
if ($maxWidth <= 0 || $text === '') {
|
||||||
|
return $size;
|
||||||
|
}
|
||||||
|
|
||||||
|
$currentSize = $size;
|
||||||
|
$textWidth = $this->measurePersonalizationTextWidth($currentSize, $angle, $font, $text);
|
||||||
|
while ($textWidth > $maxWidth && $currentSize > $minSize) {
|
||||||
|
$currentSize = max($minSize, $currentSize - 0.5);
|
||||||
|
$textWidth = $this->measurePersonalizationTextWidth($currentSize, $angle, $font, $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $currentSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrap text so each line fits maxWidth at the given font size.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
protected function wrapPersonalizationTextToWidth(
|
||||||
|
string $text,
|
||||||
|
float $size,
|
||||||
|
string $font,
|
||||||
|
int $maxWidth,
|
||||||
|
int $fallbackChars = 40
|
||||||
|
): array {
|
||||||
|
$text = trim(preg_replace('/\s+/u', ' ', $text) ?? $text);
|
||||||
|
if ($text === '') {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
if ($maxWidth <= 0) {
|
||||||
|
return explode("\n", wordwrap($text, max(1, $fallbackChars), "\n", true));
|
||||||
|
}
|
||||||
|
|
||||||
|
$words = preg_split('/\s+/u', $text) ?: [$text];
|
||||||
|
$lines = [];
|
||||||
|
$current = '';
|
||||||
|
foreach ($words as $word) {
|
||||||
|
$candidate = $current === '' ? $word : $current.' '.$word;
|
||||||
|
if ($this->measurePersonalizationTextWidth($size, 0.0, $font, $candidate) <= $maxWidth) {
|
||||||
|
$current = $candidate;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($current !== '') {
|
||||||
|
$lines[] = $current;
|
||||||
|
}
|
||||||
|
// Single word longer than width: shrink handled by caller; keep as own line
|
||||||
|
$current = $word;
|
||||||
|
}
|
||||||
|
if ($current !== '') {
|
||||||
|
$lines[] = $current;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $lines;
|
||||||
|
}
|
||||||
|
|
||||||
protected function drawPersonalizationMultilineOnImage($outputImage, object $pos, string $text): void
|
protected function drawPersonalizationMultilineOnImage($outputImage, object $pos, string $text): void
|
||||||
{
|
{
|
||||||
$fontFile = $pos->font ?? '';
|
$fontFile = $pos->font ?? '';
|
||||||
|
|
@ -13393,13 +13576,42 @@ class FormController extends Controller
|
||||||
|
|
||||||
$text = $this->formatPersonalizationText($pos, $text);
|
$text = $this->formatPersonalizationText($pos, $text);
|
||||||
$lineChars = (int) ($pos->linechars ?? 40);
|
$lineChars = (int) ($pos->linechars ?? 40);
|
||||||
$lineHeight = (int) ($pos->linehieght ?? $pos->lineheight ?? 20);
|
$baseLineHeight = (int) ($pos->linehieght ?? $pos->lineheight ?? 20);
|
||||||
$lines = wordwrap($text, $lineChars, "\n", true);
|
$size = (float) ($pos->size ?? 12);
|
||||||
$xPosition = (int) $pos->x;
|
$bounds = $this->resolvePersonalizationTextBounds($pos);
|
||||||
$yPosition = (int) $pos->y;
|
$xPosition = $bounds ? $bounds[0] : (int) $pos->x;
|
||||||
|
$maxWidth = $bounds ? $bounds[1] : 0;
|
||||||
|
|
||||||
foreach (explode("\n", $lines) as $line) {
|
if ($maxWidth > 0) {
|
||||||
imagettftext($outputImage, (float) $pos->size, 0, $xPosition, $yPosition, $textColor, $font, $line);
|
// Shrink until the longest wrapped line fits (and optionally max line count)
|
||||||
|
$maxLines = isset($pos->max_lines) ? max(1, (int) $pos->max_lines) : 6;
|
||||||
|
do {
|
||||||
|
$lines = $this->wrapPersonalizationTextToWidth($text, $size, $font, $maxWidth, $lineChars);
|
||||||
|
$longest = 0.0;
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$longest = max($longest, $this->measurePersonalizationTextWidth($size, 0.0, $font, $line));
|
||||||
|
}
|
||||||
|
$fits = $longest <= $maxWidth && count($lines) <= $maxLines;
|
||||||
|
if ($fits || $size <= 5) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$size = max(5.0, $size - 0.5);
|
||||||
|
} while (true);
|
||||||
|
$lineHeight = max(8, (int) round($baseLineHeight * ($size / max(1.0, (float) ($pos->size ?? $size)))));
|
||||||
|
} else {
|
||||||
|
$lines = explode("\n", wordwrap($text, max(1, $lineChars), "\n", true));
|
||||||
|
$lineHeight = $baseLineHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
$yPosition = (int) $pos->y;
|
||||||
|
$alignCenter = isset($pos->align) && $pos->align === 'center' && $maxWidth > 0;
|
||||||
|
foreach ($lines as $line) {
|
||||||
|
$drawX = $xPosition;
|
||||||
|
if ($alignCenter) {
|
||||||
|
$lineWidth = $this->measurePersonalizationTextWidth($size, 0.0, $font, $line);
|
||||||
|
$drawX = (int) round($xPosition + (($maxWidth - $lineWidth) / 2));
|
||||||
|
}
|
||||||
|
imagettftext($outputImage, $size, 0, $drawX, $yPosition, $textColor, $font, $line);
|
||||||
$yPosition += $lineHeight;
|
$yPosition += $lineHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -13423,29 +13635,27 @@ class FormController extends Controller
|
||||||
$text = $this->formatPersonalizationText($pos, $text);
|
$text = $this->formatPersonalizationText($pos, $text);
|
||||||
|
|
||||||
$angle = isset($pos->angle) ? (float) $pos->angle : 0.0;
|
$angle = isset($pos->angle) ? (float) $pos->angle : 0.0;
|
||||||
$size = (float) $pos->size;
|
$size = (float) ($pos->size ?? 12);
|
||||||
if (isset($pos->max_width) && $pos->max_width > 0) {
|
$bounds = $this->resolvePersonalizationTextBounds($pos);
|
||||||
$currentSize = $size;
|
$maxWidth = $bounds ? $bounds[1] : 0;
|
||||||
$box = imagettfbbox($currentSize, $angle, $font, $text);
|
if ($maxWidth > 0) {
|
||||||
$textWidth = abs($box[4] - $box[0]);
|
$size = $this->fitPersonalizationFontSize($size, $angle, $font, $text, $maxWidth);
|
||||||
while ($textWidth > $pos->max_width && $currentSize > 5) {
|
|
||||||
$currentSize--;
|
|
||||||
$box = imagettfbbox($currentSize, $angle, $font, $text);
|
|
||||||
$textWidth = abs($box[4] - $box[0]);
|
|
||||||
}
|
|
||||||
$size = $currentSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$x = $pos->x;
|
$x = is_numeric($pos->x) ? (float) $pos->x : 0.0;
|
||||||
if (isset($pos->align) && $pos->align === 'center') {
|
if (isset($pos->align) && $pos->align === 'center' && $bounds) {
|
||||||
$box = imagettfbbox($size, 0, $font, $text);
|
$textWidth = $this->measurePersonalizationTextWidth($size, 0.0, $font, $text);
|
||||||
|
$x = $bounds[0] + (($bounds[1] - $textWidth) / 2);
|
||||||
|
} elseif (isset($pos->align) && $pos->align === 'center') {
|
||||||
|
// Legacy: x range without resolved bounds
|
||||||
$xRange = explode('-', (string) $pos->x);
|
$xRange = explode('-', (string) $pos->x);
|
||||||
if (count($xRange) === 2) {
|
if (count($xRange) === 2) {
|
||||||
$x = $xRange[0] + (($xRange[1] - $xRange[0]) - $box[2]) / 2;
|
$textWidth = $this->measurePersonalizationTextWidth($size, 0.0, $font, $text);
|
||||||
|
$x = ((float) $xRange[0]) + ((((float) $xRange[1]) - ((float) $xRange[0])) - $textWidth) / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imagettftext($outputImage, $size, $angle, (int) $x, (int) $pos->y, $textColor, $font, $text);
|
imagettftext($outputImage, $size, $angle, (int) round($x), (int) $pos->y, $textColor, $font, $text);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function resolvePersonalizationPdfScript(): string
|
protected function resolvePersonalizationPdfScript(): string
|
||||||
|
|
@ -13524,6 +13734,20 @@ class FormController extends Controller
|
||||||
* Opt-in only: empty designer or export-only fields keep the legacy list.
|
* Opt-in only: empty designer or export-only fields keep the legacy list.
|
||||||
*/
|
*/
|
||||||
protected function hasDataDesignerView($form): bool
|
protected function hasDataDesignerView($form): bool
|
||||||
|
{
|
||||||
|
return $this->hasDataDesignerFlag($form, 'show_in_view');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True when the form Data Designer has at least one show_in_export field.
|
||||||
|
* Opt-in only: empty designer keeps the legacy export columns.
|
||||||
|
*/
|
||||||
|
protected function hasDataDesignerExport($form): bool
|
||||||
|
{
|
||||||
|
return $this->hasDataDesignerFlag($form, 'show_in_export');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function hasDataDesignerFlag($form, string $flag): bool
|
||||||
{
|
{
|
||||||
if (!$form) {
|
if (!$form) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -13547,9 +13771,9 @@ class FormController extends Controller
|
||||||
}
|
}
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
if (is_object($field)) {
|
if (is_object($field)) {
|
||||||
$show = $field->show_in_view ?? false;
|
$show = $field->{$flag} ?? false;
|
||||||
} elseif (is_array($field)) {
|
} elseif (is_array($field)) {
|
||||||
$show = $field['show_in_view'] ?? false;
|
$show = $field[$flag] ?? false;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,8 @@ class ZenovaReportController extends Controller
|
||||||
private function months(): array
|
private function months(): array
|
||||||
{
|
{
|
||||||
$now = now()->startOfMonth();
|
$now = now()->startOfMonth();
|
||||||
$startYear = $now->month >= 4 ? $now->year : $now->year - 1;
|
$startYear = $now->month >= 10 ? $now->year : $now->year - 1;
|
||||||
$cursor = now()->setDate($startYear, 4, 1)->startOfMonth();
|
$cursor = now()->setDate($startYear, 10, 1)->startOfMonth();
|
||||||
$months = [];
|
$months = [];
|
||||||
while ($cursor->lte($now)) {
|
while ($cursor->lte($now)) {
|
||||||
$months[$cursor->format('Y-m')] = $cursor->format('F Y');
|
$months[$cursor->format('Y-m')] = $cursor->format('F Y');
|
||||||
|
|
@ -293,13 +293,21 @@ class ZenovaReportController extends Controller
|
||||||
$demoColumns[] = $this->column($key, 'Demography & Details', $key, $type);
|
$demoColumns[] = $this->column($key, 'Demography & Details', $key, $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dayMetrics = ['GLIPIQ Total Rx', 'ABSI Camp Count', 'Patients Screened Count', 'Sitazit Total RX'];
|
$dayMetrics = [
|
||||||
|
'Glipiq Total Invoice Count',
|
||||||
|
'Obesity Strength Invoice Count',
|
||||||
|
'ABSI Camp Count',
|
||||||
|
'Patients Screened Count',
|
||||||
|
'Sitazit Total RX',
|
||||||
|
];
|
||||||
$periodMetrics = [
|
$periodMetrics = [
|
||||||
'GLIPIQ Total Rx',
|
'Glipiq Total Invoice Count',
|
||||||
|
'Obesity Strength Invoice Count',
|
||||||
'GLIPIQ New Conversion',
|
'GLIPIQ New Conversion',
|
||||||
'ABSI Camp Count',
|
'ABSI Camp Count',
|
||||||
'Patients Screened Count',
|
'Patients Screened Count',
|
||||||
'GLIPIQ Total POB Units',
|
'GLIPIQ Total POB Units',
|
||||||
|
'Obesity Strength POB Units',
|
||||||
'Sitazit Total RX',
|
'Sitazit Total RX',
|
||||||
'Sitazit New Conversions',
|
'Sitazit New Conversions',
|
||||||
'Sitazit Total POB Units',
|
'Sitazit Total POB Units',
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,14 @@
|
||||||
</div>
|
</div>
|
||||||
<br class="clearfix" />
|
<br class="clearfix" />
|
||||||
@foreach($questions as $question)
|
@foreach($questions as $question)
|
||||||
<div class="col-md-12 mb-2 question-wrapper" id="wrapper-{{$question->id}}">
|
@php
|
||||||
|
$qLabel = strtolower(trim((string) ($question->question ?? '')));
|
||||||
|
$qCode = strtolower(trim((string) ($question->code ?? '')));
|
||||||
|
$isTopic2 = str_contains($qLabel, 'topic 2') || in_array($qCode, ['topic_2', 'topic2', 'topic-2'], true);
|
||||||
|
// Honor Form Question required (default yes for legacy); Topic 2 always optional.
|
||||||
|
$isRequired = !$isTopic2 && (($question->required ?? 'yes') === 'yes');
|
||||||
|
@endphp
|
||||||
|
<div class="col-md-12 mb-2 question-wrapper" id="wrapper-{{$question->id}}" data-required="{{ $isRequired ? 'yes' : 'no' }}">
|
||||||
<label for="field-{{$question->code}}" class="form-label">{{$question->question}} <span class="req-star text-danger" style="display:none" aria-hidden="true">*</span> </label>
|
<label for="field-{{$question->code}}" class="form-label">{{$question->question}} <span class="req-star text-danger" style="display:none" aria-hidden="true">*</span> </label>
|
||||||
@switch($question->type)
|
@switch($question->type)
|
||||||
@case('hidden')
|
@case('hidden')
|
||||||
|
|
@ -198,8 +205,10 @@
|
||||||
for(let que of personalize.questions) {
|
for(let que of personalize.questions) {
|
||||||
let $w = $('#wrapper-'+que)
|
let $w = $('#wrapper-'+que)
|
||||||
$w.show()
|
$w.show()
|
||||||
$w.find('.req-star').show()
|
if ($w.attr('data-required') === 'yes') {
|
||||||
$w.find('input:not([type="hidden"]):not([type="checkbox"]), textarea, select').attr('required', 'required')
|
$w.find('.req-star').show()
|
||||||
|
$w.find('input:not([type="hidden"]):not([type="checkbox"]), textarea, select').attr('required', 'required')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$('#report-form :input').removeAttr('readonly')
|
$('#report-form :input').removeAttr('readonly')
|
||||||
$('#wrapper-template_id img').attr('src', personalize.icon)
|
$('#wrapper-template_id img').attr('src', personalize.icon)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue