Commit 3aecc3c2 authored by Vlad Pavlovic's avatar Vlad Pavlovic

Issues [#1931020] and [#1935820]: Allow custom fields for summary. Fix...

Issues [#1931020] and [#1935820]: Allow custom fields for summary. Fix repeating events causing duplicates. Add @file to DateIcalFeedsParser.inc
parent 875715bb
......@@ -150,7 +150,6 @@ function date_ical_feeds_plugins() {
return $info;
}
/**
* Implements hook_feeds_processor_targets_alter().
*
......@@ -369,3 +368,80 @@ function _date_ical_get_location_fields($base = 'node') {
cache_set($cid, $fields, 'cache_views');
return $fields;
}
/**
* Identify all potential fields that could populate the custom SUMMARY field
*/
function date_ical_get_summary_fields($base = 'node', $reset = FALSE) {
static $fields = array();
$empty = array('name' => array(), 'alias' => array());
if (empty($fields[$base]) || $reset) {
$cid = 'date_ical_summary_fields_' . $base;
if (!$reset && $cached = cache_get($cid, 'cache_views')) {
$fields[$base] = $cached->data;
}
else {
$fields[$base] = _date_ical_get_summary_fields($base);
}
}
// Make sure that empty values will be arrays in the expected format.
return !empty($fields) && !empty($fields[$base]) ? $fields[$base] : $empty;
}
/**
* Identify all potential SUMMARY fields.
* This is a cut down version of _date_views_fields() from date_views_fields.inc
* in date_views module.
*
* @return
* array with fieldname, type, and table.
* @see
* date_views_date_views_fields(), which implements hook_date_views_fields()
* for the core date fields.
*/
function _date_ical_get_summary_fields($base = 'node') {
// Make sure $base is never empty.
if (empty($base)) {
$base = 'node';
}
$cid = 'date_ical_summary_fields_' . $base;
cache_clear_all($cid, 'cache_views');
// Iterate over all the fields that Views knows about.
$all_fields = date_views_views_fetch_fields($base, 'field');
$fields = array();
foreach ($all_fields as $alias => $val) {
$name = $alias;
$tmp = explode('.', $name);
$field_name = $tmp[1];
$table_name = $tmp[0];
// Skip unsupported field types and fields that weren't defined through
// the Field module.
$info = field_info_field($field_name);
if (!$info || !in_array($info['type'], array('text', 'node_reference', 'taxonomy_term_reference'))) {
continue;
}
// Build an array of the field info that we'll need.
$alias = str_replace('.', '_', $alias);
$fields['name'][$name] = array(
'label' => "{$val['group']}: {$val['title']} ($field_name)",
'table_name' => $table_name,
'field_name' => $field_name,
'type' => $info['type'],
);
// These are here only to make this $field array conform to the same format
// as the one returned by _date_views_fields(). They're probably not needed,
// but I thought that consistency would be a good idea.
$fields['name'][$name]['real_field_name'] = $field_name;
$fields['alias'][$alias] = $fields['name'][$name];
}
cache_set($cid, $fields, 'cache_views');
return $fields;
}
<?php
/**
* @file
* Basic classes.
*/
......
......@@ -65,6 +65,23 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
Please note that HTML will be stripped from the output (link URLs will become footnotes), to comply with iCal standards."),
);
// Build the select dropdown for the text/node_reference field that the user
// wants to use to (optionally) populate the SUMMARY.
$summary_fields = date_ical_get_summary_fields($this->base_table);
$summary_options = array('default_title' => t('- Default Title -'));
foreach ($summary_fields['name'] as $item => $value) {
$summary_options[$item] = $value['label'];
}
$form['summary_field'] = array(
'#type' => 'select',
'#title' => t('SUMMARY field'),
'#options' => $summary_options,
'#default_value' => $this->options['summary_field'],
'#description' => t('You may optionally change the SUMMARY component for each event in the iCal output.
Choose which text, taxonomy term reference or Node Reference field you would like to be output as the SUMMARY.
If using a Node Reference, the Title of the referenced node will be used.'),
);
// Build the select dropdown for the text/node_reference field that the user
// wants to use to (optionally) populate the LOCATION.
$location_fields = date_ical_get_location_fields($this->base_table);
......@@ -239,7 +256,38 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
'description' => drupal_render($rendered_array),
'summary' => entity_label($this->entity_type, $entity)
);
if (!empty($this->options['summary_field']) && $this->options['summary_field'] != 'default_title') {
$summary_fields = date_ical_get_summary_fields();
$summary_info = $summary_fields['name'][$this->options['summary_field']];
$summary_field_name = $summary_info['real_field_name'];
// Only attempt this is the entity actually has this field.
$items = field_get_items($this->entity_type, $entity, $summary_field_name);
$summary = '';
if ($items) {
$summary_field = $items[$delta];
if ($summary_info['type'] == 'node_reference') {
// Make sure this Node Reference actually references a node.
if ($summary_field['nid']) {
$node = node_load($summary_field['nid']);
$summary = check_plain($node->title);
}
}
elseif ($summary_info['type'] == 'taxonomy_term_reference') {
$terms = taxonomy_term_load_multiple($items);
// Make sure that there are terms that were loaded
if ($terms) {
foreach ($terms as $term) {
$summary .= check_plain($term->name) . ', ';
}
}
$summary = trim($summary);
}
else {
$summary = check_plain($summary_field['value']);
}
$data['summary'] = ($summary)? $summary : $data['summary'];
}
}
// Allow other modules to alter the HTML of the Summary and Description,
// before it gets converted to iCal-compliant plaintext. This allows users
// to set up a newline between fields, for instance.
......@@ -265,6 +313,11 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$event['location'] = $location;
}
// If we are using a repeat rule (and not just multi-day events)
// we remove the item from the entities.
if ($event['rrule']) {
$this->entities[$id] = NULL;
}
// Pull the 'changed' date from the entity, so that subscription clients can tell if the event has been updated.
// According to the iCal standard, LAST-MODIFIED must be UTC. Fortunately, Drupal stores timestamps in the DB
// as UTC, so we just need to specify that UTC be used rather than the server's local timezone.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment