class DeviceGeolocation in Smart IP 8.4
Same name and namespace in other branches
- 8.3 modules/device_geolocation/src/DeviceGeolocation.php \Drupal\device_geolocation\DeviceGeolocation
Device Geolocation static basic methods wrapper.
@package Drupal\device_geolocation
Hierarchy
- class \Drupal\device_geolocation\DeviceGeolocation
Expanded class hierarchy of DeviceGeolocation
2 files declare their use of DeviceGeolocation
- DeviceGeolocationController.php in modules/
device_geolocation/ src/ Controller/ DeviceGeolocationController.php - Contains \Drupal\device_geolocation\Controller\DeviceGeolocationController.
- device_geolocation.module in modules/
device_geolocation/ device_geolocation.module - Provides visitor's geographical location using client device location source that implements W3C Geolocation API and Google Geocoding service.
File
- modules/
device_geolocation/ src/ DeviceGeolocation.php, line 18 - Contains \Drupal\device_geolocation\DeviceGeolocation.
Namespace
Drupal\device_geolocationView source
class DeviceGeolocation {
/**
* Check if user's location needs update via client side.
*
* @return bool
*/
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;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeviceGeolocation:: |
public static | function | Check if user's location needs update via client side. |