Пример #1
0
 /**
  * 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);
         }
     }
 }
Пример #2
0
 /**
  * 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);
         }
     }
 }
Пример #3
0
 /**
  * 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 $PAGE
  */
 function generalized_filter_curriculumclass($uniqueid, $label, $options = array())
 {
     global $PAGE;
     parent::__construct($uniqueid, $label, $options);
     $this->_fields = array();
     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 = \local_eliscore\context\helper::get_level_from_name($section['name']);
         $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) && get_string_manager()->string_exists($alias, $this->languagefile)) {
                 $label = get_string($alias, $this->languagefile);
             } else {
                 if (array_key_exists($name, $this->defaultlabels[$group]) && get_string_manager()->string_exists($this->defaultlabels[$group][$name], $this->languagefile)) {
                     $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);
         }
     }
 }