Skip to content
Snippets Groups Projects
Commit ce231e67 authored by Sam Boyer's avatar Sam Boyer
Browse files

Initial attempt at field that performs score aggregation.

parent bba5fee4
No related branches found
No related tags found
No related merge requests found
<?php
// $Id$
class quiz_views_handler_field_score_aggregate extends views_handler_field_numeric {
function construct() {
parent::construct();
// This will have to change to be set by options if the methods are ever expanded
$this->group_field = $this->definition['group field'];
}
function option_definition() {
$options = parent::option_definition();
return $options;
}
function query() {
$this->ensure_my_table();
// $this->add_additional_fields();
// $results_field_alias = $this->additional_fields['qnr_score']['field'];
dsm($this);
// $results_table = $this->query->get_table_info($this->additional_fields['qnr_score']['table']);
$this->query->add_field($this->table_alias, $this->group_field);
$this->field_alias = $this->query->add_field(
NULL, "AVERAGE($this->table_alias.$this->real_field)",
$results_table['alias'] . '__average', array('aggregate' => TRUE)
);
$this->query->add_groupby("$this->table_alias.$this->group_field"); // nid is OK for average. Others maybe not so much
// $base_join = $this->get_join_data($this->table_alias, $this->base_table);
// $results_join = $this->get_join_data($this->results_table['alias'], $this->base_table);
//
// $this->add_relationship($this->table_alias . '__join', $this->get_join_data($this->table_alias, $this->base_table), $this->base_table);
// $this->add_relationship($this->table_alias . '__join', $results_join, $this->base_table, $this->table);
dsm($this);
dsm($this->query);
}
}
\ No newline at end of file
......@@ -22,6 +22,9 @@ function quiz_views_handlers() {
'quiz_views_handler_field_user_quiz_state' => array(
'parent' => 'views_handler_field',
),
'quiz_views_handler_field_score_aggregate' => array(
'parent' => 'views_handler_field_numeric',
),
// Filters
'quiz_views_handler_filter_question_status' => array(
'parent' => 'views_handler_filter_in_operator',
......@@ -595,6 +598,15 @@ function quiz_views_data() {
),
'sort' => array('handler' => 'views_handler_sort'),
),
'score_aggregate' => array(
'title' => t('Score Aggregations'),
'help' => t('Aggregate scores on quizzes using a variety of different algorithms.'),
'real field' => 'score',
'field' => array(
'handler' => 'quiz_views_handler_field_score_aggregate',
'group field' => 'nid',
),
),
'quiz_state' => array(
'title' => t('Quiz State'),
'help' => t('The state of the quiz for the provided user. Calculated on the fly; can be "Finished," "In Progress," or "Not Started".'),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment