0

I am using the evaluation quiz module. Users fill out the question and (not using the score that is calculated by the quix module) they are given a score by giving each of their answers points which are then totaled.

I'm wondering is there an easy way to subtract one revision of the users answer from another revision to get the difference.

I have no problem getting the results from each revision but just dont know how to subtract the second to latest revision from the latest revision.

1

I could not find a module which does the same, but you can achieve this by custom codes.Not the exact codes but still covers the major things

  // get all revisions for a node
  // this function returns array of revision in order of revisions are created,with the latest revision at the top and last revision as the next array element
  $get_revisions = array_values(node_revision_list(node_load($node_id))));
  if(count($get_revisions) > 1) {
    $current_node_version = $get_revisions[0]->vid;
    $last_node_version = $get_revisions[1]->vid;
  } else {
    // No differnece,since there is only one version.
  }

  //Now load the nodes with the versions
  $current_node = node_load($node_id,$latest_node_version);
  $last_node = node_load($node_id,$last_node_version);

  // Once you have loaded nodes you can easily do the custom calculations,something like
  $field_1_diff = $current_node->field_1_diff... - $last_node->field_1_diff...
  • I need to create a custom module for this? – Craicerjack Nov 20 '13 at 21:34
  • yes, and also you need to figure out a where you will be showing the information, if on the node view itself then you can create custom blocks from code and place this code inside hook_block_view(), if you do not have problem in using php inside blocks from block module(not recommended) then you can put this code there also(in that case you will not need a custom module).**remember** you need to get the node id as required $node_id variable – arpitr Nov 20 '13 at 21:42
  • Yeah, this is just one small calculation i need it for and I'm not that familiar with module creation - I was just wondering is there a simple way to do subtraction. Thanks for the code though. If I get the time I'll look into it. – Craicerjack Nov 21 '13 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.