You are here

public function TaskManager::getUserTasks in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_tasks/src/TaskManager.php \Drupal\gdpr_tasks\TaskManager::getUserTasks()
  2. 3.0.x modules/gdpr_tasks/src/TaskManager.php \Drupal\gdpr_tasks\TaskManager::getUserTasks()

Fetch tasks for a certain user.

Parameters

null|\Drupal\Core\Session\AccountInterface $account: The user account to get tasks for. Defaults to current user.

null|string $type: Optionally filter by task type.

Return value

array|\Drupal\gdpr_tasks\Entity\TaskInterface[] Array of fully loaded task entities.

File

modules/gdpr_tasks/src/TaskManager.php, line 62

Class

TaskManager
Defines a helper class for stuff related to views data.

Namespace

Drupal\gdpr_tasks

Code

public function getUserTasks($account = NULL, $type = NULL) {
  $tasks = [];
  if (!$account) {
    $account = $this->currentUser
      ->getAccount();
  }
  $query = $this->taskStorage
    ->getQuery();
  $query
    ->condition('user_id', $account
    ->id(), '=');
  if ($type) {
    $query
      ->condition('type', $type, '=');
  }
  if (!empty($ids = $query
    ->execute())) {
    $tasks = $this->taskStorage
      ->loadMultiple($ids);
  }
  return $tasks;
}