You are here

function views_autorefresh_get_timestamp in Views Auto-Refresh 7

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

Helper function to return a view timestamp.

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 154

Code

function views_autorefresh_get_timestamp($view) {
  $autorefresh = views_autorefresh_get_settings($view);
  if (empty($autorefresh)) {
    return FALSE;
  }
  if (empty($autorefresh['incremental'])) {
    return time();
  }
  $autorefresh_display = $autorefresh['display'];
  $arguments = isset($view->display[$autorefresh_display]->display_options['arguments']) ? $view->display[$autorefresh_display]->display_options['arguments'] : $view->display['default']->display_options['arguments'];
  if ($arguments) {
    foreach ($arguments as $argument) {
      $handler = views_get_handler($argument['table'], $argument['field'], 'argument');
      switch ($handler->definition['handler']) {
        case 'views_autorefresh_handler_argument_date':
          return time();
          break;
        case 'views_autorefresh_handler_argument_base':

          // Fallback to max primary key in view rows.
          // 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;
          break;
      }
    }
  }
  return FALSE;
}