Use case
It'd be useful to be able to build calendar type views with base tables other than "node": user-based, comment-based, or custom-data-type based calendar views.

I'm working on a project that uses a custom data table instead of the node system but needs to display that custom data in a calendar view.

To get it working, a few small changes are required in both the Calandar and Date modules.

Patch
Attached is a starter patch for review. It enables user-based and comment-based calendar views on the date module side of things.

I'll post a link to the Calendar patch in the comments once it's posted.

Notes
I haven't played around with the "The flexible date filter" field (date_api.views.inc), but would it useful to expand it's scope to non-node base-table views as well?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

setvik’s picture

Component: Code » Date API

To get this working, you also need to install the following Calendar module patch:

http://drupal.org/node/385886

Finally, if you want to enable calendar views for views using a base-table other than node, comments, or users, in addition to the date and calendar patches, you'll need to define a 'date_argument' field in your module's hook_views_data() like the following (replacing YOUR_CUSTOM_BASE_TABLE with your table name):

   $data['YOUR_CUSTOM_BASE_TABLE']['date_argument'] = array(
     'group' => t('Date'),
     'title' => t('Date'),
     'help' => t('Filter any Views date field by a date argument'),
     'argument' => array(
       'handler' => 'date_api_argument_handler',
       'empty name field' => t('Undated'),
     ),
   );
 
KarenS’s picture

I'd like to get other tables working, too, but don't want to add it in until I quit getting bug reports on the current code.

I'm happy to have someone working on a fix for this, I just won't commit anything right away.

setvik’s picture

No worries at all.

I can't imagine how busy you must be maintaining some of the largest modules in Drupal. A huge huge thanks for the modules you've made available! CCK, Date, and Calendar have been a major lifesaver.

I'm using this in a project, so I'll keep this patch updated in case you decide to include it later on.

setvik’s picture

re-rolled patch against 6.x-2.0

Now supports using the date filter in non-node base tables

KarenS’s picture

Status: Needs review » Fixed

OK, added this in and did some testing to be sure it would work. This is great! Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

marqpdx’s picture

Status: Closed (fixed) » Active

hi,

i have both patches applied, and am now trying to get a CiviEvents date field to serve as the argument.

i have put the following in my own module, as well as in the civicrm.views.inc but neither seems to make it so the view allows a CiviEvent date to serve as the argument:

	$data['civicrm_event']['date_argument'] = array(
		'group' => t('Date'),
		'title' => t('Date'),
		'help' => t('Filter any Views date field by a date argument'),
		'argument' => array(
		  'handler' => 'date_api_argument_handler',
		  'empty name field' => t('Undated'),
		 ),
   );

Should this work?

thanks,
m

bigjim’s picture

The code in #7 only tells the calendar module that civicrm would like to have the Date option in it's arguments when you create a CiviCRM Event view. There is still another step which is to write a date api argument handler for CiviCRM dates. Given that CiviCRM uses the datetime format in lieu of the int timestamp (i.e. 2009-05-01 14:00:00 vs 1234567890) used in Drupal the CiviCRM project wrote a handler to call strtotime() and convert the format and deal timezone issues (well timezone issues will be dealt with in a patch submitted this week). That handler, civicrm_handler_field_datetime, is a child implementation of views_handler_field_date

All that said I started to write a handler and have run up against a brick wall in the _date_api_fields() function. In order to call a custom module's hook_date_api_fields function the date field for the module has to use views_handler_field_date which, due to the aforementioned issue, the civicrm date fields cannot use.

To solve this I would like to propose the following change to line 47 of the field_api_date.inc file. Basically I propose using the is_a() function to determine if the handler is a child of the views_handler_field_date class. This function is php4 compliant. It was deprecated in 5.0-5.2 and undeprecated (is that a word:)) in 5.3

form
[code]
elseif ($handler_name == 'views_handler_field_date') {
[/code]

to
[code]
elseif (is_a($handler,'views_handler_field_date')) {
[/code]

I have yet to get any remaining issues fixed, but I do know this one will be a deal killer for CiviCRM Event/Calendar integration.

KarenS’s picture

I'm not familiar with the is_a() function, but I am totally in agreement that there should be a way for you to use a custom handler, so I'm open to a patch if you want to write one.

KarenS’s picture

But I would also be curious what you had to override in the basic handler to get it to work. Maybe the handler needs an update to make it more flexible.

bigjim’s picture

Yea I realized not too long after posting this that you are likely correct about not needed to overwrite the handler. I had created the custom handler in an attempt to get around another issue, which I don't think i an issue any more.

I'll submit a patch, I'm assuming I should start another issue as the above patch is already incorporated into the 6.x branch?

bigjim’s picture

here's the patch for #8
http://drupal.org/node/453688

marqpdx’s picture

Just to let everyone know, huge props are due jalama for pulling this together.
it works great!!

we now have CiviEvents showing up in the Drupal calendar using this patching info:
http://forum.civicrm.org/index.php/topic,6320.0.html

Very slick.
thanks again,
m

bigjim’s picture

Karen,

I wanted to ensure that I answered your question for #10.

On the argument handler you are correct I did not need to override the basic handler provided by the DATE API.

For the field handler CiviCRM needs to override the basic handler because of 2 reasons.

1.) The basic handler is expecting an int timestamp and civi stores dates using the datetime format, essentially we are running the date through the strtotime() function.
2.) Civi does not have a timezone concept. Consequently Drupal is translating the time of events to be based on that of the timezone for the server, which is rarely correct.

Sorry if I left any confusion and wasted your time, I know you are crazy busy.

marqpdx’s picture

hi,
i just wanted to know if this has been committed to HEAD for D6? it does work as expected, and has allowed me to have CiviEvents showing in the Drupal calendar.
thanks,
m

KarenS’s picture

Status: Active » Fixed

The original patch was committed some time back. The re-opening is for another patch on another thread, so I'm re-closing this issue.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.