+ /**
+ * Get the metadata for fields to be included on the case search form.
+ *
+ * @todo ideally this would be a trait included on the case search & advanced search
+ * rather than a static function.
+ */
+ public static function getSearchFieldMetadata() {
+ $fields = ['case_type_id', 'case_status_id', 'case_start_date', 'case_end_date', 'case_subject', 'case_id', 'case_deleted'];
+ $metadata = civicrm_api3('Case', 'getfields', [])['values'];
+ $metadata = array_intersect_key($metadata, array_flip($fields));
+ $metadata['case_tags'] = [
+ 'title' => ts('Case Tag(s)'),
+ 'type' => CRM_Utils_Type::T_INT,
+ 'is_pseudofield' => TRUE,
+ ];
+ if (CRM_Core_Permission::check('access all cases and activities')) {
+ $metadata['case_owner'] = [
+ 'title' => ts('Cases'),
+ 'type' => CRM_Utils_Type::T_INT,
+ 'is_pseudofield' => TRUE,
+ ];
+ }
+ if (!CRM_Core_Permission::check('administer CiviCase')) {
+ unset($metadata['case_deleted']);
+ }
+ return $metadata;
+ }
+