Beispiel #1
0
 /**
  * Adds controls specific to this filter in the form.
  * @param object $mform a MoodleForm object to setup
  */
 function setupForm(&$mform)
 {
     global $USER, $CFG;
     /**
      * CSS includes
      */
     $mform->addElement('html', '<style>@import url("' . $CFG->wwwroot . '/lib/yui/treeview/assets/skins/sam/treeview-skin.css");</style>');
     /**(use "git add" and/or "git commit -a")
      * JavaScript includes
      */
     //include the necessary javascript libraries for the YUI TreeView
     require_js(array('yui_yahoo', 'yui_dom', 'yui_event', 'yui_treeview'));
     //for converting tree representation
     require_js('yui_json');
     //for asynch request dynamic loading
     require_js('yui_connection');
     //include our custom code that handles the YUI Treeview menu
     require_js($CFG->wwwroot . '/curriculum/js/clustertree.js');
     /**
      * Get set up necessary CSS classes
      */
     $manageclusters_css_class = block_curr_admin_get_item_css_class('manageclusters');
     $cluster_css_class = block_curr_admin_get_item_css_class('cluster_instance');
     //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';
     }
     $context_result = cm_context_set::for_user_with_capability('cluster', $capability, $USER->id);
     $extrafilters = array('contexts' => $context_result, 'parent' => 0);
     $num_records = cluster_count_records('', '', $extrafilters);
     /**
      * TreeView-related work
      */
     //CM entities for placement at the top of the menu
     $cm_entity_pages = array();
     $cm_entity_pages[] = new menuitem('root');
     if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, 0, '', '', array('parent' => 0))) {
         foreach ($clusters as $cluster) {
             $params = array('id' => $cluster->id, 'action' => 'viewreport', 'execution_mode' => $this->execution_mode);
             $cluster_count = cluster_count_records('', '', array('parent' => $cluster->id));
             $isLeaf = empty($cluster_count);
             $cm_entity_pages[] = test_cluster_tree_get_menu_item('cluster', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf);
         }
     }
     $menuitemlisting = new menuitemlisting($cm_entity_pages);
     $tree = new checkbox_treerepresentation($menuitemlisting, $this->options['report_id']);
     $tree_html = $tree->convert_to_markup($this->_uniqueid, $this->execution_mode);
     $params = array($this->options['report_id'], $this->_uniqueid, $this->options['dropdown_button_text'], $this->options['tree_button_text']);
     $param_string = implode('", "', $params);
     /**
      * UI element setup
      */
     require_once $CFG->dirroot . '/curriculum/lib/filtering/equalityselect.php';
     $choices_array = array(0 => get_string('anyvalue', 'filters'));
     //set up cluster listing
     if ($records = cluster_get_listing('name', 'ASC', 0, 0, '', '', array('contexts' => $context_result))) {
         foreach ($records as $record) {
             if ($record->parent == 0) {
                 //merge in child clusters
                 $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);
             }
         }
     }
     //get help text
     if (isset($this->options['help'])) {
         $this->_filterhelp = $this->options['help'];
     } else {
         $this->_filterhelp = null;
     }
     //add filterhelp and label to this filter
     //import required css for the fieldset
     $style = '<style>@import url("' . $CFG->wwwroot . '/curriculum/styles.css");</style>';
     //hack the nested fieldset into an html element
     $helptext = get_string('helpprefix2', $this->_filterhelp['1']) . ' (' . get_string('newwindow') . ')';
     $helpurl = '/help.php?module=' . $this->_filterhelp['2'] . '&amp;file=' . $this->_filterhelp['0'] . '.html&amp;forcelang=';
     $helplink = '<span class="helplink"><a title="' . $this->_filterhelp['1'] . '" href="' . $CFG->wwwroot . $helpurl . '"' . ' onclick="this.target=\'popup\'; return openpopup(\'' . $helpurl . '\', \'popup\', \'menubar=0,location=0,scrollbars,resizable,width=500,height=400\', 0);">' . ' <img class="iconhelp" alt="' . $helptext . '" src="' . $CFG->pixpath . '/help.gif"></a></span>';
     $nested_fieldset = false;
     $title = '';
     if ($this->options['fieldset']) {
         $nested_fieldset = '<fieldset class="nested clearfix" id="' . $this->_uniqueid . '_label' . '">' . "\n" . '<legend class="ftoggler">' . $this->_label . $helplink . '</legend>' . "\n";
     } else {
         $title = $this->_label . $helplink . '&nbsp;';
     }
     $mform->addElement('html', $style . $nested_fieldset);
     //cluster select dropdown
     $mform->addElement('select', $this->_uniqueid . '_dropdown', $title, $choices_array);
     //dropdown / cluster tree state storage
     $mform->addElement('hidden', $this->_uniqueid . '_usingdropdown');
     //default to showing dropdown if nothing has been persisted
     $report_shortname = $this->options['report_shortname'];
     $preferences = php_report_filtering_get_user_preferences($report_shortname);
     if (!isset($preferences["php_report_{$report_shortname}/{$this->_uniqueid}_usingdropdown"])) {
         $mform->setDefault($this->_uniqueid . '_usingdropdown', 1);
     }
     // dress it up like an mform element
     $tree_html = '<div class="fitem"><div class="fitemtitle"></div>' . $tree_html . '</div>';
     //cluster tree
     $mform->addElement('html', $tree_html);
     //list of explicitly selected elements
     $mform->addElement('hidden', $this->_uniqueid . '_listing');
     //list of selected and unexpanded elements
     $mform->addElement('hidden', $this->_uniqueid . '_unexpanded');
     //list of explicitly unselected elements
     $mform->addElement('hidden', $this->_uniqueid . '_clrunexpanded');
     /**
      * Work needed to initialize the state of necessary components
      */
     //parameters needed
     $params = array($this->options['report_id'], $this->_uniqueid, $this->options['dropdown_button_text'], $this->options['tree_button_text']);
     $param_string = implode('", "', $params);
     $mform->addElement('button', $this->_uniqueid . '_toggle', $this->options['dropdown_button_text'], array('onclick' => 'clustertree_toggle_tree("' . $param_string . '")'));
     //script to do the work
     $initialize_state_script = '<script type="text/javascript">
                                 clustertree_set_toggle_state("' . $param_string . '");
                                 </script>';
     $mform->addElement('html', $initialize_state_script);
     // close hacked nested fieldset
     if ($this->options['fieldset']) {
         $mform->addElement('html', '</fieldset>');
     }
 }