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

Add a Views Relationship handler for relating a Contact to their Contributions. #550

Open
wants to merge 1 commit into
base: 7.x-master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions civicrm.info
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ files[] = modules/views/civicrm/views_handler_argument_civicrm_year_month.inc
files[] = modules/views/civicrm/civicrm_handler_relationship.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_relationship.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_contact2users.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_contacts_contributions.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_memberships_contributions.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_location.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_mail.inc
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Field handler to provide relationship between contacts and contributions
*
* @ingroup civicrm_field_handlers
*/
class civicrm_handler_relationship_contacts_contributions extends views_handler_relationship {

/**
* Called to implement a relationship in a query.
*/
public function query() {
$join_type = empty($this->options['required']) ? 'LEFT' : 'INNER';
$this->ensure_my_table();
$join = new views_join();
$join->definition = array(
'table' => 'civicrm_contribution',
'field' => 'contact_id',
'left_table' => $this->table_alias,
'left_field' => 'id',
'type' => $join_type,
);
$join->construct();
$join->adjusted = TRUE;
$alias = $join->definition['table'] . '_' . $join->definition['left_table'];
$this->alias = $this->query->add_relationship($alias, $join, 'civicrm_contribution', $this->relationship);
}

}
14 changes: 14 additions & 0 deletions modules/views/components/civicrm.core.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,20 @@ function _civicrm_core_data(&$data, $enabled) {
),
);

// Link to Contribution table
if (isset($enabled['CiviContribute'])) {
$data['civicrm_contact']['contribution_id'] = array(
'title' => t('Contribution Records'),
'help' => 'Contributions records for this Contact',
'relationship' => array(
'base' => 'civicrm_contribution',
'base field' => 'id',
'handler' => 'civicrm_handler_relationship_contacts_contributions',
'label' => t('Contact -> Contribution'),
),
);
}

//----------------------------------------------------------------
// CIVICRM Relationships are here with all the connections, base tabling it up.
//----------------------------------------------------------------
Expand Down