Skip to content

Commit

Permalink
accept array of case_type_ids when finding available case statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
ufundo committed Mar 7, 2024
1 parent 8ebeaf9 commit cc13cf6
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -2995,11 +2995,28 @@ public static function buildOptions($fieldName, $context = NULL, $props = []) {

// Filter status id by case type id
case 'status_id':
if (!empty($props['case_type_id']) && is_scalar($props['case_type_id'])) {
$idField = is_numeric($props['case_type_id']) ? 'id' : 'name';
$caseType = civicrm_api3('CaseType', 'getsingle', [$idField => $props['case_type_id'], 'return' => 'definition']);
if (!empty($caseType['definition']['statuses'])) {
$params['condition'] = 'v.name IN ("' . implode('","', $caseType['definition']['statuses']) . '")';
if (!empty($props['case_type_id'])) {
// cast single values to a single value array
$caseTypeIdValues = is_array($props['case_type_id']) ? $props['case_type_id'] : [$props['case_type_id']];

$idField = is_numeric($caseTypeIdValues[0]) ? 'id' : 'name';
$caseTypeDefs = (array) \Civi\Api4\CaseType::get(TRUE)
->addSelect('definition')
->addWhere($idField, 'IN', $caseTypeIdValues)
->execute()->column('definition');

$allowAll = FALSE;
$statuses = [];
foreach ($caseTypeDefs as $definition) {
if (empty($definition['statuses'])) {
// if any case type has no status restrictions, we want to allow all options
$allowAll = TRUE;
break;
}
$statuses = array_unique(array_merge($statuses, $definition['statuses']));
}
if (!$allowAll) {
$params['condition'] = 'v.name IN ("' . implode('","', $statuses) . '")';
}
}
break;
Expand Down

0 comments on commit cc13cf6

Please sign in to comment.