// 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']
});
}
}
<i class="crm-i fa-sort-{{ $ctrl.sortDir ? 'asc' : 'desc' }}" ng-if="$ctrl.sortField === 'placement.length'"></i>
{{:: ts('Placement') }}
</th>
+ <th ng-if="$ctrl.tab === 'form'" title="{{:: ts('Click to sort') }}" ng-click="$ctrl.sortBy('submit_currently_open')">
+ <i class="crm-i fa-sort disabled" ng-if="$ctrl.sortField !== 'submit_currently_open'"></i>
+ <i class="crm-i fa-sort-{{ $ctrl.sortDir ? 'asc' : 'desc' }}" ng-if="$ctrl.sortField === 'submit_currently_open'"></i>
+ {{:: ts('Status') }}
+ </th>
<th ng-if="$ctrl.tab === 'form'" title="{{:: ts('Click to sort') }}" ng-click="$ctrl.sortBy('submission_count')">
<i class="crm-i fa-sort disabled" ng-if="$ctrl.sortField !== 'submission_count'"></i>
<i class="crm-i fa-sort-{{ $ctrl.sortDir ? 'asc' : 'desc' }}" ng-if="$ctrl.sortField === 'submission_count'"></i>
</a>
</td>
<td>{{:: afform.placement.join(', ') }}</td>
+ <td ng-if="$ctrl.tab === 'form'">
+ {{:: afform.submit_currently_open ? ts('Open') : ts('Closed') }}
+ <span ng-if="afform.submit_limit && afform.submit_enabled">
+ ({{:: ts('%1 remaining', {1: afform.submit_limit - afform.submission_count}) }})
+ </span>
+ </td>
<td ng-if="$ctrl.tab === 'form'">
<a ng-if="afform.submission_count" ng-href="{{:: crmUrl('civicrm/admin/afform/submissions#/?name=' + afform.name) }}">
{{:: afform.submission_count === 1 ? ts('1 Submission') : ts('%1 Submissions', {1: afform.submission_count}) }}
}
// 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))
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']);
}
}
'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',