You are here

public function QueryActivity::validActivity in Activity 8

Valid function.

Parameters

string $eventId: The action id.

Return value

bool Return the entity.

1 call to QueryActivity::validActivity()
QueryActivity::insertActivity in src/QueryActivity.php
Insert into activity.

File

src/QueryActivity.php, line 138

Class

QueryActivity
Provides queries for activity.

Namespace

Drupal\activity

Code

public function validActivity($eventId) {
  $timestamp = \Drupal::time()
    ->getCurrentTime();

  // Get the right value for window option.
  // When to insert logs based on timestamp.
  $queryEvent = $this->database
    ->select('activity_events', 'ev')
    ->fields('ev', [
    'message',
  ])
    ->condition('event_id', $eventId, '=')
    ->execute()
    ->fetchAll();
  $message = $queryEvent[0]->message;
  $message = json_decode($message);
  $window = $message->window;

  // Count if there are similar actions with the same label
  // in the last $window seconds.
  $count = $this->database
    ->select('activity', 'act')
    ->fields('act', [
    'action_id',
  ])
    ->condition('event_id', $eventId, '=')
    ->condition('created', $timestamp - $window, '>')
    ->countQuery()
    ->execute()
    ->fetchField();
  return $count == 0;
}