<?php

class bigw_handler_user_complete_quiz extends views_handler_field {

	/**
	 * Loads additional fields.
	 */
	function query() {
		$this->ensure_my_table();
		$this->add_additional_fields();
	}

	/**
	 * Default options form.
	 */
	function option_definition() {
		$options = parent::option_definition();

		$options['nid'] = array('default' => '');

		return $options;
	}

	/**
	 * Creates the form item for the options added.
	 */
	function options_form(&$form, &$form_state) {
		parent::options_form($form, $form_state);

		$form['nid'] = array(
			'#type' => 'textfield',
			'#title' => t('nid'),
			'#default_value' => $this->options['nid'],
			'#description' => t('Pass nid to get how many users complete quiz.'),
			'#weight' => -10,
		);
	}

	/**
	 * Renders the field handler.
	 */
	function render($values) {
		$value = count(bigw_get_users_from_quiz($values->nid));
		return $value;
	}
}