From 10552f2251a3591bb3836ed1d79aadd571c08894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavs=20G=C5=ABtmanis?= Date: Mon, 13 Jan 2025 16:57:26 +0200 Subject: [PATCH] [SFT-1629]: A way to visualize how many "In Progress" saved form submissions there are (#1705) feat(SFT-1629): saved submission counters --- .../Bundles/Form/Types/Regular/AttachFormLinks.php | 12 ++++++++++++ .../Transformers/Builder/Form/FormTransformer.php | 2 ++ packages/plugin/src/Services/SubmissionsService.php | 12 ++++++++++++ 3 files changed, 26 insertions(+) diff --git a/packages/plugin/src/Bundles/Form/Types/Regular/AttachFormLinks.php b/packages/plugin/src/Bundles/Form/Types/Regular/AttachFormLinks.php index b9aca954f..139157f34 100644 --- a/packages/plugin/src/Bundles/Form/Types/Regular/AttachFormLinks.php +++ b/packages/plugin/src/Bundles/Form/Types/Regular/AttachFormLinks.php @@ -58,9 +58,11 @@ function (GenerateLinksEvent $event) { $submissionCount = $data->counters['submissions']; $spamCount = $data->counters['spam']; + $savedCount = $data->counters['saved']; $submissions = Freeform::t('{count} Submissions', ['count' => $submissionCount]); $spam = Freeform::t('{count} Spam', ['count' => $spamCount]); + $saved = Freeform::t('{count} Saved', ['count' => $savedCount]); if ($canManageForm) { $event->add( @@ -86,6 +88,16 @@ function (GenerateLinksEvent $event) { 'linkList', $spamCount, ); + + if ($savedCount) { + $event->add( + $saved, + 'saved', + null, + 'linkList', + $savedCount, + ); + } } ); } diff --git a/packages/plugin/src/Bundles/Transformers/Builder/Form/FormTransformer.php b/packages/plugin/src/Bundles/Transformers/Builder/Form/FormTransformer.php index 6258f00b6..eabf3a497 100644 --- a/packages/plugin/src/Bundles/Transformers/Builder/Form/FormTransformer.php +++ b/packages/plugin/src/Bundles/Transformers/Builder/Form/FormTransformer.php @@ -140,12 +140,14 @@ private function decorateWithSubmissionStatistics(array $forms): array $chartData = $this->chartsService->getMinimalSubmissionChartData($formIds); $submissions = $this->submissionsService->getSubmissionCountByForm(); $spamSubmissions = $this->submissionsService->getSubmissionCountByForm(true); + $savedSubmissions = $this->submissionsService->getSavedSubmissionCountByForm(); foreach ($forms as $form) { $form->chartData = $chartData[$form->id] ?? []; $form->counters = [ 'submissions' => $submissions[$form->id] ?? 0, 'spam' => $spamSubmissions[$form->id] ?? 0, + 'saved' => $savedSubmissions[$form->id] ?? 0, ]; } diff --git a/packages/plugin/src/Services/SubmissionsService.php b/packages/plugin/src/Services/SubmissionsService.php index 30ccf861c..dc9771c65 100644 --- a/packages/plugin/src/Services/SubmissionsService.php +++ b/packages/plugin/src/Services/SubmissionsService.php @@ -34,6 +34,7 @@ use Solspace\Freeform\Library\Database\SubmissionHandlerInterface; use Solspace\Freeform\Library\Helpers\PermissionHelper; use Solspace\Freeform\Records\FormRecord; +use Solspace\Freeform\Records\SavedFormRecord; use Twig\Markup; use yii\base\Event; @@ -156,6 +157,17 @@ public function getSubmissionCountByForm(bool $isSpam = false, ?Carbon $rangeSta return $query->column(); } + public function getSavedSubmissionCountByForm(): array + { + return (new Query()) + ->select('COUNT(*)') + ->from(SavedFormRecord::TABLE) + ->groupBy('formId') + ->indexBy('formId') + ->column() + ; + } + public function handleSubmission(Form $form): void { $submission = $form->getSubmission();