Example #1
0
 /**
  * Adds controls specific to this filter in the form.
  * @param object $mform a MoodleForm object to setup
  */
 function setupForm(&$mform)
 {
     global $USER;
     $choices_array = array();
     //figure out which capability to check
     if ($this->execution_mode == php_report::EXECUTION_MODE_SCHEDULED) {
         $capability = 'block/php_report:schedule';
     } else {
         $capability = 'block/php_report:view';
     }
     //obtain all course contexts where this user can view reports
     $contexts = get_contexts_by_capability_for_user('user', $capability, $USER->id);
     $context_array = array('contexts' => $contexts);
     if ($records = cluster_get_listing('name', 'ASC', 0, 0, '', '', $context_array)) {
         foreach ($records as $record) {
             if ($record->parent == 0) {
                 $choices_array[$record->id] = $record->name;
                 $child_array = $this->find_child_clusters($records, $record->id);
                 $choices_array = $this->merge_array_keep_keys($choices_array, $child_array);
             }
         }
     }
     //explicitly set the list of available options
     $this->_options = $choices_array;
     parent::setupForm($mform);
 }
Example #2
0
 /**
  * Constructor
  * @param string $name the name of the filter instance
  * @param string $label the label of the filter instance
  * @param boolean $advanced advanced form element flag
  * @param string $field user table filed name
  * @param array $options select options
  */
 function generalized_filter_clusterselect($uniqueid, $alias, $name, $label, $advanced, $field, $options = array())
 {
     global $USER;
     //figure out which capability to check
     if ($this->execution_mode == php_report::EXECUTION_MODE_SCHEDULED) {
         $capability = 'local/elisreports:schedule';
     } else {
         $capability = 'local/elisreports:view';
     }
     //obtain all cluster contexts where this user can view reports
     $contexts = get_contexts_by_capability_for_user('cluster', $capability, $USER->id);
     //set up cluster listing
     $choices_array = array();
     if ($records = $this->cluster_dropdown_get_listing($contexts)) {
         foreach ($records as $record) {
             if (empty($choices_array[$record->id])) {
                 //if (count($choices_array) > 1) {
                 //    $choices_array[-$record->id] = $cluster_group_separator;
                 //}
                 $ancestors = $record->depth - 1;
                 // shorten really long cluster names
                 $clstname = strlen($record->name) > 100 ? substr($record->name, 0, 100) . '...' : $record->name;
                 $choices_array[$record->id] = $ancestors ? str_repeat('- ', $ancestors) . $clstname : $clstname;
                 //merge in child clusters
                 $child_array = $this->find_child_clusters($records, $record->id, $ancestors);
                 $choices_array = $this->merge_array_keep_keys($choices_array, $child_array);
             }
         }
     }
     //explicitly set the list of available options
     $this->_options = $choices_array;
     //expected by the parent class
     $options['choices'] = $choices_array;
     $options['numeric'] = true;
     parent::generalized_filter_equalityselect($uniqueid, $alias, $name, $label, $advanced, $field, $options);
 }