updated date pathauto addressfield honeypot features modules
This commit is contained in:
@@ -12,9 +12,9 @@ files[] = includes/date_views_filter_handler_simple.inc
|
||||
files[] = includes/date_views.views.inc
|
||||
files[] = includes/date_views_plugin_pager.inc
|
||||
|
||||
; Information added by Drupal.org packaging script on 2014-07-29
|
||||
version = "7.x-2.8"
|
||||
; Information added by Drupal.org packaging script on 2015-09-08
|
||||
version = "7.x-2.9"
|
||||
core = "7.x"
|
||||
project = "date"
|
||||
datestamp = "1406653438"
|
||||
datestamp = "1441727353"
|
||||
|
||||
|
@@ -28,3 +28,27 @@ function date_views_uninstall() {
|
||||
variable_del('date_views_week_format_with_year');
|
||||
variable_del('date_views_week_format_without_year');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default date views variables.
|
||||
*/
|
||||
function date_views_update_7200() {
|
||||
if (!variable_get('date_views_month_format_with_year', FALSE)) {
|
||||
variable_set('date_views_month_format_with_year', 'F Y');
|
||||
}
|
||||
if (!variable_get('date_views_month_format_without_year', FALSE)) {
|
||||
variable_set('date_views_month_format_without_year', 'F');
|
||||
}
|
||||
if (!variable_get('date_views_day_format_with_year', FALSE)) {
|
||||
variable_set('date_views_day_format_with_year', 'l, F j, Y');
|
||||
}
|
||||
if (!variable_get('date_views_day_format_without_year', FALSE)) {
|
||||
variable_set('date_views_day_format_without_year', 'l, F j');
|
||||
}
|
||||
if (!variable_get('date_views_week_format_with_year', FALSE)) {
|
||||
variable_set('date_views_week_format_with_year', 'F j, Y');
|
||||
}
|
||||
if (!variable_get('date_views_week_format_without_year', FALSE)) {
|
||||
variable_set('date_views_week_format_without_year', 'F j');
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,9 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Date Views module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
@@ -11,7 +15,7 @@ function date_views_menu() {
|
||||
'description' => 'Configure settings for date views.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('date_views_settings'),
|
||||
'access arguments' => array('administer site configuration '),
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
);
|
||||
|
||||
@@ -86,13 +90,30 @@ function date_views_theme() {
|
||||
'file' => 'theme.inc',
|
||||
'path' => "$path/theme",
|
||||
);
|
||||
return array(
|
||||
'date_nav_title' => $base + array('variables' => array('granularity' => NULL, 'view' => NULL, 'link' => NULL, 'format' => NULL)),
|
||||
'date_views_filter_form' => $base + array('template' => 'date-views-filter-form', 'render element' => 'form'),
|
||||
'date_calendar_day' => $base + array('variables' => array('date' => NULL)),
|
||||
|
||||
return array(
|
||||
'date_nav_title' => $base + array(
|
||||
'variables' => array(
|
||||
'granularity' => NULL,
|
||||
'view' => NULL,
|
||||
'link' => NULL,
|
||||
'format' => NULL,
|
||||
),
|
||||
),
|
||||
'date_views_filter_form' => $base + array(
|
||||
'template' => 'date-views-filter-form',
|
||||
'render element' => 'form',
|
||||
),
|
||||
'date_calendar_day' => $base + array(
|
||||
'variables' => array(
|
||||
'date' => NULL,
|
||||
),
|
||||
),
|
||||
'date_views_pager' => $base + array(
|
||||
'variables' => array('plugin' => NULL, 'input' => NULL),
|
||||
'variables' => array(
|
||||
'plugin' => NULL,
|
||||
'input' => NULL,
|
||||
),
|
||||
// Register a pattern so that it can work like all views templates.
|
||||
'pattern' => 'date_views_pager__',
|
||||
'template' => 'date-views-pager',
|
||||
@@ -100,6 +121,9 @@ function date_views_theme() {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function date_views_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
@@ -119,7 +143,7 @@ function date_views_views_fetch_fields($base, $type) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify all potential date/timestamp fields and cache the data.
|
||||
* Identify all potential date/timestamp fields and cache the data.
|
||||
*/
|
||||
function date_views_fields($base = 'node', $reset = FALSE) {
|
||||
static $fields = array();
|
||||
@@ -141,8 +165,8 @@ function date_views_fields($base = 'node', $reset = FALSE) {
|
||||
|
||||
/**
|
||||
* Implements hook_date_views_entities().
|
||||
* Map extra Views tables to the entity that holds its date fields,
|
||||
* needed for Views tables other than the primary tables identified in entity_info().
|
||||
*
|
||||
* Map extra Views tables to the entity that holds its date fields, needed for Views tables other than the primary tables identified in entity_info().
|
||||
*/
|
||||
function date_views_date_views_extra_tables() {
|
||||
return array(
|
||||
@@ -151,14 +175,13 @@ function date_views_date_views_extra_tables() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to map entity types to the Views base table they use,
|
||||
* to make it easier to infer the entity type from a base table.
|
||||
* Helper function to map entity types to the Views base table they use, to make it easier to infer the entity type from a base table.
|
||||
*
|
||||
* Views has a new handler called views_handler_field_entity() that loads
|
||||
* entities, and you can use something like the following to get the
|
||||
* entity type from a view, but not all our base tables contain the
|
||||
* entity information we need, (i.e. revisions) so it won't work here
|
||||
* and we resort to creating information from entity_get_info().
|
||||
* Views has a new handler called views_handler_field_entity() that loads entities.
|
||||
*
|
||||
* And you can use something like the following to get the entity type from a view, but not all our base tables contain the entity information we need, (i.e. revisions).
|
||||
*
|
||||
* So it won't work here and we resort to creating information from entity_get_info().
|
||||
*
|
||||
* // A method to get the entity type for a base table.
|
||||
* $table_data = views_fetch_data($base_table);
|
||||
@@ -193,11 +216,7 @@ function date_views_base_tables() {
|
||||
/**
|
||||
* Implements hook_date_views_fields().
|
||||
*
|
||||
* All modules that create custom fields that use the
|
||||
* 'views_handler_field_date' handler can provide
|
||||
* additional information here about the type of
|
||||
* date they create so the date can be used by
|
||||
* the Date API views date argument and date filter.
|
||||
* All modules that create custom fields that use the 'views_handler_field_date' handler can provide additional information here about the type of date they create so the date can be used by the Date API views date argument and date filter.
|
||||
*/
|
||||
function date_views_date_views_fields($field) {
|
||||
$values = array(
|
||||
@@ -263,12 +282,15 @@ function date_pager_url($view, $date_type = NULL, $date_arg = NULL, $force_view_
|
||||
case 'year':
|
||||
$args[$pos] = date_pad($view->date_info->year, 4);
|
||||
break;
|
||||
|
||||
case 'week':
|
||||
$args[$pos] = date_pad($view->date_info->year, 4) . '-W' . date_pad($view->date_info->week);
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
$args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month) . '-' . date_pad($view->date_info->day);
|
||||
break;
|
||||
|
||||
default:
|
||||
$args[$pos] = date_pad($view->date_info->year, 4) . '-' . date_pad($view->date_info->month);
|
||||
break;
|
||||
@@ -298,9 +320,14 @@ function date_pager_url($view, $date_type = NULL, $date_arg = NULL, $force_view_
|
||||
// if they use exposed filters.
|
||||
return url($view->get_url($args), array(
|
||||
'query' => date_views_querystring($view),
|
||||
'absolute' => $absolute));
|
||||
'absolute' => $absolute,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifier of a date block.
|
||||
*/
|
||||
function date_block_identifier($view) {
|
||||
if (!empty($view->block_identifier)) {
|
||||
return $view->block_identifier;
|
||||
@@ -311,12 +338,9 @@ function date_block_identifier($view) {
|
||||
/**
|
||||
* Implements hook_field_views_data_alter().
|
||||
*
|
||||
* Create a Views field for each date column we care about
|
||||
* to supplement the generic 'entity_id' and 'revision_id'
|
||||
* fields that are automatically created.
|
||||
* Create a Views field for each date column we care about to supplement the generic 'entity_id' and 'revision_id' fields that are automatically created.
|
||||
*
|
||||
* Also use friendlier labels to distinguish the start date
|
||||
* and end date in listings (for fields that use both).
|
||||
* Also use friendlier labels to distinguish the start date and end date in listings (for fields that use both).
|
||||
*/
|
||||
function date_views_field_views_data_alter(&$result, $field, $module) {
|
||||
if ($module == 'date') {
|
||||
@@ -336,8 +360,8 @@ function date_views_field_views_data_alter(&$result, $field, $module) {
|
||||
$result[$table][$column]['field']['is date'] = TRUE;
|
||||
// Not sure yet if we still need a custom field handler in D7 now that custom formatters are available.
|
||||
// Might still need it to handle grouping of multiple value dates.
|
||||
//$result[$table][$column]['field']['handler'] = 'date_handler_field_date';
|
||||
//$result[$table][$column]['field']['add fields to query'] = TRUE;
|
||||
// $result[$table][$column]['field']['handler'] = 'date_handler_field_date';
|
||||
// $result[$table][$column]['field']['add fields to query'] = TRUE;
|
||||
}
|
||||
|
||||
// For filters, arguments, and sorts, determine if this column is for
|
||||
@@ -395,12 +419,25 @@ function date_views_field_views_data_alter(&$result, $field, $module) {
|
||||
// translatable string. This is a hack to get it to appear right
|
||||
// before 'end date' in the listing (i.e., in a non-alphabetical,
|
||||
// but more user friendly, order).
|
||||
$result[$table][$column]['title'] = t('@label - start date (!name)', array('@label' => $label, '!name' => $field['field_name']));
|
||||
$result[$table][$column]['title short'] = t('@label - start date', array('@label' => $label));
|
||||
$result[$table][$column]['title'] = t('@label - start date (!name)', array(
|
||||
'@label' => $label,
|
||||
'!name' => $field['field_name'],
|
||||
));
|
||||
$result[$table][$column]['title short'] = t('@label - start date', array(
|
||||
'@label' => $label,
|
||||
));
|
||||
break;
|
||||
|
||||
case 'value2':
|
||||
$result[$table][$column]['title'] = t('@label - end date (!name:!column)', array('@label' => $label, '!name' => $field['field_name'], '!column' => $this_column));
|
||||
$result[$table][$column]['title short'] = t('@label - end date:!column', array('@label' => $label, '!column' => $this_column));
|
||||
$result[$table][$column]['title'] = t('@label - end date (!name:!column)', array(
|
||||
'@label' => $label,
|
||||
'!name' => $field['field_name'],
|
||||
'!column' => $this_column,
|
||||
));
|
||||
$result[$table][$column]['title short'] = t('@label - end date:!column', array(
|
||||
'@label' => $label,
|
||||
'!column' => $this_column,
|
||||
));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -421,18 +458,15 @@ function date_views_form_views_ui_edit_form_alter(&$form, &$form_state, $form_id
|
||||
}
|
||||
|
||||
/**
|
||||
* The instanceof function makes this work for any handler that was derived
|
||||
* from 'views_handler_filter_date' or 'views_handler_argument_date',
|
||||
* which includes core date fields like the node updated field.
|
||||
* The instanceof function makes this work for any handler that was derived from 'views_handler_filter_date' or 'views_handler_argument_date', which includes core date fields like the node updated field.
|
||||
*
|
||||
* The test for $handler->min_date tells us that this is an argument that
|
||||
* not only is derived from the views date handler but also has been processed
|
||||
* by the Date Views filter or argument code.
|
||||
*/
|
||||
* The test for $handler->min_date tells us that this is an argument that not only is derived from the views date handler but also has been processed by the Date Views filter or argument code.
|
||||
*/
|
||||
function date_views_handler_is_date($handler, $type = 'argument') {
|
||||
switch ($type) {
|
||||
case 'filter':
|
||||
return $handler instanceof views_handler_filter_date && !empty($handler->min_date);
|
||||
|
||||
case 'argument':
|
||||
return $handler instanceof views_handler_argument_date && !empty($handler->min_date);
|
||||
}
|
||||
@@ -441,8 +475,8 @@ function date_views_handler_is_date($handler, $type = 'argument') {
|
||||
|
||||
/**
|
||||
* Validation hook for exposed filters that use the select widget.
|
||||
* This is to ensure the the user completes all parts of the date
|
||||
* not just some parts. Only needed for the select widget.
|
||||
*
|
||||
* This is to ensure the the user completes all parts of the date not just some parts. Only needed for the select widget.
|
||||
*/
|
||||
function date_views_select_validate(&$form, &$form_state) {
|
||||
// If there are no values just return.
|
||||
@@ -453,7 +487,7 @@ function date_views_select_validate(&$form, &$form_state) {
|
||||
$filled = array();
|
||||
$value = drupal_array_get_nested_value($form_state['input'], $form['#parents']);
|
||||
foreach ($granularity as $part) {
|
||||
if (!empty($value['value'][$part])) {
|
||||
if (isset($value['value']) && is_numeric($value['value'][$part])) {
|
||||
$filled[] = $part;
|
||||
}
|
||||
}
|
||||
@@ -464,18 +498,23 @@ function date_views_select_validate(&$form, &$form_state) {
|
||||
case 'year':
|
||||
form_error($form['value'][$part], t('Please choose a year.'), $form_state);
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
form_error($form['value'][$part], t('Please choose a month.'), $form_state);
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
form_error($form['value'][$part], t('Please choose a day.'), $form_state);
|
||||
break;
|
||||
|
||||
case 'hour':
|
||||
form_error($form['value'][$part], t('Please choose an hour.'), $form_state);
|
||||
break;
|
||||
|
||||
case 'minute':
|
||||
form_error($form['value'][$part], t('Please choose a minute.'), $form_state);
|
||||
break;
|
||||
|
||||
case 'second':
|
||||
form_error($form['value'][$part], t('Please choose a second.'), $form_state);
|
||||
break;
|
||||
@@ -487,8 +526,7 @@ function date_views_select_validate(&$form, &$form_state) {
|
||||
/**
|
||||
* Implements hook_date_formatter_view_alter().
|
||||
*
|
||||
* If we are displaying a date from a view, see if we have information about
|
||||
* which multiple value to display. If so, set the date_id in the entity.
|
||||
* If we are displaying a date from a view, see if we have information about which multiple value to display. If so, set the date_id in the entity.
|
||||
*/
|
||||
function date_views_date_formatter_pre_view_alter(&$entity, &$variables) {
|
||||
// Some views have no row index.
|
||||
@@ -501,4 +539,4 @@ function date_views_date_formatter_pre_view_alter(&$entity, &$variables) {
|
||||
$entity->date_id = 'date.' . $date_item->$date_id . '.' . $field['field_name'] . '.' . $date_item->$date_delta . '.0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Empty file to avoid fatal error if it doesn't exist.
|
||||
* Formerly the attachment for the Date Browser.
|
||||
*/
|
||||
*/
|
||||
|
@@ -27,8 +27,9 @@
|
||||
* links by date, requires the date argument and uses the current
|
||||
* date argument default to set a starting point for the view.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_plugins
|
||||
* Implements hook_views_plugins().
|
||||
*/
|
||||
function date_views_views_plugins() {
|
||||
$path = drupal_get_path('module', 'date_views');
|
||||
@@ -36,7 +37,8 @@ function date_views_views_plugins() {
|
||||
module_load_include('inc', 'date_views', 'theme/theme');
|
||||
|
||||
return array(
|
||||
'module' => 'date_views', // This just tells our themes are elsewhere.
|
||||
// This just tells our themes are elsewhere.
|
||||
'module' => 'date_views',
|
||||
'display' => array(
|
||||
// Display plugin for date navigation.
|
||||
'date_nav' => array(
|
||||
@@ -83,7 +85,7 @@ function date_views_views_plugins() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_data()
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function date_views_views_data() {
|
||||
$data = array();
|
||||
@@ -95,12 +97,12 @@ function date_views_views_data() {
|
||||
$data[$base_table]['date_argument'] = array(
|
||||
'group' => t('Date'),
|
||||
'title' => t('Date (!base_table)', array('!base_table' => $base_table)),
|
||||
'help' => t('Filter any Views !base_table date field by a date argument, using any common ISO date/period format (i.e. YYYY, YYYY-MM, YYYY-MM-DD, YYYY-W99, YYYY-MM-DD--P3M, P90D, etc). ', array('!base_table' => $base_table)),
|
||||
'help' => t('Filter any Views !base_table date field by a date argument, using any common ISO date/period format (i.e. YYYY, YYYY-MM, YYYY-MM-DD, YYYY-W99, YYYY-MM-DD--P3M, P90D, etc).', array('!base_table' => $base_table)),
|
||||
'argument' => array(
|
||||
'handler' => 'date_views_argument_handler',
|
||||
'empty field name' => t('Undated'),
|
||||
'is date' => TRUE,
|
||||
//'skip base' => $base_table,
|
||||
// 'skip base' => $base_table,
|
||||
),
|
||||
);
|
||||
// The flexible date filter.
|
||||
@@ -112,7 +114,7 @@ function date_views_views_data() {
|
||||
'handler' => 'date_views_filter_handler',
|
||||
'empty field name' => t('Undated'),
|
||||
'is date' => TRUE,
|
||||
//'skip base' => $base_table,
|
||||
// 'skip base' => $base_table,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -140,8 +142,9 @@ function date_views_views_data_alter(&$data) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Central function for setting up the right timezone values
|
||||
* in the SQL date handler.
|
||||
* Central function for setting up the right timezone values.
|
||||
*
|
||||
* In the SQL date handler.
|
||||
*
|
||||
* The date handler will use this information to decide if the
|
||||
* database value needs a timezone conversion.
|
||||
@@ -152,30 +155,45 @@ function date_views_views_data_alter(&$data) {
|
||||
*/
|
||||
function date_views_set_timezone(&$date_handler, &$view, $field) {
|
||||
switch ($field['tz_handling']) {
|
||||
case 'date' :
|
||||
case 'date':
|
||||
$date_handler->db_timezone = 'UTC';
|
||||
$date_handler->local_timezone_field = $field['timezone_field'];
|
||||
$date_handler->offset_field = $field['offset_field'];
|
||||
break;
|
||||
|
||||
case 'none':
|
||||
$date_handler->db_timezone = date_default_timezone();
|
||||
$date_handler->local_timezone = date_default_timezone();
|
||||
break;
|
||||
|
||||
case 'utc':
|
||||
$date_handler->db_timezone = 'UTC';
|
||||
$date_handler->local_timezone = 'UTC';
|
||||
break;
|
||||
default :
|
||||
|
||||
default:
|
||||
$date_handler->db_timezone = 'UTC';
|
||||
$date_handler->local_timezone = date_default_timezone();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to generate a query string.
|
||||
*
|
||||
* @param object $view
|
||||
* A View object.
|
||||
*
|
||||
* @param array $extra_params
|
||||
* An extra parameters.
|
||||
*
|
||||
* @return null/string
|
||||
* Return a query or NULL.
|
||||
*/
|
||||
function date_views_querystring($view, $extra_params = array()) {
|
||||
$query_params = array_merge($_GET, $extra_params);
|
||||
// Allow NULL params to be removed from the query string.
|
||||
foreach ($extra_params AS $key => $value) {
|
||||
foreach ($extra_params as $key => $value) {
|
||||
if (!isset($value)) {
|
||||
unset($query_params[$key]);
|
||||
}
|
||||
|
@@ -3,12 +3,14 @@
|
||||
* @file
|
||||
* Date API views argument handler.
|
||||
* This argument combines multiple date arguments into a single argument
|
||||
* where all fields are controlled by the same date and can be combined with either AND or OR.
|
||||
* where all fields are controlled by the same date and can be combined
|
||||
* with either AND or OR.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Date API argument handler.
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
class date_views_argument_handler extends date_views_argument_handler_simple {
|
||||
|
||||
/**
|
||||
@@ -198,3 +200,4 @@ class date_views_argument_handler extends date_views_argument_handler_simple {
|
||||
}
|
||||
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
@@ -7,11 +7,13 @@
|
||||
/**
|
||||
* Date API argument handler.
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
|
||||
/**
|
||||
* Get granularity and use it to create the formula and a format
|
||||
* for the results.
|
||||
* Get granularity.
|
||||
*
|
||||
* Use it to create the formula and a format for the results.
|
||||
*/
|
||||
function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
@@ -29,12 +31,14 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
$this->date_handler->local_timezone = date_get_timezone($field['settings']['tz_handling']);
|
||||
}
|
||||
$this->date_handler->granularity = $this->options['granularity'];
|
||||
// This value needs to be initialized so it exists even if the query doesn't run.
|
||||
// This value needs to be initialized so
|
||||
// it exists even if the query doesn't run.
|
||||
$this->date_handler->placeholders = array();
|
||||
|
||||
$this->format = $this->date_handler->views_formats($this->date_handler->granularity, 'display');
|
||||
$this->sql_format = $this->date_handler->views_formats($this->date_handler->granularity, 'sql');
|
||||
// $this->arg_format is the format the parent date handler will use to create a default argument.
|
||||
// $this->arg_format is the format the parent date
|
||||
// handler will use to create a default argument.
|
||||
$this->arg_format = $this->format();
|
||||
|
||||
// Identify the base table for this field.
|
||||
@@ -43,6 +47,9 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function format() {
|
||||
if (!empty($this->options['granularity'])) {
|
||||
return $this->date_handler->views_formats($this->options['granularity']);
|
||||
@@ -53,8 +60,9 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the empty argument value to the current date,
|
||||
* formatted appropriately for this argument.
|
||||
* Set the empty argument value to the current date.
|
||||
*
|
||||
* Formatted appropriately for this argument.
|
||||
*/
|
||||
function get_default_argument($raw = FALSE) {
|
||||
$is_default = FALSE;
|
||||
@@ -85,6 +93,7 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
$options = parent::option_definition();
|
||||
$options['year_range'] = array('default' => '-3:+3');
|
||||
$options['granularity'] = array('default' => 'month');
|
||||
$options['granularity_reset'] = array('default' => FALSE);
|
||||
$options['default_argument_type']['default'] = 'date';
|
||||
$options['add_delta'] = array('default' => '');
|
||||
$options['use_fromto'] = array('default' => '');
|
||||
@@ -116,7 +125,9 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
'#attributes' => array('class' => array('dependent-options')),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="options[default_action]"]' => array('value' => 'summary')
|
||||
':input[name="options[default_action]"]' => array(
|
||||
'value' => 'summary',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -129,23 +140,37 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
'#attributes' => array('class' => array('dependent-options')),
|
||||
'#states' => array(
|
||||
'visible' => array(
|
||||
':input[name="options[title_format]"]' => array('value' => 'custom')
|
||||
':input[name="options[title_format]"]' => array(
|
||||
'value' => 'custom',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Get default granularity options
|
||||
$options = $this->date_handler->date_parts();
|
||||
unset($options['second'], $options['minute']);
|
||||
$options += array('week' => t('Week', array(), array('context' => 'datetime')));
|
||||
// Add the 'week' option.
|
||||
$options += array(
|
||||
'week' => t('Week', array(), array(
|
||||
'context' => 'datetime',
|
||||
)),
|
||||
);
|
||||
|
||||
$form['granularity'] = array(
|
||||
'#title' => t('Granularity'),
|
||||
'#type' => 'radios',
|
||||
'#options' => $options,
|
||||
'#default_value' => $this->options['granularity'],
|
||||
'#multiple' => TRUE,
|
||||
'#description' => t("Select the type of date value to be used in defaults, summaries, and navigation. For example, a granularity of 'month' will set the default date to the current month, summarize by month in summary views, and link to the next and previous month when using date navigation."),
|
||||
);
|
||||
|
||||
$form['granularity_reset'] = array(
|
||||
'#title' => t('Use granularity from argument value'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => $this->options['granularity_reset'],
|
||||
'#description' => t("If the granularity of argument value is different from selected, use it from argument value."),
|
||||
);
|
||||
|
||||
$form['year_range'] = array(
|
||||
'#title' => t('Date year range'),
|
||||
'#type' => 'textfield',
|
||||
@@ -172,16 +197,18 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
'#default_value' => $this->options['add_delta'],
|
||||
'#options' => array('' => t('No'), 'yes' => t('Yes')),
|
||||
'#description' => t('Add an identifier to the view to show which multiple value date fields meet the filter criteria. Note: This option may introduce duplicate values into the view. Required when using multiple value fields in a Calendar or any time you want the node view of multiple value dates to display only the values that match the view filters.'),
|
||||
// Only let mere mortals tweak this setting for multi-value fields
|
||||
// Only let mere mortals tweak this setting for multi-value fields.
|
||||
'#access' => $access,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function options_validate(&$form, &$form_state) {
|
||||
// It is very important to call the parent function here:
|
||||
parent::options_validate($form, $form_state);
|
||||
if (!preg_match('/^(?:\-[0-9]{1,4}|[0-9]{4}):(?:[\+|\-][0-9]{1,4}|[0-9]{4})$/', $form_state['values']['options']['year_range'])) {
|
||||
if (!preg_match('/^(?:\-[0-9]{1,4}|[0-9]{4}):(?:[\+\-][0-9]{1,4}|[0-9]{4})$/', $form_state['values']['options']['year_range'])) {
|
||||
form_error($form['year_range'], t('Date year range must be in the format -9:+9, 2005:2010, -9:2010, or 2005:+9'));
|
||||
}
|
||||
}
|
||||
@@ -209,14 +236,15 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
$format = !empty($this->options['title_format_custom']) && !empty($this->options['title_format_custom']) ? $this->options['title_format_custom'] : $this->date_handler->views_formats($this->options['granularity'], 'display');
|
||||
$range = $this->date_handler->arg_range($this->argument);
|
||||
return date_format_date($range[0], 'custom', $format);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the argument to use to link from the summary to the next level;
|
||||
* this will be called once per row of a summary, and used as part of
|
||||
* Provide the argument to use to link from the summary to the next level.
|
||||
*
|
||||
* This will be called once per row of a summary, and used as part of
|
||||
* $view->get_url().
|
||||
*
|
||||
* @param $data
|
||||
* @param object $data
|
||||
* The query results for the row.
|
||||
*/
|
||||
function summary_argument($data) {
|
||||
@@ -234,10 +262,11 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
*/
|
||||
function summary_query() {
|
||||
|
||||
// @TODO The summary values are computed by the database. Unless the database has
|
||||
// built-in timezone handling it will use a fixed offset, which will not be
|
||||
// right for all dates. The only way I can see to make this work right is to
|
||||
// store the offset for each date in the database so it can be added to the base
|
||||
// @TODO The summary values are computed by the database.
|
||||
// Unless the database has built-in timezone handling it will use
|
||||
// a fixed offset, which will not be right for all dates.
|
||||
// The only way I can see to make this work right is to store the offset
|
||||
// for each date in the database so it can be added to the base
|
||||
// date value before the database formats the result. Because this is a huge
|
||||
// architectural change, it won't go in until we start a new branch.
|
||||
$this->formula = $this->date_handler->sql_format($this->sql_format, $this->date_handler->sql_field("***table***.$this->real_field"));
|
||||
@@ -245,7 +274,8 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
// Now that our table is secure, get our formula.
|
||||
$formula = $this->get_formula();
|
||||
|
||||
// Add the field, give it an alias that does NOT match the actual field name or grouping won't work right.
|
||||
// Add the field, give it an alias that does NOT match the actual
|
||||
// field name or grouping won't work right.
|
||||
$this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field . '_summary');
|
||||
$this->query->set_count_field(NULL, $formula, $this->field);
|
||||
|
||||
@@ -254,20 +284,22 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
|
||||
/**
|
||||
* Inject a test for valid date range before the regular query.
|
||||
*
|
||||
* Override the parent query to be able to control the $group.
|
||||
*/
|
||||
function query($group_by = FALSE) {
|
||||
|
||||
// @TODO Not doing anything with $group_by yet, need to figure out what has to be done.
|
||||
// @TODO Not doing anything with $group_by yet,
|
||||
// need to figure out what has to be done.
|
||||
|
||||
if ($this->date_forbid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// See if we need to reset granularity based on an argument value.
|
||||
// Make sure we don't try to reset to some bogus value if someone has typed in an unexpected argument.
|
||||
$granularity = $this->date_handler->arg_granularity($this->argument);
|
||||
if (!empty($granularity)) {
|
||||
// Make sure we don't try to reset to some bogus value if someone has
|
||||
// typed in an unexpected argument.
|
||||
if ($this->options['granularity_reset'] && $granularity = $this->date_handler->arg_granularity($this->argument)) {
|
||||
$this->date_handler->granularity = $granularity;
|
||||
$this->format = $this->date_handler->views_formats($this->date_handler->granularity, 'display');
|
||||
$this->sql_format = $this->date_handler->views_formats($this->date_handler->granularity, 'sql');
|
||||
@@ -276,7 +308,8 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
$this->ensure_my_table();
|
||||
$group = !empty($this->options['date_group']) ? $this->options['date_group'] : 0;
|
||||
|
||||
// If requested, add the delta field to the view so we can later find the value that matched our query.
|
||||
// If requested, add the delta field to the view so
|
||||
// we can later find the value that matched our query.
|
||||
if (!empty($this->options['add_delta']) && (substr($this->real_field, -6) == '_value' || substr($this->real_field, -7) == '_value2')) {
|
||||
$this->query->add_field($this->table_alias, 'delta');
|
||||
$real_field_name = str_replace(array('_value', '_value2'), '', $this->real_field);
|
||||
@@ -291,7 +324,8 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
$view_max_placeholder = $this->placeholder();
|
||||
$this->date_handler->placeholders = array($view_min_placeholder => $view_min, $view_max_placeholder => $view_max);
|
||||
|
||||
// Are we comparing this field only or the Start/End date range to the view criteria?
|
||||
// Are we comparing this field only or the Start/End date range
|
||||
// to the view criteria?
|
||||
if (!empty($this->options['use_fromto'])) {
|
||||
|
||||
// The simple case, match the field to the view range.
|
||||
@@ -302,10 +336,14 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
}
|
||||
else {
|
||||
|
||||
// Look for the intersection of the range of the date field with the range of the view.
|
||||
// Get the Start/End values for this field. Retrieve using the original table name.
|
||||
// Swap the current table name (adjusted for relationships) into the query.
|
||||
// @TODO We may be able to use Views substitutions here, investigate that later.
|
||||
// Look for the intersection of the range
|
||||
// of the date field with the range of the view.
|
||||
// Get the Start/End values for this field.
|
||||
// Retrieve using the original table name.
|
||||
// Swap the current table name (adjusted for relationships)
|
||||
// into the query.
|
||||
// @TODO We may be able to use Views substitutions here,
|
||||
// investigate that later.
|
||||
$fields = date_views_fields($this->base_table);
|
||||
$fields = $fields['name'];
|
||||
$fromto = $fields[$this->original_table . '.' . $this->real_field]['fromto'];
|
||||
@@ -321,7 +359,10 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a callback to determine if we have moved outside the valid date range for this argument.
|
||||
* Add a callback.
|
||||
*
|
||||
* To determine if we have moved outside
|
||||
* the valid date range for this argument.
|
||||
*/
|
||||
function date_forbid() {
|
||||
if (empty($this->argument)) {
|
||||
@@ -343,3 +384,4 @@ class date_views_argument_handler_simple extends views_handler_argument_date {
|
||||
}
|
||||
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
@@ -5,13 +5,11 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Identify all potential date/timestamp fields.
|
||||
* Identify all potential date/timestamp fields.
|
||||
*
|
||||
* @return
|
||||
* array with fieldname, type, and table.
|
||||
* @see
|
||||
* date_views_date_views_fields() which implements
|
||||
* the hook_date_views_fields() for the core date fields.
|
||||
* @return array
|
||||
* An array with fieldname, type, and table.
|
||||
* @see date_views_date_views_fields()
|
||||
*/
|
||||
function _date_views_fields($base = 'node') {
|
||||
|
||||
@@ -60,7 +58,7 @@ function _date_views_fields($base = 'node') {
|
||||
$handler = views_get_handler($table_name, $field_name, 'filter');
|
||||
$handler_name = $handler->definition['handler'];
|
||||
|
||||
// We don't care about anything but date handlers
|
||||
// We don't care about anything but date handlers.
|
||||
if (empty($handler->definition['is date'])) {
|
||||
continue;
|
||||
}
|
||||
@@ -72,14 +70,17 @@ function _date_views_fields($base = 'node') {
|
||||
$field = field_info_field($handler->definition['field_name']);
|
||||
$is_field = TRUE;
|
||||
switch ($field['type']) {
|
||||
case 'date':
|
||||
case 'date':
|
||||
$sql_type = DATE_ISO;
|
||||
break;
|
||||
|
||||
case 'datestamp':
|
||||
break;
|
||||
|
||||
case 'datetime':
|
||||
$sql_type = DATE_DATETIME;
|
||||
break;
|
||||
|
||||
default:
|
||||
// If this is not a date field, nothing more to do.
|
||||
continue;
|
||||
@@ -88,7 +89,8 @@ function _date_views_fields($base = 'node') {
|
||||
$revision = in_array($base, array('node_revision')) ? FIELD_LOAD_REVISION : FIELD_LOAD_CURRENT;
|
||||
$db_info = date_api_database_info($field, $revision);
|
||||
$name = $table_name . "." . $field_name;
|
||||
$granularity = !empty($field['granularity']) ? $field['granularity'] : array('year', 'month', 'day', 'hour', 'minute', 'second');
|
||||
$grans = array('year', 'month', 'day', 'hour', 'minute', 'second');
|
||||
$granularity = !empty($field['granularity']) ? $field['granularity'] : $grans;
|
||||
|
||||
$fromto = array(
|
||||
$table_name . '.' . $db_info['columns'][$table_name]['value'],
|
||||
|
@@ -3,9 +3,11 @@
|
||||
* @file
|
||||
* A flexible, configurable date filter.
|
||||
* This filter combines multiple date filters into a single filter
|
||||
* where all fields are controlled by the same date and can be combined with either AND or OR.
|
||||
* where all fields are controlled by the same date and can be combined
|
||||
* with either AND or OR.
|
||||
*/
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
class date_views_filter_handler extends date_views_filter_handler_simple {
|
||||
function init(&$view, &$options) {
|
||||
parent::init($view, $options);
|
||||
@@ -64,6 +66,9 @@ class date_views_filter_handler extends date_views_filter_handler_simple {
|
||||
if ($field['table_name'] != $this->table || !empty($this->relationship)) {
|
||||
$this->related_table_alias = $this->query->ensure_table($field['table_name'], $this->relationship);
|
||||
}
|
||||
else {
|
||||
$this->related_table_alias = null;
|
||||
}
|
||||
$table_alias = !empty($this->related_table_alias) ? $this->related_table_alias : $field['table_name'];
|
||||
$field_name = $table_alias . '.' . $field['field_name'];
|
||||
|
||||
@@ -179,3 +184,4 @@ class date_views_filter_handler extends date_views_filter_handler_simple {
|
||||
}
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* A standard Views filter for a single date field, using Date API form selectors and sql handling.
|
||||
* A standard Views filter for a single date field,
|
||||
* using Date API form selectors and sql handling.
|
||||
*/
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
class date_views_filter_handler_simple extends views_handler_filter_date {
|
||||
var $date_handler = NULL;
|
||||
var $offset = NULL;
|
||||
@@ -263,7 +265,7 @@ class date_views_filter_handler_simple extends views_handler_filter_date {
|
||||
}
|
||||
|
||||
function extra_options_validate($form, &$form_state) {
|
||||
if (!preg_match('/^(?:\-[0-9]{1,4}|[0-9]{4}):(?:[\+|\-][0-9]{1,4}|[0-9]{4})$/', $form_state['values']['options']['year_range'])) {
|
||||
if (!preg_match('/^(?:[\+\-][0-9]{1,4}|[0-9]{4}):(?:[\+\-][0-9]{1,4}|[0-9]{4})$/', $form_state['values']['options']['year_range'])) {
|
||||
form_error($form['year_range'], t('Date year range must be in the format -9:+9, 2005:2010, -9:2010, or 2005:+9'));
|
||||
}
|
||||
}
|
||||
@@ -332,7 +334,7 @@ class date_views_filter_handler_simple extends views_handler_filter_date {
|
||||
* @return
|
||||
* The form date part element for this instance.
|
||||
*/
|
||||
function date_parts_form($form_state, $prefix, $source, $which, $operator_values, $identifier, $relative_id) {
|
||||
function date_parts_form(&$form_state, $prefix, $source, $which, $operator_values, $identifier, $relative_id) {
|
||||
module_load_include('inc', 'date_api', 'date_api_elements');
|
||||
switch ($prefix) {
|
||||
case 'min':
|
||||
@@ -379,7 +381,10 @@ class date_views_filter_handler_simple extends views_handler_filter_date {
|
||||
$form[$prefix]['#dependency'] = array($source => $operator_values);
|
||||
}
|
||||
if (!isset($form_state['input'][$identifier][$prefix])) {
|
||||
$form_state['input'][$identifier][$prefix] = $this->value[$prefix];
|
||||
// Ensure these exist.
|
||||
foreach ($granularity as $key) {
|
||||
$form_state['input'][$identifier][$prefix][$key] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -530,3 +535,4 @@ class date_views_filter_handler_simple extends views_handler_filter_date {
|
||||
}
|
||||
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
@@ -2,50 +2,74 @@
|
||||
/**
|
||||
* @file
|
||||
* Date pager.
|
||||
* Works with a Date argument, the argument filters the view and the pager provides back/next navigation.
|
||||
* Works with a Date argument, the argument filters
|
||||
* the view and the pager provides back/next navigation.
|
||||
*
|
||||
* USER NOTES:
|
||||
*
|
||||
* To use this, add a pager to a view, and choose the option to 'Page by date'.
|
||||
* There are several settings:
|
||||
* - The pager id: Set an id to be used as the identifier in the url for pager values, defaults to 'date'.
|
||||
* - Pager position: Choose whether to display the date pager above, below, or both above and below the content.
|
||||
* - Link format: Choose whether the pager links will be in the simple 'calendar/2011-12' format or the
|
||||
* more complex 'calendar/?date=2011-12' pager format. The second one is more likely to work correctly
|
||||
* if the pager is used in blocks and panels.
|
||||
* - The pager id: Set an id to be used as the identifier
|
||||
* in the url for pager values, defaults to 'date'.
|
||||
* - Pager position: Choose whether to display the date
|
||||
* pager above, below, or both above and below the content.
|
||||
* - Link format: Choose whether the pager links will be in t
|
||||
* he simple 'calendar/2011-12' format or the
|
||||
* more complex 'calendar/?date=2011-12' pager format.
|
||||
* The second one is more likely to work correctly
|
||||
* if the pager is used in blocks and panels.
|
||||
*
|
||||
* The pager works in combination with a Date argument and it will use the date fields and granularity
|
||||
* set in that argument to create its back/next links. If the view has no Date argument, the pager can
|
||||
* do nothing. The argument can either be a 'Date' argument that lets you select one or more date fields
|
||||
* in the argument, or the simple 'Content' argument for an individual date field. It must be an
|
||||
* The pager works in combination with a Date argument
|
||||
* and it will use the date fields and granularity
|
||||
* set in that argument to create its back/next links.
|
||||
* If the view has no Date argument, the pager can
|
||||
* do nothing. The argument can either be a 'Date' argument
|
||||
* that lets you select one or more date fields
|
||||
* in the argument, or the simple 'Content' argument for an
|
||||
* individual date field. It must be an
|
||||
* argument that uses the date argument handler.
|
||||
*
|
||||
* DEVELOPER NOTES
|
||||
*
|
||||
* The pager could technically create a query of its own rather than depending on the date argument to
|
||||
* set the query, but it has only a limited set of tools to work with because it is a plugin, not a handler:
|
||||
* it has no knowledge about relationships, it cannot use the ensure_my_table() function,
|
||||
* plugins are not even invoked in pre_query(), so can't do anything there.
|
||||
* The pager could technically create a query of its own rather
|
||||
* than depending on the date argument to
|
||||
* set the query, but it has only a limited set of tools to work
|
||||
* with because it is a plugin, not a handler:
|
||||
* it has no knowledge about relationships, it cannot use the
|
||||
* ensure_my_table() function, plugins are not even invoked in pre_query(),
|
||||
* so can't do anything there.
|
||||
*
|
||||
* My conclusion was that the date pager simply is not powerful enough to create its own queries for
|
||||
* date fields, which require very complex queries. Instead, we can combine this with a date argument and
|
||||
* let the argument create the query and let the pager just provide the back/next links. If there is no
|
||||
* My conclusion was that the date pager simply
|
||||
* is not powerful enough to create its own queries for
|
||||
* date fields, which require very complex queries.
|
||||
* Instead, we can combine this with a date argument and
|
||||
* let the argument create the query and let the pager
|
||||
* just provide the back/next links. If there is no
|
||||
* date argument, the pager will do nothing.
|
||||
*
|
||||
* There are still other problems. The pager is not even initialized until after all the handlers
|
||||
* have created their queries, so it has no chance to alter values ahead of that. And the argument
|
||||
* has no knowledge of the pager, so it can't check for pager values before the query is created.
|
||||
* There are still other problems. The pager is not even
|
||||
* initialized until after all the handlers
|
||||
* have created their queries, so it has no chance
|
||||
* to alter values ahead of that. And the argument
|
||||
* has no knowledge of the pager, so it can't check
|
||||
* for pager values before the query is created.
|
||||
*
|
||||
* The solution used here is to let the argument create the original query. The pager query
|
||||
* runs after that, so the pager checks to see if there is a pager value that needs to be used in the query.
|
||||
* The date argument has identified the placeholders it used in the query. So if a change is needed,
|
||||
* we can swap the pager value into the query created by the date argument and adjust the
|
||||
* $view->date_info values set by the argument accordingly so the theme will pick up the new information.
|
||||
* The solution used here is to let the argument create
|
||||
* the original query. The pager query
|
||||
* runs after that, so the pager checks to see
|
||||
* if there is a pager value that needs to be used in the query.
|
||||
* The date argument has identified the placeholders
|
||||
* it used in the query. So if a change is needed,
|
||||
* we can swap the pager value into the query created
|
||||
* by the date argument and adjust the
|
||||
* $view->date_info values set by the argument accordingly
|
||||
* so the theme will pick up the new information.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Example plugin to handle paging by month.
|
||||
*/
|
||||
// @codingStandardsIgnoreStart
|
||||
class date_views_plugin_pager extends views_plugin_pager {
|
||||
|
||||
/**
|
||||
@@ -79,6 +103,7 @@ class date_views_plugin_pager extends views_plugin_pager {
|
||||
$options['link_format'] = array('default' => 'pager');
|
||||
$options['date_argument'] = array('default' => 'Unknown');
|
||||
$options['granularity'] = array('default' => 'Unknown');
|
||||
$options['skip_empty_pages'] = array('default' => FALSE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
@@ -110,6 +135,12 @@ class date_views_plugin_pager extends views_plugin_pager {
|
||||
'#default_value' => $this->options['link_format'],
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['skip_empty_pages'] = array(
|
||||
'#title' => t('Skip empty pages'),
|
||||
'#type' => 'checkbox',
|
||||
'#description' => t('When selected, the pager will not display pages with no result for the given date. This causes a slight performance degradation because two additional queries need to be executed.'),
|
||||
'#default_value' => $this->options['skip_empty_pages'],
|
||||
);
|
||||
$form['date_argument']['#type'] = 'hidden';
|
||||
$form['date_argument']['#value'] = $this->options['date_argument'];
|
||||
$form['granularity']['#type'] = 'hidden';
|
||||
@@ -150,13 +181,7 @@ class date_views_plugin_pager extends views_plugin_pager {
|
||||
|
||||
// Reset values set by argument if pager requires it.
|
||||
if (!empty($value)) {
|
||||
$argument->argument = $value;
|
||||
$argument->date_range = $argument->date_handler->arg_range($value);
|
||||
$argument->min_date = $argument->date_range[0];
|
||||
$argument->max_date = $argument->date_range[1];
|
||||
// $argument->is_default works correctly for normal arguments, but does not
|
||||
// work correctly if we are swapping in a new value from the pager.
|
||||
$argument->is_default = FALSE;
|
||||
$this->set_argument_value($argument, $value);
|
||||
}
|
||||
|
||||
// The pager value might move us into a forbidden range, so test it.
|
||||
@@ -164,13 +189,102 @@ class date_views_plugin_pager extends views_plugin_pager {
|
||||
$this->view->build_info['fail'] = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (empty($this->view->date_info)) $this->view->date_info = new stdClass();
|
||||
// Write date_info to store information to be used
|
||||
// in the theming functions.
|
||||
if (empty($this->view->date_info)) {
|
||||
$this->view->date_info = new stdClass();
|
||||
}
|
||||
$this->view->date_info->granularity = $argument->date_handler->granularity;
|
||||
$format = $this->view->date_info->granularity == 'week' ? DATE_FORMAT_DATETIME : $argument->sql_format;
|
||||
$this->view->date_info->placeholders = isset($argument->placeholders) ? $argument->placeholders : $argument->date_handler->placeholders;
|
||||
$this->view->date_info->date_arg = $argument->argument;
|
||||
$this->view->date_info->date_arg_pos = $i;
|
||||
$this->view->date_info->limit = $argument->limit;
|
||||
$this->view->date_info->url = $this->view->get_url();
|
||||
$this->view->date_info->pager_id = $this->options['date_id'];
|
||||
$this->view->date_info->date_pager_position = $this->options['pager_position'];
|
||||
$this->view->date_info->date_pager_format = $this->options['link_format'];
|
||||
$this->view->date_info->skip_empty_pages = $this->options['skip_empty_pages'] == 1;
|
||||
// Execute two additional queries to find
|
||||
// the previous and next page with values.
|
||||
if ($this->view->date_info->skip_empty_pages) {
|
||||
$q = clone $argument->query;
|
||||
$field = $argument->table_alias . '.' . $argument->real_field;
|
||||
$fieldsql = $date_handler->sql_field($field);
|
||||
$fieldsql = $date_handler->sql_format($format, $fieldsql);
|
||||
$q->clear_fields();
|
||||
$q->orderby = array();
|
||||
$q->set_distinct(TRUE, TRUE);
|
||||
// Date limits of this argument.
|
||||
$datelimits = $argument->date_handler->arg_range($argument->limit[0] . '--' . $argument->limit[1]);
|
||||
// Find the first two dates between the minimum date
|
||||
// and the upper bound of the current value.
|
||||
$q->add_orderby(NULL, $fieldsql, 'DESC', 'date');
|
||||
$this->set_argument_placeholders($this->view->date_info->placeholders, $datelimits[0], $argument->max_date, $q, $format);
|
||||
|
||||
$compiledquery = $q->query();
|
||||
$compiledquery->range(0, 2);
|
||||
$results = $compiledquery->execute()->fetchCol(0);
|
||||
|
||||
$prevdate = array_shift($results);
|
||||
$prevdatealt = array_shift($results);
|
||||
// Find the first two dates between the lower bound
|
||||
// of the current value and the maximum date.
|
||||
$q->add_orderby(NULL, $fieldsql, 'ASC', 'date');
|
||||
$this->set_argument_placeholders($this->view->date_info->placeholders, $argument->min_date, $datelimits[1], $q, $format);
|
||||
|
||||
$compiledquery = $q->query();
|
||||
$compiledquery->range(0, 2);
|
||||
$results = $compiledquery->execute()->fetchCol(0);
|
||||
|
||||
$nextdate = array_shift($results);
|
||||
$nextdatealt = array_shift($results);
|
||||
|
||||
// Set the default value of the query to $prevfirst or $nextfirst
|
||||
// when there is no value and $prevsecond or $nextsecond is set.
|
||||
if (empty($value)) {
|
||||
// @Todo find out which of $prevdate or $nextdate is closest to the
|
||||
// default argument date value and choose that one.
|
||||
if ($prevdate && $prevdatealt) {
|
||||
$this->set_argument_value($argument, $prevdate);
|
||||
$value = $prevdate;
|
||||
$prevdate = $prevdatealt;
|
||||
// If the first next date is the same as the first previous date,
|
||||
// move to the following next date.
|
||||
if ($value == $nextdate) {
|
||||
$nextdate = $nextdatealt;
|
||||
$nextdatealt = NULL;
|
||||
}
|
||||
}
|
||||
elseif ($nextdate && $nextdatealt) {
|
||||
$this->set_argument_value($argument, $nextdate);
|
||||
$value = $nextdate;
|
||||
$nextdate = $nextdatealt;
|
||||
// If the first previous date is the same as the first next date,
|
||||
// move to the following previous date.
|
||||
if ($value == $prevdate) {
|
||||
$prevdate = $prevdatealt;
|
||||
$prevdatealt = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// $prevdate and $nextdate are the same as $value, so move to
|
||||
// the next values.
|
||||
$prevdate = $prevdatealt;
|
||||
$nextdate = $nextdatealt;
|
||||
}
|
||||
|
||||
$this->view->date_info->prev_date = $prevdate ? new DateObject($prevdate, NULL, $format) : NULL;
|
||||
$this->view->date_info->next_date = $nextdate ? new DateObject($nextdate, NULL, $format) : NULL;
|
||||
}
|
||||
else {
|
||||
$this->view->date_info->prev_date = clone($argument->min_date);
|
||||
date_modify($this->view->date_info->prev_date, '-1 ' . $argument->date_handler->granularity);
|
||||
$this->view->date_info->next_date = clone($argument->max_date);
|
||||
date_modify($this->view->date_info->next_date, '+1 ' . $argument->date_handler->granularity);
|
||||
}
|
||||
// Write the date_info properties that depend on the current value.
|
||||
$this->view->date_info->year = date_format($argument->min_date, 'Y');
|
||||
$this->view->date_info->month = date_format($argument->min_date, 'n');;
|
||||
$this->view->date_info->day = date_format($argument->min_date, 'j');
|
||||
@@ -178,11 +292,6 @@ class date_views_plugin_pager extends views_plugin_pager {
|
||||
$this->view->date_info->date_range = $argument->date_range;
|
||||
$this->view->date_info->min_date = $argument->min_date;
|
||||
$this->view->date_info->max_date = $argument->max_date;
|
||||
$this->view->date_info->limit = $argument->limit;
|
||||
$this->view->date_info->url = $this->view->get_url();
|
||||
$this->view->date_info->pager_id = $this->options['date_id'];
|
||||
$this->view->date_info->date_pager_position = $this->options['pager_position'];
|
||||
$this->view->date_info->date_pager_format = $this->options['link_format'];
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
@@ -191,20 +300,33 @@ class date_views_plugin_pager extends views_plugin_pager {
|
||||
// If there is pager input and the argument has set the placeholders,
|
||||
// swap the pager value in for the placeholder set by the argument.
|
||||
if (!empty($value) && !empty($this->view->date_info->placeholders)) {
|
||||
$placeholders = $this->view->date_info->placeholders;
|
||||
$count = count($placeholders);
|
||||
foreach ($this->view->query->where as $group => $data) {
|
||||
foreach ($data['conditions'] as $delta => $condition) {
|
||||
if (array_key_exists('value', $condition) && is_array($condition['value'])) {
|
||||
foreach ($condition['value'] as $placeholder => $placeholder_value) {
|
||||
if (array_key_exists($placeholder, $placeholders)) {
|
||||
// If we didn't get a match, this is a > $min < $max query that uses the view
|
||||
// min and max dates as placeholders.
|
||||
$date = ($count == 2) ? $this->view->date_info->min_date : $this->view->date_info->max_date;
|
||||
$next_placeholder = array_shift($placeholders);
|
||||
$this->view->query->where[$group]['conditions'][$delta]['value'][$placeholder] = $date->format($format);
|
||||
$count--;
|
||||
}
|
||||
$this->set_argument_placeholders($this->view->date_info->placeholders, $this->view->date_info->min_date, $this->view->date_info->max_date, $this->view->query, $format);
|
||||
}
|
||||
}
|
||||
|
||||
function set_argument_value($argument, $value) {
|
||||
$argument->argument = $value;
|
||||
$argument->date_range = $argument->date_handler->arg_range($value);
|
||||
$argument->min_date = $argument->date_range[0];
|
||||
$argument->max_date = $argument->date_range[1];
|
||||
// $argument->is_default works correctly for normal arguments, but does not
|
||||
// work correctly if we are swapping in a new value from the pager.
|
||||
$argument->is_default = FALSE;
|
||||
}
|
||||
|
||||
function set_argument_placeholders($placeholders, $mindate, $maxdate, $query, $format) {
|
||||
$count = count($placeholders);
|
||||
foreach ($query->where as $group => $data) {
|
||||
foreach ($data['conditions'] as $delta => $condition) {
|
||||
if (array_key_exists('value', $condition) && is_array($condition['value'])) {
|
||||
foreach ($condition['value'] as $placeholder => $placeholder_value) {
|
||||
if (array_key_exists($placeholder, $placeholders)) {
|
||||
// If we didn't get a match, this is a > $min < $max query that uses the view
|
||||
// min and max dates as placeholders.
|
||||
$date = ($count == 2) ? $mindate : $maxdate;
|
||||
$next_placeholder = array_shift($placeholders);
|
||||
$query->where[$group]['conditions'][$delta]['value'][$placeholder] = $date->format($format);
|
||||
$count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -230,4 +352,5 @@ class date_views_plugin_pager extends views_plugin_pager {
|
||||
$pager_theme = views_theme_functions('date_views_pager', $this->view, $this->display);
|
||||
return theme($pager_theme, array('plugin' => $this, 'input' => $input));
|
||||
}
|
||||
}
|
||||
}
|
||||
// @codingStandardsIgnoreEnd
|
||||
|
@@ -27,8 +27,10 @@
|
||||
* be used in the l() function, including rel=nofollow.
|
||||
*/
|
||||
?>
|
||||
<?php if (!empty($pager_prefix)) print $pager_prefix; ?>
|
||||
<div class="date-nav-wrapper clearfix<?php if (!empty($extra_classes)) print $extra_classes; ?>">
|
||||
<?php if (!empty($pager_prefix)) : ?>
|
||||
<?php print $pager_prefix; ?>
|
||||
<?php endif; ?>
|
||||
<div class="date-nav-wrapper clearfix<?php if (!empty($extra_classes)): print $extra_classes; endif; ?>">
|
||||
<div class="date-nav item-list">
|
||||
<div class="date-heading">
|
||||
<h3><?php print $nav_title ?></h3>
|
||||
@@ -36,7 +38,11 @@
|
||||
<ul class="pager">
|
||||
<?php if (!empty($prev_url)) : ?>
|
||||
<li class="date-prev">
|
||||
<?php print l('«' . ($mini ? '' : ' ' . t('Prev', array(), array('context' => 'date_nav'))), $prev_url, $prev_options); ?>
|
||||
<?php
|
||||
$text = '«';
|
||||
$text .= $mini ? '' : ' ' . t('Prev', array(), array('context' => 'date_nav'));
|
||||
print l(t($text), $prev_url, $prev_options);
|
||||
?>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($next_url)) : ?>
|
||||
@@ -46,4 +52,4 @@
|
||||
<?php endif; ?>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -4,6 +4,7 @@
|
||||
* @file
|
||||
* Theme files for Date Pager.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Jump in and move the pager.
|
||||
*/
|
||||
@@ -15,9 +16,11 @@ function date_views_preprocess_views_view(&$vars) {
|
||||
$vars['header'] .= $vars['pager'];
|
||||
$vars['pager'] = '';
|
||||
break;
|
||||
|
||||
case 'both':
|
||||
$vars['header'] .= $vars['pager'];
|
||||
break;
|
||||
|
||||
default:
|
||||
// Already on the bottom.
|
||||
}
|
||||
@@ -66,28 +69,37 @@ function template_preprocess_date_views_pager(&$vars) {
|
||||
}
|
||||
|
||||
if (empty($date_info->hide_nav)) {
|
||||
$prev_date = clone($min_date);
|
||||
date_modify($prev_date, '-1 ' . $granularity);
|
||||
$next_date = clone($min_date);
|
||||
date_modify($next_date, '+1 ' . $granularity);
|
||||
$format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d');
|
||||
switch ($granularity) {
|
||||
case 'week':
|
||||
$next_week = date_week(date_format($next_date, 'Y-m-d'));
|
||||
$prev_week = date_week(date_format($prev_date, 'Y-m-d'));
|
||||
$next_arg = date_format($next_date, 'o-\W') . date_pad($next_week);
|
||||
$prev_arg = date_format($prev_date, 'o-\W') . date_pad($prev_week);
|
||||
break;
|
||||
default:
|
||||
$next_arg = date_format($next_date, $format[$granularity]);
|
||||
$prev_arg = date_format($prev_date, $format[$granularity]);
|
||||
$prev_date = $date_info->prev_date;
|
||||
$next_date = $date_info->next_date;
|
||||
|
||||
$format = array('year' => 'Y', 'month' => 'Y-m', 'day' => 'Y-m-d', 'hour' => 'Y-m-d\TH');
|
||||
if (!empty($prev_date)) {
|
||||
switch ($granularity) {
|
||||
case 'week':
|
||||
$prev_week = date_week(date_format($prev_date, 'Y-m-d'));
|
||||
$prev_arg = date_format($prev_date, 'Y-\W') . date_pad($prev_week);
|
||||
break;
|
||||
default:
|
||||
$prev_arg = date_format($prev_date, $format[$granularity]);
|
||||
}
|
||||
$prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
|
||||
$prev_args[$pos] = $prev_arg;
|
||||
$vars['prev_url'] = date_pager_url($view, NULL, $prev_arg);
|
||||
}
|
||||
$next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
|
||||
$prev_path = str_replace($date_info->date_arg, $prev_arg, $date_info->url);
|
||||
$next_args[$pos] = $next_arg;
|
||||
$prev_args[$pos] = $prev_arg;
|
||||
$vars['next_url'] = date_pager_url($view, NULL, $next_arg);
|
||||
$vars['prev_url'] = date_pager_url($view, NULL, $prev_arg);
|
||||
if (!empty($next_date)) {
|
||||
switch ($granularity) {
|
||||
case 'week':
|
||||
$next_week = date_week(date_format($next_date, 'Y-m-d'));
|
||||
$next_arg = date_format($next_date, 'Y-\W') . date_pad($next_week);
|
||||
break;
|
||||
default:
|
||||
$next_arg = date_format($next_date, $format[$granularity]);
|
||||
}
|
||||
$next_path = str_replace($date_info->date_arg, $next_arg, $date_info->url);
|
||||
$next_args[$pos] = $next_arg;
|
||||
$vars['next_url'] = date_pager_url($view, NULL, $next_arg);
|
||||
}
|
||||
|
||||
$vars['next_options'] = $vars['prev_options'] = array();
|
||||
}
|
||||
else {
|
||||
@@ -117,14 +129,17 @@ function template_preprocess_date_views_pager(&$vars) {
|
||||
$prev_title = t('Navigate to previous year');
|
||||
$next_title = t('Navigate to next year');
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
$prev_title = t('Navigate to previous month');
|
||||
$next_title = t('Navigate to next month');
|
||||
break;
|
||||
|
||||
case 'week':
|
||||
$prev_title = t('Navigate to previous week');
|
||||
$next_title = t('Navigate to next week');
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
$prev_title = t('Navigate to previous day');
|
||||
$next_title = t('Navigate to next day');
|
||||
@@ -157,34 +172,44 @@ function template_preprocess_date_views_pager(&$vars) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme the calendar title
|
||||
* Theme the calendar title.
|
||||
*/
|
||||
function theme_date_nav_title($params) {
|
||||
$title = '';
|
||||
$granularity = $params['granularity'];
|
||||
$view = $params['view'];
|
||||
$date_info = $view->date_info;
|
||||
$link = !empty($params['link']) ? $params['link'] : FALSE;
|
||||
$format = !empty($params['format']) ? $params['format'] : NULL;
|
||||
$format_with_year = variable_get('date_views_' . $granularity . 'format_with_year', 'l, F j, Y');
|
||||
$format_without_year = variable_get('date_views_' . $granularity . 'format_without_year', 'l, F j');
|
||||
$format_with_year = variable_get('date_views_' . $granularity . '_format_with_year', 'l, F j, Y');
|
||||
$format_without_year = variable_get('date_views_' . $granularity . '_format_without_year', 'l, F j');
|
||||
switch ($granularity) {
|
||||
case 'year':
|
||||
$title = $date_info->year;
|
||||
$date_arg = $date_info->year;
|
||||
break;
|
||||
|
||||
case 'month':
|
||||
$format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
|
||||
$title = date_format_date($date_info->min_date, 'custom', $format);
|
||||
$date_arg = $date_info->year . '-' . date_pad($date_info->month);
|
||||
break;
|
||||
|
||||
case 'day':
|
||||
$format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
|
||||
$title = date_format_date($date_info->min_date, 'custom', $format);
|
||||
$date_arg = $date_info->year . '-' . date_pad($date_info->month) . '-' . date_pad($date_info->day);
|
||||
$date_arg = $date_info->year;
|
||||
$date_arg .= '-';
|
||||
$date_arg .= date_pad($date_info->month);
|
||||
$date_arg .= '-';
|
||||
$date_arg .= date_pad($date_info->day);
|
||||
break;
|
||||
|
||||
case 'week':
|
||||
$format = !empty($format) ? $format : (empty($date_info->mini) ? $format_with_year : $format_without_year);
|
||||
$title = t('Week of @date', array('@date' => date_format_date($date_info->min_date, 'custom', $format)));
|
||||
$title = t('Week of @date', array(
|
||||
'@date' => date_format_date($date_info->min_date, 'custom', $format),
|
||||
));
|
||||
$date_arg = $date_info->year . '-W' . date_pad($date_info->week);
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user