-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Drupal Views CiviCRM: Allow Participant record to be used from Event.
- Loading branch information
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
modules/views/civicrm/civicrm_handler_relationship_participant.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters