Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Gets all revisions for a Quiz and calculates completed takes for each revision.
- *
- * @param string $vid
- * @return array
- */
- function _get_revisions( $vid ) {
- // Fetch node id for the given revision id ($vid).
- $sql = "SELECT nid FROM {node_revisions} WHERE vid = %d";
- $nid = db_result( db_query( $sql, $vid ) );
- // Fetch all revisions of a quiz, and count how many takes
- // for each revision.
- $sql = "SELECT
- nr.vid,
- COUNT(qnr.vid) AS count
- FROM
- node_revisions nr
- INNER JOIN
- quiz_node_results qnr ON qnr.vid = nr.vid
- WHERE
- nr.nid = %d
- GROUP BY
- nr.vid
- ORDER BY
- nr.vid DESC";
- $result = db_query( $sql, $nid );
- // Make for options from last query
- $options = array();
- $revision_count = mysql_num_rows( $result );
- while( $arr = db_fetch_array($result) ) {
- $options[$arr['vid']] = t('Revision %revision (%takes)', array( '%revision' => $revision_count, '%takes' => format_plural($arr['count'], '1 take', '@count takes')));
- $revision_count--;
- }
- // Make form
- $form = array();
- $form['quiz-revision'] = array(
- '#type' => 'fieldset',
- '#title' => t('Select Quiz revision'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['quiz-revision']['revisions'] = array(
- '#type' => 'select',
- '#title' => t('Choose revision'),
- '#default_value' => $vid,
- '#options' => $options,
- '#description' => t('Change revision and statistics should update to show that revision'),
- );
- // Return form
- return $form;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement