You are here

function _revisioning_get_all_revisions_for_node in Revisioning 6.4

Same name and namespace in other branches
  1. 8 revisioning_api.inc \_revisioning_get_all_revisions_for_node()
  2. 6.3 revisioning_api.inc \_revisioning_get_all_revisions_for_node()
  3. 7 revisioning_api.inc \_revisioning_get_all_revisions_for_node()

Retrieve a list of all revisions (archive, 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 _revisioning_get_all_revisions_for_node()
revisioning_revisions_summary in ./revisioning_theme.inc
Return revisions summary table data. If the Diff modules is enabled, the object returned includes a column of checkboxes allowing the user to select two revisions for side-by-side comparison.

File

./revisioning_api.inc, line 370
API functions of Revisioning module

Code

function _revisioning_get_all_revisions_for_node($nid, $include_taxonomy_terms = FALSE) {
  $sql_select = 'SELECT n.type, 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_where .= ', term ASC';
  }
  $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;
}