*/
public $_paymentId = NULL;
- /**
- * array of participant role custom data
- */
- public $_participantRoleIds = array();
-
/**
* Function to set variables up before form is built
*
);
}
$this->set('onlinePendingContributionId', $this->_onlinePendingContributionId);
- $roleIds = CRM_Event_PseudoConstant::participantRole();
- if (!empty($roleIds)) {
- $query = "
-SELECT civicrm_custom_group.name as name,
- civicrm_custom_group.id as id,
- extends_entity_column_value as value
- FROM civicrm_custom_group
- WHERE ( extends_entity_column_value REGEXP '[[:<:]]" . implode('[[:>:]]|[[:<:]]', array_keys($roleIds)) . "[[:>:]]'
- OR extends_entity_column_value IS NULL )
- AND extends_entity_column_id = '{$this->_roleCustomDataTypeID}'
- AND extends = 'Participant'
- AND is_active = 1";
-
- $dao = CRM_Core_DAO::executeQuery($query);
- while ($dao->fetch()) {
- if ($dao->value) {
- $getRole = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->value);
- foreach ($getRole as $r) {
- if (!$r) {
- continue;
- }
- if (isset($this->_participantRoleIds[$r])) {
- $this->_participantRoleIds[$r] .= ',' . $dao->name;
- }
- else {
- $this->_participantRoleIds[$r] = $dao->name;
- }
- }
- }
- else {
- if (isset($this->_participantRoleIds[0])) {
- $this->_participantRoleIds[0] .= ',' . $dao->name;
- }
- else {
- $this->_participantRoleIds[0] = $dao->name;
- }
- }
- }
- $dao->free();
- }
- foreach ($roleIds as $k => $v) {
- if (!isset($this->_participantRoleIds[$k])) {
- $this->_participantRoleIds[$k] = '';
- }
- }
- $this->assign('participantRoleIds', $this->_participantRoleIds);
}
/**
$roleIDs = explode(',', $urlRoleIDS);
}
if (isset($roleIDs)) {
- foreach ($roleIDs as $roleID) {
- $defaults[$this->_id]["role_id[{$roleID}]"] = 1;
- }
- unset($defaults[$this->_id]['role_id']);
- $this->assign('roleID', $roleIDs);
+ $defaults[$this->_id]['role_id'] = implode(',', $roleIDs);
}
if (isset($eventID)) {
$this->assign('entityID', $this->_id);
}
- $roleids = CRM_Event_PseudoConstant::participantRole();
-
- foreach ($roleids as $rolekey => $rolevalue) {
- $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue);
- }
-
- $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
- $this->addRule('role_id', ts('Role is required'), 'required');
+ $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
// CRM-4395
$checkCancelledJs = array('onchange' => "return sendNotification( );");
//modify params according to parameter used in create
//participant method (addParticipant)
$this->_params['participant_status_id'] = $params['status_id'];
- $this->_params['participant_role_id'] = $params['role_id'];
+ $this->_params['participant_role_id'] = explode(',', $params['role_id']);
$this->_params['participant_register_date'] = $params['register_date'];
$eventTitle =
$contactID = CRM_Contact_BAO_Contact::createProfileContact($params, $fields, $this->_contactId, NULL, NULL, $ctype);
}
- $roleAllIds = CRM_Utils_Array::value('role_id', $params);
- if ($roleAllIds) {
- foreach ($roleAllIds as $rkey => $rvalue) {
+ if ($this->_params['participant_role_id']) {
+ foreach ($this->_params['participant_role_id'] as $rkey) {
$customFieldsRole = CRM_Core_BAO_CustomField::getFields('Participant', FALSE, FALSE, $rkey, $this->_roleCustomDataTypeID);
$customFieldsEvent = CRM_Core_BAO_CustomField::getFields('Participant',
FALSE,
$participants = array();
if (!empty($this->_params['participant_role_id']) && is_array($this->_params['participant_role_id'])) {
$this->_params['participant_role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR,
- array_keys($this->_params['participant_role_id'])
+ $this->_params['participant_role_id']
);
}
$participants[] = CRM_Event_Form_Registration::addParticipant($this->_params, $contactID);
$participants = array();
if ($this->_single) {
if ($params['role_id']) {
- foreach ($params['role_id'] as $k => $v) {
- $rolesIDS[] = $k;
- }
- $seperator = CRM_Core_DAO::VALUE_SEPARATOR;
- $params['role_id'] = implode($seperator, $rolesIDS);
+ $params['role_id'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
}
else {
$params['role_id'] = 'NULL';
$commonParams = $params;
$commonParams['contact_id'] = $contactID;
if ($commonParams['role_id']) {
- $rolesIDS = array();
- foreach ($commonParams['role_id'] as $k => $v) {
- $rolesIDS[] = $k;
- }
- $seperator = CRM_Core_DAO::VALUE_SEPARATOR;
- $commonParams['role_id'] = implode($seperator, $rolesIDS);
- $commonParams['participant_role_id'] = implode($seperator, $rolesIDS);
+ $commonParams['participant_role_id'] = $commonParams['role_id'] = str_replace(',', CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
}
else {
$commonParams['role_id'] = 'NULL';
var info = $(this).select2('data').extra;
// Set role from default
- $('[name^=role_id]:checkbox', $form).each(function() {
- var check = $(this).is('[name="role_id[' + info.default_role_id + ']"]');
- if (check !== $(this).prop('checked')) {
- $(this).prop('checked', check).change();
- }
- });
+ $('select[name^=role_id]', $form).select2('val', [info.default_role_id], true);
// Set campaign default
$('#campaign_id', $form).select2('val', info.campaign_id);
});
// Handle participant role selection
- $('[name^=role_id]:checkbox', $form).change(function() {
- var roleId = $(this).attr('name').replace(/role_id\[|\]/g, '');
- showCustomData('Participant', roleId, {/literal}{$roleCustomDataTypeID}{literal});
- });
- $('[name^=role_id]:checked', $form).change();
+ $('select[name^=role_id]', $form).change(buildRoleCustomData);
+ if ($('select[name^=role_id]', $form).val()) {
+ buildRoleCustomData();
+ }
buildFeeBlock();
buildFeeBlock($('#discount_id', $form).val());
}
+ function buildRoleCustomData() {
+ var roleId = $('select[name^=role_id]', $form).select2('val').join();
+ CRM.buildCustomData('Participant', roleId, {/literal}{$roleCustomDataTypeID}{literal});
+ }
+
//build fee block
function buildFeeBlock(discountId) {
var dataUrl = {/literal}"{crmURL p=$urlPath h=0 q="snippet=4&qfKey=$qfKey"}";
$.ajax({
url: dataUrl,
- async: false,
- global: false,
success: function ( html ) {
$("#feeBlock").html( html ).trigger('crmLoad');
}
}
}
- var roleGroupMapper = {/literal}{$participantRoleIds|@json_encode}{literal};
- function showCustomData( type, subType, subName ) {
- var dataUrl = {/literal}"{crmURL p=$urlPath h=0 q='snippet=4&type='}"{literal} + type;
- var roleid = "role_id_"+subType;
- var loadData = false;
-
- if ( document.getElementById( roleid ).checked == true ) {
- if ( typeof roleGroupMapper !== 'undefined' && roleGroupMapper[subType] ) {
- var splitGroup = roleGroupMapper[subType].split(",");
- for ( i = 0; i < splitGroup.length; i++ ) {
- var roleCustomGroupId = splitGroup[i];
- if ( $( '#'+roleCustomGroupId ).length > 0 ) {
- $( '#'+roleCustomGroupId ).remove( );
- }
- }
- loadData = true;
- }
- }
- else {
- var groupUnload = [];
- var x = 0;
-
- if ( roleGroupMapper[0] ) {
- var splitGroup = roleGroupMapper[0].split(",");
- for ( x = 0; x < splitGroup.length; x++ ) {
- groupUnload[x] = splitGroup[x];
- }
- }
-
- for ( var i in roleGroupMapper ) {
- if ( ( i > 0 ) && ( document.getElementById( "role_id_"+i ).checked ) ) {
- var splitGroup = roleGroupMapper[i].split(",");
- for ( j = 0; j < splitGroup.length; j++ ) {
- groupUnload[x+j+1] = splitGroup[j];
- }
- }
- }
-
- if ( roleGroupMapper[subType] ) {
- var splitGroup = roleGroupMapper[subType].split(",");
- for ( i = 0; i < splitGroup.length; i++ ) {
- var roleCustomGroupId = splitGroup[i];
- if ( $( '#'+roleCustomGroupId ).length > 0 ) {
- if ( $.inArray( roleCustomGroupId, groupUnload ) == -1 ) {
- $( '#'+roleCustomGroupId ).remove( );
- }
- }
- }
- }
- }
-
- if ( !( loadData ) ) {
- return false;
- }
-
- if ( subType ) {
- dataUrl += '&subType=' + subType;
- }
-
- if ( subName ) {
- dataUrl += '&subName=' + subName;
- $( '#customData' + subName ).show( );
- }
- else {
- $( '#customData' ).show( );
- }
-
- {/literal}
- {if $urlPathVar}
- dataUrl += '&{$urlPathVar}';
- {/if}
- {if $groupID}
- dataUrl += '&groupID=' + '{$groupID}';
- {/if}
- {if $qfKey}
- dataUrl += '&qfKey=' + '{$qfKey}';
- {/if}
- {if $entityID}
- dataUrl += '&entityID=' + '{$entityID}';
- {/if}
-
- {literal}
-
- if ( subName && subName != 'null' ) {
- var fname = '#customData' + subName;
- }
- else {
- var fname = '#customData';
- }
-
- var response = $.ajax({url: dataUrl,
- async: false
- }).responseText;
-
- if ( subType != 'null' ) {
- if ( document.getElementById(roleid).checked == true ) {
- var response_text = '<div style="display:block;" id = '+subType+'_chk >'+response+'</div>';
- $( fname ).append(response_text).trigger('crmLoad');
- }
- else {
- $('#'+subType+'_chk').remove();
- }
- }
- }
-
{/literal}
CRM.buildCustomData( '{$customDataType}', 'null', 'null' );
{if $eventID}