Skip to content

Commit

Permalink
[SFT-1629]: A way to visualize how many "In Progress" saved form subm…
Browse files Browse the repository at this point in the history
…issions there are (#1705)

feat(SFT-1629): saved submission counters
  • Loading branch information
gustavs-gutmanis authored Jan 13, 2025
1 parent 3f13285 commit 10552f2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/plugin/src/Bundles/Form/Types/Regular/AttachFormLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -86,6 +88,16 @@ function (GenerateLinksEvent $event) {
'linkList',
$spamCount,
);

if ($savedCount) {
$event->add(
$saved,
'saved',
null,
'linkList',
$savedCount,
);
}
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand Down
12 changes: 12 additions & 0 deletions packages/plugin/src/Services/SubmissionsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 10552f2

Please sign in to comment.