Updated the user loading to only include fields that are relevant to the roles, accounting for the fact that certain roles (eg. juge) have different fields for different conference types.

This commit is contained in:
jacob 2010-12-02 20:28:19 +00:00
parent 336cec80e0
commit 8817e5eb86

View File

@ -140,14 +140,14 @@ function user_load($users_id, $accounts_id = false)
break;
case 'judge':
$u['years_school'] = intval($u['years_school']);
$u['years_regional'] = intval($u['years_regional']);
$u['years_national'] = intval($u['years_national']);
$u['willing_chair'] = ($u['willing_chair'] == 'yes') ? 'yes' : 'no';
$u['special_award_only'] = ($u['special_award_only'] == 'yes') ? 'yes' : 'no';
$u['cat_prefs'] = (strlen($u['cat_prefs']) > 0) ? unserialize($u['cat_prefs']) : array();
$u['div_prefs'] = (strlen($u['div_prefs']) > 0) ? unserialize($u['div_prefs']) : array();
$u['divsub_prefs'] = (strlen($u['divsub_prefs']) > 0) ? unserialize($u['divsub_prefs']) : array();
if(in_array('years_school', $fields)) $u['years_school'] = intval($u['years_school']);
if(in_array('years_regional', $fields)) $u['years_regional'] = intval($u['years_regional']);
if(in_array('years_national', $fields)) $u['years_national'] = intval($u['years_national']);
if(in_array('willing_chair', $fields)) $u['willing_chair'] = ($u['willing_chair'] == 'yes') ? 'yes' : 'no';
if(in_array('special_award_only', $fields)) $u['special_award_only'] = ($u['special_award_only'] == 'yes') ? 'yes' : 'no';
if(in_array('cat_prefs', $fields)) $u['cat_prefs'] = (strlen($u['cat_prefs']) > 0) ? unserialize($u['cat_prefs']) : array();
if(in_array('div_prefs', $fields)) $u['div_prefs'] = (strlen($u['div_prefs']) > 0) ? unserialize($u['div_prefs']) : array();
if(in_array('divsub_prefs', $fields)) $u['divsub_prefs'] = (strlen($u['divsub_prefs']) > 0) ? unserialize($u['divsub_prefs']) : array();
// $u['expertise_other'] = $u['expertise_other'];
//if it hasnt been parsed/converted yet
if(!is_array($u['languages']))
@ -179,8 +179,10 @@ function user_load($users_id, $accounts_id = false)
}
foreach($should_be_arrays as $k) {
if(in_array($val, $fields)){
if(!is_array($u[$k])) $u[$k] = array();
}
}
// now let's populate the fields that are not stored in the users table
foreach($specialFields as $field){
@ -266,15 +268,20 @@ function user_load_by_email($email)
}
function user_get_role_fields($role){
global $conference;
switch($role){
case 'committee':
$fields = array('emailprivate','ord','displayemail');
break;
case 'judge':
if($conference['type'] == 'scienceolympics'){
$fields = array('languages');
}else{
$fields = array('years_school','years_regional','years_national',
'willing_chair','special_award_only',
'cat_prefs','div_prefs','divsub_prefs',
'expertise_other','languages', 'highest_psd');
}
break;
case 'participant':
$fields = array('grade', 'schools_id');
@ -322,17 +329,7 @@ function user_get_field_info($noConference = false){
'firstaid' => array('label' => 'First Aid', 'group' => 'Personal Information'),
'cpr' => array('label' => 'CPR', 'group' => 'Personal Information'),
'displayemail' => array('label' => 'Display Email', 'group' => 'Personal Information'),
'years_school' => array('label' => 'Years experience judging at school level', 'group' => 'Judges'),
'years_regional' => array('label' => 'Years experience judging at regional level', 'group' => 'Judges'),
'years_national' => array('label' => 'Years experience judging at national level', 'group' => 'Judges'),
'willing_chair' => array('label' => 'Willing to lead a judging team', 'group' => 'Judges'),
'special_award_only' => array('label' => 'Judging only for a special award', 'group' => 'Judges'),
'cat_prefs' => array('label' => 'Category Preferences', 'group' => 'Judges'),
'div_prefs' => array('label' => 'Division Preferences', 'group' => 'Judges'),
'divsub_prefs' => array('label' => 'Subdivision Preferences', 'group' => 'Judges'),
'languages' => array('label' => 'Spoken Languages', 'group' => 'Judges'),
'highest_psd' => array('label' => 'Highest post-secondary degree', 'group' => 'Judges'),
'expertise_other' => array('label' => 'Other areas of expertise', 'group' => 'Judges'),
'sponsors_id' => array('label' => 'Sponsor', 'group' => 'Sponsors'),
'primary' => array('label' => 'Primary Contact', 'group' => 'Sponsors'),
'position' => array('label' => 'Position', 'group' => 'Sponsors'),
@ -343,11 +340,31 @@ function user_get_field_info($noConference = false){
'volunteer_positions' => array('label' => 'Volunteer Positions', 'group' => 'Volunteers')
);
if($noConference){
$returnval['cat_prefs'] = array('label' => 'Category Preferences', 'group' => 'Judges');
$returnval['div_prefs'] = array('label' => 'Division Preferences', 'group' => 'Judges');
$returnval['divsub_prefs'] = array('label' => 'Subdivision Preferences', 'group' => 'Judges');
$returnval['years_school'] = array('label' => 'Years experience judging at school level', 'group' => 'Judges');
$returnval['years_regional'] = array('label' => 'Years experience judging at regional level', 'group' => 'Judges');
$returnval['years_national'] = array('label' => 'Years experience judging at national level', 'group' => 'Judges');
$returnval['willing_chair'] = array('label' => 'Willing to lead a judging team', 'group' => 'Judges');
$returnval['special_award_only'] = array('label' => 'Judging only for a special award', 'group' => 'Judges');
$returnval['highest_psd'] = array('label' => 'Highest post-secondary degree', 'group' => 'Judges');
$returnval['expertise_other'] = array('label' => 'Other areas of expertise', 'group' => 'Judges');
$returnval['available_times'] = array('label' => 'Times Available', 'group' => 'Judges');
$returnval['available_events'] = array('label' => 'Event Availability', 'group' => 'Judges,Volunteers');
}else{
switch($conference['type']){
case 'sciencefair':
$returnval['cat_prefs'] = array('label' => 'Category Preferences', 'group' => 'Judges');
$returnval['div_prefs'] = array('label' => 'Division Preferences', 'group' => 'Judges');
$returnval['divsub_prefs'] = array('label' => 'Subdivision Preferences', 'group' => 'Judges');
$returnval['years_school'] = array('label' => 'Years experience judging at school level', 'group' => 'Judges');
$returnval['years_regional'] = array('label' => 'Years experience judging at regional level', 'group' => 'Judges');
$returnval['years_national'] = array('label' => 'Years experience judging at national level', 'group' => 'Judges');
$returnval['willing_chair'] = array('label' => 'Willing to lead a judging team', 'group' => 'Judges');
$returnval['special_award_only'] = array('label' => 'Judging only for a special award', 'group' => 'Judges');
$returnval['highest_psd'] = array('label' => 'Highest post-secondary degree', 'group' => 'Judges');
$returnval['expertise_other'] = array('label' => 'Other areas of expertise', 'group' => 'Judges');
$returnval['available_times'] = array('label' => 'Times Available', 'group' => 'Judges');
$returnval['available_events'] = array('label' => 'Event Availability', 'group' => 'Volunteers');
break;
@ -645,21 +662,11 @@ function user_save(&$u)
'address','address2','city','province','postalcode','sex',
'firstaid', 'cpr', 'lang', 'notes');
$fields_for_role['committee'] = array('emailprivate','ord','displayemail');
$fields_for_role['judge'] = array('years_school','years_regional','years_national',
'willing_chair','special_award_only',
'cat_prefs','div_prefs','divsub_prefs',
'expertise_other','languages', 'highest_psd');
$fields_for_role['participant'] = array('schools_id', 'grade');
$fields_for_role['fair'] = array('fairs_id');
$fields_for_role['sponsor'] = array('sponsors_id','primary','position');
$fields_for_role['teacher'] = array();
$fields_for_role['volunteer'] = array('languages');
/* Merge fields as necessary, build a big list of fields to save */
foreach($new_roles as $r) {
if(!array_key_exists($r, $fields_for_role)) continue;
$fields = array_merge($fields, $fields_for_role[$r]);
$fields = array_merge($fields, user_get_role_fields($r));
}
$fields = array_unique($fields);
$set = "";
foreach($fields as $f) {