You are here

function gdpr_tasks_request in General Data Protection Regulation 7

Request page for user.

1 string reference to 'gdpr_tasks_request'
gdpr_tasks_menu in modules/gdpr_tasks/gdpr_tasks.module
Implements hook_menu().

File

modules/gdpr_tasks/gdpr_tasks.pages.inc, line 22
Page callbacks for the GDPR Tasks module.

Code

function gdpr_tasks_request($account, $gdpr_task_type) {
  $tasks = gdpr_tasks_get_user_tasks($account, $gdpr_task_type);
  $pending = FALSE;
  if ($tasks) {
    foreach ($tasks as $task) {
      if (in_array($task->status, array(
        'requested',
        'processed',
      ), TRUE)) {
        $pending = TRUE;
      }
    }
  }
  if ($pending) {
    drupal_set_message(t('You already have a pending task.'), 'warning');
  }
  else {
    global $user;
    $values = array(
      'type' => $gdpr_task_type,
      'user_id' => $account->uid,
      'requested_by' => $user->uid,
    );
    $task = entity_create('gdpr_task', $values);
    $task
      ->save();

    // Send confirmation email to user.
    if ($task->requested_by == $task->user_id) {
      gdpr_tasks_send_mail('task_requested_self', $task);
    }
    else {
      gdpr_tasks_send_mail('task_requested_other', $task);
    }
    drupal_set_message(t('Your request has been logged.'));
  }
  drupal_goto("user/{$account->uid}/gdpr/requests");
}