From: atif-shaikh Date: Fri, 24 Oct 2014 15:25:55 +0000 (+0530) Subject: CRM-15427 - Profiles using Participants (Event type), Participants (Event Name) and... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=99e239bc880ee0a9165f97c8594a3046c4238295;p=civicrm-core.git CRM-15427 - Profiles using Participants (Event type), Participants (Event Name) and Participants (Role) fields are not available for online registration https://issues.civicrm.org/jira/browse/CRM-15427 --- diff --git a/CRM/Contribute/Form/ContributionPage/Custom.php b/CRM/Contribute/Form/ContributionPage/Custom.php index 9c86c2b04f..284499e4bf 100644 --- a/CRM/Contribute/Form/ContributionPage/Custom.php +++ b/CRM/Contribute/Form/ContributionPage/Custom.php @@ -55,19 +55,21 @@ class CRM_Contribute_Form_ContributionPage_Custom extends CRM_Contribute_Form_Co // Register 'contribution_1' $financialTypeId = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'financial_type_id'); $allowCoreTypes[] = 'Contribution'; - // $allowSubTypes['ContributionType'] = array($financialTypeId); - $entities[] = array('entity_name' => 'contribution_1', 'entity_type' => 'ContributionModel', 'entity_sub_type' => $financialTypeId); + //CRM-15427 + $allowSubTypes['ContributionType'] = array($financialTypeId); + $entities[] = array('entity_name' => 'contribution_1', 'entity_type' => 'ContributionModel', 'entity_sub_type' => '*'); // If applicable, register 'membership_1' $member = CRM_Member_BAO_Membership::getMembershipBlock($this->_id); if ($member && $member['is_active']) { - $entities[] = array('entity_name' => 'membership_1', 'entity_type' => 'MembershipModel', 'entity_sub_type' => $member['membership_type_default']); + //CRM-15427 + $entities[] = array('entity_name' => 'membership_1', 'entity_type' => 'MembershipModel', 'entity_sub_type' => '*'); $allowCoreTypes[] = 'Membership'; $allowSubTypes['MembershipType'] = explode(',', $member['membership_types']); } - - $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities); - $this->addProfileSelector('custom_post_id', ts('Include Profile') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities); + //CRM-15427 + $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE); + $this->addProfileSelector('custom_post_id', ts('Include Profile') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE); $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id); diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index 184f520dd7..a877eaffe3 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -3103,9 +3103,10 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) $groupTypeExpr .= implode(',', $coreTypes); } if ($subTypes) { - if (count($subTypes) > 1) { - throw new CRM_Core_Exception("Multiple subtype filtering is not currently supported by widget."); - } + //CRM-15427 Allow Multiple subtype filtering + //if (count($subTypes) > 1) { + //throw new CRM_Core_Exception("Multiple subtype filtering is not currently supported by widget."); + //} foreach ($subTypes as $subType => $subTypeIds) { $groupTypeExpr .= $delim . $subType . ':' . implode(':', $subTypeIds); } diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index f328e17fe7..deb7eac180 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1078,8 +1078,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page { * @param string $allowCoreTypes only present a UFGroup if its group_type includes a subset of $allowCoreTypes; e.g. 'Individual', 'Activity' * @param string $allowSubTypes only present a UFGroup if its group_type is compatible with $allowSubypes * @param array $entities + * @param bool $default //CRM-15427 */ - function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities) { + function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities, $default = FALSE) { // Output widget // FIXME: Instead of adhoc serialization, use a single json_encode() CRM_UF_Page_ProfileEditor::registerProfileScripts(); @@ -1089,6 +1090,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page { // Note: client treats ';;' as equivalent to \0, and ';;' works better in HTML 'data-group-type' => CRM_Core_BAO_UFGroup::encodeGroupType($allowCoreTypes, $allowSubTypes, ';;'), 'data-entities' => json_encode($entities), + //CRM-15427 + 'data-default' => $default, )); } diff --git a/CRM/Event/Form/ManageEvent/Registration.php b/CRM/Event/Form/ManageEvent/Registration.php index 3fb66a6ec7..040f42e098 100644 --- a/CRM/Event/Form/ManageEvent/Registration.php +++ b/CRM/Event/Form/ManageEvent/Registration.php @@ -339,12 +339,12 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent $form->addWysiwyg('footer_text', ts('Footer Text'), $footerAttribs); extract( self::getProfileSelectorTypes() ); + //CRM-15427 + $form->addProfileSelector( 'custom_pre_id', ts('Include Profile') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); + $form->addProfileSelector( 'custom_post_id', ts('Include Profile') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); - $form->addProfileSelector( 'custom_pre_id', ts('Include Profile') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities); - $form->addProfileSelector( 'custom_post_id', ts('Include Profile') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities); - - $form->addProfileSelector( 'additional_custom_pre_id', ts('Profile for Additional Participants') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities); - $form->addProfileSelector( 'additional_custom_post_id', ts('Profile for Additional Participants') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities); + $form->addProfileSelector( 'additional_custom_pre_id', ts('Profile for Additional Participants') . '
' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); + $form->addProfileSelector( 'additional_custom_post_id', ts('Profile for Additional Participants') . '
' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE); } /** @@ -379,9 +379,15 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent $configs['allowCoreTypes'][] = 'Contact'; $configs['allowCoreTypes'][] = 'Individual'; $configs['allowCoreTypes'][] = 'Participant'; + //CRM-15427 + $participantEventType = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $_GET['id'], 'event_type_id', 'id'); + $participantRole = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $_GET['id'], 'default_role_id'); + $configs['allowSubTypes']['ParticipantEventName'] = array($_GET['id']); + $configs['allowSubTypes']['ParticipantEventType'] = array($participantEventType); + $configs['allowSubTypes']['ParticipantRole'] = array($participantRole); $configs['profileEntities'][] = array('entity_name' => 'contact_1', 'entity_type' => 'IndividualModel'); - $configs['profileEntities'][] = array('entity_name' => 'participant_1', 'entity_type' => 'ParticipantModel'); + $configs['profileEntities'][] = array('entity_name' => 'participant_1', 'entity_type' => 'ParticipantModel', 'entity_sub_type' => '*'); return $configs; } diff --git a/js/jquery/jquery.crmProfileSelector.js b/js/jquery/jquery.crmProfileSelector.js index f973335520..8bb4a51e4f 100644 --- a/js/jquery/jquery.crmProfileSelector.js +++ b/js/jquery/jquery.crmProfileSelector.js @@ -28,16 +28,41 @@ var matchingUfGroups, $select = $(this).hide().addClass('rendered'); + var validTypesId = []; if (options.groupTypeFilter) { matchingUfGroups = ufGroupCollection.subcollection({ filter: function(ufGroupModel) { - return ufGroupModel.checkGroupType(options.groupTypeFilter); + return ufGroupModel.checkGroupType(options.groupTypeFilter, options.allowAllSubtypes); } }); } else { matchingUfGroups = ufGroupCollection; } + //CRM-15427 check for valid subtypes raise a warning if not valid + if (options.allowAllSubtypes && $.isEmptyObject(validTypesId)) { + validTypes = ufGroupCollection.subcollection({ + filter: function(ufGroupModel) { + return ufGroupModel.checkGroupType(options.groupTypeFilter); + } + }); + _.each(validTypes.models, function(validTypesattr) { + validTypesId.push(validTypesattr.id); + }); + } + if (!$.isEmptyObject(validTypesId) && $.inArray($select.val(), validTypesId) == -1) { + var civiComponent; + if (options.groupTypeFilter.indexOf('Membership') !== -1) { + civiComponent = 'Membership'; + } + else if (options.groupTypeFilter.indexOf('Participant') !== -1) { + civiComponent = 'Event'; + } + else { + civiComponent = 'Contribution'; + } + CRM.alert(ts('The selected profile is using a custom field which is not assigned to the '+civiComponent+' being configured.'),ts('Warning')); + } var view = new CRM.ProfileSelector.View({ ufGroupId: $select.val(), ufGroupCollection: matchingUfGroups, @@ -58,7 +83,9 @@ $('.crm-profile-selector:not(.rendered)', this).each(function() { $(this).crmProfileSelector({ groupTypeFilter: $(this).data('groupType'), - entities: $(this).data('entities') + entities: $(this).data('entities'), + //CRM-15427 + allowAllSubtypes: $(this).data('default') }); }); }); diff --git a/js/model/crm.uf.js b/js/model/crm.uf.js index e72c8383c5..392d0a4414 100644 --- a/js/model/crm.uf.js +++ b/js/model/crm.uf.js @@ -54,13 +54,27 @@ }); } + //CRM-15427 Allow Multiple subtype filtering if (subTypesExpr && subTypesExpr != '') { - var subTypes = subTypesExpr.split(':'); - var subTypeKey = subTypes.shift(); - typeList.subTypes[subTypeKey] = {}; - _.each(subTypes, function(subTypeId){ - typeList.subTypes[subTypeKey][subTypeId] = true; - }); + if (subTypesExpr.indexOf(';;') !== -1) { + var subTypeparts = subTypesExpr.replace(/;;/g,'\0').split('\0'); + _.each(subTypeparts, function(subTypepart) { + var subTypes = subTypepart.split(':'); + var subTypeKey = subTypes.shift(); + typeList.subTypes[subTypeKey] = {}; + _.each(subTypes, function(subTypeId) { + typeList.subTypes[subTypeKey][subTypeId] = true; + }); + }); + } + else { + var subTypes = subTypesExpr.split(':'); + var subTypeKey = subTypes.shift(); + typeList.subTypes[subTypeKey] = {}; + _.each(subTypes, function(subTypeId) { + typeList.subTypes[subTypeKey][subTypeId] = true; + }); + } } return typeList; }; @@ -379,7 +393,8 @@ return result; }, isSectionEnabled: function(section) { - return (!section || !section.extends_entity_column_value || _.contains(section.extends_entity_column_value, this.get('entity_sub_type'))); + //CRM-15427 + return (!section || !section.extends_entity_column_value || _.contains(section.extends_entity_column_value, this.get('entity_sub_type')) || this.get('entity_sub_type') == '*'); }, getSections: function() { var ufEntityModel = this; @@ -647,9 +662,11 @@ * Check that the group_type contains *only* the types listed in validTypes * * @param string validTypesExpr + * @param bool allowAllSubtypes * @return {Boolean} */ - checkGroupType: function(validTypesExpr) { + //CRM-15427 + checkGroupType: function(validTypesExpr, allowAllSubtypes = false) { var allMatched = true; if (! this.get('group_type') || this.get('group_type') == '') { return true; @@ -665,22 +682,25 @@ } }); - // Every actual.subType is a valid.subType - _.each(actualTypes.subTypes, function(actualSubTypeIds, actualSubTypeKey) { - if (!validTypes.subTypes[actualSubTypeKey]) { - allMatched = false; - return; - } - // actualSubTypeIds is a list of all subtypes which can be used by group, - // so it's sufficient to match any one of them - var subTypeMatched = false; - _.each(actualSubTypeIds, function(ignore, actualSubTypeId) { - if (validTypes.subTypes[actualSubTypeKey][actualSubTypeId]) { - subTypeMatched = true; + //CRM-15427 allow all subtypes + if (!$.isEmptyObject(validTypes.subTypes) && !allowAllSubtypes) { + // Every actual.subType is a valid.subType + _.each(actualTypes.subTypes, function(actualSubTypeIds, actualSubTypeKey) { + if (!validTypes.subTypes[actualSubTypeKey]) { + allMatched = false; + return; } + // actualSubTypeIds is a list of all subtypes which can be used by group, + // so it's sufficient to match any one of them + var subTypeMatched = false; + _.each(actualSubTypeIds, function(ignore, actualSubTypeId) { + if (validTypes.subTypes[actualSubTypeKey][actualSubTypeId]) { + subTypeMatched = true; + } + }); + allMatched = allMatched && subTypeMatched; }); - allMatched = allMatched && subTypeMatched; - }); + } return allMatched; }, calculateContactEntityType: function() {