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?
Comment | File | Size | Author |
---|---|---|---|
#4 | date.non-node-base-tables.patch | 2.91 KB | setvik |
date.non-node-base-tables.patch | 3.25 KB | setvik | |
Comments
Comment #1
setvik CreditAttribution: setvik commentedTo 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):
Comment #2
KarenS CreditAttribution: KarenS commentedI'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.
Comment #3
setvik CreditAttribution: setvik commentedNo 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.
Comment #4
setvik CreditAttribution: setvik commentedre-rolled patch against 6.x-2.0
Now supports using the date filter in non-node base tables
Comment #5
KarenS CreditAttribution: KarenS commentedOK, added this in and did some testing to be sure it would work. This is great! Thanks!
Comment #7
marqpdx CreditAttribution: marqpdx commentedhi,
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:
Should this work?
thanks,
m
Comment #8
bigjim CreditAttribution: bigjim commentedThe 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.
Comment #9
KarenS CreditAttribution: KarenS commentedI'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.
Comment #10
KarenS CreditAttribution: KarenS commentedBut 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.
Comment #11
bigjim CreditAttribution: bigjim commentedYea 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?
Comment #12
bigjim CreditAttribution: bigjim commentedhere's the patch for #8
http://drupal.org/node/453688
Comment #13
marqpdx CreditAttribution: marqpdx commentedJust 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
Comment #14
bigjim CreditAttribution: bigjim commentedKaren,
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.
Comment #15
marqpdx CreditAttribution: marqpdx commentedhi,
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
Comment #16
KarenS CreditAttribution: KarenS commentedThe original patch was committed some time back. The re-opening is for another patch on another thread, so I'm re-closing this issue.