You are here

public static function DeviceGeolocation::isNeedUpdate in Smart IP 8.3

Same name and namespace in other branches
  1. 8.4 modules/device_geolocation/src/DeviceGeolocation.php \Drupal\device_geolocation\DeviceGeolocation::isNeedUpdate()

Check if user's location needs update via client side.

Return value

bool

2 calls to DeviceGeolocation::isNeedUpdate()
DeviceGeolocationController::check in modules/device_geolocation/src/Controller/DeviceGeolocationController.php
Check for Geolocation attempt.
device_geolocation_page_attachments in modules/device_geolocation/device_geolocation.module
Implements hook_page_attachments().

File

modules/device_geolocation/src/DeviceGeolocation.php, line 25
Contains \Drupal\device_geolocation\DeviceGeolocation.

Class

DeviceGeolocation
Device Geolocation static basic methods wrapper.

Namespace

Drupal\device_geolocation

Code

public static function isNeedUpdate() {
  $config = \Drupal::config(SmartIpEventSubscriber::configName());
  $frequencyCheck = $config
    ->get('frequency_check');
  $timestamp = SmartIp::getSession('device_geolocation_last_attempt');
  if ($frequencyCheck === NULL) {

    // User's device geolocation checking is set disabled.
    return FALSE;
  }
  elseif (is_null(SmartIp::getSession('device_geolocation')) && empty($timestamp)) {

    // The user has not allowed to share his/her location yet then return that
    // user's location needs update and start the timer.
    SmartIp::setSession('device_geolocation_last_attempt', \Drupal::time()
      ->getRequestTime());
    return TRUE;
  }
  elseif (!empty($timestamp) && $frequencyCheck < \Drupal::time()
    ->getRequestTime() - $timestamp) {

    // Return that user's location needs update and reset the timer.
    SmartIp::setSession('device_geolocation_last_attempt', \Drupal::time()
      ->getRequestTime());
    return TRUE;
  }
  return FALSE;
}