Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core/dev#692 : Support search arguments to Case Search form #15370

Merged
merged 1 commit into from
Oct 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions CRM/Case/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,34 @@ public static function tableNames(&$tables) {
}
}

/**
* 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;
}

/**
* Add all the elements shared between case search and advanced search.
*
Expand All @@ -687,8 +715,8 @@ public static function buildSearchForm(&$form) {
$configured = CRM_Case_BAO_Case::isCaseConfigured();
$form->assign('notConfigured', !$configured['configured']);

$form->addField('case_type_id', ['context' => 'search', 'entity' => 'Case']);
$form->addField('case_status_id', ['context' => 'search', 'entity' => 'Case']);
$form->addSearchFieldMetadata(['Case' => self::getSearchFieldMetadata()]);
$form->addFormFieldsFromMetadata();

CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE);
Expand Down Expand Up @@ -719,20 +747,6 @@ public static function buildSearchForm(&$form) {
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_case', NULL, TRUE, FALSE);

if (CRM_Core_Permission::check('administer CiviCase')) {
$form->addElement('checkbox', 'case_deleted', ts('Deleted Cases'));
}

$form->addElement('text',
'case_subject',
ts('Case Subject'),
['class' => 'huge']
);
$form->addElement('text',
'case_id',
ts('Case ID')
);

self::addCustomFormFields($form, ['Case']);

$form->setDefaults(['case_owner' => 1]);
Expand Down
6 changes: 6 additions & 0 deletions CRM/Case/DAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ public static function &fields() {
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
'html' => [
'type' => 'Text',
],
],
'case_type_id' => [
'name' => 'case_type_id',
Expand Down Expand Up @@ -265,6 +268,9 @@ public static function &fields() {
'entity' => 'Case',
'bao' => 'CRM_Case_BAO_Case',
'localizable' => 0,
'html' => [
'type' => 'CheckBox',
],
],
'case_created_date' => [
'name' => 'created_date',
Expand Down
22 changes: 8 additions & 14 deletions CRM/Case/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search {
*/
protected $_prefix = 'case_';

/**
* @return string
*/
public function getDefaultEntity() {
return 'Case';
}

/**
* Processing needed for buildForm and later.
*/
Expand Down Expand Up @@ -204,7 +211,7 @@ public function postProcess() {
}

$this->_done = TRUE;
$this->_formValues = $this->controller->exportValues($this->_name);
$this->setFormValues();
$this->fixFormValues();

if (isset($this->_ssID) && empty($_POST)) {
Expand Down Expand Up @@ -314,19 +321,6 @@ public static function formRule($fields, $files, $form) {
return TRUE;
}

/**
* Set the default form values.
*
*
* @return array
* the default array reference
*/
public function setDefaultValues() {
$defaults = [];
$defaults = $this->_formValues;
return $defaults;
}

public function fixFormValues() {
if (!$this->_force) {
return;
Expand Down
6 changes: 6 additions & 0 deletions xml/schema/Case/Case.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<import>true</import>
<title>Case ID</title>
<comment>Unique Case ID</comment>
<html>
<type>Text</type>
</html>
<add>1.8</add>
</field>
<primaryKey>
Expand Down Expand Up @@ -186,6 +189,9 @@
<default>0</default>
<import>true</import>
<title>Case Deleted</title>
<html>
<type>CheckBox</type>
</html>
<add>2.2</add>
</field>
<index>
Expand Down