Unverified Commit 7dd2478a authored by eileen's avatar eileen 🎱 Committed by GitHub

Merge pull request #11600 from mattwire/CRM-21720_core_task_search_classes

CRM-21720 Cleanup search classes to use enumerators instead of hardcoded values
parents f2774867 eda34f9b
......@@ -56,7 +56,8 @@ class CRM_Contact_BAO_Query {
// There is no 4,
MODE_MEMBER = 8,
MODE_EVENT = 16,
// No 32, no 64.
MODE_CONTACTSRELATED = 32,
// no 64.
MODE_GRANT = 128,
MODE_PLEDGEBANK = 256,
MODE_PLEDGE = 512,
......@@ -67,6 +68,13 @@ class CRM_Contact_BAO_Query {
MODE_MAILING = 16384,
MODE_ALL = 17407;
/**
* Constants for search operators
*/
const
SEARCH_OPERATOR_AND = 'AND',
SEARCH_OPERATOR_OR = 'OR';
/**
* The default set of return properties.
*
......
This diff is collapsed.
......@@ -206,7 +206,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
$this->normalizeDefaultValues($defaults);
if ($this->_context === 'amtg') {
$defaults['task'] = CRM_Contact_Task::GROUP_CONTACTS;
$defaults['task'] = CRM_Contact_Task::GROUP_ADD;
}
return $defaults;
......
......@@ -111,7 +111,7 @@ class CRM_Contact_Form_Search_Basic extends CRM_Contact_Form_Search {
}
if ($this->_context === 'amtg') {
$defaults['task'] = CRM_Contact_Task::GROUP_CONTACTS;
$defaults['task'] = CRM_Contact_Task::GROUP_ADD;
}
if ($this->_context === 'smog') {
......
......@@ -158,32 +158,6 @@ class CRM_Contact_Form_Search_Criteria {
);
$componentModes = CRM_Contact_Form_Search::getModeSelect();
$enabledComponents = CRM_Core_Component::getEnabledComponents();
// unset disabled components that must should have been enabled
// to the option be viable
if (!array_key_exists('CiviMail', $enabledComponents)) {
unset($componentModes['8']);
}
// unset contributions or participants if user does not have
// permission on them
if (!CRM_Core_Permission::access('CiviContribute')) {
unset($componentModes['2']);
}
if (!CRM_Core_Permission::access('CiviEvent')) {
unset($componentModes['3']);
}
if (!CRM_Core_Permission::access('CiviMember')) {
unset($componentModes['5']);
}
if (!CRM_Core_Permission::check('view all activities')) {
unset($componentModes['4']);
}
if (count($componentModes) > 1) {
$form->add('select',
'component_mode',
......@@ -198,8 +172,8 @@ class CRM_Contact_Form_Search_Criteria {
'operator',
ts('Search Operator'),
array(
'AND' => ts('AND'),
'OR' => ts('OR'),
CRM_Contact_BAO_Query::SEARCH_OPERATOR_AND => ts('AND'),
CRM_Contact_BAO_Query::SEARCH_OPERATOR_OR => ts('OR'),
),
array('allowClear' => FALSE)
);
......
......@@ -66,9 +66,12 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task {
$values = $this->controller->exportValues('Basic');
}
// Get Task name
$modeValue = CRM_Contact_Form_Search::getModeValue($values['component_mode']);
$className = $modeValue['taskClassName'];
$taskList = $className::taskTitles();
$this->_task = CRM_Utils_Array::value('task', $values);
$crmContactTaskTasks = CRM_Contact_Task::taskTitles();
$this->assign('taskName', CRM_Utils_Array::value($this->_task, $crmContactTaskTasks));
$this->assign('taskName', CRM_Utils_Array::value($this->_task, $taskList));
}
/**
......@@ -208,12 +211,9 @@ class CRM_Contact_Form_Task_SaveSearch extends CRM_Contact_Form_Task {
$params = array();
$params['title'] = $formValues['title'];
$params['description'] = $formValues['description'];
if (isset($formValues['group_type']) &&
is_array($formValues['group_type'])
) {
if (isset($formValues['group_type']) && is_array($formValues['group_type']) && count($formValues['group_type'])) {
$params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
array_keys($formValues['group_type'])
) . CRM_Core_DAO::VALUE_SEPARATOR;
array_keys($formValues['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR;
}
else {
$params['group_type'] = '';
......
......@@ -103,15 +103,10 @@ class CRM_Contact_StateMachine_Search extends CRM_Core_StateMachine {
}
$this->_controller->set('task', $value);
if ($value) {
$componentMode = $this->_controller->get('component_mode');
$modeValue = CRM_Contact_Form_Search::getModeValue($componentMode);
$taskClassName = $modeValue['taskClassName'];
return $taskClassName::getTask($value);
}
else {
return CRM_Contact_Task::getTask($value);
}
$componentMode = $this->_controller->get('component_mode');
$modeValue = CRM_Contact_Form_Search::getModeValue($componentMode);
$taskClassName = $modeValue['taskClassName'];
return $taskClassName::getTask($value);
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment