1

I am trying to filter my view by using a date range so that it shows all the activities for an event for which Activity Start >= Event End & Activity End <= Event Start.

To do this I have set up a view to show all the activities with a contextual filter to allow the event dates to be accessed.

I added the 4 fields to my table: Activity Start, Activity End, Event Start, and Event End.

My $Row data when adding a Global:PHP filter criteria now has the four variables accessible to carry out the comparison above.

  • Activity Start: $Row->field_start_date_and_time
  • Activity End: $Row->field_start_date_and_time_1
  • Event Start: $Row->field_start_date_and_time_2
  • Event End: $Row->field_start_date_and_time_3

I am using views_php 7.x-2.x-dev, which fixed the issue of $row not populating.

I am trying to write the above comparison in PHP and I am not getting what I expected. (I thought this would be the easy bit; I have spent a long time getting this far.)

However, it appears that the date format is not being read correctly as it is not returning any result. I have done some research which would indicate it might need to be in Unix timecode to do the comparison accurately.

Is this correct? What does the code look like to do it?

1 Answer 1

0

You really shouldn't use PHP in Views have you seen the warning on the module page:

While this module allows you to directly use PHP inside views which may be useful for quick and easy solutions, it is highly advisable to use regular handlers and plugins when available (or even to create one yourself). Take note that filtering and sorting a view using PHP always has a considerable performance impact.

Also this post has instructions how to write a Views handler or Plugin.

You should be able to achieve what you're trying to do with a combination of contextual filters, normal filters and relationships.

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.