From: Coleman Watts Date: Sun, 17 Feb 2019 19:20:09 +0000 (-0500) Subject: Move entityRef filters into their respective BAOs X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=1d6f94ab4500e31538daac9aaccfb56171d4acad;p=civicrm-core.git Move entityRef filters into their respective BAOs --- diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index e4bee42129..090ef3b103 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -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')], + ]; + } + } diff --git a/CRM/Campaign/BAO/Campaign.php b/CRM/Campaign/BAO/Campaign.php index aad66fc160..3113591884 100644 --- a/CRM/Campaign/BAO/Campaign.php +++ b/CRM/Campaign/BAO/Campaign.php @@ -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 * diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 9237e00d3e..18549754e0 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -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; + } + } diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index f0cea76bcc..b72f1b409a 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -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'], + ]; + } + } diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 3f0d19b886..eb24e0ed28 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -2810,6 +2810,13 @@ SELECT contact_id } } + /** + * @return array + */ + public static function getEntityRefFilters() { + return []; + } + /** * Get exportable fields with pseudoconstants rendered as an extra field. * diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index 412731d34a..17786d3f0d 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -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); diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 68216a7e5f..755847c056 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -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'), + ], + ], + ], + ]; + } + }