1

I have users in different groups; depending on the group they are in, when they see the events listing, I'd like them to only see events that are relevant for them based on the group(s) they are in.

For example, let's say I have users in 3 groups: Employee, Manager, Contractor. Manager gets to see events for all groups. Contractor only gets to see Contractor events. Employee gets to see events for Employee and Contractor.

Right now I am just using the basic CiviEvent listing: https://mysiteurl/civicrm/event/ical?reset=1&list=1&html=1.

One option I have thought of is to use the "Event Type" as a filtering mechanism because you can then use URLs like https://mysiteurl/civicrm/event/ical?reset=1&list=1&html=1&type=XXX. So then for event display I would create my own event listing page and embed iframes. I would still need to find a way to identify programmatically what group the user is in and only display the iframe for that user. The problem with this option is that it does not show the events in date order: it would show the Employee events in date order, then in a separate section the Manager events in date order, and in a third section the Contractor events in date order. I feel this would become confusing for people. I'd rather show them just one single event list that is in date order and only shows events that are relevant to them.

I guess it might be possible to use views? But I don't know much about views.

So I'm looking for advice or help. I haven't been able to find any plugins or sample code that might do this but it seems like it would be a super common use case?

THanks!

PS: I am on Drupal 7 and Civi 4.6.X.

1 Answer 1

1

I solved this by:

  • Enabling the PHP module that comes as part of Drupal 7 core but is disabled by default. Enabling this module creates a new text format called "PHP Code"
  • Creating a new page and setting the text format of that page to "PHP Code". I called the page "Calendar of Events".
  • Putting the following code in the body of that new page:

    <?php $role = user_role_load_by_name('My Role'); if (user_has_role($role->rid)) { header("Location: https://mysite/civicrm/event/ical? reset=1&list=1&html=1&type=7"); /* Redirect browser */ exit(); } ?>

This solution requires you to have a separate Drupal role for each group of users you want to show different events to. It also requires that you have defined different event types. So for example, users in the group Managers would see events that have event types such as "Manager Meeting", "Employee Meeting", and "Very Secret Meeting". You define the event types in CiviCRM's Administer menu for CiviEvent. The &type=X is what defines what event types will be displayed; the X value comes from the event type list in CiviCRM's CiviEvent administration. You can comma separate the &type=X,Y,Z for example to show one user role multiple event types.

6
  • did you know there was a civigroup roles sync module (part of civi core), so people in Group X can be given role x automatically?
    – petednz - fuzion
    Feb 17, 2016 at 9:47
  • Hi petednz, yes, that is how I assign users to drupal roles. It is much easier to query a drupal role assignment with PHP than it is to query a CiviCRM group membership in PHP. So I use the CiviGroup Roles Sync to sync membership in various CiviCRM groups to Drupal roles. Then I query whether the logged in user is a member of the drupal roles in order to show them specific events from the list of events that are relevant to them. Feb 23, 2016 at 5:04
  • cool. just checking :)
    – petednz - fuzion
    Feb 23, 2016 at 19:48
  • curious. would an approach that used different Views Attachments ie so you showed an attachment of 'Very Secret' below an attachment of 'very public' and have each display set to access by different Roles have worked in your case?
    – petednz - fuzion
    Feb 23, 2016 at 19:50
  • Hi petednz. I haven't really used Views much yet. I don't have Drupal and CiviCRM integrated with views. I think by reading the docs that if I could pass CiviCRM entities to views then I would be able to set up a calendar that only shows some event types and not others but because my Civi and Drupal databases are separate there seems to be a fair bit of mucking about needed to get this working and I've been shying away from it. Feb 24, 2016 at 4:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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