You are here

function views_autorefresh_get_timestamp in Views Auto-Refresh 7.2

Same name and namespace in other branches
  1. 7 views_autorefresh.module \views_autorefresh_get_timestamp()

Helper function to return view's "timestamp" - either real timestamp or max primary key in view rows.

2 calls to views_autorefresh_get_timestamp()
theme_views_autorefresh in ./views_autorefresh.module
Theme function for 'views_autorefresh'.
views_autorefresh_views_ajax_data_alter in ./views_autorefresh.module
Implementation of hook_views_ajax_data_alter().

File

./views_autorefresh.module, line 105

Code

function views_autorefresh_get_timestamp($view) {
  $autorefresh = $view->header['autorefresh']->options;
  if (empty($autorefresh)) {
    return FALSE;
  }
  if (empty($autorefresh['incremental'])) {
    return time();
  }
  foreach ($view->argument as $argument) {
    $handler = views_get_handler($argument->table, $argument->field, 'argument');
    if ($handler->definition['handler'] == 'views_autorefresh_handler_argument_date') {
      return time();
    }
    else {
      if ($handler->definition['handler'] == 'views_autorefresh_handler_argument_base') {

        // Find the max nid/uid/... of the result set.
        $max_id = array_reduce($view->result, function ($max_id, $row) use ($view) {
          return max($max_id, $row->{$view->base_field});
        }, ~PHP_INT_MAX);
        return $max_id === ~PHP_INT_MAX ? FALSE : $max_id;
      }
    }
  }
  return FALSE;
}