/** * Adds controls specific to this filter in the form. * @param object $mform a MoodleForm object to setup * @uses $CFG * @uses $OUTPUT * @uses $PAGE * @uses $USER */ function setupForm(&$mform) { global $CFG, $OUTPUT, $PAGE, $USER; // Javascript for cluster dropdown onchange event $cluster_group_separator = '------------------------------'; $js = ' <script type="text/javascript"> //<![CDATA[ function dropdown_separator(selectelem) { /* alert("dropdown_separator(" + selectelem.selectedIndex + ")"); */ if (selectelem.options[selectelem.selectedIndex].value < 0) { return 0; } return selectelem.selectedIndex; } //]]> </script> '; /** * CSS includes */ $mform->addElement('html', '<style>@import url("' . $CFG->wwwroot . '/lib/yui/2.9.0/build/treeview/assets/skins/sam/treeview-skin.css");</style>' . $js); /** * Get set up necessary CSS classes */ $manageclusters_css_class = block_elisadmin_get_item_css_class('manageclusters'); $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance'); //figure out which capability to check if ($this->execution_mode == php_report::EXECUTION_MODE_SCHEDULED) { $capability = 'local/elisreports:schedule'; } else { $capability = 'local/elisreports:view'; } $context_result = pm_context_set::for_user_with_capability('cluster', $capability, $USER->id); /** * 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']); /** * UI element setup */ require_once $CFG->dirroot . '/local/eliscore/lib/filtering/equalityselect.php'; $choices_array = array(0 => get_string('anyvalue', 'filters')); //set up cluster listing if ($records = $this->cluster_dropdown_get_listing($context_result)) { 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 $name = strlen($record->name) > 100 ? substr($record->name, 0, 100) . '...' : $record->name; $choices_array[$record->id] = $ancestors ? str_repeat('- ', $ancestors) . $name : $name; //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); } } } //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 . '/local/elisprogram/styles.css");</style>'; $helplink = ''; $nested_fieldset = ''; $title = ''; if ($this->options['fieldset']) { $nested_fieldset = '<fieldset class="nested clearfix" id="' . $this->_uniqueid . "_label\">\n"; } else { $title = $this->_label . $helplink . ' '; } $legend = '<legend class="ftoggler">' . $this->_label . "</legend>\n"; $mform->addElement('html', $style . $nested_fieldset . $legend); $mform->addElement('static', $this->_uniqueid . '_help', ''); // cluster select dropdown $selectparams = array('onchange' => 'this.selectedIndex = dropdown_separator(this);'); $mform->addElement('select', $this->_uniqueid . '_dropdown', $title, $choices_array, $selectparams); //dropdown / cluster tree state storage $mform->addElement('hidden', $this->_uniqueid . '_usingdropdown'); $mform->setType($this->_uniqueid . '_usingdropdown', PARAM_BOOL); // Must use addHelpButton() to NOT open help link on page, but in popup! $mform->addHelpButton($this->_uniqueid . '_dropdown', $this->_filterhelp[0], $this->_filterhelp[2]); // TBV //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); } $initclustertreeopts = array($CFG->httpswwwroot, $tree->instanceid, $this->_uniqueid, $tree->get_js_object(), $this->execution_mode, $this->options['report_id'], $this->options['dropdown_button_text'], $this->options['tree_button_text']); $PAGE->requires->yui_module('moodle-local_elisprogram-clustertree', 'M.local_elisprogram.init_clustertree', $initclustertreeopts, null, true); // cluster tree $clustertreehtml = '<div class="fitem"><div class="fitemtitle"></div>' . '<style>@import url("' . $CFG->wwwroot . '/lib/yui/2.9.0/build/treeview/assets/skins/sam/treeview.css");</style>' . '<div id="cluster_param_tree_' . $tree->instanceid . '_' . $this->_uniqueid . '" class="ygtv-checkbox felement"></div>' . '</div>'; $mform->addElement('html', $clustertreehtml); //list of explicitly selected elements $mform->addElement('hidden', $this->_uniqueid . '_listing'); $mform->setType($this->_uniqueid . '_listing', PARAM_TEXT); //list of selected and unexpanded elements $mform->addElement('hidden', $this->_uniqueid . '_unexpanded'); $mform->setType($this->_uniqueid . '_unexpanded', PARAM_TEXT); //list of explicitly unselected elements $mform->addElement('hidden', $this->_uniqueid . '_clrunexpanded'); $mform->setType($this->_uniqueid . '_clrunexpanded', PARAM_TEXT); $mform->addElement('button', $this->_uniqueid . '_toggle', ''); // close hacked nested fieldset if ($this->options['fieldset']) { $mform->addElement('html', '</fieldset>'); } }
/** * 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'] . '&file=' . $this->_filterhelp['0'] . '.html&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 . ' '; } $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>'); } }