From 37edd450d93e93cb389682072cb32bdd03626106 Mon Sep 17 00:00:00 2001 From: puresyntax71 <34715246+puresyntax71@users.noreply.github.com> Date: Thu, 26 Mar 2020 23:22:45 +0800 Subject: [PATCH] Add initial support for handling special cases for properties in views. --- civicrm_entity.views.inc | 12 ++++ config/schema/civicrm_entity.views.schema.yml | 33 ++++++++++ ...tityCivicrmActivityContactRecordFilter.php | 66 +++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 config/schema/civicrm_entity.views.schema.yml create mode 100644 src/Plugin/views/filter/CivicrmEntityCivicrmActivityContactRecordFilter.php diff --git a/civicrm_entity.views.inc b/civicrm_entity.views.inc index 0ad2ba43..a4785933 100644 --- a/civicrm_entity.views.inc +++ b/civicrm_entity.views.inc @@ -60,6 +60,18 @@ function civicrm_entity_views_data_alter(&$data) { } // End: views_views_data_alter() snippet. // @codingStandardsIgnoreEnd + + $data['civicrm_activity']['source_contact_id']['filter'] = [ + 'id' => 'civicrm_entity_civicrm_activity_contact_record_filter', + ]; + + $data['civicrm_activity']['assignee_id']['filter'] = [ + 'id' => 'civicrm_entity_civicrm_activity_contact_record_filter', + ]; + + $data['civicrm_activity']['target_id']['filter'] = [ + 'id' => 'civicrm_entity_civicrm_activity_contact_record_filter', + ]; } /** diff --git a/config/schema/civicrm_entity.views.schema.yml b/config/schema/civicrm_entity.views.schema.yml new file mode 100644 index 00000000..7cd61dea --- /dev/null +++ b/config/schema/civicrm_entity.views.schema.yml @@ -0,0 +1,33 @@ +# Schema for the civicrm_entity filter plugins. + +views.filter.civicrm_entity_civicrm_activity_contact_record_filter: + type: views_filter + label: 'Numeric' + mapping: + expose: + type: mapping + label: 'Exposed' + mapping: + min_placeholder: + type: label + label: 'Min placeholder' + max_placeholder: + type: label + label: 'Max placeholder' + placeholder: + type: label + label: 'Placeholder' + +views.filter_value.civicrm_entity_civicrm_activity_contact_record_filter: + type: mapping + label: 'Numeric' + mapping: + min: + type: string + label: 'Min' + max: + type: string + label: 'And max' + value: + type: string + label: 'Value' diff --git a/src/Plugin/views/filter/CivicrmEntityCivicrmActivityContactRecordFilter.php b/src/Plugin/views/filter/CivicrmEntityCivicrmActivityContactRecordFilter.php new file mode 100644 index 00000000..1af927dc --- /dev/null +++ b/src/Plugin/views/filter/CivicrmEntityCivicrmActivityContactRecordFilter.php @@ -0,0 +1,66 @@ + 1, + * 'option_group_id' => 'activity_contacts', + * ]); + * @endcode + */ + const RECORD_TYPE_MAPPING = [ + 'assignee_id' => 1, + 'source_contact_id' => 2, + 'target_id' => 3, + ]; + + /** + * {@inheritdoc} + */ + public function query() { + $this->ensureMyTable(); + + $civicrm_activity_contact_table = 'civicrm_activity_contact'; + + $configuration = [ + 'table' => $civicrm_activity_contact_table, + 'field' => 'activity_id', + 'left_table' => $this->tableAlias, + 'left_field' => 'id', + 'operator' => '=', + ]; + + $join = Views::pluginManager('join')->createInstance('standard', $configuration); + + $civicrm_activity_contact_table_alias = $this->query->addRelationship($civicrm_activity_contact_table, $join, $this->tableAlias); + + $field = "$civicrm_activity_contact_table_alias.contact_id"; + $info = $this + ->operators(); + if (!empty($info[$this->operator]['method']) && self::RECORD_TYPE_MAPPING[$this->realField]) { + $condition = new Condition('AND'); + $condition->condition($field, $this->value['value'], $this->operator); + $condition->condition("$civicrm_activity_contact_table_alias.record_type_id", self::RECORD_TYPE_MAPPING[$this->realField]); + + $this->query->addWhere($this->options['group'], $condition); + } + } + +}