I'm working on a view that displays the body and links for the current and latest (pending) revision.

Content:Body will display the current revision body.
Using Views PHP, I was able to output the link for the pending revision.
Does anyone have any ideas on how I can display the body for the pending revision?
I'd like to have a side by side comparison on one page.

Thanks,

  $nid = $row->nid;
  $latest_vid = revisioning_get_latest_revision_id($nid);
  $current_vid = revisioning_get_current_node_revision_id($nid);
  if ($current_vid == $latest_vid) {
    echo "<a href='node/$nid/edit'>Edit current</a>";
  } else {
    echo "<a href='node/$nid/revisions/$latest_vid/compare'>Compare</a>";
  }
CommentFileSizeAuthor
#5 views diff.jpg148.9 KBkingdee40
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

RdeBoer’s picture

Hi kingdee,
Why not use the Diff module integration that comes with Revisioning?
Rik

kingdee40’s picture

Diff does a side by side comparison of one revision, I need a side by side comparison of all revisions on one page.

RdeBoer’s picture

This is rather crude, but should do the trick:

  $revision = node_load($row->nid, revisioning_get_latest_revision_id($row->nid));
  echo $revision->body[$revision->language][0]['value'];

Rik

RdeBoer’s picture

Assigned: Unassigned » RdeBoer
Status: Active » Fixed
kingdee40’s picture

FileSize
148.9 KB

Cool, thanks for the help. I kinda wrote my own diff for views display. It's for admin use only so performance isn't my concern. If anyone is interested I'll post the code. It doesn't work as well as the real diff module but I needed a quick visual of all revisions on one page.
This is for views php module:


$str_new = db_query('SELECT body_value FROM `field_data_body` WHERE entity_id = ' . $data->nid)->fetchColumn();

$str_old = db_query('SELECT body_value FROM `field_revision_body` frb JOIN `node` n ON n.nid = frb.entity_id AND n.vid = frb.revision_id WHERE entity_id = ' . $data->nid)->fetchColumn();

$cv = explode("\n", $str_new); // Current Version
$ov = explode("\n", $str_old); // Old Version

// Count Lines - Set to Longer Version
$lc = (count($cv) > count($ov)) ? count($cv) : count($ov);

// Fix Mismatched Line Counts
for ($flc = count($ov); $flc != $lc; $flc++) {
    $ov["$flc"] = '';
}

for ($l = '0'; $l != $lc; $l++) {
    // Word Arrays
    $cw = explode(' ', $cv["$l"]); // Current Version
    $ow = explode(' ', $ov["$l"]); // Old Version

    // Count Words - Set to Longer Version
    $wc = (count($cw) > count($ow)) ? count($cw) : count($ow);

    // Fix Mismatched Word Counts
    for ($fwc = count($ow); $fwc != $wc; $fwc++) {
        $ow["$fwc"] = '';
    }

    // If each line is identical, just echo the normal line. If not,
    // check if each word is identical. If not, wrap colored "<b>"
    // tags around the mismatched words.
    if ($cv["$l"] !== $ov["$l"]) {
        for ($w = '0'; $w != $wc; $w++) {
            if ($cw["$w"] === $ow["$w"]) {
                echo $cw["$w"];
                echo ($w != ($wc - 1)) ? ' ' : "\n";
            } else {
                echo '<b style="color: #00BB00;">' . $cw["$w"];
                echo ($w != ($wc - 1)) ? '</b> ' : "</b>\n";
            }
        }
    } else {
        echo $cv["$l"] . "\n";
    }
}

RdeBoer’s picture

That's pretty impressive kingdee!

RdeBoer’s picture

Added reference to this issue to the project page. Thanks again kingdee!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.