CRM-16915 - Filter Profile selector in Configure Event - Registration tab for non...
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 28 Jul 2015 13:34:43 +0000 (19:04 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Tue, 28 Jul 2015 13:34:43 +0000 (19:04 +0530)
CRM/Core/DAO/permissions.php
CRM/Core/Form.php
CRM/Event/Form/ManageEvent/Registration.php
CRM/UF/Page/ProfileEditor.php
js/jquery/jquery.crmProfileSelector.js
js/model/crm.uf.js

index a93074565e5571432a5a40fc574e82a205bf96ee..98b3cb6c46e74ed7cd790d7185c90bd03f2f56e1 100644 (file)
@@ -495,7 +495,7 @@ function _civicrm_api3_permissions($entity, $action, &$params) {
       ),
     ),
   );
-  $permissions['uf_field'] = $permissions['uf_group'];
+  $permissions['uf_field'] = $permissions['uf_join'] = $permissions['uf_group'];
   $permissions['uf_field']['delete'] = array(
     'access CiviCRM',
     array(
index bfd99ab3111e5dfc519367435aeb1e76b7df5cad..9b36db582d61fe89c2d2933645907f446a167e64 100644 (file)
@@ -1115,7 +1115,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @param bool $default
    *   //CRM-15427.
    */
-  public function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities, $default = FALSE) {
+  public function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities, $default = FALSE, $usedFor = NULL) {
     // Output widget
     // FIXME: Instead of adhoc serialization, use a single json_encode()
     CRM_UF_Page_ProfileEditor::registerProfileScripts();
@@ -1127,6 +1127,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       'data-entities' => json_encode($entities),
       //CRM-15427
       'data-default' => $default,
+      'data-usedfor' => json_encode($usedFor),
     ));
   }
 
index 3a24bb1d96838998bdafd0c0f1943523bcd73600..19a6641c7ea1634cf883bf83875d6a52469ffb10 100644 (file)
@@ -328,11 +328,11 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
 
     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, TRUE, $usedFor);
+    $form->addProfileSelector('custom_post_id', ts('Include Profile') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
 
-    $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);
+    $form->addProfileSelector('additional_custom_pre_id', ts('Profile for Additional Participants') . '<br />' . ts('(top of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
+    $form->addProfileSelector('additional_custom_post_id', ts('Profile for Additional Participants') . '<br />' . ts('(bottom of page)'), $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
   }
 
   /**
@@ -353,7 +353,7 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
     extract((is_null($configs)) ? self::getProfileSelectorTypes() : $configs);
     $element = $prefix . "custom_post_id_multiple[$count]";
     $label .= '<br />' . ts('(bottom of page)');
-    $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE);
+    $form->addProfileSelector($element, $label, $allowCoreTypes, $allowSubTypes, $profileEntities, TRUE, $usedFor);
   }
 
   /**
@@ -367,6 +367,7 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
       'allowCoreTypes' => array(),
       'allowSubTypes' => array(),
       'profileEntities' => array(),
+      'usedFor' => array(),
     );
 
     $configs['allowCoreTypes'] = array_merge(array(
@@ -374,6 +375,9 @@ class CRM_Event_Form_ManageEvent_Registration extends CRM_Event_Form_ManageEvent
         'Individual',
       ), CRM_Contact_BAO_ContactType::subTypes('Individual'));
     $configs['allowCoreTypes'][] = 'Participant';
+    if (CRM_Core_Permission::check('manage event profiles') && !CRM_Core_Permission::check('administer CiviCRM')) {
+      $configs['usedFor'][] = 'CiviEvent';
+    }
     //CRM-15427
     $id = CRM_Utils_Request::retrieve('id', 'Integer');
     if ($id) {
index 4a3709832d87c4208c251c4b872e5a9621e170b9..a7bd90bb468567ae13c799881d4bcb894c13bd8c 100644 (file)
@@ -20,18 +20,26 @@ class CRM_UF_Page_ProfileEditor extends CRM_Core_Page {
 
     CRM_Core_Resources::singleton()
       ->addSettingsFactory(function () {
+        $ufGroups = civicrm_api3('UFGroup', 'get', array(
+          'sequential' => 1,
+          'is_active' => 1,
+          'rowCount' => 1000, // FIXME
+        ));
+        if (CRM_Core_Permission::check('manage event profiles') && !CRM_Core_Permission::check('administer CiviCRM')) {
+          foreach ($ufGroups['values'] as $key => $value) {
+            $ufJoin = CRM_Core_BAO_UFGroup::getUFJoinRecord($value['id']);
+            if (in_array('CiviEvent', $ufJoin)) {
+              $ufGroups['values'][$key]['module'] = 'CiviEvent';
+            }
+          }
+        }
         return array(
           'PseudoConstant' => array(
             'locationType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'),
             'websiteType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'),
             'phoneType' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'),
           ),
-          'initialProfileList' => civicrm_api('UFGroup', 'get', array(
-            'version' => 3,
-            'sequential' => 1,
-            'is_active' => 1,
-            'rowCount' => 1000, // FIXME
-          )),
+          'initialProfileList' => $ufGroups,
           'contactSubTypes' => CRM_Contact_BAO_ContactType::subTypes(),
           'profilePreviewKey' => CRM_Core_Key::get('CRM_UF_Form_Inline_Preview', TRUE),
         );
index b46dd499dced245a2d6c870d4d1d39d8c899b0ef..ab6d7f55c44910309b66c7457dffa51c796c3946 100644 (file)
         $select = $(this).hide().addClass('rendered');
 
       var validTypesId = [];
+      var usedByFilter = null;
       if (options.groupTypeFilter) {
         matchingUfGroups = ufGroupCollection.subcollection({
           filter: function(ufGroupModel) {
-            return ufGroupModel.checkGroupType(options.groupTypeFilter, options.allowAllSubtypes);
+            if(!$.isEmptyObject(options.usedByFilter)) {
+              usedByFilter = options.usedByFilter;
+            }
+            return ufGroupModel.checkGroupType(options.groupTypeFilter, options.allowAllSubtypes, usedByFilter);
           }
         });
       } else {
@@ -85,7 +89,8 @@
         groupTypeFilter: $(this).data('groupType'),
         entities: $(this).data('entities'),
         //CRM-15427
-        allowAllSubtypes: $(this).data('default')
+        allowAllSubtypes: $(this).data('default'),
+        usedByFilter: $(this).data('usedfor')
       });
     });
   });
index 99d456e539467b76c1de659b596ec1bfe1e4e6c6..d275f116d6073a414b0660871142861e865e0d1e 100644 (file)
      * @return {Boolean}
      */
     //CRM-15427
-    checkGroupType: function(validTypesExpr, allowAllSubtypes) {
+    checkGroupType: function(validTypesExpr, allowAllSubtypes, usedByFilter) {
       var allMatched = true;
       allowAllSubtypes = allowAllSubtypes || false;
+      usedByFilter = usedByFilter || null;
       if (_.isEmpty(this.get('group_type'))) {
         return true;
       }
+      if (usedByFilter && _.isEmpty(this.get('module'))) {
+        return false;
+      }
 
       var actualTypes = CRM.UF.parseTypeList(this.get('group_type'));
       var validTypes = CRM.UF.parseTypeList(validTypesExpr);
         }
       });
 
+      if (usedByFilter && this.get('module') != usedByFilter) {
+        allMatched = false;
+      }
+
       //CRM-15427 allow all subtypes
       if (!$.isEmptyObject(validTypes.subTypes) && !allowAllSubtypes) {
         // Every actual.subType is a valid.subType