/** * Constructor * * @param string $uniqueid Unique id for filter * @param string $label Filter label * @param array $options Filter options (see above) * @return array of sub-filters */ function generalized_filter_elisuserprofile($uniqueid, $label, $options = array()) { parent::__construct($uniqueid, $label, $options); foreach ($this->tables as $key => $val) { foreach ($val as $table => $alias) { if (empty($options['tables'][$key][$table])) { //use defaults table aliases since not specified $options['tables'][$key][$table] = $alias; } } } //default help setup if (empty($options['help'])) { $options['help'] = array(); } $this->_filters = array(); foreach ($this->_fields as $group => $fields) { $this->_filters[$group] = array(); foreach ($fields as $userfield => $fieldlabel) { //error_log("elisuserprofile.php: creating filter for {$userfield} => {$fieldlabel}"); if ($fieldlabel instanceof field) { $fieldlabel = $fieldlabel->name; } // must setup select choices for specific fields $myoptions = $this->make_filter_options($group, $userfield, $options['help']); $filterid = $uniqueid . substr($userfield, 0, MAX_FILTER_SUFFIX_LEN); $ftype = (string) $this->fieldtofiltermap[$group][$userfield]; $advanced = !empty($options['advanced']) && in_array($userfield, $options['advanced']) || !empty($options['notadvanced']) && !in_array($userfield, $options['notadvanced']); //error_log("elisuserprofile.php: creating filter using: new generalized_filter_entry( $filterid, {$myoptions['talias']}, {$myoptions['dbfield']}, $fieldlabel, $advanced, $ftype, myoptions)"); // Create the filter $this->_filters[$group][$userfield] = new generalized_filter_entry($filterid, $myoptions['talias'], $myoptions['dbfield'], $fieldlabel, $advanced, $ftype, $myoptions); } } }
/** * Constructor * * @param string $uniqueid Unique id for filter * @param string $label Filter label * @param array $options Filter options (see above) * @return array of sub-filters */ function generalized_filter_elisuserprofile($uniqueid, $label, $options = array()) { parent::multifilter($uniqueid, $label, $options); foreach ($this->tables as $key => $val) { foreach ($val as $table => $alias) { if (empty($options['tables'][$key][$table])) { //use defaults table aliases since not specified $options['tables'][$key][$table] = $alias; } } } //default help setup if (empty($options['help'])) { $options['help'] = array(); } // Get the custom fields that belong to the user context $ctxlvl = context_level_base::get_custom_context_level('user', 'block_curr_admin'); $fields = field::get_for_context_level($ctxlvl); $fields = $fields ? $fields : array(); $this->get_custom_fields('up', $fields); //create field listing, including display names $allfields = array(); foreach ($options['choices'] as $choice) { $choicestring = $choice; if (array_key_exists($choice, $this->labels['up'])) { $choicestring = get_string($this->labels['up'][$choice], $this->languagefile); } if (0 == strcmp($choice, 'customfields')) { foreach ($fields as $field) { $allfields['customfield-' . $field->id] = $field->name; } } else { $allfields[$choice] = $choicestring; } } //add all fields foreach ($allfields as $userfield => $fieldlabel) { //calculate any necessary custom options $myoptions = $this->make_filter_options('up', $userfield, $options['help'], $options['tables']); //determine field type from mapping $ftype = (string) $this->fieldtofiltermap['up'][$userfield]; $advanced = !empty($options['advanced']) && in_array($userfield, $options['advanced']) || !empty($options['notadvanced']) && !in_array($userfield, $options['notadvanced']); //create the sub-filter object $this->_filters['up'][$userfield] = new generalized_filter_entry($userfield, $myoptions['talias'], $myoptions['dbfield'], $fieldlabel, $advanced, $ftype, $myoptions); } }
/** * Constructor * * @param string $uniqueid Unique prefix for filters * @param string $label Filter label * @param array $options Filter options (see above) * @return array The sub-filters * @uses $CFG */ function generalized_filter_curriculumclass($uniqueid, $label, $options = array()) { global $CFG; parent::multifilter($uniqueid, $label, $options); $this->_fields = array(); require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_connection', 'yui_json', "{$CFG->wwwroot}/curriculum/js/dependentselect.js"), true); if (empty($options['help'])) { $options['help'] = array(); } // Get table aliases if (empty($options['tables'])) { $options['tables'] = array(); } $allfields = array(); foreach ($this->labels as $group => $labels) { foreach ($labels as $key => $val) { $this->record_short_field_name($group . '-' . $key); } } // Check for & assign table aliases foreach ($this->tables as $group => $tables) { if (!array_key_exists($group, $options['tables'])) { continue; } foreach ($tables as $key => $val) { if (!empty($options['tables'][$group][$key])) { // use defaults table aliases if not specified $this->tables[$group][$key] = $options['tables'][$group][$key]; } } } foreach ($this->sections as $group => $section) { $ctxtlvl = context_level_base::get_custom_context_level($section['name'], 'block_curr_admin'); $this->sections[$group]['contextlevel'] = $ctxtlvl; // Add custom fields to array $extrafields = field::get_for_context_level($ctxtlvl); $this->get_custom_fields($group, $extrafields); } // Force $options['choices'] to be an associative array foreach ($options['choices'] as $key => $choices) { if (!$this->is_assoc_array($choices)) { $options['choices'][$key] = array_fill_keys($choices, ''); } } foreach ($options['choices'] as $group => $choices) { $allfields[$group] = array(); foreach ($choices as $name => $alias) { $label = $name; if (!empty($alias)) { $label = get_string($alias, $this->languagefile); } else { if (array_key_exists($name, $this->defaultlabels[$group])) { $label = get_string($this->defaultlabels[$group][$name], $this->languagefile); } else { foreach ($this->sections as $section) { if (array_key_exists($name, $section['custom'])) { $label = $section['custom'][$name]; } } } } $allfields[$group][$name] = $label; } if (!empty($options['extra']) && !empty($this->sections[$group]['custom'])) { $allfields[$group] = array_merge($allfields[$group], $this->sections[$group]['custom']); } } foreach ($allfields as $group => $fields) { $this->_filters[$group] = array(); foreach ($fields as $name => $label) { // must setup select choices for specific fields $myoptions = $this->make_filter_options($group, $name, $options['help'], $options['tables']); if (!is_array($myoptions)) { continue; } $filterid = $this->_uniqueid . $group . '-' . substr($name, 0, MAX_FILTER_SUFFIX_LEN); $ftype = (string) $this->fieldtofiltermap[$group][$name]; $advanced = !empty($options['advanced'][$group]) && in_array($name, $options['advanced'][$group]) || !empty($options['notadvanced'][$group]) && !in_array($name, $options['notadvanced'][$group]); $this->_filters[$group][$name] = new generalized_filter_entry($filterid, $myoptions['talias'], $myoptions['dbfield'], $label, $advanced, $ftype, $myoptions); } } }
/** * Constructor * * @param string $uniqueid Unique id for filter * @param string $label Filter label * @param array $options Filter options (see above) * @return array of sub-filters * @uses $DB */ function __construct($uniqueid, $label, $options = array()) { global $DB; parent::__construct($uniqueid, $label, $options); if (empty($options['help'])) { $options['help'] = array(); } // Get table aliases if (empty($options['tables'])) { $options['tables'] = array(); } $this->fieldtofiltermap['up']['fullname'] = self::filtertypetext; if (!empty($options['extra'])) { $extrafields = $DB->get_recordset('user_info_field', null, 'sortorder ASC', 'id, shortname, name, datatype'); $this->get_custom_fields('up', $extrafields); } $this->_filters['up'] = array(); foreach ($this->_fields as $group => $fields) { foreach ($fields as $userfield => $fieldlabel) { //error_log("userprofilematch.php: creating filter for {$userfield} => {$fieldlabel}"); // must setup select choices for specific fields $myoptions = $this->make_filter_options_custom(array(), $group, $userfield); $filterid = $uniqueid . substr($userfield, 0, MAX_FILTER_SUFFIX_LEN); $ftype = (string) $this->fieldtofiltermap[$group][$userfield]; $advanced = !empty($options['advanced']) && in_array($userfield, $options['advanced']) || !empty($options['notadvanced']) && !in_array($userfield, $options['notadvanced']); //error_log("userprofilematch.php: creating filter using: new generalized_filter_entry( $filterid, $talias, $dbfield, $fieldlabel, $advanced, $ftype, $myoptions)"); // Create the filter $this->_filters[$group][$userfield] = new generalized_filter_entry($filterid, $myoptions['talias'], $myoptions['dbfield'], $fieldlabel, $advanced, $ftype, $myoptions); } } }
/** * Constructor * * @param string $uniqueid Unique id for filter * @param string $label Filter label * @param array $options Filter options (see above) * @return array of sub-filters */ function generalized_filter_userprofilematch($uniqueid, $label, $options = array()) { parent::multifilter($uniqueid, $label, $options); if (empty($options['help'])) { $options['help'] = array(); } $langfile = $this->languagefile; // Get table aliases if (empty($options['tables'])) { $options['tables'] = array(); } $shortfields = array(); // to store/check truncated field names used for filterids foreach ($this->labels as $key => $val) { $shortfieldname = substr($key, 0, MAX_FILTER_SUFFIX_LEN); if (in_array($shortfieldname, $shortfields)) { error_log("generalized_filter_userprofilematch::non-unique field name: '{$shortfieldname}' in main user profile - modify code!"); } else { $shortfields[] = $shortfieldname; } } // Check for & assign table aliases foreach ($this->tables['up'] as $key => $val) { if (!empty($options['tables']['up'][$key])) { // use defaults table aliases if not specified $this->tables['up'][$key] = $options['tables']['up'][$key]; } } $this->fieldtofiltermap['up']['fullname'] = generalized_filter_userprofilematch::filtertypetext; // Add custom user profile fields to array $extrafields = get_records('user_info_field', '', '', 'sortorder ASC', 'id,shortname,name,datatype'); $extrafields = $extrafields ? $extrafields : array(); // Array $xoptions to append to existing options['choices'] $this->get_custom_fields('up', $extrafields); $this->_fields = array(); $allfields = array(); $xoptions = $this->sections['up']['custom']; // First check if $options['choices'] is associative array with labels if (!$this->is_assoc_array($options['choices'])) { foreach ($options['choices'] as $upfield) { $allfields[$upfield] = array_key_exists($upfield, $this->labels['up']) ? get_string($this->labels['up'][$upfield], $this->languagefile) : (array_key_exists($upfield, $xoptions) ? $xoptions[$upfield] : $upfield); } } else { // just fillin empty labels foreach ($options['choices'] as $key => $val) { $allfields[$key] = !empty($val) ? get_string($val, $langfile) : (array_key_exists($key, $this->labels['up']) ? get_string($this->labels['up'][$key], $this->languagefile) : (array_key_exists($key, $xoptions) ? $xoptions[$key] : $key)); } } if (!empty($options['extra']) && !empty($xoptions)) { $allfields += $xoptions; } $this->_filters['up'] = array(); foreach ($allfields as $userfield => $fieldlabel) { // must setup select choices for specific fields $myoptions = $this->make_filter_options('up', $userfield, $options['help']); $filterid = $uniqueid . substr($userfield, 0, MAX_FILTER_SUFFIX_LEN); $ftype = (string) $this->fieldtofiltermap['up'][$userfield]; $advanced = !empty($options['advanced']) && in_array($userfield, $options['advanced']) || !empty($options['notadvanced']) && !in_array($userfield, $options['notadvanced']); //error_log("userprofilematch.php: creating filter using: new generalized_filter_entry( $filterid, $talias, $dbfield, $fieldlabel, $advanced, $ftype, $myoptions)"); // Create the filter $this->_filters['up'][$userfield] = new generalized_filter_entry($filterid, $myoptions['talias'], $myoptions['dbfield'], $fieldlabel, $advanced, $ftype, $myoptions); } }