diff --git a/lib/Db/SubmissionMapper.php b/lib/Db/SubmissionMapper.php
index abb80d97f..6116ca5b1 100644
--- a/lib/Db/SubmissionMapper.php
+++ b/lib/Db/SubmissionMapper.php
@@ -106,6 +106,23 @@ public function findParticipantsByForm(int $formId): array {
return $userIds;
}
+ /**
+ * @throws DBException
+ */
+ public function countSubmissions(int $formId): int {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select($qb->func()->count('*', 'num_submissions'))
+ ->from($this->getTableName())
+ ->where($qb->expr()->eq('form_id', $qb->createNamedParameter($formId, IQueryBuilder::PARAM_INT)));
+
+ $result = $qb->executeQuery();
+ $row = $result->fetch();
+ $result->closeCursor();
+
+ return (int) ($row['num_submissions' ?? 0]);
+ }
+
/**
* Delete the Submission, including answers.
* @param int $id of the submission to delete
diff --git a/lib/Service/FormsService.php b/lib/Service/FormsService.php
index 08d63d764..35b99be9e 100644
--- a/lib/Service/FormsService.php
+++ b/lib/Service/FormsService.php
@@ -186,6 +186,11 @@ public function getForm(int $id): array {
// Append canSubmit, to be able to show proper EmptyContent on internal view.
$result['canSubmit'] = $this->canSubmit($form->getId());
+ // Append submissionCount if currentUser is owner
+ if ($this->currentUser && $form->getOwnerId() === $this->currentUser->getUID()) {
+ $result['submissionCount'] = $this->submissionMapper->countSubmissions($id);
+ }
+
return $result;
}
@@ -199,7 +204,7 @@ public function getForm(int $id): array {
public function getPartialFormArray(int $id): array {
$form = $this->formMapper->findById($id);
- return [
+ $result = [
'id' => $form->getId(),
'hash' => $form->getHash(),
'title' => $form->getTitle(),
@@ -207,6 +212,13 @@ public function getPartialFormArray(int $id): array {
'permissions' => $this->getPermissions($form->getId()),
'partial' => true
];
+
+ // Append submissionCount if currentUser is owner
+ if ($this->currentUser && $form->getOwnerId() === $this->currentUser->getUID()) {
+ $result['submissionCount'] = $this->submissionMapper->countSubmissions($id);
+ }
+
+ return $result;
}
/**
diff --git a/src/components/AppNavigationForm.vue b/src/components/AppNavigationForm.vue
index 749d7c17b..4e2d08e6a 100644
--- a/src/components/AppNavigationForm.vue
+++ b/src/components/AppNavigationForm.vue
@@ -21,14 +21,22 @@
-->
-
+
+
+
+
+ {{ formSubtitle }}
+
{{ t('forms', 'Share form') }}
@@ -48,7 +56,7 @@
{{ t('forms', 'Delete form') }}
-
+
+
+
diff --git a/tests/Unit/Service/FormsServiceTest.php b/tests/Unit/Service/FormsServiceTest.php
index 457773ed8..d0963285c 100644
--- a/tests/Unit/Service/FormsServiceTest.php
+++ b/tests/Unit/Service/FormsServiceTest.php
@@ -130,7 +130,7 @@ public function dataGetForm() {
'hash' => 'abcdefg',
'title' => 'Form 1',
'description' => 'Description Text',
- 'ownerId' => 'someUser',
+ 'ownerId' => 'currentUser',
'created' => 123456789,
'access' => [
'permitAllUsers' => false,
@@ -140,6 +140,7 @@ public function dataGetForm() {
'isAnonymous' => false,
'submitMultiple' => true,
'canSubmit' => true,
+ 'submissionCount' => 123,
'questions' => [
[
'id' => 1,
@@ -178,11 +179,13 @@ public function dataGetForm() {
'id' => 1,
'formId' => 42,
'shareType' => 0,
- 'shareWith' => 'currentUser',
- 'displayName' => 'Current User'
+ 'shareWith' => 'someUser',
+ 'displayName' => 'Some User'
]
],
'permissions' => [
+ 'edit',
+ 'results',
'submit'
]
]]
@@ -201,7 +204,7 @@ public function testGetForm(array $expected) {
$form->setHash('abcdefg');
$form->setTitle('Form 1');
$form->setDescription('Description Text');
- $form->setOwnerId('someUser');
+ $form->setOwnerId('currentUser');
$form->setCreated(123456789);
$form->setAccess([
'permitAllUsers' => false,
@@ -220,10 +223,10 @@ public function testGetForm(array $expected) {
$user = $this->createMock(IUser::class);
$user->expects($this->once())
->method('getDisplayName')
- ->willReturn('Current User');
+ ->willReturn('Some User');
$this->userManager->expects($this->once())
->method('get')
- ->with('currentUser')
+ ->with('someUser')
->willReturn($user);
// Questions
@@ -266,13 +269,18 @@ public function testGetForm(array $expected) {
$share->setId(1);
$share->setFormId(42);
$share->setShareType(0);
- $share->setShareWith('currentUser');
+ $share->setShareWith('someUser');
- $this->shareMapper->expects($this->exactly(3))
+ $this->shareMapper->expects($this->any())
->method('findByForm')
->with(42)
->willReturn([$share]);
+ $this->submissionMapper->expects($this->once())
+ ->method('countSubmissions')
+ ->with(42)
+ ->willReturn(123);
+
// Run the test
$this->assertEquals($expected, $this->formsService->getForm(42));
}
@@ -285,6 +293,7 @@ public function dataGetPartialForm() {
'title' => 'Form 1',
'expires' => 0,
'permissions' => ['edit', 'results', 'submit'],
+ 'submissionCount' => 123,
'partial' => true
]]
];
@@ -307,6 +316,11 @@ public function testGetPartialForm(array $expected) {
->with(42)
->willReturn($form);
+ $this->submissionMapper->expects($this->once())
+ ->method('countSubmissions')
+ ->with(42)
+ ->willReturn(123);
+
// Run the test
$this->assertEquals($expected, $this->formsService->getPartialFormArray(42));
}