You are here

public function SmartIpLocation::getData in Smart IP 8.2

Same name and namespace in other branches
  1. 8.4 src/SmartIpLocation.php \Drupal\smart_ip\SmartIpLocation::getData()
  2. 8.3 src/SmartIpLocation.php \Drupal\smart_ip\SmartIpLocation::getData()

Gets all the Smart IP location data.

Return value

array An array of Smart IP location data.

Overrides SmartIpLocationInterface::getData

1 call to SmartIpLocation::getData()
SmartIpLocation::get in src/SmartIpLocation.php
Gets an item in Smart IP location data or all the Smart IP location data if supplied no parameter.

File

src/SmartIpLocation.php, line 149
Contains \Drupal\smart_ip\SmartIpLocation.

Class

SmartIpLocation
Implements wrapper and utility methods for Smart IP's data location.

Namespace

Drupal\smart_ip

Code

public function getData() {
  if (empty($this->allData)) {
    $user = \Drupal::currentUser();
    SmartIp::updateUserLocation();

    // Get current user's stored location from session
    $data = SmartIp::getSession('smart_ip');
    if (empty($data['location']) && $user
      ->id() != 0) {

      /** @var \Drupal\user\UserData $userData */
      $userData = \Drupal::service('user.data');

      // Get current user's stored location from user_data
      $data = $userData
        ->get('smart_ip', $user
        ->id(), 'geoip_location');
    }
    if (!empty($data['location'])) {

      // Populate the Smart IP location from current user's data or session
      $this
        ->setData($data['location']);
    }
  }
  return $this->allData;
}