forked from science-ation/science-ation
Add support for listing judges div/cat prefs in columns. This now
completes everything the judges csv could do. The downside ist hat each fair could have different numbers of divs/cats, so each will have to create the report (and keep it up to date if they change the number of divs/cats)
This commit is contained in:
parent
dc29349e7c
commit
510d4a7e5f
@ -31,7 +31,35 @@ function report_judges_languages(&$report, $field, $text)
|
|||||||
return join(' ', $l);
|
return join(' ', $l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* It's possible to get through this code and need to have access to more
|
||||||
|
* than one year, so we're going to index this array by year first */
|
||||||
$report_judges_divs = array();
|
$report_judges_divs = array();
|
||||||
|
$report_judges_cats = array();
|
||||||
|
|
||||||
|
function report_judges_load_divs($year)
|
||||||
|
{
|
||||||
|
global $report_judges_divs;
|
||||||
|
/* Load divisions for this year, only once */
|
||||||
|
if(!array_key_exists($year, $report_judges_divs)) {
|
||||||
|
$report_judges_divs[$year] = array();
|
||||||
|
$q = mysql_query("SELECT * FROM projectdivisions WHERE year='$year'");
|
||||||
|
while(($d = mysql_fetch_assoc($q))) {
|
||||||
|
$report_judges_divs[$year][$d['id']] = $d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function report_judges_load_cats($year)
|
||||||
|
{
|
||||||
|
global $report_judges_cats;
|
||||||
|
if(!array_key_exists($year, $report_judges_cats)) {
|
||||||
|
$q = mysql_query("SELECT * FROM projectcategories WHERE year='$year'");
|
||||||
|
while(($c = mysql_fetch_assoc($q))) {
|
||||||
|
$report_judges_cats[$year][$c['id']] = $c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function report_judges_5_div(&$report, $field, $text)
|
function report_judges_5_div(&$report, $field, $text)
|
||||||
{
|
{
|
||||||
global $report_judges_divs;
|
global $report_judges_divs;
|
||||||
@ -41,21 +69,15 @@ function report_judges_5_div(&$report, $field, $text)
|
|||||||
$divprefs = unserialize($text);
|
$divprefs = unserialize($text);
|
||||||
if(!is_array($divprefs)) return '';
|
if(!is_array($divprefs)) return '';
|
||||||
|
|
||||||
/* Load divisions, only once */
|
report_judges_load_divs($year);
|
||||||
if(count($report_judges_divs) == 0) {
|
|
||||||
$q = mysql_query("SELECT * FROM projectdivisions WHERE year='$year'");
|
|
||||||
while(($d = mysql_fetch_assoc($q))) {
|
|
||||||
$report_judges_divs[$d['id']] = $d;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find all 5-expert selections, and add them to the return */
|
/* Find all 5-expert selections, and add them to the return */
|
||||||
$ret = array();
|
$ret = array();
|
||||||
$retl = array();
|
$retl = array();
|
||||||
foreach($divprefs as $div_id=>$sel) {
|
foreach($divprefs as $div_id=>$sel) {
|
||||||
if($sel != 5) continue;
|
if($sel != 5) continue;
|
||||||
$ret[] = $report_judges_divs[$div_id]['division_shortform'];
|
$ret[] = $report_judges_divs[$year][$div_id]['division_shortform'];
|
||||||
$retl[] = $report_judges_divs[$div_id]['division'];
|
$retl[] = $report_judges_divs[$year][$div_id]['division'];
|
||||||
}
|
}
|
||||||
/* Join it all together with spaces */
|
/* Join it all together with spaces */
|
||||||
if($field == 'div_prefs_5')
|
if($field == 'div_prefs_5')
|
||||||
@ -63,7 +85,6 @@ function report_judges_5_div(&$report, $field, $text)
|
|||||||
return join(', ', $retl);
|
return join(', ', $retl);
|
||||||
}
|
}
|
||||||
|
|
||||||
$report_judges_cats = array();
|
|
||||||
function report_judges_highest_cat(&$report, $field, $text)
|
function report_judges_highest_cat(&$report, $field, $text)
|
||||||
{
|
{
|
||||||
global $report_judges_cats;
|
global $report_judges_cats;
|
||||||
@ -73,20 +94,15 @@ function report_judges_highest_cat(&$report, $field, $text)
|
|||||||
$catprefs = unserialize($text);
|
$catprefs = unserialize($text);
|
||||||
if(!is_array($catprefs)) return '';
|
if(!is_array($catprefs)) return '';
|
||||||
|
|
||||||
if(count($report_judges_cats) == 0) {
|
report_judges_load_cats($year);
|
||||||
$q = mysql_query("SELECT * FROM projectcategories WHERE year='$year'");
|
|
||||||
while(($c = mysql_fetch_assoc($q))) {
|
|
||||||
$report_judges_cats[$c['id']] = $c;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Find all 2-highest selections, and add them to the return */
|
/* Find all 2-highest selections, and add them to the return */
|
||||||
$ret = array();
|
$ret = array();
|
||||||
$retl = array();
|
$retl = array();
|
||||||
foreach($catprefs as $cat_id=>$sel) {
|
foreach($catprefs as $cat_id=>$sel) {
|
||||||
if($sel != 2) continue;
|
if($sel != 2) continue;
|
||||||
$ret[] = $report_judges_cats[$cat_id]['category_shortform'];
|
$ret[] = $report_judges_cats[$year][$cat_id]['category_shortform'];
|
||||||
$retl[] = $report_judges_cats[$cat_id]['category'];
|
$retl[] = $report_judges_cats[$year][$cat_id]['category'];
|
||||||
}
|
}
|
||||||
/* Join it all together with spaces */
|
/* Join it all together with spaces */
|
||||||
if($field == 'cat_prefs_highest')
|
if($field == 'cat_prefs_highest')
|
||||||
@ -114,6 +130,34 @@ function report_judges_custom_question(&$report, $field, $text)
|
|||||||
return $answer['answer'];
|
return $answer['answer'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function report_judges_div_exp(&$report, $field, $text)
|
||||||
|
{
|
||||||
|
/* Field is 'div_exp_x', users_id is passed in $text */
|
||||||
|
$div_id = substr($field, 8);
|
||||||
|
$year = $report['year'];
|
||||||
|
$users_id = $text;
|
||||||
|
|
||||||
|
$divprefs = unserialize($text);
|
||||||
|
if(!is_array($divprefs)) return '';
|
||||||
|
|
||||||
|
return $divprefs[$div_id];
|
||||||
|
}
|
||||||
|
function report_judges_cat_pref(&$report, $field, $text)
|
||||||
|
{
|
||||||
|
$prefs = array(-2 => 'Lowest', -1 => 'Low',
|
||||||
|
0 => '--',
|
||||||
|
'1' => 'High', 2=>'Highest');
|
||||||
|
/* Field is 'div_pref_x', users_id is passed in $text */
|
||||||
|
$cat_id = substr($field, 9);
|
||||||
|
$year = $report['year'];
|
||||||
|
$users_id = $text;
|
||||||
|
|
||||||
|
$catprefs = unserialize($text);
|
||||||
|
if(!is_array($catprefs)) return '';
|
||||||
|
|
||||||
|
return i18n($prefs[$catprefs[$cat_id]]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Components: languages, teams */
|
/* Components: languages, teams */
|
||||||
@ -245,6 +289,9 @@ $report_judges_fields = array(
|
|||||||
'table' => 'users_judge.highest_psd',
|
'table' => 'users_judge.highest_psd',
|
||||||
'components' => array('users_judge')),
|
'components' => array('users_judge')),
|
||||||
|
|
||||||
|
|
||||||
|
/* Headers for Division Expertise/Preference Selection */
|
||||||
|
|
||||||
'div_prefs_5' => array(
|
'div_prefs_5' => array(
|
||||||
'name' => 'Judge -- Divisions Selected as 5-Expert (Shortform)',
|
'name' => 'Judge -- Divisions Selected as 5-Expert (Shortform)',
|
||||||
'header' => 'Expert Div',
|
'header' => 'Expert Div',
|
||||||
@ -261,6 +308,89 @@ $report_judges_fields = array(
|
|||||||
'exec_function' => 'report_judges_5_div', /* Yes, the same function as div_prefs_5 */
|
'exec_function' => 'report_judges_5_div', /* Yes, the same function as div_prefs_5 */
|
||||||
'components' => array('users_judge')),
|
'components' => array('users_judge')),
|
||||||
|
|
||||||
|
'div_exp_1' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 1',
|
||||||
|
'header' => 'div1',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true, /* Only disables in the report editor, a report can still use it */
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_2' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 2',
|
||||||
|
'header' => 'div2',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_3' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 3',
|
||||||
|
'header' => 'div3',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_4' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 4',
|
||||||
|
'header' => 'div4',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_5' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 5',
|
||||||
|
'header' => 'div5',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_6' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 6',
|
||||||
|
'header' => 'div6',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_7' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 7',
|
||||||
|
'header' => 'div7',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_8' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 8',
|
||||||
|
'header' => 'div8',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_9' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 9',
|
||||||
|
'header' => 'div9',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'div_exp_10' => array(
|
||||||
|
'name' => 'Judge -- Expertise for Division ID 10',
|
||||||
|
'header' => 'div10',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.div_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_div_exp',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
|
||||||
|
/* Category preferences */
|
||||||
|
|
||||||
'cat_prefs_highest' => array(
|
'cat_prefs_highest' => array(
|
||||||
'name' => 'Judge -- Age Categories Selected as Highest Preference (Shortform)',
|
'name' => 'Judge -- Age Categories Selected as Highest Preference (Shortform)',
|
||||||
'header' => 'Pref Cat',
|
'header' => 'Pref Cat',
|
||||||
@ -277,6 +407,89 @@ $report_judges_fields = array(
|
|||||||
'exec_function' => 'report_judges_highest_cat', /* Yes, the same function as cat_prefs_highest */
|
'exec_function' => 'report_judges_highest_cat', /* Yes, the same function as cat_prefs_highest */
|
||||||
'components' => array('users_judge')),
|
'components' => array('users_judge')),
|
||||||
|
|
||||||
|
'cat_pref_1' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 1',
|
||||||
|
'header' => 'cat1',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true, /* Only disables in the report editor, a report can still use it */
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_2' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 2',
|
||||||
|
'header' => 'cat2',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_3' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 3',
|
||||||
|
'header' => 'cat3',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_4' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 4',
|
||||||
|
'header' => 'cat4',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_5' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 5',
|
||||||
|
'header' => 'cat5',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_6' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 6',
|
||||||
|
'header' => 'cat6',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_7' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 7',
|
||||||
|
'header' => 'cat7',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_8' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 8',
|
||||||
|
'header' => 'cat8',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_9' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 9',
|
||||||
|
'header' => 'cat9',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
'cat_pref_10' => array(
|
||||||
|
'name' => 'Judge -- Age Category Preference for Category ID 10',
|
||||||
|
'header' => 'cat10',
|
||||||
|
'width' => 0.5,
|
||||||
|
'table' => 'users_judge.cat_prefs',
|
||||||
|
'editor_disabled' => true,
|
||||||
|
'exec_function' => 'report_judges_cat_pref',
|
||||||
|
'components' => array('users_judge')),
|
||||||
|
|
||||||
|
/* Others */
|
||||||
|
|
||||||
'special_award_only' => array(
|
'special_award_only' => array(
|
||||||
'name' => 'Judge -- Special Award Only Requested',
|
'name' => 'Judge -- Special Award Only Requested',
|
||||||
'header' => 'SA Only',
|
'header' => 'SA Only',
|
||||||
@ -481,10 +694,47 @@ function report_judges_update_questions($year)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function report_judges_update_divs($year)
|
||||||
|
{
|
||||||
|
global $report_judges_fields, $report_judges_divs;
|
||||||
|
|
||||||
|
report_judges_load_divs($year);
|
||||||
|
|
||||||
|
if(count($report_judges_divs[$year]) > 10) {
|
||||||
|
echo "Not enough judge division fields, please file a bug report at sfiab.ca and report that you have ".count($qs)." divisions, but the system can handle a maximum of 10.";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
foreach($report_judges_divs[$year] as $div_id=>$d) {
|
||||||
|
$f = "div_exp_$div_id";
|
||||||
|
$report_judges_fields[$f]['header'] = "{$d['division_shortform']} - {$d['division']}";
|
||||||
|
$report_judges_fields[$f]['name'] = 'Judge -- Expertise in Division: '.$d['division'];
|
||||||
|
$report_judges_fields[$f]['editor_disabled'] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function report_judges_update_cats($year)
|
||||||
|
{
|
||||||
|
global $report_judges_fields, $report_judges_cats;
|
||||||
|
|
||||||
|
report_judges_load_cats($year);
|
||||||
|
|
||||||
|
if(count($report_judges_cats[$year]) > 10) {
|
||||||
|
echo "Not enough judge age category fields, please file a bug report at sfiab.ca and report that you have ".count($qs)." age categories, but the system can handle a maximum of 10.";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
foreach($report_judges_cats[$year] as $cat_id=>$d) {
|
||||||
|
$f = "cat_pref_$cat_id";
|
||||||
|
$report_judges_fields[$f]['header'] = "{$d['category_shortform']} - {$d['category']}";
|
||||||
|
$report_judges_fields[$f]['name'] = 'Judge -- Preference for Age Category: '.$d['category'];
|
||||||
|
$report_judges_fields[$f]['editor_disabled'] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$report_judges_questions_updated = false;
|
$report_judges_questions_updated = false;
|
||||||
/* Do the overwrites for the current year, this is for the editor, because
|
/* Do the overwrites for the current year, this is for the editor, because
|
||||||
* it doesn't call a _fromwhere */
|
* it doesn't call a _fromwhere */
|
||||||
report_judges_update_questions($config['FAIRYEAR']);
|
report_judges_update_questions($config['FAIRYEAR']);
|
||||||
|
report_judges_update_divs($config['FAIRYEAR']);
|
||||||
|
report_judges_update_cats($config['FAIRYEAR']);
|
||||||
|
|
||||||
function report_judges_fromwhere($report, $components)
|
function report_judges_fromwhere($report, $components)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user