forked from science-ation/science-ation
Support custom judge questions in the report editor
This commit is contained in:
parent
355447ac76
commit
e65f899731
@ -21,6 +21,7 @@
|
||||
Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
require_once('../questions.inc.php');
|
||||
|
||||
/* Take the language array in users_judge, unserialize it, and join it
|
||||
* with a space */
|
||||
@ -93,6 +94,27 @@ function report_judges_highest_cat(&$report, $field, $text)
|
||||
return join(', ', $retl);
|
||||
}
|
||||
|
||||
function report_judges_custom_question(&$report, $field, $text)
|
||||
{
|
||||
/* Field is 'question_x', users_id is passed in $text */
|
||||
$q_ord = substr($field, 9);
|
||||
$year = $report['year'];
|
||||
$users_id = $text;
|
||||
|
||||
/* Find the actual question ID */
|
||||
$q = mysql_query("SELECT * FROM questions WHERE year='$year' AND ord='$q_ord'");
|
||||
if(mysql_num_rows($q) != 1)
|
||||
return 'Question not specified';
|
||||
$question = mysql_fetch_assoc($q);
|
||||
|
||||
$q = mysql_query("SELECT * FROM question_answers WHERE users_id='$users_id' AND questions_id='{$question['id']}'");
|
||||
if(mysql_num_rows($q) != 1)
|
||||
return '';
|
||||
$answer = mysql_fetch_assoc($q);
|
||||
return $answer['answer'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Components: languages, teams */
|
||||
|
||||
@ -353,21 +375,120 @@ $report_judges_fields = array(
|
||||
'table' => "judges_timeslots.date",
|
||||
'components' => array('teams', 'projects')),
|
||||
|
||||
'question_1' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 1',
|
||||
'header' => 'Q1',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_2' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 2',
|
||||
'header' => 'Q2',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_3' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 3',
|
||||
'header' => 'Q3',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_4' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 4',
|
||||
'header' => 'Q4',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_5' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 5',
|
||||
'header' => 'Q5',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_6' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 6',
|
||||
'header' => 'Q6',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_7' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 7',
|
||||
'header' => 'Q7',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_8' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 8',
|
||||
'header' => 'Q8',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_9' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 9',
|
||||
'header' => 'Q9',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'question_10' => array(
|
||||
'name' => 'Judge -- Custom Judge Registration Question 10',
|
||||
'header' => 'Q10',
|
||||
'width' => 1,
|
||||
'table' => 'users.id',
|
||||
'exec_function' => 'report_judges_custom_question'),
|
||||
|
||||
'static_text' => array(
|
||||
'name' => 'Static Text (useful for labels)',
|
||||
'header' => '',
|
||||
'width' => 0.1,
|
||||
'table' => "CONCAT(' ')"),
|
||||
|
||||
);
|
||||
|
||||
function report_judges_fromwhere($report, $components)
|
||||
{
|
||||
|
||||
/* Overwrite the question_1 .. question_10 fields with the
|
||||
* question name and header from the list of questions */
|
||||
function report_judges_update_questions($year)
|
||||
{
|
||||
global $report_judges_fields;
|
||||
$qs = questions_load_questions('judgereg', $year);
|
||||
if(count($qs) > 10) {
|
||||
echo "Not enough judge question fields, please file a bug report at sfiab.ca and report that you have ".count($qs)." custom judge questions, but the system can handle a maximum of 10.";
|
||||
exit;
|
||||
}
|
||||
foreach($qs as $qid=>$q) {
|
||||
$f = "question_{$q['ord']}";
|
||||
$report_judges_fields[$f]['header'] = $q['db_heading'];
|
||||
$report_judges_fields[$f]['name'] = 'Judge -- Custom Judge Question: '.$q['question'];
|
||||
}
|
||||
}
|
||||
|
||||
$report_judges_questions_updated = false;
|
||||
/* Do the overwrites for the current year, this is for the editor, because
|
||||
* it doesn't call a _fromwhere */
|
||||
report_judges_update_questions($config['FAIRYEAR']);
|
||||
|
||||
function report_judges_fromwhere($report, $components)
|
||||
{
|
||||
global $config, $report_judges_fields;
|
||||
|
||||
$fields = $report_judges_fields;
|
||||
$year = $report['year'];
|
||||
|
||||
if($report_judges_questions_updated == false) {
|
||||
/* Do overwrites for the report year, overwriting the previous
|
||||
* overwrites for the current year, because the report year
|
||||
* could be different, and the questions may have changed */
|
||||
report_judges_update_questions($year);
|
||||
$report_judges_questions_updated = true;
|
||||
}
|
||||
|
||||
if(in_array('users_judge', $components)) {
|
||||
$uj_from = 'LEFT JOIN users_judge ON users_judge.users_id=users.id';
|
||||
}
|
||||
|
@ -117,10 +117,14 @@ function questions_print_answer_editor($section, &$u, $array_name)
|
||||
"name=\"$iname\" size=10 maxlen=11 ".
|
||||
"value=\"{$ans[$qid]}\" >\n");
|
||||
break;
|
||||
case 'check':
|
||||
if($ans[$qid]=="yes") $ch="checked=\"checked\""; else $ch="";
|
||||
print("<input $ch type=\"checkbox\" name=\"$iname\" value=\"yes\">\n");
|
||||
break;
|
||||
case 'check':
|
||||
if($ans[$qid]=="yes") $ch="checked=\"checked\""; else $ch="";
|
||||
print("<input $ch type=\"checkbox\" name=\"$iname\" value=\"yes\">\n");
|
||||
break;
|
||||
case 'text':
|
||||
print("<input type=\"text\" name=\"$iname\" value=\"{$ans[$qid]}\">\n");
|
||||
break;
|
||||
|
||||
}
|
||||
print("</td>\n");
|
||||
print("</tr>\n");
|
||||
|
Loading…
Reference in New Issue
Block a user