You are here

function gdpr_consent_display_changes in GDPR Consent 7

Get all changes since user last accepted.

Parameters

array $form: Form array.

int $uid: User uid.

Return value

array Returns changes to form.

2 calls to gdpr_consent_display_changes()
gdpr_consent_accept_form in ./gdpr_consent.module
Consent acceptance form.
gdpr_consent_form_user_profile_form_alter in ./gdpr_consent.module
Implements hook_form_FORM_ID_alter().

File

./gdpr_consent.module, line 973
Module file for GDPR Consent.

Code

function gdpr_consent_display_changes(array $form, $uid) {
  $bullet_points = array();
  $last_accepted = gdpr_consent_get_accept($uid);
  if (empty($last_accepted)) {
    return $form;
  }
  $result = db_select('gdpr_consent_conditions', 'lc')
    ->fields('lc')
    ->condition(db_or()
    ->condition('version', $last_accepted['version'], '>')
    ->condition(db_and()
    ->condition('version', $last_accepted['version'])
    ->condition('revision', $last_accepted['revision'], '>')))
    ->condition('language', $last_accepted['language'])
    ->orderBy('revision', 'ASC')
    ->orderBy('version', 'ASC')
    ->execute()
    ->fetchAllAssoc('tc_id');
  if (empty($result)) {
    return $form;
  }
  foreach ($result as $term) {
    $changes = filter_xss_admin($term->changes);
    if (!empty($changes)) {
      $bullet_points = array_merge($bullet_points, explode("\r\n", $changes));
    }
  }
  if (empty($bullet_points)) {
    return $form;
  }
  $form['changes'] = array(
    '#type' => 'fieldset',
    '#title' => t('Changes list'),
    '#description' => t('Changes to the consent since last accepted:'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#tree' => TRUE,
  );
  $form['changes']['bullet_points'] = array(
    '#markup' => theme('item_list', array(
      'items' => $bullet_points,
    )),
  );
  return $form;
}