Commit 32126161 authored by Robert Rollins's avatar Robert Rollins

Fixed up loads of issues reported by www.PAReview.sh

parent 1e130962
...@@ -23,10 +23,11 @@ Date iCal has several required dependencies, and an optional one: ...@@ -23,10 +23,11 @@ Date iCal has several required dependencies, and an optional one:
- The Feeds module is optional, but it's needed to enable import of iCal feeds - The Feeds module is optional, but it's needed to enable import of iCal feeds
from other sites. from other sites.
To install the iCalcreator library, download it from http://github.com/iCalcreator/iCalcreator To install the iCalcreator library, download it from the project's github:
using either git clone or the "Download Zip" button. Inside you'll find the file http://github.com/iCalcreator/iCalcreator
iCalcreator.class.php. Copy that file to a folder in your Drupal site named Using either git clone or the "Download Zip" button, you'll find the file
sites/all/libraries/iCalcreator. iCalcreator.class.php inside. Copy that file to a folder in your Drupal site
named sites/all/libraries/iCalcreator.
Or, if you have drush, install iCalcreator by running this command from your Or, if you have drush, install iCalcreator by running this command from your
site's root directory: site's root directory:
...@@ -50,10 +51,10 @@ the iCal Fields plugin is a bit more versatile. ...@@ -50,10 +51,10 @@ the iCal Fields plugin is a bit more versatile.
HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN
1. Go to the Manage Display page for the content type you want to export in an 1. Go to the Manage Display page for the content type you want to export in an
iCal feed. On the "Default" tab, check the box for "iCal" in the section iCal feed. On the "Default" tab, check the box for "iCal" in the section
titled "Use custom display settings for the following view modes", then click titled "Use custom display settings for the following view modes", then
Save. click Save.
2. Click the new "iCal" tab that now appears in the upper-right corner of the 2. Click the new "iCal" tab that now appears in the upper-right corner of the
Manage Display page for this content type. Manage Display page for this content type.
3. Set up the iCal view mode to contain whatever should be exported as the 3. Set up the iCal view mode to contain whatever should be exported as the
...@@ -63,10 +64,10 @@ HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN ...@@ -63,10 +64,10 @@ HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN
site's iCal feeds. site's iCal feeds.
5. Create a new View that displays the entities that you want to include in the 5. Create a new View that displays the entities that you want to include in the
iCal feed. iCal feed.
6. Add a "Feed" to the view. Change the Format to 'iCal Feed'. When you click 6. Add a "Feed" to the view. Change the Format to 'iCal Feed'. When you click
Apply from that dialog, you'll be given the option to name the calendar. This Apply from that dialog, you'll be given the option to name the calendar,
name will appear in your users' calendar clients as the calendar's title. which will appear in your users' calendar clients as the calendar's title.
7. Change the Show setting to 'iCal Entity' (rather than 'Content' or 'Fields'). 7. Change the Show setting to 'iCal Entity'.
8. In the settings for iCal Entity, select the date field that should be used 8. In the settings for iCal Entity, select the date field that should be used
as the event date for the iCal feed. Make sure that you choose a field that as the event date for the iCal feed. Make sure that you choose a field that
is a part of every entity that your View displays. Otherwise, the entities is a part of every entity that your View displays. Otherwise, the entities
...@@ -95,10 +96,10 @@ HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN ...@@ -95,10 +96,10 @@ HOW TO EXPORT AN ICAL FEED USING THE iCal Entities PLUGIN
HOW TO EXPORT AN ICAL FEED USING THE iCal Fields PLUGIN HOW TO EXPORT AN ICAL FEED USING THE iCal Fields PLUGIN
1-6.These steps are the same as above. 1-6.These steps are the same as above.
7. Add views fields for each piece of information that you want to populate your 7. Add views fields for each piece of information that you want to populate
iCal feed with. A Date field is required, and fields that will act as the your iCal feed with. A Date field is required, and fields that will act as
Title and Description of the events are reccomended. You can also include a the Title and Description of the events are reccomended. You can also
Location field. include a Location field.
8. Back in the FORMAT section, change the Show setting to 'iCal Fields'. 8. Back in the FORMAT section, change the Show setting to 'iCal Fields'.
9. In the settings for iCal Fields, choose which views fields you want to use 9. In the settings for iCal Fields, choose which views fields you want to use
for the Date, Title, Description, and Location. for the Date, Title, Description, and Location.
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* - 'summary': The title field string * - 'summary': The title field string
* - 'location': The location field string. * - 'location': The location field string.
* @param object $view * @param object $view
* The view object that is being executed to render the iCal feed. * The view object that is being executed to render the iCal feed.
* @param array $context * @param array $context
* Depending on whether this event is being constructed using the Fields or * Depending on whether this event is being constructed using the Fields or
* Entity plugins, this context array will have different keys and values. * Entity plugins, this context array will have different keys and values.
...@@ -96,7 +96,7 @@ function hook_date_ical_export_raw_event_alter(&$event, $view, $context) { ...@@ -96,7 +96,7 @@ function hook_date_ical_export_raw_event_alter(&$event, $view, $context) {
* @param object $vevent * @param object $vevent
* A reference to an iCalcreator vevent which will be exported in this feed. * A reference to an iCalcreator vevent which will be exported in this feed.
* @param object $view * @param object $view
* The view object that is being executed to render the iCal feed. * The view object that is being executed to render the iCal feed.
* @param object $event_array * @param object $event_array
* The array representation of the event that's been rendered to the $vevent. * The array representation of the event that's been rendered to the $vevent.
*/ */
...@@ -113,7 +113,7 @@ function hook_date_ical_export_vevent_alter(&$vevent, $view, $event_array) { ...@@ -113,7 +113,7 @@ function hook_date_ical_export_vevent_alter(&$vevent, $view, $event_array) {
* @param object $vcalendar * @param object $vcalendar
* A reference to the iCalcreator vcalendar object representing this feed. * A reference to the iCalcreator vcalendar object representing this feed.
* @param object $view * @param object $view
* The view object that is being executed to render the iCal feed. * The view object that is being executed to render the iCal feed.
*/ */
function hook_date_ical_export_vcalendar_alter(&$vcalendar, $view) { function hook_date_ical_export_vcalendar_alter(&$vcalendar, $view) {
...@@ -128,7 +128,7 @@ function hook_date_ical_export_vcalendar_alter(&$vcalendar, $view) { ...@@ -128,7 +128,7 @@ function hook_date_ical_export_vcalendar_alter(&$vcalendar, $view) {
* @param string $rendered_calendar * @param string $rendered_calendar
* A reference to the string containing the rendered the iCal feed. * A reference to the string containing the rendered the iCal feed.
* @param object $view * @param object $view
* The view that is being executed to render this iCal feed. * The view that is being executed to render this iCal feed.
*/ */
function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) { function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) {
...@@ -149,7 +149,7 @@ function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) { ...@@ -149,7 +149,7 @@ function hook_date_ical_export_post_render_alter(&$rendered_calendar, $view) {
* - 'fetcher_result': The FeedsFetcherResult object for this Feed. * - 'fetcher_result': The FeedsFetcherResult object for this Feed.
*/ */
function hook_date_ical_import_vcalendar_alter(&$calendar, $context) { function hook_date_ical_import_vcalendar_alter(&$calendar, $context) {
} }
/** /**
...@@ -165,14 +165,15 @@ function hook_date_ical_import_vcalendar_alter(&$calendar, $context) { ...@@ -165,14 +165,15 @@ function hook_date_ical_import_vcalendar_alter(&$calendar, $context) {
* - 'fetcher_result': The FeedsFetcherResult object for this Feed. * - 'fetcher_result': The FeedsFetcherResult object for this Feed.
*/ */
function hook_date_ical_import_component_alter(&$component, $context) { function hook_date_ical_import_component_alter(&$component, $context) {
// Example of what might be done with this alter hook // Example of what might be done with this alter hook.
if ($component->objName == 'vevent') { if ($component->objName == 'vevent') {
// Do something for vevents ... // Do something for vevents...
} }
else if ($component->objName == 'valarm') { elseif ($component->objName == 'valarm') {
// Do something different for valarms ... // Do something different for valarms...
} }
} }
/** /**
* Alter the timezone string from an imported iCal Feed. * Alter the timezone string from an imported iCal Feed.
* *
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Install, update and uninstall functions for the date_ical module. * Install, update and uninstall functions for the date_ical module.
* *
*/ */
/** /**
* Implements hook_requirements(). * Implements hook_requirements().
*/ */
...@@ -41,7 +42,7 @@ function date_ical_requirements($phase) { ...@@ -41,7 +42,7 @@ function date_ical_requirements($phase) {
} }
/** /**
* Implementation of hook_enable(). * Implements of hook_enable().
*/ */
function date_ical_enable() { function date_ical_enable() {
cache_clear_all('plugins:feeds:plugins', 'cache'); cache_clear_all('plugins:feeds:plugins', 'cache');
...@@ -53,6 +54,7 @@ function date_ical_enable() { ...@@ -53,6 +54,7 @@ function date_ical_enable() {
/** /**
* Migrates all iCal feed importers for from Date iCal 2.x to 3.0. * Migrates all iCal feed importers for from Date iCal 2.x to 3.0.
*
* <br> * <br>
* PLEASE NOTE: If any of your importers are defined by Features, you'll need * PLEASE NOTE: If any of your importers are defined by Features, you'll need
* to update their feature(s) to match. * to update their feature(s) to match.
...@@ -96,7 +98,7 @@ function date_ical_update_7300() { ...@@ -96,7 +98,7 @@ function date_ical_update_7300() {
// parser plugin being missing. We corrected that warning above, so we // parser plugin being missing. We corrected that warning above, so we
// should clear it out to avoid potential confusion. // should clear it out to avoid potential confusion.
$messages = drupal_get_messages('warning'); $messages = drupal_get_messages('warning');
foreach($messages['warning'] as $warning) { foreach ($messages['warning'] as $warning) {
// Calling drupal_get_messages() removed *every* warning from the // Calling drupal_get_messages() removed *every* warning from the
// message queue, so we need to re-issue any warnings that aren't // message queue, so we need to re-issue any warnings that aren't
// about missing Feeds plugins. // about missing Feeds plugins.
......
This diff is collapsed.
<?php <?php
/** /**
* @file * @file
* DateiCalFeedsParser is Date iCal's Feeds parser plugin. * DateiCalFeedsParser is Date iCal's Feeds parser plugin.
*/ */
class DateiCalFeedsParser extends FeedsParser { class DateiCalFeedsParser extends FeedsParser {
...@@ -44,7 +43,7 @@ class DateiCalFeedsParser extends FeedsParser { ...@@ -44,7 +43,7 @@ class DateiCalFeedsParser extends FeedsParser {
// We've got a vcalendar object created from the feed data. Now we need to // We've got a vcalendar object created from the feed data. Now we need to
// convert that vcalendar into an array of Feeds-compatible data arrays. // convert that vcalendar into an array of Feeds-compatible data arrays.
// ParserVcalendar->parse() does that. // ParserVcalendar->parse() does that.
require_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_ical') . '/libraries/ParserVcalendar.inc'); require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'date_ical') . '/libraries/ParserVcalendar.inc';
$parser = new ParserVcalendar($calendar, $source, $fetcher_result, $source->getConfigFor($this)); $parser = new ParserVcalendar($calendar, $source, $fetcher_result, $source->getConfigFor($this));
// Using the stored progress pointer (or 0 if it's not set), // Using the stored progress pointer (or 0 if it's not set),
...@@ -103,8 +102,6 @@ class DateiCalFeedsParser extends FeedsParser { ...@@ -103,8 +102,6 @@ class DateiCalFeedsParser extends FeedsParser {
/** /**
* Creates the list of mapping sources offered by DateiCalFeedsParser. * Creates the list of mapping sources offered by DateiCalFeedsParser.
*
* @return array
*/ */
public static function getiCalMappingSources() { public static function getiCalMappingSources() {
$sources = array(); $sources = array();
......
...@@ -6,25 +6,30 @@ ...@@ -6,25 +6,30 @@
*/ */
/** /**
* Plugin which creates a view on the resulting object * A Views plugin which builds an iCal VEVENT from a single node.
* and formats it as an iCal VEVENT.
*/ */
class date_ical_plugin_row_ical_entity extends views_plugin_row { class date_ical_plugin_row_ical_entity extends views_plugin_row {
// Basic properties that let the row style follow relationships. // Basic properties that let the row style follow relationships.
var $base_table = 'node'; protected $base_table = 'node';
var $base_field = 'nid'; protected $base_field = 'nid';
// Stores the nodes loaded with pre_render. // Stores the nodes loaded with pre_render.
var $entities = array(); protected $entities = array();
function init(&$view, &$display, $options = NULL) { /**
* Initialize the row plugin.
*/
public function init(&$view, &$display, $options = NULL) {
parent::init($view, $display, $options); parent::init($view, $display, $options);
$this->base_table = $view->base_table; $this->base_table = $view->base_table;
$this->base_field = $view->base_field; $this->base_field = $view->base_field;
} }
function option_definition() { /**
* Set up the options for the row plugin.
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['date_field'] = array('default' => array()); $options['date_field'] = array('default' => array());
$options['summary_field'] = array('default' => array()); $options['summary_field'] = array('default' => array());
...@@ -33,17 +38,18 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -33,17 +38,18 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
} }
/** /**
* Provide a form for setting options. * Build the form for setting the row plugin's options.
*/ */
function options_form(&$form, &$form_state) { public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
// Build the select dropdown for the date field that the user wants to use // Build the select dropdown for the Date field that the user wants to use
// to populate the date fields in VEVENTs. // to populate the date properties in VEVENTs.
$data = date_views_fields($this->base_table); $data = date_views_fields($this->base_table);
$options = array(); $options = array();
foreach ($data['name'] as $item => $value) { foreach ($data['name'] as $item => $value) {
// We only want to see one value for each field, skip '_value2', and other columns. // We only want to see one value for each field, so we need to
// skip '_value2' and other columns.
if ($item == $value['fromto'][0]) { if ($item == $value['fromto'][0]) {
$options[$item] = $value['label']; $options[$item] = $value['label'];
} }
...@@ -58,7 +64,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -58,7 +64,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
'#required' => TRUE, '#required' => TRUE,
); );
$form['instructions'] = array( $form['instructions'] = array(
// The surrounding <div> is necessary to ensure that the settings dialog expands to show everything. // The surrounding <div> ensures that the settings dialog expands.
'#prefix' => '<div style="font-size: 90%">', '#prefix' => '<div style="font-size: 90%">',
'#suffix' => '</div>', '#suffix' => '</div>',
'#markup' => t("Each item's Title and iCal view mode will be included as the SUMMARY and DESCRIPTION elements (respectively) in the VEVENTs output by this View. '#markup' => t("Each item's Title and iCal view mode will be included as the SUMMARY and DESCRIPTION elements (respectively) in the VEVENTs output by this View.
...@@ -101,18 +107,21 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -101,18 +107,21 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
); );
} }
function pre_render($values) { /**
// @TODO When the date is coming in through a relationship, the nid * Preload the list of entities which will appear in the view.
// of the view is not the right node to use, then we need the related node. *
// Need to sort out how that should be handled. * @TODO: When the date is coming in through a relationship, the nid
* of the view is not the right node to use, then we need the related node.
* Need to sort out how that should be handled.
*/
public function pre_render($values) {
// Preload each entity used in this view from the cache. // Preload each entity used in this view from the cache.
// Provides all the entity values relatively cheaply, and we don't // Provides all the entity values relatively cheaply, and we don't
// need to do it repeatedly for the same entity if there are // need to do it repeatedly for the same entity if there are
// multiple results for one entity. // multiple results for one entity.
$ids = array(); $ids = array();
foreach ($values as $row) { foreach ($values as $row) {
// Use the $id as the key so we don't create more than one value per entity. // Use the $id as the key so we create only value per entity.
$id = $row->{$this->field_alias}; $id = $row->{$this->field_alias};
// Node revisions need special loading. // Node revisions need special loading.
...@@ -140,8 +149,10 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -140,8 +149,10 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
} }
} }
function render($row) { /**
global $base_url; * Renders the entities returned by the view into event arrays.
*/
public function render($row) {
$id = $row->{$this->field_alias}; $id = $row->{$this->field_alias};
if (!is_numeric($id)) { if (!is_numeric($id)) {
return NULL; return NULL;
...@@ -157,20 +168,17 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -157,20 +168,17 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$date_fields = date_views_fields($this->base_table); $date_fields = date_views_fields($this->base_table);
$date_info = $date_fields['name'][$this->options['date_field']]; $date_info = $date_fields['name'][$this->options['date_field']];
$field_name = str_replace(array('_value', '_value2'), '', $date_info['real_field_name']); $field_name = str_replace(array('_value', '_value2'), '', $date_info['real_field_name']);
$table_name = $date_info['table_name'];
$delta_field = $date_info['delta_field']; $delta_field = $date_info['delta_field'];
$is_field = $date_info['is_field']; $is_field = $date_info['is_field'];
// This is ugly and hacky but I can't figure out any generic way to // Sometimes the timestamp is actually the revision timestamp.
// recognize that the node module is going to give some the revision timestamp
// a different field name on the entity than the actual column name in the database.
if ($this->view->base_table == 'node_revision' && $field_name == 'timestamp') { if ($this->view->base_table == 'node_revision' && $field_name == 'timestamp') {
$field_name = 'revision_timestamp'; $field_name = 'revision_timestamp';
} }
if (!isset($entity->$field_name)) { if (!isset($entity->$field_name)) {
// This entity doesn't have the date property that the user configured // This entity doesn't have the date property that the user configured
// our view to use. We can't do anything with it // our view to use. We can't do anything with it.
return NULL; return NULL;
} }
$date_field = $entity->$field_name; $date_field = $entity->$field_name;
...@@ -193,7 +201,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -193,7 +201,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
if (!empty($date_field['value'])) { if (!empty($date_field['value'])) {
$start = new DateObject($date_field['value'], $date_field['timezone_db']); $start = new DateObject($date_field['value'], $date_field['timezone_db']);
if (array_key_exists('value2', $date_field)) { if (!empty($date_field['value2'])) {
$end = new DateObject($date_field['value2'], $date_field['timezone_db']); $end = new DateObject($date_field['value2'], $date_field['timezone_db']);
} }
else { else {
...@@ -244,7 +252,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -244,7 +252,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
} }
elseif ($location_info['type'] == 'addressfield') { elseif ($location_info['type'] == 'addressfield') {
$locations = array(); $locations = array();
foreach($location_field as $key => $loc) { foreach ($location_field as $key => $loc) {
if ($loc && !in_array($key, array('first_name', 'last_name'))) { if ($loc && !in_array($key, array('first_name', 'last_name'))) {
$locations[] = $loc; $locations[] = $loc;
} }
...@@ -257,11 +265,12 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -257,11 +265,12 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
} }
} }
// Create the rendered display using the display settings from the 'iCal' view mode. // Create the rendered event using the display settings from the
// iCal view mode.
$rendered_array = entity_view($this->entity_type, array($entity), 'ical', $this->language, TRUE); $rendered_array = entity_view($this->entity_type, array($entity), 'ical', $this->language, TRUE);
$data = array( $data = array(
'description' => drupal_render($rendered_array), 'description' => drupal_render($rendered_array),
'summary' => entity_label($this->entity_type, $entity) 'summary' => entity_label($this->entity_type, $entity),
); );
if (!empty($this->options['summary_field']) && $this->options['summary_field'] != 'default_title') { if (!empty($this->options['summary_field']) && $this->options['summary_field'] != 'default_title') {
$summary_fields = date_ical_get_summary_fields(); $summary_fields = date_ical_get_summary_fields();
...@@ -281,7 +290,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -281,7 +290,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
} }
elseif ($summary_info['type'] == 'taxonomy_term_reference') { elseif ($summary_info['type'] == 'taxonomy_term_reference') {
$terms = taxonomy_term_load_multiple($items); $terms = taxonomy_term_load_multiple($items);
// Make sure that there are terms that were loaded // Make sure that there are terms that were loaded.
if ($terms) { if ($terms) {
$term_names = array(); $term_names = array();
foreach ($terms as $term) { foreach ($terms as $term) {
...@@ -293,7 +302,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -293,7 +302,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
else { else {
$summary = trim($summary_field['value']); $summary = trim($summary_field['value']);
} }
$data['summary'] = $summary ? $summary : $data['summary']; $data['summary'] = $summary ? $summary : $data['summary'];
} }
} }
// Allow other modules to alter the HTML of the Summary and Description, // Allow other modules to alter the HTML of the Summary and Description,
...@@ -320,8 +329,8 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -320,8 +329,8 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
$event['location'] = $location; $event['location'] = $location;
} }
// For this event's UID, use either the date_id generated by the Date module, or the // For this event's UID, use either the date_id generated by the Date
// event page's URL, if the date_id isn't available. // module, or the event page's URL if the date_id isn't available.
$event['uid'] = !empty($entity->date_id) ? $entity->date_id[0] : $event['url']; $event['uid'] = !empty($entity->date_id) ? $entity->date_id[0] : $event['url'];
// If we are using a repeat rule (and not just multi-day events) we // If we are using a repeat rule (and not just multi-day events) we
...@@ -342,7 +351,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row { ...@@ -342,7 +351,7 @@ class date_ical_plugin_row_ical_entity extends views_plugin_row {
if (isset($entity->changed)) { if (isset($entity->changed)) {
$event['last-modified'] = new DateObject($entity->changed, 'UTC'); $event['last-modified'] = new DateObject($entity->changed, 'UTC');
} }
else if (isset($entity->created)) { elseif (isset($entity->created)) {
// If changed is unset, but created is, use that for last-modified. // If changed is unset, but created is, use that for last-modified.
$event['last-modified'] = new DateObject($entity->created, 'UTC'); $event['last-modified'] = new DateObject($entity->created, 'UTC');
} }
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
*/ */
/** /**
* Plugin which creates a view on the resulting object * A Views plugin which builds an iCal VEVENT from a views row with Fields.
* and formats it as an iCal VEVENT.
*/ */
class date_ical_plugin_row_ical_fields extends views_plugin_row { class date_ical_plugin_row_ical_fields extends views_plugin_row {
function option_definition() { /**
* Set up the options for the row plugin.
*/
public function option_definition() {
$options = parent::option_definition(); $options = parent::option_definition();
$options['date_field'] = array('default' => ''); $options['date_field'] = array('default' => '');
$options['title_field'] = array('default' => ''); $options['title_field'] = array('default' => '');
...@@ -21,7 +23,10 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -21,7 +23,10 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
return $options; return $options;
} }
function options_form(&$form, &$form_state) { /**
* Build the form for setting the row plugin's options.
*/
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state); parent::options_form($form, $form_state);
$all_field_labels = $this->display->handler->get_field_labels(); $all_field_labels = $this->display->handler->get_field_labels();
$date_field_labels = $this->get_date_field_candidates($all_field_labels); $date_field_labels = $this->get_date_field_candidates($all_field_labels);
...@@ -29,7 +34,7 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -29,7 +34,7 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
$text_field_label_options = array_merge(array('' => t('- None -')), $all_field_labels); $text_field_label_options = array_merge(array('' => t('- None -')), $all_field_labels);
$form['instructions'] = array( $form['instructions'] = array(
// The surrounding <div> is necessary to ensure that the settings dialog expands to show everything. // The surrounding <div> ensures that the settings dialog expands.
'#prefix' => '<div style="font-size: 90%">', '#prefix' => '<div style="font-size: 90%">',
'#suffix' => '</div>', '#suffix' => '</div>',
'#markup' => t("Once you've finished setting up the fields for this View, you may want to return to this dialog to set the Date field."), '#markup' => t("Once you've finished setting up the fields for this View, you may want to return to this dialog to set the Date field."),
...@@ -84,7 +89,10 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -84,7 +89,10 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
); );
} }
function pre_render($result) { /**
* Set up the environment for the render() function.
*/
public function pre_render($result) {
// Get the language for this view. // Get the language for this view.
$this->language = $this->display->handler->get_option('field_language'); $this->language = $this->display->handler->get_option('field_language');
$substitutions = views_views_query_substitutions($this->view); $substitutions = views_views_query_substitutions($this->view);
...@@ -95,10 +103,9 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -95,10 +103,9 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
} }
/** /**
* Returns an Event array based on the query result from the view whose * Returns an Event array row in the query with index: $row->index.
* index is $row->index.
*/ */
function render($row) { public function render($row) {
$date_field_name = $this->options['date_field']; $date_field_name = $this->options['date_field'];
// If this view is set to use the first populated date field, check each // If this view is set to use the first populated date field, check each
...@@ -153,7 +160,7 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -153,7 +160,7 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
if (isset($entity->changed)) { if (isset($entity->changed)) {
$event['last-modified'] = new DateObject($entity->changed, 'UTC'); $event['last-modified'] = new DateObject($entity->changed, 'UTC');
} }
else if (isset($entity->created)) { elseif (isset($entity->created)) {
// If changed is unset, but created is, use that for last-modified. // If changed is unset, but created is, use that for last-modified.
$event['last-modified'] = new DateObject($entity->created, 'UTC'); $event['last-modified'] = new DateObject($entity->created, 'UTC');
} }
...@@ -238,8 +245,8 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -238,8 +245,8 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
* *
* @return array * @return array
* The normalized array. * The normalized array.
*/ */
function get_row_date($row, $date_field_name) { protected function get_row_date($row, $date_field_name) {
$start = NULL; $start = NULL;
$end = NULL; $end = NULL;
$rrule = NULL; $rrule = NULL;
...@@ -315,24 +322,27 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -315,24 +322,27 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
} }
/** /**
* Filter the list of views fields down to only those which are supported date-type fields. * Filter the list of views fields down to only supported date-type fields.
* At this time, the supported date-type fields are timestamps and the three Date fields. *
* The supported date-type fields are timestamps and the three Date fields.
* *
* @param array $view_fields * @param array $view_fields
* An key=>value array @see views_plugin_display::get_field_labels(). * An associative array like views_plugin_display::get_field_labels().
* *
* @return array * @return array
* An key=>value array (alias => label) of date fields. * An associative array (alias => label) of date fields.
*/ */
function get_date_field_candidates($view_fields) { protected function get_date_field_candidates($view_fields) {
$handlers = $this->display->handler->get_handlers('field'); $handlers = $this->display->handler->get_handlers('field');
$field_candidates = array(); $field_candidates = array();
// These are Date, Date (ISO format), and Date (Unix timestamp).
$date_fields = array('datetime', 'date', 'datestamp');
foreach ($view_fields as $alias => $label) { foreach ($view_fields as $alias => $label) {
$handler = $handlers[$alias]; $handler_class = get_class($handlers[$alias]);
if (get_class($handler) == 'views_handler_field_date' if ($handler_class == 'views_handler_field_date'
|| (get_class($handler) == 'views_handler_field_field' && || ($handler_class == 'views_handler_field_field'
// These are Date, Date (ISO format), and Date (Unix timestamp). && in_array($handlers[$alias]->field_info['type'], $date_fields))) {
in_array($handler->field_info['type'], array('datetime', 'date', 'datestamp')))) {
$field_candidates[$alias] = $label; $field_candidates[$alias] = $label;
} }
} }
...@@ -347,9 +357,9 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row { ...@@ -347,9 +357,9 @@ class date_ical_plugin_row_ical_fields extends views_plugin_row {
* @param string $field_id * @param string $field_id
* The ID assigned to the required field in the display. * The ID assigned to the required field in the display.
* *
* @see views_plugin_style::get_field(). * @see views_plugin_style::get_field()
*/ */
function get_field($index, $field_id) { protected function get_field(