Commit 1d6f94ab authored by colemanw's avatar colemanw

Move entityRef filters into their respective BAOs

parent 54048b41
......@@ -3228,4 +3228,14 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name =
return FALSE;
}
/**
* @return array
*/
public static function getEntityRefFilters() {
return [
['key' => 'activity_type_id', 'value' => ts('Activity Type')],
['key' => 'status_id', 'value' => ts('Activity Status')],
];
}
}
......@@ -665,6 +665,44 @@ INNER JOIN civicrm_group grp ON ( grp.id = campgrp.entity_id )
$form->assign('campaignInfo', $campaignInfo);
}
/**
* @return array
*/
public static function getEntityRefFilters() {
return [
['key' => 'campaign_type_id', 'value' => ts('Campaign Type')],
['key' => 'status_id', 'value' => ts('Status')],
[
'key' => 'start_date',
'value' => ts('Start Date'),
'options' => [
['key' => '{">":"now"}', 'value' => ts('Upcoming')],
[
'key' => '{"BETWEEN":["now - 3 month","now"]}',
'value' => ts('Past 3 Months'),
],
[
'key' => '{"BETWEEN":["now - 6 month","now"]}',
'value' => ts('Past 6 Months'),
],
[
'key' => '{"BETWEEN":["now - 1 year","now"]}',
'value' => ts('Past Year'),
],
],
],
[
'key' => 'end_date',
'value' => ts('End Date'),
'options' => [
['key' => '{">":"now"}', 'value' => ts('In the future')],
['key' => '{"<":"now"}', 'value' => ts('In the past')],
['key' => '{"IS NULL":"1"}', 'value' => ts('Not set')],
],
],
];
}
/**
* Links to create new campaigns from entityRef widget
*
......
......@@ -3261,4 +3261,28 @@ WHERE id IN (' . implode(',', $copiedActivityIds) . ')';
return "$name <$address>";
}
/**
* @return array
*/
public static function getEntityRefFilters() {
$filters = [
[
'key' => 'case_id.case_type_id',
'value' => ts('Case Type'),
'entity' => 'Case',
],
[
'key' => 'case_id.status_id',
'value' => ts('Case Status'),
'entity' => 'Case',
],
];
foreach (CRM_Contact_BAO_Contact::getEntityRefFilters() as $filter) {
$filter += ['entity' => 'contact'];
$filter['key'] = 'contact_id.' . $filter['key'];
$filters[] = $filter;
}
return $filters;
}
}
......@@ -3660,4 +3660,22 @@ LEFT JOIN civicrm_address ON ( civicrm_address.contact_id = civicrm_contact.id )
return CRM_Core_Permission::check([['profile create', 'profile listings and forms']]);
}
/**
* @return array
*/
public static function getEntityRefFilters() {
return [
['key' => 'contact_type', 'value' => ts('Contact Type')],
['key' => 'group', 'value' => ts('Group'), 'entity' => 'group_contact'],
['key' => 'tag', 'value' => ts('Tag'), 'entity' => 'entity_tag'],
['key' => 'state_province', 'value' => ts('State/Province'), 'entity' => 'address'],
['key' => 'country', 'value' => ts('Country'), 'entity' => 'address'],
['key' => 'gender_id', 'value' => ts('Gender'), 'condition' => ['contact_type' => 'Individual']],
['key' => 'is_deceased', 'value' => ts('Deceased'), 'condition' => ['contact_type' => 'Individual']],
['key' => 'contact_id', 'value' => ts('Contact ID'), 'type' => 'text'],
['key' => 'external_identifier', 'value' => ts('External ID'), 'type' => 'text'],
['key' => 'source', 'value' => ts('Contact Source'), 'type' => 'text'],
];
}
}
......@@ -2810,6 +2810,13 @@ SELECT contact_id
}
}
/**
* @return array
*/
public static function getEntityRefFilters() {
return [];
}
/**
* Get exportable fields with pseudoconstants rendered as an extra field.
*
......
......@@ -804,7 +804,6 @@ class CRM_Core_Resources {
/**
* Provide a list of available entityRef filters.
* @todo: move component filters into their respective components (e.g. CiviEvent)
*
* @return array
*/
......@@ -812,102 +811,28 @@ class CRM_Core_Resources {
$filters = array();
$config = CRM_Core_Config::singleton();
if (in_array('CiviEvent', $config->enableComponents)) {
$filters['event'] = array(
array('key' => 'event_type_id', 'value' => ts('Event Type')),
array(
'key' => 'start_date',
'value' => ts('Start Date'),
'options' => array(
array('key' => '{">":"now"}', 'value' => ts('Upcoming')),
array(
'key' => '{"BETWEEN":["now - 3 month","now"]}',
'value' => ts('Past 3 Months'),
),
array(
'key' => '{"BETWEEN":["now - 6 month","now"]}',
'value' => ts('Past 6 Months'),
),
array(
'key' => '{"BETWEEN":["now - 1 year","now"]}',
'value' => ts('Past Year'),
),
),
),
);
}
$filters['activity'] = array(
array('key' => 'activity_type_id', 'value' => ts('Activity Type')),
array('key' => 'status_id', 'value' => ts('Activity Status')),
);
$filters['contact'] = [
['key' => 'contact_type', 'value' => ts('Contact Type')],
['key' => 'group', 'value' => ts('Group'), 'entity' => 'group_contact'],
['key' => 'tag', 'value' => ts('Tag'), 'entity' => 'entity_tag'],
['key' => 'state_province', 'value' => ts('State/Province'), 'entity' => 'address'],
['key' => 'country', 'value' => ts('Country'), 'entity' => 'address'],
['key' => 'gender_id', 'value' => ts('Gender'), 'condition' => ['contact_type' => 'Individual']],
['key' => 'is_deceased', 'value' => ts('Deceased'), 'condition' => ['contact_type' => 'Individual']],
['key' => 'contact_id', 'value' => ts('Contact ID'), 'type' => 'text'],
['key' => 'external_identifier', 'value' => ts('External ID'), 'type' => 'text'],
['key' => 'source', 'value' => ts('Contact Source'), 'type' => 'text'],
];
if (in_array('CiviCase', $config->enableComponents)) {
$filters['case'] = array(
array(
'key' => 'case_id.case_type_id',
'value' => ts('Case Type'),
'entity' => 'Case',
),
array(
'key' => 'case_id.status_id',
'value' => ts('Case Status'),
'entity' => 'Case',
),
);
foreach ($filters['contact'] as $filter) {
$filter += array('entity' => 'contact');
$filter['key'] = 'contact_id.' . $filter['key'];
$filters['case'][] = $filter;
$disabledComponents = [];
$dao = CRM_Core_DAO::executeQuery("SELECT name, namespace FROM civicrm_component");
while ($dao->fetch()) {
if (!in_array($dao->name, $config->enableComponents)) {
$disabledComponents[$dao->name] = $dao->namespace;
}
}
if (in_array('CiviCampaign', $config->enableComponents)) {
$filters['campaign'] = [
['key' => 'campaign_type_id', 'value' => ts('Campaign Type')],
['key' => 'status_id', 'value' => ts('Status')],
[
'key' => 'start_date',
'value' => ts('Start Date'),
'options' => [
['key' => '{">":"now"}', 'value' => ts('Upcoming')],
[
'key' => '{"BETWEEN":["now - 3 month","now"]}',
'value' => ts('Past 3 Months'),
],
[
'key' => '{"BETWEEN":["now - 6 month","now"]}',
'value' => ts('Past 6 Months'),
],
[
'key' => '{"BETWEEN":["now - 1 year","now"]}',
'value' => ts('Past Year'),
],
],
],
[
'key' => 'end_date',
'value' => ts('End Date'),
'options' => [
['key' => '{">":"now"}', 'value' => ts('In the future')],
['key' => '{"<":"now"}', 'value' => ts('In the past')],
['key' => '{"IS NULL":"1"}', 'value' => ts('Not set')],
],
],
];
foreach (CRM_Core_DAO_AllCoreTables::daoToClass() as $entity => $daoName) {
// Skip DAOs of disabled components
foreach ($disabledComponents as $nameSpace) {
if (strpos($daoName, $nameSpace) === 0) {
continue 2;
}
}
$baoName = str_replace('_DAO_', '_BAO_', $daoName);
if (class_exists($baoName)) {
$entityFilters = $baoName::getEntityRefFilters();
if ($entityFilters) {
$filters[_civicrm_api_get_entity_name_from_camel($entity)] = $entityFilters;
}
}
}
CRM_Utils_Hook::entityRefFilters($filters);
......
......@@ -2370,4 +2370,32 @@ LEFT JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field
return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
}
/**
* @return array
*/
public static function getEntityRefFilters() {
return [
['key' => 'event_type_id', 'value' => ts('Event Type')],
[
'key' => 'start_date',
'value' => ts('Start Date'),
'options' => [
['key' => '{">":"now"}', 'value' => ts('Upcoming')],
[
'key' => '{"BETWEEN":["now - 3 month","now"]}',
'value' => ts('Past 3 Months'),
],
[
'key' => '{"BETWEEN":["now - 6 month","now"]}',
'value' => ts('Past 6 Months'),
],
[
'key' => '{"BETWEEN":["now - 1 year","now"]}',
'value' => ts('Past Year'),
],
],
],
];
}
}
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