You are here

function redhen_contact_revision_list in RedHen CRM 7

Page callback for listing contact revisions.

Parameters

Entity $contact: The contact entity.

Return value

array A renderable array.

1 string reference to 'redhen_contact_revision_list'
redhen_contact_menu in modules/redhen_contact/redhen_contact.module
Implements hook_menu().

File

modules/redhen_contact/includes/redhen_contact.pages.inc, line 204

Code

function redhen_contact_revision_list(Entity $contact) {
  drupal_set_title(t('Revisions for %title', array(
    '%title' => $contact
      ->label(),
  )), PASS_THROUGH);
  $header = array(
    t('Revision'),
    array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );

  // There is no way to list revisions using EFQ, thus use a direct SQL query.
  $revision_ids = db_select('redhen_contact_revision', 'r')
    ->fields('r', array(
    'revision_id',
  ))
    ->condition('contact_id', $contact->contact_id)
    ->orderBy('updated', 'DESC')
    ->execute()
    ->fetchCol();
  $rows = array();
  foreach ($revision_ids as $revision_id) {
    $row = array();
    $operations = array();
    $revision = entity_revision_load('redhen_contact', $revision_id);
    if ($revision
      ->isDefaultRevision()) {
      $row[] = array(
        'data' => t('!date by !username', array(
          '!date' => l(format_date($revision->updated, 'short'), "redhen/contact/{$revision->contact_id}"),
          '!username' => theme('username', array(
            'account' => user_load($revision->author_uid),
          )),
        )),
        'class' => array(
          'revision-default',
        ),
      );
      $operations[] = array(
        'data' => drupal_placeholder(t('default revision')),
        'class' => array(
          'revision-default',
        ),
        'colspan' => 2,
      );
    }
    else {
      $row[] = t('!date by !username', array(
        '!date' => l(format_date($revision->updated, 'short'), "redhen/contact/{$revision->contact_id}/revisions/{$revision->revision_id}/view"),
        '!username' => theme('username', array(
          'account' => user_load($revision->author_uid),
        )),
      ));
      if (redhen_contact_access('edit', $revision)) {
        $operations[] = l(t('edit'), "redhen/contact/{$revision->contact_id}/revisions/{$revision->revision_id}/edit");
      }
      if (redhen_contact_access('delete', $revision)) {
        $operations[] = l(t('delete'), "redhen/contact/{$revision->contact_id}/revisions/{$revision->revision_id}/delete");
      }
    }
    $rows[] = array_merge($row, $operations);
  }
  $build['revisions_table'] = array(
    '#theme' => 'table',
    '#rows' => $rows,
    '#header' => $header,
  );
  return $build;
}