You are here

function views_revisions_page in Views Revisions 7

Same name and namespace in other branches
  1. 6 views_revisions.module \views_revisions_page()

Page callback function for the views revisions page.

1 string reference to 'views_revisions_page'
views_revisions_menu in ./views_revisions.module
Implements hook_menu().

File

./views_revisions.module, line 115
A module to provide revisions of Views.

Code

function views_revisions_page($name) {
  $html = "<h2>{$name}</h2><p>" . l('Go Back to View', "admin/structure/views/view/{$name}") . " &raquo;</p>";
  $result = db_query("SELECT vid FROM {views_view} WHERE name = :name", array(
    ':name' => $name,
  ))
    ->fetch();
  if (!$result) {
    $html .= t('Failed to load view!');
    return $html;
  }
  $vid = $result->vid;
  $revisions = db_query("SELECT vr.vrvid, vr.vid, vr.uid, vr.created, vr.log, u.name\n    FROM {views_revisions} vr\n    LEFT OUTER JOIN {users} u ON vr.uid = u.uid\n    WHERE vr.vid = :vid\n    ORDER BY vr.created DESC", array(
    ':vid' => $vid,
  ))
    ->fetchAll();
  if (sizeof($revisions) == 0) {
    $html .= t('There are no revisions for this view.');
    return $html;
  }
  $header = array(
    array(
      "data" => t('User'),
    ),
    array(
      "data" => t('Message'),
    ),
    array(
      "data" => t('Created'),
    ),
    array(
      "data" => t('Revision'),
    ),
  );
  $rows = array();
  foreach ($revisions as $revision) {
    $row = array(
      l($revision->name, "user/{$revision->uid}"),
      filter_xss($revision->log),
      format_date($revision->created, 'custom', 'Y-m-d H:i:s'),
      l('View', "admin/structure/views/revisions/revision/{$revision->vrvid}") . "<br>" . l("Edit message", "admin/structure/views/revisions/revision/{$revision->vrvid}/edit"),
    );
    $rows[] = $row;
  }
  $html .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
  ));
  return $html;
}