Skip to content

Commit

Permalink
Drupal Views CiviCRM: Allow Participant record to be used from Event.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnFF committed Aug 5, 2018
1 parent a6a3276 commit d2fee9b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions civicrm.info
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ files[] = modules/views/civicrm/civicrm_handler_relationship_phone.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_im.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_website.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_address.inc
files[] = modules/views/civicrm/civicrm_handler_relationship_participant.inc

; views plugins
files[] = modules/views/plugins/calendar_plugin_row_civicrm.inc
Expand Down
74 changes: 74 additions & 0 deletions modules/views/civicrm/civicrm_handler_relationship_participant.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/**
* This relationship handler is used when joining the civicrm_relationship table
* to the civicrm_contact table. This handler allows us to optionally add conditions
* to the join clause based on relationship_type_id and is_active.
*/
class civicrm_handler_relationship_participant extends views_handler_relationship {
static $participant_types;

/**
* Preload the list of relationship_types and store in the static variable
* $relationship_types
*/
public function construct() {
parent::construct();

if (!civicrm_initialize()) {
return;
}

$rawParticipantRoles = civicrm_api3('Participant', 'getoptions', [
'field' => "participant_role_id",
]);

self::$participant_types = $rawParticipantRoles['values'];
}

/**
* Add additional options for relationship_type and relationship_state
* to the view. By defining these here, Views will take care of saving the
* values submitted from the options form.
*/
public function option_definition() {
$options = parent::option_definition();
$options['participant_type'] = array('default' => 0);
return $options;
}

/**
* Add relationship_type drowndown and relationship_state checkbox to
* relationship configuration form.
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);

$form['participant_type'] = array(
'#type' => 'select',
'#multiple' => TRUE,
'#title' => 'Choose a specific Participant type',
'#options' => self::$participant_types,
'#description' => t('Choose to limit this relationship to one or more specific types of CiviCRM Participant.'),
'#default_value' => $this->options['participant_type'],
);
}

/**
* Modify the default views relationship query to optionally specify
* join conditions for relationship_type or is_active (relationship_state).
*/
public function query() {
parent::query();

// Specify the type of relationships to join
if (isset($this->options['participant_type']) && $this->options['participant_type']) {
$this->query->table_queue[$this->alias]['join']->extra[] = array(
'value' => $this->options['participant_type'],
'numeric' => TRUE,
'field' => 'role_id',
);
}
}

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

$data['civicrm_event']['civicrm_participant'] = array(
'real field' => 'id',
'title' => t('CiviCRM Participant (starting from Event)'),
'help' => t('Allows a Participant Contact relationship from an Event'),
'relationship' => array(
'base' => 'civicrm_participant',
'base field' => 'event_id',
'handler' => 'civicrm_handler_relationship_participant',
'label' => t('CiviCRM Participant (starting from Event)'),
),
);

// Drupal ID of the contact (from uf_match.uf_id)
$data['civicrm_contact']['drupal_id'] = array(
'real field' => 'id',
Expand Down

0 comments on commit d2fee9b

Please sign in to comment.