PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.4
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.4
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Services / Submission / SubmissionService.php

SubmissionService.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.4, at app/Services/Submission/SubmissionService.php

781 lines 26.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Services\Submission;
4
5 defined('ABSPATH') or die;
6
7 use Exception;
8 use FluentForm\App\Models\EntryDetails;
9 use FluentForm\App\Models\Form;
10 use FluentForm\App\Helpers\Helper;
11 use FluentForm\App\Models\FormMeta;
12 use FluentForm\App\Models\Submission;
13 use FluentForm\Framework\Support\Arr;
14 use FluentForm\App\Models\SubmissionMeta;
15 use FluentForm\Framework\Support\Collection;
16 use FluentForm\App\Services\Form\FormService;
17 use FluentForm\App\Modules\Form\FormDataParser;
18 use FluentForm\App\Modules\Form\FormFieldsParser;
19
20 class SubmissionService
21 {
22 /**
23 * @var \FluentForm\App\Models\Submission|\FluentForm\Framework\Database\Query\Builder|\FluentForm\Framework\Database\Orm\Builder
24 */
25 protected $model;
26 protected $formService;
27
28 public function __construct()
29 {
30 $this->model = new Submission();
31 $this->formService = new FormService();
32 }
33
34 public function get($attributes = [])
35 {
36 if (!defined('FLUENTFORM_RENDERING_ENTRIES')) {
37 define('FLUENTFORM_RENDERING_ENTRIES', true);
38 }
39
40 $entries = $this->model->paginateEntries($attributes);
41
42 if (Arr::get($attributes, 'parse_entry')) {
43 $form = Form::find(Arr::get($attributes, 'form_id'));
44
45 $parsedEntries = FormDataParser::parseFormEntries($entries->items(), $form);
46
47 $entries->setCollection(Collection::make($parsedEntries));
48 }
49
50 return apply_filters('fluentform/get_submissions', $entries);
51 }
52
53 public function find($submissionId)
54 {
55 try {
56 if (!defined('FLUENTFORM_RENDERING_ENTRY')) {
57 define('FLUENTFORM_RENDERING_ENTRY', true);
58 }
59
60 $submission = $this->model->with(['form','submissionMeta' => function($q) {
61 $q->where('meta_key', '_entry_uid_hash');
62 }])->findOrFail($submissionId);
63
64 $form = $submission->form;
65
66
67 $autoRead = apply_filters_deprecated(
68 'fluentform_auto_read',
69 [true, $form],
70 FLUENTFORM_FRAMEWORK_UPGRADE,
71 'fluentform/auto_read_submission'
72 );
73
74 $autoRead = apply_filters('fluentform/auto_read_submission', $autoRead, $form);
75
76 if ('unread' === $submission->status && $autoRead) {
77 $submission->fill(['status' => 'read'])->save();
78 }
79
80 $meta = $submission->submissionMeta;
81 if (count($meta)) {
82 $submission->_entry_uid_hash = Arr::get($meta, '0.value');
83 $this->setEntryUidLink($submission);
84 }
85
86 $submission = apply_filters('fluentform/submission_before_parse', $submission, $form);
87
88 $submission = FormDataParser::parseFormEntry($submission, $form, null, true);
89 $this->enrichWithUser($submission);
90
91 $submission = apply_filters_deprecated(
92 'fluentform_single_response_data',
93 [$submission, $form->id],
94 FLUENTFORM_FRAMEWORK_UPGRADE,
95 'fluentform/find_submission'
96 );
97
98 return apply_filters('fluentform/find_submission', $submission, $form->id)->makeHidden('form');
99 } catch (Exception $e) {
100 throw new Exception(
101 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception message, not output
102 __('No Entry found.', 'fluentform')
103 );
104 }
105 }
106
107
108 /**
109 * @param array{
110 * formId?: int, // Optional when using uidHash
111 * serialNumber?: int, // Required if using formId without uidHash
112 * uidHash?: string, // Can be used with or without formId
113 * isHtml?: bool
114 * } $params Either (formId + serialNumber) OR uidHash required
115 *
116 * @return Submission
117 * @throws Exception
118 */
119 public function findByParams($params)
120 {
121 try {
122 if (!defined('FLUENTFORM_RENDERING_ENTRY')) {
123 define('FLUENTFORM_RENDERING_ENTRY', true);
124 }
125
126 $formId = $params['formId'] ?? null;
127 $serialNumber = $params['serialNumber'] ?? null;
128 $uidHash = $params['uidHash'] ?? null;
129 $isHtml = $params['isHtml'] ?? false;
130 if (!($uidHash || ($formId && $serialNumber))) {
131 throw new \Exception(
132 __('Either uidHash or (formId + serialNumber) must be provided', 'fluentform')
133 );
134 }
135
136 $query = Submission::query();
137
138 if ($formId) {
139 $query->where('form_id', $formId);
140 }
141
142 if ($serialNumber) {
143 $query->where('serial_number', $serialNumber);
144 } else {
145 $query->whereHas('submissionMeta', function ($metaQuery) use ($uidHash) {
146 $metaQuery->where('meta_key', '_entry_uid_hash')
147 ->where('value', $uidHash); // Changed to 'value' column
148 });
149 }
150
151 $submission = $query->orderBy('serial_number', 'desc')->first();
152
153 if (!$submission) {
154 throw new \Exception(
155 __('No entry found matching the criteria', 'fluentform')
156 );
157 }
158 $form = $submission->form;
159
160 $autoRead = apply_filters('fluentform/auto_read_submission', true, $form);
161
162 if ('unread' === $submission->status && $autoRead) {
163 $submission->fill(['status' => 'read'])->save();
164 }
165
166 $meta = $submission->submissionMeta()->where('meta_key', '_entry_uid_hash')->first();
167 if ($meta && $meta->value) {
168 $submission->_entry_uid_hash = $meta->value;
169 $this->setEntryUidLink($submission);
170 }
171
172 $submission = FormDataParser::parseFormEntry($submission, $form, null, $isHtml);
173 $this->enrichWithUser($submission);
174
175 return apply_filters('fluentform/find_submission', $submission, $form->id);
176 } catch (Exception $e) {
177 throw new Exception(
178 sprintf(
179 /* translators: %s: error message */
180 esc_html__('No Entry found. Error: %s', 'fluentform'),
181 esc_html($e->getMessage())
182 )
183 );
184 }
185 }
186
187 public function resources($attributes)
188 {
189 $resources = [];
190
191 $formId = Arr::get($attributes, 'form_id');
192 $submissionId = Arr::get($attributes, 'entry_id');
193
194 if (Arr::get($attributes, 'counts')) {
195 $resources['counts'] = $this->model->countByGroup($formId);
196 }
197
198 $formInputsAndLabels = null;
199
200 $wantsLabels = Arr::get($attributes, 'labels');
201
202 if ($wantsLabels) {
203 $formInputsAndLabels = $this->formService->getInputsAndLabels($formId);
204 $resources['labels'] = $formInputsAndLabels['labels'];
205 }
206
207 if (Arr::get($attributes, 'fields')) {
208 $formInputsAndLabels = $formInputsAndLabels ? $formInputsAndLabels : $this->formService->getInputsAndLabels($formId);
209 $resources['fields'] = $formInputsAndLabels['inputs'];
210 }
211
212 if (Arr::get($attributes, 'visibleColumns')) {
213 $resources['visibleColumns'] = Helper::getFormMeta($formId, '_visible_columns', null);
214 }
215
216 if (Arr::get($attributes, 'columnsOrder')) {
217 $resources['columnsOrder'] = Helper::getFormMeta($formId, '_columns_order', null);
218 }
219
220 if (Arr::get($attributes, 'next')) {
221 $resources['next'] = $this->model->findAdjacentSubmission($attributes);
222 }
223
224 if (Arr::get($attributes, 'previous')) {
225 $attributes['direction'] = 'previous';
226 $resources['previous'] = $this->model->findAdjacentSubmission($attributes);
227 }
228 if (count(array_intersect(['orderData', 'widgets', 'cards'], array_keys($attributes))) > 0) {
229 try {
230 $submission = $this->model->with('form')->findOrFail($submissionId);
231 } catch (Exception $e) {
232 throw new Exception(
233 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception message, not output
234 __('No Entry found.', 'fluentform')
235 );
236 }
237
238 if (Arr::get($attributes, 'orderData')) {
239 $hasPayment = $submission->payment_status || $submission->payment_total || 'subscription' === $submission->payment_type;
240
241 if ($hasPayment) {
242 $resources['orderData'] = apply_filters(
243 'fluentform/submission_order_data',
244 false,
245 $submission,
246 $submission->form
247 );
248
249 if ($wantsLabels) {
250 $resources['labels'] = apply_filters(
251 'fluentform/submission_labels',
252 $resources['labels'],
253 $submission,
254 $submission->form
255 );
256 }
257 }
258 }
259
260 if (Arr::get($attributes, 'widgets')) {
261 $resources['widgets'] = apply_filters(
262 'fluentform/submissions_widgets', [], $resources, $submission
263 );
264 }
265
266 if (Arr::get($attributes, 'cards')) {
267 $resources['cards'] = apply_filters(
268 'fluentform/submission_cards', [], $resources, $submission
269 );
270 }
271 }
272
273 return apply_filters('fluentform/submission_resources', $resources);
274 }
275
276 public function updateStatus($attributes = [])
277 {
278 $submissionId = intval(Arr::get($attributes, 'entry_id'));
279
280 $status = sanitize_text_field(Arr::get($attributes, 'status'));
281
282 $this->model->amend($submissionId, ['status' => $status]);
283
284 do_action('fluentform/after_submission_status_update', $submissionId, $status);
285
286 return $status;
287 }
288
289 public function toggleIsFavorite($submissionId)
290 {
291 try {
292 $submission = $this->model->findOrFail($submissionId);
293 } catch (Exception $e) {
294 throw new Exception(
295 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception message, not output
296 __('No Entry found.', 'fluentform')
297 );
298 }
299
300 if ($submission->is_favourite) {
301 $message = __('The entry has been removed from favorites', 'fluentform');
302 } else {
303 $message = __('The entry has been marked as favorites', 'fluentform');
304 }
305
306 $submission->fill(['is_favourite' => !$submission->is_favourite])->save();
307
308 return [$message, $submission->is_favourite];
309 }
310
311 public function storeColumnSettings($attributes = [])
312 {
313 $formId = intval(Arr::get($attributes, 'form_id'));
314 $metaKey = sanitize_text_field(Arr::get($attributes, 'meta_key'));
315
316 $allowedKeys = ['_visible_columns', '_columns_order'];
317 if (!in_array($metaKey, $allowedKeys)) {
318 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
319 throw new \Exception(__('Invalid meta key for column settings.', 'fluentform'));
320 }
321
322 $metaValue = wp_unslash(Arr::get($attributes, 'settings'));
323
324 FormMeta::persist($formId, $metaKey, $metaValue);
325 }
326
327 public function handleBulkActions($attributes = [])
328 {
329 $formId = intval(Arr::get($attributes, 'form_id'));
330
331 $submissionIds = fluentFormSanitizer(Arr::get($attributes, 'entries', []));
332
333 $actionType = sanitize_text_field(Arr::get($attributes, 'action_type'));
334
335 if (!$formId || !count($submissionIds)) {
336 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception message, not output
337 throw new Exception(__('Please select entries first', 'fluentform'));
338 }
339
340 $query = $this->model->where('form_id', $formId)->whereIn('id', $submissionIds);
341
342 $statuses = Helper::getEntryStatuses($formId);
343
344 $message = '';
345
346 if (isset($statuses[$actionType])) {
347 $query->update([
348 'status' => $actionType,
349 'updated_at' => current_time('mysql'),
350 ]);
351
352 foreach ($submissionIds as $submissionId) {
353 do_action('fluentform/after_submission_status_update', $submissionId, $actionType);
354 }
355
356 $message = 'Selected entries successfully marked as ' . $statuses[$actionType];
357 } elseif ('other.delete_permanently' == $actionType) {
358 $this->deleteEntries($submissionIds, $formId);
359
360 $message = __('Selected entries successfully deleted', 'fluentform');
361 } elseif ('other.make_favorite' == $actionType) {
362 $query->update([
363 'is_favourite' => 1,
364 ]);
365
366 $message = __('Selected entries successfully marked as favorites', 'fluentform');
367 } elseif ('other.unmark_favorite' == $actionType) {
368 $query->update([
369 'is_favourite' => 0,
370 ]);
371
372 $message = __('Selected entries successfully removed from favorites', 'fluentform');
373 }
374
375 return $message;
376 }
377
378 public function deleteEntries($submissionIds, $formId)
379 {
380 $submissionIds = (array)$submissionIds;
381
382 do_action('fluentform/before_deleting_entries', $submissionIds, $formId);
383
384 foreach ($submissionIds as $submissionId) {
385 do_action_deprecated(
386 'fluentform_before_entry_deleted',
387 [$submissionId, $formId],
388 FLUENTFORM_FRAMEWORK_UPGRADE,
389 'fluentform/before_deleting_entries'
390 );
391 }
392
393 $this->deleteFiles($submissionIds, $formId);
394
395 Submission::remove($submissionIds);
396
397 do_action('fluentform/after_deleting_submissions', $submissionIds, $formId);
398
399 foreach ($submissionIds as $submissionId) {
400 do_action_deprecated(
401 'fluentform_after_entry_deleted',
402 [$submissionId, $formId],
403 FLUENTFORM_FRAMEWORK_UPGRADE,
404 'fluentform/after_deleting_entries'
405 );
406 }
407 }
408
409 public function deleteFiles($submissionIds, $formId)
410 {
411 apply_filters_deprecated(
412 'fluentform_disable_attachment_delete',
413 [
414 false,
415 $formId
416 ],
417 FLUENTFORM_FRAMEWORK_UPGRADE,
418 'fluentform/disable_attachment_delete',
419 'Use fluentform/disable_attachment_delete instead of fluentform_disable_attachment_delete'
420 );
421
422 $disableAttachmentDelete = apply_filters(
423 'fluentform/disable_attachment_delete', false, $formId
424 );
425
426 $shouldDelete = defined('FLUENTFORMPRO') && $formId && !$disableAttachmentDelete;
427
428 if ($shouldDelete) {
429 $deletables = $this->getAttachments($submissionIds, $formId);
430
431 foreach ($deletables as $file) {
432 $file = wp_upload_dir()['basedir'] . FLUENTFORM_UPLOAD_DIR . '/' . basename($file);
433
434 if (is_readable($file) && !is_dir($file)) {
435 wp_delete_file($file);
436 }
437 }
438 // Empty Temp Uploads
439 if (defined('FLUENTFORMPRO')) {
440 $tempDir = wp_upload_dir()['basedir'] . FLUENTFORM_UPLOAD_DIR . '/temp/';
441 $files = glob($tempDir . '*');
442 if(!empty($files)){
443 foreach ($files as $file) {
444 if (basename($file) !== 'index.php') {
445 wp_delete_file($file);
446 }
447 }
448 }
449 }
450
451 }
452 }
453
454 public function getAttachments($submissionIds, $form)
455 {
456 $submissionIds = (array)$submissionIds;
457
458 if (!$form instanceof Form) {
459 $form = Form::find($form);
460 }
461
462 $fields = FormFieldsParser::getAttachmentInputFields($form, ['element', 'attributes']);
463
464 $attachments = [];
465
466 if ($fields) {
467 $fields = Arr::pluck($fields, 'attributes.name');
468
469 $submissions = $this->model->whereIn('id', $submissionIds)->get();
470
471 foreach ($submissions as $submission) {
472 $response = json_decode($submission->response, true);
473
474 $files = Arr::collapse(Arr::only($response, $fields));
475
476 $attachments = array_merge($attachments, $files);
477 }
478 }
479
480 return $attachments;
481 }
482
483 public function getNotes($submissionId, $attributes)
484 {
485 $formId = (int)Arr::get($attributes, 'form_id');
486 $apiLog = 'yes' === sanitize_text_field(Arr::get($attributes, 'api_log'));
487
488 $metaKeys = ['_notes'];
489
490 if ($apiLog) {
491 $metaKeys[] = 'api_log';
492 }
493
494 $perPage = (int) Arr::get($attributes, 'per_page', 0);
495 $page = (int) Arr::get($attributes, 'page', 1);
496
497 $query = SubmissionMeta::where('response_id', $submissionId)
498 ->whereIn('meta_key', $metaKeys)
499 ->orderBy('id', 'DESC');
500
501 if ($perPage > 0) {
502 $perPage = min($perPage, 100);
503 $notes = $query->forPage($page, $perPage)->get();
504 } else {
505 $notes = $query->get();
506 }
507
508 // Batch-fetch users to avoid N+1 queries
509 $userIds = $notes->pluck('user_id')->filter()->unique()->values()->toArray();
510 $usersMap = [];
511 if (!empty($userIds)) {
512 $users = get_users(['include' => $userIds, 'fields' => ['ID', 'display_name']]);
513 foreach ($users as $user) {
514 $usersMap[$user->ID] = $user->display_name;
515 }
516 }
517
518 foreach ($notes as $note) {
519 if ($note->user_id) {
520 $note->pemalink = get_edit_user_link($note->user_id);
521 if (isset($usersMap[$note->user_id])) {
522 $note->created_by = $usersMap[$note->user_id];
523 } else {
524 $note->created_by = __('Fluent Forms Bot', 'fluentform');
525 }
526 } else {
527 $note->pemalink = false;
528 }
529 }
530
531 apply_filters_deprecated(
532 'fluentform_entry_notes',
533 [
534 $notes,
535 $submissionId,
536 $formId
537 ],
538 FLUENTFORM_FRAMEWORK_UPGRADE,
539 'fluentform/entry_notes',
540 'Use fluentform/entry_notes instead of fluentform_entry_notes'
541 );
542
543 $notes = apply_filters('fluentform/entry_notes', $notes, $submissionId, $formId);
544
545 return apply_filters('fluentform/submission_notes', $notes, $submissionId, $formId);
546 }
547
548 public function storeNote($submissionId, $attributes = [])
549 {
550 $formId = intval(Arr::get($attributes, 'form_id'));
551
552 $content = sanitize_textarea_field($attributes['note']['content']);
553 $status = sanitize_text_field($attributes['note']['status']);
554 $user = get_user_by('ID', get_current_user_id());
555 $now = current_time('mysql');
556
557 $note = [
558 'response_id' => $submissionId,
559 'form_id' => $formId,
560 'meta_key' => '_notes',
561 'value' => $content,
562 'status' => $status,
563 'user_id' => $user->ID,
564 'name' => $user->display_name,
565 'created_at' => $now,
566 'updated_at' => $now,
567 ];
568
569 $note = apply_filters_deprecated(
570 'fluentform_add_response_note',
571 [$note],
572 FLUENTFORM_FRAMEWORK_UPGRADE,
573 'fluentform/store_submission_note'
574 );
575
576 $note = apply_filters('fluentform/store_submission_note', $note);
577
578 $submissionMeta = new SubmissionMeta;
579
580 $submissionMeta->fill($note)->save();
581
582 do_action_deprecated(
583 'fluentform_new_response_note_added',
584 [$submissionMeta->id, $submissionMeta],
585 FLUENTFORM_FRAMEWORK_UPGRADE,
586 'fluentform/submission_note_stored'
587 );
588
589 do_action('fluentform/submission_note_stored', $submissionMeta->id, $submissionMeta);
590
591 return [
592 'message' => __('Note has been successfully added', 'fluentform'),
593 'note' => $submissionMeta,
594 'insert_id' => $submissionMeta->id,
595 ];
596 }
597
598 public function updateSubmissionUser($userId, $submissionId)
599 {
600 if (!$userId || !$submissionId) {
601 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception message, not output
602 throw new Exception(__('Submission ID and User ID is required', 'fluentform'));
603 }
604
605 $submission = Submission::find($submissionId);
606 $user = get_user_by('ID', $userId);
607
608 if (!$submission || $submission->user_id == $userId || !$user) {
609 // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Exception message, not output
610 throw new Exception(__('Invalid Request', 'fluentform'));
611 }
612
613 Submission::where('id', $submission->id)
614 ->update([
615 'user_id' => $userId,
616 'updated_at' => current_time('mysql'),
617 ]);
618
619 if (defined('FLUENTFORMPRO')) {
620 // let's update the corresponding user IDs for transactions
621 \FluentForm\App\Models\Transaction::where('submission_id', $submission->id)
622 ->update([
623 'user_id' => $userId,
624 'updated_at' => current_time('mysql'),
625 ]);
626 }
627
628 do_action('fluentform/log_data', [
629 'parent_source_id' => $submission->form_id,
630 'source_type' => 'submission_item',
631 'source_id' => $submission->id,
632 'component' => 'General',
633 'status' => 'info',
634 'title' => 'Associate user has been changed from ' . $submission->user_id . ' to ' . $userId,
635 ]);
636
637 do_action_deprecated(
638 'fluentform_submission_user_changed',
639 [
640 $submission,
641 $user
642 ],
643 FLUENTFORM_FRAMEWORK_UPGRADE,
644 'fluentform/submission_user_changed',
645 'Use fluentform/submission_user_changed instead of fluentform_submission_user_changed.'
646 );
647
648 do_action('fluentform/submission_user_changed', $submission, $user);
649
650 return ([
651 'message' => __('Selected user has been successfully assigned to this submission', 'fluentform'),
652 'user' => [
653 'name' => $user->display_name,
654 'email' => $user->user_email,
655 'ID' => $user->ID,
656 'permalink' => get_edit_user_link($user->ID),
657 ],
658 'user_id' => $userId,
659 ]);
660 }
661
662 public function updateEntryDiffs($entryId, $formId, $formData)
663 {
664 EntryDetails::where('submission_id', $entryId)
665 ->where('form_id', $formId)
666 ->whereIn('field_name', array_keys($formData))
667 ->delete();
668
669 $entryItems = [];
670 foreach ($formData as $dataKey => $dataValue) {
671 if (!$dataValue) {
672 continue;
673 }
674
675 if (is_array($dataValue)) {
676 foreach ($dataValue as $subKey => $subValue) {
677 $entryItems[] = [
678 'form_id' => $formId,
679 'submission_id' => $entryId,
680 'field_name' => $dataKey,
681 'sub_field_name' => $subKey,
682 'field_value' => maybe_serialize($subValue),
683 ];
684 }
685 } else {
686 $entryItems[] = [
687 'form_id' => $formId,
688 'submission_id' => $entryId,
689 'field_name' => $dataKey,
690 'sub_field_name' => '',
691 'field_value' => $dataValue,
692 ];
693 }
694 }
695
696 if ($entryItems) {
697 EntryDetails::insert($entryItems);
698 }
699
700 return true;
701 }
702
703 public function recordEntryDetails($entryId, $formId, $data)
704 {
705 $formData = Arr::except($data, Helper::getWhiteListedFields($formId));
706
707 $entryItems = [];
708 foreach ($formData as $dataKey => $dataValue) {
709 if ($dataValue === '' || $dataValue === null) {
710 continue;
711 }
712
713 if (is_array($dataValue) || is_object($dataValue)) {
714 foreach ($dataValue as $subKey => $subValue) {
715 if (empty($subValue)) {
716 continue;
717 }
718 $entryItems[] = [
719 'form_id' => $formId,
720 'submission_id' => $entryId,
721 'field_name' => trim($dataKey),
722 'sub_field_name' => $subKey,
723 'field_value' => maybe_serialize($subValue),
724 ];
725 }
726 } else {
727 $entryItems[] = [
728 'form_id' => $formId,
729 'submission_id' => $entryId,
730 'field_name' => trim($dataKey),
731 'sub_field_name' => '',
732 'field_value' => $dataValue,
733 ];
734 }
735 }
736
737 if ($entryItems) {
738 EntryDetails::insert($entryItems);
739 }
740
741 return true;
742 }
743
744 public function getPrintContent($attr)
745 {
746 $content = (new SubmissionPrint())->getContent($attr);
747 return array('success' => true, 'content' => $content);
748 }
749
750 private function setEntryUidLink($submission)
751 {
752 $frontEndSettings = Helper::getFormMeta($submission->form_id, 'front_end_entry_view', []);
753 if (Arr::get($frontEndSettings, 'status') === 'yes') {
754 $submission->entry_uid_link = site_url('?ff_entry=1&hash=' . $submission->_entry_uid_hash);
755 }
756 }
757
758 private function enrichWithUser($submission)
759 {
760 if (!$submission->user_id) {
761 return;
762 }
763
764 $user = get_user_by('ID', $submission->user_id);
765 if (!$user) {
766 return;
767 }
768
769 $userDisplayName = trim($user->first_name . ' ' . $user->last_name);
770 if (!$userDisplayName) {
771 $userDisplayName = $user->display_name;
772 }
773
774 $submission->user = [
775 'ID' => $user->ID,
776 'name' => $userDisplayName,
777 'permalink' => get_edit_user_link($user->ID),
778 ];
779 }
780 }
781