You are here

function profile2_diff_profile2_revisions in Profile 2 7.2

Input form to select two revisions.

Parameters

$viewed_profile: Profile whose revisions are displayed for selection.

1 string reference to 'profile2_diff_profile2_revisions'
profile2_diff_diffs_overview in contrib/profile2_diff.pages.inc
Generate an overview table of older revisions of a profile and provide an input form to select two revisions for a comparison.

File

contrib/profile2_diff.pages.inc, line 48
Menu callbacks for hook_menu().

Code

function profile2_diff_profile2_revisions($form, $form_state, $viewed_profile) {

  /*
    $revision_list = profile2_revision_list($viewed_profile);
    $revision_count = count($revision_list);

    if ($revision_count > REVISION_LIST_SIZE) {
      // If the list of revisions is longer than the number shown on one page split the array.
      $page = isset($_GET['page']) ? $_GET['page'] : '0';
      $revision_chunks = array_chunk(profile2_revision_list($viewed_user), REVISION_LIST_SIZE);
      $revisions = $revision_chunks[$page];
      // Set up global pager variables as would 'pager_query' do.
      // These variables are then used in the theme('pager') call later.
      global $pager_page_array, $pager_total, $pager_total_items;
      $pager_total_items[0] = $revision_count;
      $pager_total[0] = ceil($revision_count / REVISION_LIST_SIZE);
      $pager_page_array[0] = max(0, min($page, ((int)$pager_total[0]) - 1));
    }
    else {
      $revisions = $revision_list;
    }*/
  $data = profile2_revision_list_build($viewed_profile);

  // Each element of $data is an array containing:
  // 'row': an array keyed by the revision-id, containing an array keyed 'data' containing markup.
  // 'operations: an array containing revert and delete links.
  foreach ($data as $item) {
    $row = $item['row'];
    $vid = key($row);
    $revision_ids[$vid] = '';
    $form['info'][$vid] = array(
      '#markup' => $row[$vid]['data'],
      '#revision' => $row[$vid]['revision'],
    );
    $operations = array();
    foreach ($item['operations'] as $operation) {
      if (!is_array($operation)) {
        $operations[] = array(
          '#markup' => $operation,
        );
      }
    }
    $form['operations'][$vid] = $operations;
  }
  $new_vid = key($revision_ids);
  next($revision_ids);
  $old_vid = key($revision_ids);
  $form['diff']['old'] = array(
    '#type' => 'radios',
    '#options' => $revision_ids,
    '#default_value' => $old_vid,
  );
  $form['diff']['new'] = array(
    '#type' => 'radios',
    '#options' => $revision_ids,
    '#default_value' => $new_vid,
  );
  $form['profile'] = array(
    '#type' => 'value',
    '#value' => $viewed_profile,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Compare'),
  );

  //   if ($revision_count > REVISION_LIST_SIZE) {
  //     $form['#suffix'] = theme('pager', NULL, REVISION_LIST_SIZE, 0);
  //   }
  // use the diff module's theme function.
  $form['#attached'] = diff_build_attachments(TRUE);
  $form['#theme'] = 'diff_node_revisions';
  return $form;
}