You are here

function _get_all_revisions_for_node in Revisioning 6

Retrieve a list of all revisions (old, current, pending) belonging to the supplied node.

Parameters

$nid: The node id to retrieve.

$include_taxonomy_terms: Whether to also retrieve the taxonomy terms for each revision

Return value

An array of revision objects, each with published flag, log message, vid, title, timestamp and name of user that created the revision

1 call to _get_all_revisions_for_node()
_theme_node_revisions in ./revisioning.module
Theme the revisions of the supplied node in a table.

File

./revisioning.module, line 526

Code

function _get_all_revisions_for_node($nid, $include_taxonomy_terms = FALSE) {
  $sql_select = 'SELECT n.status, r.vid, r.title, r.log, r.uid, r.timestamp, u.name';
  $sql_from = ' FROM {node_revisions} r LEFT JOIN {node} n ON n.vid=r.vid INNER JOIN {users} u ON u.uid=r.uid';
  $sql_where = ' WHERE r.nid=%d ORDER BY r.vid DESC';
  if ($include_taxonomy_terms) {
    $sql_select .= ', td.name AS term';
    $sql_from .= ' LEFT JOIN {term_node} tn ON r.vid=tn.vid LEFT JOIN {term_data} td ON tn.tid=td.tid';
  }
  $sql = $sql_select . $sql_from . $sql_where;
  $result = db_query($sql, $nid);
  $revisions = array();
  while ($revision = db_fetch_object($result)) {
    if (empty($revisions[$revision->vid])) {
      $revisions[$revision->vid] = $revision;
    }
    elseif ($include_taxonomy_terms) {

      // If a revision has more than one taxonomy term, these will be returned
      // by the query as seperate objects differing only in their term fields.
      $existing_revision = $revisions[$revision->vid];
      $existing_revision->term .= '/' . $revision->term;
    }
  }
  return $revisions;
}