/** * Get custom fields * * This function returns an array of custom field names to labels, and has a few side effects * that set up data to use the custom fields later. The side effects reduce the number of * database lookups required to generate the form. * * @param array $fields An array of db records representing custom fields * @return array Custom field names mapped to labels. */ function get_custom_fields($group, $fields) { $yesno = array(1 => get_string('yes'), 0 => get_string('no')); // Array $xoptions to append to existing options['choices'] $options = array(); if (!$fields instanceof Iterator) { $fields = array(); } foreach ($fields as $field) { $field = new field($field); if (!isset($field->owners['manual'])) { error_log("multifilter.php::get_custom_fields() - no field->owners['manual'] for {$field->name} ({$field_identifier})"); continue; } $field_identifier = 'customfield-' . $field->id; $this->_fields[$group][$field_identifier] = $field; $this->record_short_field_name($field_identifier); $this->labels[$group][$field_identifier] = $field->name; $options[$field_identifier] = $field->name; $owner = new field_owner($field->owners['manual']); $params = unserialize($owner->params); //error_log("multifilter.php::get_custom_fields(): {$field_identifier} => {$params['control']} ({$this->datatypemap[$params['control']]})"); $this->fieldtofiltermap[$group][$field_identifier] = $this->datatypemap[$params['control']]; switch ($params['control']) { case 'datetime': // TBD - options required for datetime fields? $this->_choices[$field_identifier] = array('startyear' => $params['startyear'], 'stopyear' => $params['stopyear'], 'inctime' => isset($params['inctime']) ? $params['inctime'] : false); break; case 'checkbox': $this->_choices[$field_identifier] = $yesno; break; case 'menu': $choices = $owner->get_menu_options(); if (!empty($choices)) { $this->_choices[$field_identifier] = array(); foreach ($choices as $key => $choice) { $choice = trim($choice); // preserve anyvalue key => '' //$key = ($key === '') ? $key : $choice; $this->_choices[$field_identifier][$key] = $choice; } } else { error_log("multifilter::get_custom_fields() - empty menu options for fieldid = {$field->id} ... using: Yes, No"); $this->_choices[$field_identifier] = $yesno; } break; case 'text': // fall-thru case! // fall-thru case! case 'textarea': // no options required for text fields break; default: error_log("multifilter.php:: control = {$params['control']}, datatype = {$field->data_type()} not supported"); break; } } $this->sections[$group]['custom'] = $options; }