1

[apologies for cross posting. This question is also on Drupal answers, but since the options for filtering would be based on civiEvent fields, I am posting here as well)

We have a view that displays upcoming events. We use civiCRM for events. Some of our events are ongoing: they have the same title, but different dates. What logic could I use to display the next upcoming event, without displaying all upcoming events?

For instance, at the moment the events displayed are based on date. Any event that is not yet passed will display in the view. But for a class which repeats 10 times, I do not want 10 of the same title, just the next class and its date/time.

4
  • Is your view a calendar view or a list view? Commented Oct 25, 2018 at 18:46
  • list: jewishideas.org/events Commented Oct 25, 2018 at 22:33
  • Not all that straightforward. The views output is unique to each event. So even if the titles are the same the dates are different. So you cannot use View Aggregation to get the results you want. I think you might have to do some views preprocessing and aggregate the view output on the event title so you just get a single views row per event title. Commented Oct 26, 2018 at 12:21
  • you might find that views_field_view could do what you need if you pass the Title over as the 'contextual filter' to another view, and have that view set up to only show 1 result that is in the future
    – petednz - fuzion
    Commented Oct 28, 2018 at 4:26

2 Answers 2

1

I do not think there is an easy way to do this via the Drupal Views interface.

However you can do it using jQuery or maybe CSS to hide all but the first instance of your repeating event.

Start off by creating a custom event option field to identify each type of event. You could even use the event type ID if you wanted and just add more options to it.

So it could be

  • Jane's classes would have an ID of 1
  • Joe's classes would have an ID of 2

So whatever you choose, each event will have an ID that identifies the type of event.

You can get these ID values into the View. Make sure you have Civicrm Entities module installed.

So now you have a view that shows say

  • Start date

  • Title

  • Event type ID or your custom field ID

Now you create a Row template for the View

Now you wrap the row in a div and you add in a class to the div dynamically, from the event_type_id.

So something like

<?php $id = $fields['event_type_id']->raw;?>
<div class="event_type_<?php print $id;?>">
-----rest of the fields
</div>

If you inspect the output on the page, then each row for Jane's classes will be wrapped in this div

<div class="event_type_1">

for example.

jQuery solution

Now what you do is make yourself a Drupal module that adds a bit of jQuery for when the page has loaded.

It should have a function with a selector like this

$('event_type_1').slice(1).remove();

That would remove all but the first row of Jane's classes.

Or this selector could do it

$('event_type_1:not(first-child)').remove();

CSS solution

Add a class for the view using the Class option in Advanced section of Views admin for the view display.

Then try

.view-class-added > event_type_1:not(:first-child) {
display: none;
}
0

If you think that you can do it by using php code, i.e to filter only one event among the recurring events, then you can use the 'Views_php' module to obtain the component you want as field. You just need to call the function <?php civicrm_initialize(); first and then start pulling the data you need with your code. You have many examples in online on 'how to use the views_php module?'.

Your Answer

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

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