I would like to be able to show assignments by due date in my Calendar module view. However the Calendar module only displays date fields that are registered via hook_date_api_fields().
Looking at the CVS repository it appears that the code is being reorganized, and the file I modified to add this support (gradebookapi.views.inc) has been removed. So rather than providing a diff, here is the code necessary to allow the Calendar module to display assignments by due date:
/**
* Implementation of hook_views_data().
*/
function gradebookapi_views_data() {
$data = array();
$data['gradebookapi_assignment']['table']['group'] = t('Gradebook Assignment');
// tables + fields that can be used for SQL Joins
$data['gradebookapi_assignment']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
);
$data['gradebookapi_assignment']['due_date'] = array(
'title' => t('Due Date'),
'help' => t('Date on which the Gradebook Assignment is due.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['gradebookapi_assignment']['publish_date'] = array(
'title' => t('Publish Date'),
'help' => t('Date on which the Gradebook Assignment was published.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
/**
* Implementation of hook_date_api_fields().
*/
function gradebookapi_date_api_fields($field) {
if ($field == 'gradebookapi_assignment.publish_date') {
return array(
'sql_type' => DATE_UNIX, // DATE_ISO or DATE_UNIX or DATE_DATETIME
'tz_handling' => 'site', // 'site' or 'none' or 'date' or 'utc'
);
}
if ($field == 'gradebookapi_assignment.due_date') {
return array(
'sql_type' => DATE_UNIX, // DATE_ISO or DATE_UNIX or DATE_DATETIME
'tz_handling' => 'site', // 'site' or 'none' or 'date' or 'utc'
);
}
}
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | gradebookapi-calendar-view.patch | 857 bytes | lxs |
Comments
Comment #1
marqpdx commenteddid this work for you. we have tried something similar, and it won't accept our field as a date for the calendar display style in the view.
thanks!
m
Comment #2
MGN commented@lxs. Thanks for this contribution! I think this could be very helpful.
The file you are looking for (gradebookapi.views.inc) is in the cvs repository under the DRUPAL-6--2 branch (http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/gradebook/g...).
If you can submit a patch, adding your date_api_fields function, I would be happy to test it out and commit it after its been tested.
Comment #3
lxs commentedYeah, using my code on a test site and the assignments show up in the calendar. In case module versions matter I'm using:
drupal-6.11 (6.10 worked too)
date-6.x-2.1
calendar-6.x-2.1
views-6.x-2.5
Once you've applied that patch you can test it by cloning the calendar view that comes with the calendar module. Then edit the Date: Date argument, uncheck Node: Updated date, and check Gradebook Assignment: Due Date under Date field(s). I don't remember having to clear any caches to get it working but if the gradebook date doesn't show up you might try the Views cache and the Drupal cache.
If your calendar is already displaying other dates you can leave them checked. My calendar is a mix of assignments and class events (a node with a cck date field).
Comment #4
lxs commentedHere's a patch.
Comment #5
MGN commentedComment #6
MGN commentedThanks lxs! Committed to 6.x-2.x-dev.