You are here

class IpPosts in IP address manager 8.2

Hierarchy

Expanded class hierarchy of IpPosts

1 file declares its use of IpPosts
ip.module in ./ip.module
IP address manager module.

File

src/IpPosts.php, line 19
Contains Drupal\ip\IpPosts

Namespace

Drupal\ip
View source
class IpPosts {
  private $connection;
  private $entity;
  private $request;
  function __construct(Connection $connection, Request $request, EntityInterface $entity) {
    $this->connection = $connection;
    $this->request = $request;
    $this->entity = $entity;
  }

  /**
   * Save the IpTrack
   * @return type
   */
  function save() {
    $ip = $this->request
      ->getClientIp();
    $iplong = ip2long($ip);
    if (!empty($iplong) && is_numeric($this->entity
      ->id())) {
      return $this->connection
        ->insert('ip_posts')
        ->fields(array(
        'type' => $this->entity
          ->getEntityTypeId(),
        'id' => $this->entity
          ->id(),
        'ip' => $iplong,
      ))
        ->execute();
    }
  }

  /**
   * Remove records in the ip_posts table for a certain entity.
   */
  function remove() {
    return $this->connection
      ->delete('ip_posts')
      ->condition('type', $this->entity
      ->getEntityTypeId())
      ->condition('id', $this->entity
      ->id())
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IpPosts::$connection private property
IpPosts::$entity private property
IpPosts::$request private property
IpPosts::remove function Remove records in the ip_posts table for a certain entity.
IpPosts::save function Save the IpTrack
IpPosts::__construct function