3

I have a use case where there are public and non public events. Public events should be seen by everyone and can be registered for. Non public events should only be seen and registerable for a certain group (members.

With ACLs I deactivated the CMS permissions and added the rights to view / edit an event. I got as far as to create a seperate ACL for each event which grants the appropriate right in order to make an event public / non-public. This process however is very tedious since it required the creation of a seperate ACL for each event. Is there a way to make this more "global" so that events of a certain category (custom field) are public while others are non public?

1

You could apply the same techniques for event pages that are described for contribution pages here: Are private contribution pages a thing?.

EDIT: Actually that's only a piece of the puzzle, let me give an example (and make it CMS-agnostic). Assuming you want to limit access to members of "Newsletter Subscribers"

function hook_civicrm_preProcess($formName, &$form) {

  $redirectPath = 'home';  // set this to the url to redirect to if access is denied

  if ($formName == "CRM_Event_Form_Registration_Register") {
    $contactId = CRM_Core_Session::singleton()->getLoggedInContactID();
    $result = civicrm_api3('Contact', 'get', array(
      'group' => "Newsletter Subscribers",
      'id' => $contactId,
    ));
    if ($result['count'] === 0) {
      CRM_Utils_System::redirect($redirectPath);
    }
  }
}

Note: This will hide ALL event registrations. You'll have to find a variable in the $form object to use to determine whether this code should run on a particular page and modify the if condition.

  • Is there a specific technique you are referring to? Checked this thread before but haven't seen a solution/technique to solve this problem. – florian norbert bepunkt Feb 2 '18 at 14:38
  • @floriannorbertbepunkt I updated my answer. – Jon G - Megaphone Tech Feb 2 '18 at 16:11
  • okay, I get what you mean. thank you for posting the example… my question was about a different approach: tieing an ACL to a custom field of an event (or more general extending an acls functionality to include conditional checks). with your approach you would not use ACLs at all but implement a query to conditionally show the data. – florian norbert bepunkt Feb 2 '18 at 16:19
  • Yes, that's correct. I understand what you're asking for - and even have the same need myself! This is higher-performance than ACLs, but I agree that what you're asking for is more user-friendly. – Jon G - Megaphone Tech Feb 2 '18 at 17:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.