From: colemanw Date: Thu, 31 Aug 2023 00:57:21 +0000 (-0400) Subject: Afform - Add submit_currently_open calc field X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9cd8914523f2b866baaeddbb8683ea06756b2147;p=civicrm-core.git Afform - Add submit_currently_open calc field --- diff --git a/ext/afform/admin/ang/afAdmin.js b/ext/afform/admin/ang/afAdmin.js index 758d85d7fa..8d45473732 100644 --- a/ext/afform/admin/ang/afAdmin.js +++ b/ext/afform/admin/ang/afAdmin.js @@ -11,7 +11,7 @@ // Load data for lists afforms: function(crmApi4) { return crmApi4('Afform', 'get', { - select: ['name', 'title', 'type', 'server_route', 'is_public', 'submission_count', 'submission_date', 'has_local', 'has_base', 'base_module', 'base_module:label', 'is_dashlet', 'contact_summary:label'] + select: ['name', 'title', 'type', 'server_route', 'is_public', 'submission_count', 'submission_date', 'submit_limit', 'submit_enabled', 'submit_currently_open', 'has_local', 'has_base', 'base_module', 'base_module:label', 'is_dashlet', 'contact_summary:label'] }); } } diff --git a/ext/afform/admin/ang/afAdmin/afAdminList.html b/ext/afform/admin/ang/afAdmin/afAdminList.html index a4f20e2cf3..a15be805b4 100644 --- a/ext/afform/admin/ang/afAdmin/afAdminList.html +++ b/ext/afform/admin/ang/afAdmin/afAdminList.html @@ -60,6 +60,11 @@ {{:: ts('Placement') }} + + + + {{:: ts('Status') }} + @@ -86,6 +91,12 @@ {{:: afform.placement.join(', ') }} + + {{:: afform.submit_currently_open ? ts('Open') : ts('Closed') }} + + ({{:: ts('%1 remaining', {1: afform.submit_limit - afform.submission_count}) }}) + + {{:: afform.submission_count === 1 ? ts('1 Submission') : ts('%1 Submissions', {1: afform.submission_count}) }} diff --git a/ext/afform/core/Civi/Api4/Action/Afform/Get.php b/ext/afform/core/Civi/Api4/Action/Afform/Get.php index 9e0e5d448a..6ee8487073 100644 --- a/ext/afform/core/Civi/Api4/Action/Afform/Get.php +++ b/ext/afform/core/Civi/Api4/Action/Afform/Get.php @@ -100,7 +100,7 @@ class Get extends \Civi\Api4\Generic\BasicGetAction { } // Fetch submission aggregates in bulk - if ($afforms && $this->_isFieldSelected('submission_count', 'submission_date')) { + if ($afforms && $this->_isFieldSelected('submission_count', 'submission_date', 'submit_currently_open')) { $afformSubmissions = \Civi\Api4\AfformSubmission::get(FALSE) ->addSelect('afform_name', 'COUNT(id) AS count', 'MAX(submission_date) AS date') ->addWhere('afform_name', 'IN', array_keys($afforms)) @@ -109,6 +109,7 @@ class Get extends \Civi\Api4\Generic\BasicGetAction { foreach ($afforms as $name => $record) { $afforms[$name]['submission_count'] = $afformSubmissions[$name]['count'] ?? 0; $afforms[$name]['submission_date'] = $afformSubmissions[$name]['date'] ?? NULL; + $afforms[$name]['submit_currently_open'] = ($record['submit_enabled'] ?? TRUE) && (empty($record['submit_limit']) || $record['submit_limit'] > $afforms[$name]['submission_count']); } } diff --git a/ext/afform/core/Civi/Api4/Afform.php b/ext/afform/core/Civi/Api4/Afform.php index 9afadc5e10..f21cb4b5e6 100644 --- a/ext/afform/core/Civi/Api4/Afform.php +++ b/ext/afform/core/Civi/Api4/Afform.php @@ -277,6 +277,14 @@ class Afform extends Generic\AbstractEntity { 'description' => 'Date & time of last form submission', 'readonly' => TRUE, ]; + $fields[] = [ + 'name' => 'submit_currently_open', + 'type' => 'Extra', + 'data_type' => 'Boolean', + 'input_type' => 'Select', + 'description' => 'Based on settings and current submission count, is the form open for submissions', + 'readonly' => TRUE, + ]; $fields[] = [ 'name' => 'has_local', 'type' => 'Extra',