Answers.Body: <p>I solved this by:</p>
  
  <ul>
  <li>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"</li>
  <li>Creating a new page and setting the text format of that page to "PHP Code".  I called the page "Calendar of Events".</li>
  <li><p>Putting the following code in the body of that new page:</p>
  
  <blockquote>
    <p><code>&lt;?php
       $role = user_role_load_by_name('My Role');
       if (user_has_role($role-&gt;rid)) {
         header("Location: https://mysite/civicrm/event/ical? 
         reset=1&amp;list=1&amp;html=1&amp;type=7");  /* Redirect browser */
         exit();
       }
       ?&gt;</code></p>
  </blockquote></li>
  </ul>
  
  <p>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 <code>&amp;type=X</code> 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 <code>&amp;type=X,Y,Z</code> for example to show one user role multiple event types.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-17T09:47:44.907Z
Answers.Text: 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?
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-23T05:04:45.067Z
Answers.Text: 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.
Answers.UserDisplayName: richardsplayground
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-23T19:48:57.343Z
Answers.Text: cool. just checking :)
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-23T19:50:36.230Z
Answers.Text: 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?
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-24T04:13:46.110Z
Answers.Text: 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.
Answers.UserDisplayName: richardsplayground
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-24T05:02:46.233Z
Answers.Text: hi richard - you may find out the mucking around is not that hard. if you go to civicrm/admin/setting/uf?reset=1 you should find the list of tables in civi all ready for you to copy and paste in to your drupal settings.php file. Personally as a non-coder I find Views gives me all sorts of capabilities in terms of manipulating/exposing data that extends what civi itself can do
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-17T08:39:23.297Z
Answers.LastActivityDate: 2016-02-17T08:39:23.297Z
Answers.UserDisplayName: richardsplayground
Body: <p>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.</p>
  
  <p>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.</p>
  
  <p>Right now I am just using the basic CiviEvent listing: <a href="https://mysiteurl/civicrm/event/ical?reset=1&amp;list=1&amp;html=1" rel="nofollow">https://mysiteurl/civicrm/event/ical?reset=1&amp;list=1&amp;html=1</a>.  </p>
  
  <p>One option I have thought of is to use the "Event Type" as a filtering mechanism because you can then use URLs like <a href="https://mysiteurl/civicrm/event/ical?reset=1&amp;list=1&amp;html=1&amp;type=XXX" rel="nofollow">https://mysiteurl/civicrm/event/ical?reset=1&amp;list=1&amp;html=1&amp;type=XXX</a>.  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.</p>
  
  <p>I guess it might be possible to use views?  But I don't know much about views.</p>
  
  <p>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?</p>
  
  <p>THanks!</p>
  
  <p>PS: I am on Drupal 7 and Civi 4.6.X.</p>
  
Tags: <civievent><groups><drupal-views>
Title: Show different events to different user groups
ThreadText: # Show different events to different user groups
  
  (Asked by: username_0 on 2016-01-30)
  
  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.
  
  **Tags:** civievent, groups, drupal-views
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-02-17. Score: 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.
  
  > **Comments:**
  > **username_1**: 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?  
  > **username_0**: Hi username_1, 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.  
  > **username_1**: cool. just checking :)  
  > **username_1**: 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?  
  > **username_0**: Hi username_1.  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.  
  > **username_1**: hi richard - you may find out the mucking around is not that hard. if you go to civicrm/admin/setting/uf?reset=1 you should find the list of tables in civi all ready for you to copy and paste in to your drupal settings.php file. Personally as a non-coder I find Views gives me all sorts of capabilities in terms of manipulating/exposing data that extends what civi itself can do  
  
  ---
  
  