Skip to content
Snippets Groups Projects
Commit 403d6284 authored by Lucas García's avatar Lucas García
Browse files

feat: parse fileupload fields

parent 9d3bccd4
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,12 @@ function wpct_crm_forms_parse_form_entry($entry, $form) ...@@ -12,7 +12,12 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
foreach ($form['fields'] as $field) { foreach ($form['fields'] as $field) {
if ($field->type === 'consent') continue; if ($field->type === 'consent') continue;
$input_name = $field->inputName ? $field->inputName : $field->label; $input_name = $field->inputName
? $field->inputName
: ($field->adminLabel
? $field->adminLabel
: $field->label);
$inputs = $field->get_entry_inputs(); $inputs = $field->get_entry_inputs();
if (is_array($inputs)) { if (is_array($inputs)) {
// composed fields // composed fields
...@@ -31,7 +36,7 @@ function wpct_crm_forms_parse_form_entry($entry, $form) ...@@ -31,7 +36,7 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
foreach ($inputs as $input) { foreach ($inputs as $input) {
$value = rgar($entry, (string) $input['id']); $value = rgar($entry, (string) $input['id']);
if ($input_name && $value) { if ($input_name && $value) {
$values[] = $value; $values[] = wpct_crm_forms_format_value($value, $field, $input);
} }
} }
...@@ -40,7 +45,8 @@ function wpct_crm_forms_parse_form_entry($entry, $form) ...@@ -40,7 +45,8 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
} else { } else {
// simple fields // simple fields
if ($input_name) { if ($input_name) {
$form_vals[$input_name] = rgar($entry, (string) $field->id); $raw_value = rgar($entry, (string) $field->id);
$form_vals[$input_name] = wpct_crm_forms_format_value($raw_value, $field);
} }
} }
} }
...@@ -48,6 +54,15 @@ function wpct_crm_forms_parse_form_entry($entry, $form) ...@@ -48,6 +54,15 @@ function wpct_crm_forms_parse_form_entry($entry, $form)
return $form_vals; return $form_vals;
} }
function wpct_crm_forms_format_value($value, $field, $input = null)
{
if ($field->type === 'fileupload') {
if (!is_array($field->get_entry_inputs())) return json_decode($value)[0];
}
return $value;
}
function wpct_crm_forms_add_cord_id($form_values) function wpct_crm_forms_add_cord_id($form_values)
{ {
if (!isset($form_values['company_id']) || !$form_values['company_id']) { if (!isset($form_values['company_id']) || !$form_values['company_id']) {
...@@ -104,6 +119,7 @@ function wpct_crm_forms_get_submission_payload($form_vals) ...@@ -104,6 +119,7 @@ function wpct_crm_forms_get_submission_payload($form_vals)
/** /**
* Pipe form submission transformations to get the submission post payload * Pipe form submission transformations to get the submission post payload
*/ */
add_filter('wpct_crm_forms_prepare_submission', 'wpct_crm_forms_prepare_submission', 10, 2);
function wpct_crm_forms_prepare_submission($form_vals) function wpct_crm_forms_prepare_submission($form_vals)
{ {
$form_vals = wpct_crm_forms_add_cord_id($form_vals); $form_vals = wpct_crm_forms_add_cord_id($form_vals);
...@@ -111,22 +127,26 @@ function wpct_crm_forms_prepare_submission($form_vals) ...@@ -111,22 +127,26 @@ function wpct_crm_forms_prepare_submission($form_vals)
return wpct_crm_forms_get_submission_payload($form_vals); return wpct_crm_forms_get_submission_payload($form_vals);
} }
add_filter('wpct_crm_forms_prepare_submission', 'wpct_crm_forms_prepare_submission', 10, 2);
/** /**
* Store uploads on a custom folder * Store uploads on a custom folder
*/ */
add_filter('gform_upload_path', 'wpct_forms_sm_upload_path', 90); add_filter('gform_upload_path', 'wpct_crm_forms_upload_path', 90);
function wpct_forms_sm_upload_path() function wpct_crm_forms_upload_path($path_info)
{ {
$upload_dir = wp_upload_dir(); $upload_dir = wp_upload_dir();
$path = $upload_dir['basedir'] . '/forms'; $basedir = dirname($upload_dir['basedir']);
if (!is_dir($path)) mkdir($path);
$path = $basedir . '/crm-uploads';
if (!is_dir($path)) mkdir($path, 0700);
$path .= '/' . date('Y'); $path .= '/' . date('Y');
if (!is_dir($path)) mkdir($path); if (!is_dir($path)) mkdir($path, 0700);
$path .= '/' . date('m'); $path .= '/' . date('m');
if (!is_dir($path)) mkdir($path); if (!is_dir($path)) mkdir($path, 0700);
$path_info['path'] = $path;
$url = content_url(str_replace($basedir, '', $path)) . '/';
$path_info['url'] = $url;
return $path; return $path_info;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment