Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. /**
  2.  * Gets all revisions for a Quiz and calculates completed takes for each revision.
  3.  *
  4.  * @param string $vid
  5.  * @return array
  6.  */
  7. function _get_revisions( $vid ) {
  8.  
  9.   // Fetch node id for the given revision id ($vid).
  10.   $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
  11.   $nid = db_result( db_query( $sql, $vid ) );
  12.  
  13.   // Fetch all revisions of a quiz, and count how many takes
  14.   // for each revision.
  15.   $sql = "SELECT
  16.            nr.vid,
  17.            COUNT(qnr.vid) AS count
  18.          FROM
  19.            node_revisions nr
  20.          INNER JOIN
  21.            quiz_node_results qnr ON qnr.vid = nr.vid
  22.          WHERE
  23.            nr.nid = %d
  24.          GROUP BY
  25.            nr.vid
  26.          ORDER BY
  27.            nr.vid DESC";
  28.  
  29.   $result = db_query( $sql, $nid );
  30.  
  31.   // Make for options from last query
  32.   $options = array();
  33.   $revision_count = mysql_num_rows( $result );
  34.  
  35.   while( $arr = db_fetch_array($result) ) {
  36.     $options[$arr['vid']] = t('Revision %revision (%takes)', array( '%revision' => $revision_count, '%takes' => format_plural($arr['count'], '1 take', '@count takes')));
  37.     $revision_count--;
  38.   }
  39.  
  40.   // Make form
  41.   $form = array();
  42.   $form['quiz-revision'] = array(
  43.     '#type' => 'fieldset',
  44.     '#title' => t('Select Quiz revision'),
  45.     '#collapsible' => TRUE,
  46.     '#collapsed' => FALSE,
  47.   );
  48.  
  49.   $form['quiz-revision']['revisions'] = array(
  50.     '#type' => 'select',
  51.     '#title' => t('Choose revision'),
  52.     '#default_value' => $vid,
  53.     '#options' => $options,
  54.     '#description' => t('Change revision and statistics should update to show that revision'),
  55.   );
  56.  
  57.   // Return form
  58.   return $form;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement