function _revisioning_get_all_revisions_for_node in Revisioning 8
Same name and namespace in other branches
- 6.4 revisioning_api.inc \_revisioning_get_all_revisions_for_node()
- 6.3 revisioning_api.inc \_revisioning_get_all_revisions_for_node()
- 7 revisioning_api.inc \_revisioning_get_all_revisions_for_node()
Retrieve a list of all revisions belonging to the supplied node.
Includes archive, current, and pending revisions.
Parameters
int $nid: The node id to retrieve.
bool $include_taxonomy_terms: Whether to also retrieve the taxonomy terms for each revision
Return value
array 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.
File
- ./
revisioning_api.inc, line 876 - API functions of Revisioning module
Code
function _revisioning_get_all_revisions_for_node($nid, $include_taxonomy_terms = FALSE) {
$node = node_load($nid);
$sql_select = 'SELECT r.vid, r.status, r.title, r.log, r.uid, r.timestamp, u.name';
$sql_from = ' FROM {node_revision} r INNER JOIN {users} u ON r.uid=u.uid';
$sql_where = ' WHERE r.nid = :nid ORDER BY r.vid DESC';
if ($include_taxonomy_terms) {
$conditions = array(
'type' => 'taxonomy_term_reference',
);
$fields = field_read_fields($conditions);
foreach ($fields as $field => $data) {
$field_instance = field_read_instance('node', $field, $node->type);
if ($field_instance) {
$sql_select .= ", ttd_{$field}.name AS " . ($field == 'field_tags' ? 'tags' : 'term');
$sql_from .= " LEFT JOIN {field_revision_{$field}} r_{$field} ON r.vid = r_{$field}.revision_id LEFT JOIN {taxonomy_term_data} ttd_{$field} ON r_{$field}.{$field}_tid=ttd_{$field}.tid";
}
}
}
$sql = $sql_select . $sql_from . $sql_where;
$result = db_query($sql, array(
':nid' => $nid,
));
$revisions = array();
foreach ($result as $revision) {
if (empty($revisions[$revision->vid])) {
$revision->current = $node->vid;
$revisions[$revision->vid] = $revision;
}
elseif ($include_taxonomy_terms) {
$existing_revision = $revisions[$revision->vid];
if (!empty($revision->term)) {
if (strpos($existing_revision->term, $revision->term) === FALSE) {
// Bit of a quick & dirty -- goes wrong if a term is substr of
// another.
$existing_revision->term .= ", {$revision->term}";
}
}
if (!empty($revision->tags)) {
if (strpos($existing_revision->tags, $revision->tags) === FALSE) {
$existing_revision->tags .= ", {$revision->tags}";
}
}
}
}
return $revisions;
}