You are here

function profile2_revision_list_build in Profile 2 7.2

Build the table of older revisions of a profile.

This is used by both revisions view and revisions_diff view.

2 calls to profile2_revision_list_build()
profile2_diff_profile2_revisions in contrib/profile2_diff.pages.inc
Input form to select two revisions.
profile2_revision_overview in ./profile2.module
Generate an overview table of older revisions of a profile.

File

./profile2.module, line 1574
Support for configurable user profiles.

Code

function profile2_revision_list_build($profile) {
  $revisions = profile2_revision_list($profile);

  //   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 = array();
  foreach ($revisions as $revision) {
    $row = array();
    $operations = array();

    // Set the base of the path for links in the page.
    $link_base = _profile2_revision_base_path($profile, TRUE);
    $revert_permission = user_access('administer profiles') || profile2_access('update', $profile) && _profile2_revision_access($profile, array(
      'revert own profile revisions',
      'revert any profile revisions',
    ));
    $delete_permission = user_access('administer profiles') || profile2_access('update', $profile) && _profile2_revision_access($profile, array(
      'delete own profile revisions',
      'delete any profile revisions',
    ));
    $vid = $revision->vid;
    $row[$vid] = array(
      'data' => t('!date by !username', array(
        '!date' => l(format_date($revision->timestamp), "{$link_base}/view/{$vid}"),
        '!username' => theme('username', array(
          'account' => $revision,
        )),
      )) . ($revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : ''),
      'revision' => $revision,
    );
    if ($revision->current_vid > 0) {
      $operations[] = array(
        'data' => drupal_placeholder(t('current revision')),
        'class' => array(
          'revision-current',
        ),
        'colspan' => 2,
      );
    }
    else {
      $operations[] = $revert_permission ? l(t('revert'), "{$link_base}/{$vid}/revert") : '';
      $operations[] = $delete_permission ? l(t('delete'), "{$link_base}/{$vid}/delete") : '';
    }
    $data[] = array(
      'row' => $row,
      'operations' => $operations,
    );
  }
  return $data;
}