CRM-15427 - Profiles using Participants (Event type), Participants (Event Name) and...
authoratif-shaikh <shaikh388@gmail.com>
Fri, 24 Oct 2014 15:25:55 +0000 (20:55 +0530)
committeratif-shaikh <shaikh388@gmail.com>
Fri, 24 Oct 2014 15:25:55 +0000 (20:55 +0530)
https://issues.civicrm.org/jira/browse/CRM-15427

CRM/Contribute/Form/ContributionPage/Custom.php
CRM/Core/BAO/UFGroup.php
CRM/Core/Form.php
CRM/Event/Form/ManageEvent/Registration.php
js/jquery/jquery.crmProfileSelector.js
js/model/crm.uf.js

index 9c86c2b04f90f23bb0d427a83af85c6cf23d6444..284499e4bfef10bfa81bdf5476ac93bde0d9a680 100644 (file)
@@ -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') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities);
-    $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities);
+    //CRM-15427
+    $this->addProfileSelector('custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE);
+    $this->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $entities, TRUE);
 
     $this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Custom', 'formRule'), $this->_id);
 
index 184f520dd7baf893096732038ee5ba56e3103171..a877eaffe3b9a487a2a75ad30bb048a8d611a59a 100644 (file)
@@ -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);
       }
index f328e17fe74f6e756763d6d6a4b7adb35a2e1e94..deb7eac180fe06814f7f8be1d2a5c1dc5793e74c 100644 (file)
@@ -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,
     ));
   }
 
index 3fb66a6ec723b77224740b6c3a37d65b0f37b117..040f42e09895c180393b1fbcba2ac820746b8e30 100644 (file)
@@ -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') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
+    $form->addProfileSelector( 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
 
-    $form->addProfileSelector( 'custom_pre_id', ts('Include Profile') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
-    $form->addProfileSelector( 'custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
-
-    $form->addProfileSelector( 'additional_custom_pre_id',  ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
-    $form->addProfileSelector( 'additional_custom_post_id',  ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities);
+    $form->addProfileSelector( 'additional_custom_pre_id',  ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
+    $form->addProfileSelector( 'additional_custom_post_id',  ts('Profile for Additional Participants') . '<br />' . 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;
   }
index f97333552078d0ca177ef23e89e6ad5d0fa202a5..8bb4a51e4f50b065cb94f835a0214f8e2c1742b7 100644 (file)
       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')
       });
     });
   });
index e72c8383c58aa7efb4e010c571b29955f5adbc2a..392d0a44141cd4e1c44823eb452f8dfd6dae2936 100644 (file)
       });
     }
 
+    //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;
   };
       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;
      * 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;
         }
       });
 
-      // 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() {