Choose Visible columns & in csv with removed field (#11)

* Choose Visible columns & in csv with removed field

* toggle UI fixes
This commit is contained in:
Chirag
2022-10-17 13:15:28 +05:30
committed by GitHub
parent 993bab7cff
commit 8f528155f5
6 changed files with 92 additions and 66 deletions

View File

@@ -35,7 +35,8 @@ class FormSubmissionController extends Controller
foreach ($form->submissions->toArray() as $row) {
$formatter = (new FormSubmissionFormatter($form, $row['data']))
->outputStringsOnly()
->setEmptyForNoValue();
->setEmptyForNoValue()
->showRemovedFields();
$tmp = $formatter->getCleanKeyValue();
$tmp['Create Date'] = date("Y-m-d H:i", strtotime($row['created_at']));
$allRows[] = $tmp;

View File

@@ -45,6 +45,7 @@ class FormResource extends JsonResource
'visibility' => $this->visibility,
'notification_emails' => $this->notification_emails,
'slack_webhook_url' => $this->slack_webhook_url,
'removed_properties' => $this->removed_properties
] : [];
$baseData = $this->getFilteredFormData(parent::toArray($request), $this->userIsFormOwner());

View File

@@ -27,6 +27,8 @@ class FormSubmissionFormatter
private $setEmptyForNoValue = false;
private $showRemovedFields = false;
public function __construct(private Form $form, private array $formData)
{
}
@@ -55,6 +57,12 @@ class FormSubmissionFormatter
return $this;
}
public function showRemovedFields()
{
$this->showRemovedFields = true;
return $this;
}
/**
* Return a nice "FieldName": "Field Response" array
* - If createLink enabled, returns html link for emails and links
@@ -63,10 +71,15 @@ class FormSubmissionFormatter
public function getCleanKeyValue()
{
$data = $this->formData;
$fields = $this->form->properties;
$fields = ($this->showRemovedFields) ? array_merge($this->form->properties, $this->form->removed_properties) : $this->form->properties;
$returnArray = [];
foreach ($fields as &$field) {
$isRemoved = in_array($field['id'], array_column($this->form->removed_properties, 'id')) ?? false;
if($isRemoved){
$field['name'] = $field['name']." (deleted)";
}
// If not present skip
if (!isset($data[$field['id']])) {
if ($this->setEmptyForNoValue) {