/** * Dynamically loads child menu items for a cluster entity (similar to block_elisadmin_load_menu_children * but only includes clusters and always includes all children) * * @param int $id The entity id * @param int $parent_cluster_id The last cluster passed going down the elisadmin tree, or 0 if none * @param int $parent_curriculum_id The last curriculum passed going down the elisadmin tree, or 0 if none * @param string $parent_path Path of parent curriculum elements in the tree * @param int $execution_mode The constant representing the execution mode * @return menuitem array The appropriate child items */ function clustertree_load_menu_children_cluster($id, $parent_cluster_id, $parent_curriculum_id, $parent_path, $execution_mode) { $result_items = array(new menuitem('root')); /***************************************** * Cluster - Child Cluster Associations *****************************************/ $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance'); //get all child clusters $listing = cluster_get_listing('priority, name', 'ASC', 0, 0, '', '', array('parent' => $id)); if (!empty($listing)) { foreach ($listing as $item) { $params = array('id' => $item->id, 'action' => 'viewreport', 'execution_mode' => $execution_mode); //don't need permissions checking because custom contexts don't support //prevents / prohibits $cluster_count = cluster_count_records('', '', array('parent' => $item->id)); $isLeaf = empty($cluster_count); $result_items[] = block_elisadmin_get_menu_item('cluster', $item, 'root', $cluster_css_class, $item->id, $parent_curriculum_id, $params, $isLeaf, $parent_path); } } return $result_items; }
/** * Specifies the tree entries used to represent links to PHP reports * * @return menuitem array List of menu items to add (including report categories * but excluding the top-level report entry) */ function block_elisadmin_get_report_tree_items() { global $CFG, $DB; // If the reports block is not installed, no entries will be displayed. if (file_exists($CFG->dirroot . '/local/elisreports/version.php') !== true) { return array(); } //get the category-level links $items = block_elisadmin_get_report_category_items(); //path to library file for scheduling classes $schedulelib_path = $CFG->dirroot . '/local/elisreports/lib/schedulelib.php'; //check to make sure the required functionality is there //todo: remove this check when it's safe to do so if (file_exists($schedulelib_path)) { //reporting base class require_once $schedulelib_path; //schedule report entry //make sure we are using a "clean" page to check global permissions $test_permissions_page = new scheduling_page(array()); //make sure we can access the report listing if ($test_permissions_page->can_do('list')) { //create a direct url to the list page $schedule_reports_page = new menuitempage('url_page', 'lib/menuitem.class.php', $CFG->wwwroot . '/local/elisreports/schedule.php?action=list'); //convert to a menu item $css_class = block_elisadmin_get_item_css_class('schedulereports'); $schedule_reports_item = new menuitem('schedule_reports', $schedule_reports_page, 'rept', get_string('schedule_reports', 'local_elisreports'), $css_class, '', FALSE, 'rept'); //merge in with the current result $items = array_merge(array($schedule_reports_item), $items); } } //for storing the items bucketed by category $buckets = array(); //look for all report instances if (file_exists($CFG->dirroot . '/local/elisreports/instances') && ($handle = opendir($CFG->dirroot . '/local/elisreports/instances'))) { while (FALSE !== ($report_shortname = readdir($handle))) { //grab a test instance of the report in question $default_instance = php_report::get_default_instance($report_shortname); //make sure the report shortname is valid if ($default_instance !== FALSE) { //make sure the current user can access this report if ($default_instance->is_available() && $default_instance->can_view_report()) { //user-friendly report name $displayname = $default_instance->get_display_name(); //add the item to the necessary bucket $item_category = $default_instance->get_category(); if (!isset($buckets[$item_category])) { $buckets[$item_category] = array(); } //obtain the page specific to this report $report_page_classpath = $CFG->dirroot . '/local/elisreports/lib/reportpage.class.php'; $report_page_params = array('report' => $report_shortname); $page = new generic_menuitempage('report_page', $report_page_classpath, $report_page_params); //retrieve the actual menuitem $page_css_class = block_elisadmin_get_item_css_class('reportinstance'); $category_path = 'rept/' . $item_category; $buckets[$item_category][$displayname] = new menuitem($report_shortname, $page, $item_category, $displayname, $page_css_class, '', FALSE, $category_path); } } } } //retrieve the items representing the reports themselves from the bucketed listings $report_instance_items = block_elisadmin_get_report_bucket_items($buckets); //merge the flat listings of category items and report instance items $items = array_merge($items, $report_instance_items); //return the flat listing return $items; }
/** * 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>'); } }
function get_content() { global $CFG, $ADMIN, $USER, $HTTPSPAGEREQUIRED, $PAGE, $DB, $SITE; require_once $CFG->libdir . '/adminlib.php'; //dependencies on page classes require_once elispm::file('usersetpage.class.php'); require_once elispm::file('curriculumpage.class.php'); require_once elispm::file('coursepage.class.php'); require_once elispm::file('trackpage.class.php'); //require_once($CFG->dirroot . '/my/pagelib.php'); /// Determine the users CM access level. $access = cm_determine_access($USER->id); //make sure local_elisprogram / custom contexts set up correctly //to prevent error before the upgrade to ELIS 2 if (empty($access) || $this->content !== NULL || !defined('CONTEXT_ELIS_PROGRAM')) { return $this->content; } //if we are not on a PM page, disable the expansion of //entities in the curr admin tree (logic in curriculum/index.php) if (!is_a($PAGE, 'pm_page') && $PAGE->pagetype != 'admin-setting-local_elisprogram_settings') { unset($USER->currentitypath); } // Include Icon CSS. $PAGE->requires->css('/local/elisprogram/icons.css'); //CM entities for placement at the top of the menu $cm_entity_pages = array(); $cm_entity_pages[] = new menuitem('root'); $num_block_icons = isset(elis::$config->local_elisprogram->num_block_icons) ? elis::$config->local_elisprogram->num_block_icons : 5; /***************************************** * Clusters *****************************************/ if (!isset(elis::$config->local_elisprogram->display_clusters_at_top_level) || !empty(elis::$config->local_elisprogram->display_clusters_at_top_level)) { $manageclusters_css_class = block_elisadmin_get_item_css_class('manageclusters'); $cluster_css_class = block_elisadmin_get_item_css_class('cluster_instance'); require_once elispm::lib('contexts.php'); $context_result = pm_context_set::for_user_with_capability('cluster', 'local/elisprogram:userset_view', $USER->id); $extrafilters = array('contexts' => $context_result, 'parent' => 0); $num_records = cluster_count_records('', '', $extrafilters); if ($clusters = cluster_get_listing('priority, name', 'ASC', 0, $num_block_icons, '', '', $extrafilters)) { foreach ($clusters as $cluster) { $params = array('id' => $cluster->id, 'action' => 'view'); //count sub-clusters $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view')); $cluster_count = cluster_count_records('', '', array('parent' => $cluster->id), $cluster_filter); //count associated curricula $curriculum_filter = array('contexts' => curriculumpage::get_contexts('local/elisprogram:program_view')); $curriculum_count = clustercurriculum::count_curricula($cluster->id, $curriculum_filter); $isLeaf = empty($cluster_count) && empty($curriculum_count); $cm_entity_pages[] = block_elisadmin_get_menu_item('userset', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf); } } if ($num_block_icons < $num_records) { $cm_entity_pages[] = block_elisadmin_get_menu_summary_item('userset', $cluster_css_class, $num_records - $num_block_icons); } } /***************************************** * Curricula *****************************************/ if (!empty(elis::$config->local_elisprogram->display_curricula_at_top_level)) { $managecurricula_css_class = block_elisadmin_get_item_css_class('managecurricula'); $curriculum_css_class = block_elisadmin_get_item_css_class('curriculum_instance'); require_once elispm::file('curriculumpage.class.php'); $num_records = curriculum_count_records('', '', curriculumpage::get_contexts('local/elisprogram:program_view')); $curricula = $DB->get_recordset(curriculum::TABLE, null, 'priority ASC, name ASC', '*', 0, $num_block_icons); foreach ($curricula as $curriculum) { $params = array('id' => $curriculum->id, 'action' => 'view'); //count associated courses $course_filter = array('contexts' => coursepage::get_contexts('local/elisprogram:course_view')); $course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter); //count associated tracks $track_contexts = trackpage::get_contexts('local/elisprogram:track_view'); $track_count = track_count_records('', '', $curriculum->id, 0, $track_contexts); //count associated clusters $cluster_filter = array('contexts' => usersetpage::get_contexts('local/elisprogram:userset_view')); $cluster_count = clustercurriculum::count_clusters($curriculum->id, 0, $cluster_filter); $isLeaf = empty($course_count) && empty($track_count) && empty($cluster_count); $cm_entity_pages[] = block_elisadmin_get_menu_item('curriculum', $curriculum, 'root', $managecurricula_css_class, 0, $curriculum->id, $params, $isLeaf); } unset($curricula); if ($num_block_icons < $num_records) { $cm_entity_pages[] = block_elisadmin_get_menu_summary_item('curriculum', $curriculum_css_class, $num_records - $num_block_icons); } } //general cm pages $pages = array(new menuitem('dashboard', new menuitempage('dashboardpage'), 'root', '', block_elisadmin_get_item_css_class('dashboard')), new menuitem('admn', null, 'root', get_string('admin'), block_elisadmin_get_item_css_class('admn', true)), new menuitem('bulkuser', new menuitempage('bulkuserpage'), null, get_string('userbulk', 'admin'), block_elisadmin_get_item_css_class('bulkuser')), new menuitem('resultsconfig', new menuitempage('resultsconfigpage'), null, 'Default Results Engine Score Settings', block_elisadmin_get_item_css_class('resultsconfig'))); // ELIS-3208 - commented out this code as the Jasper reports no longer work in ELIS 2 /* //show the Jasper report server link if applicable if (cm_jasper_link_enabled()) { //page action $jasper_link_params = array('action' => 'reportslist'); //page instance $jasper_link_page = new menuitempage('jasperreportpage', '', $jasper_link_params); //styling for the link $jasper_link_css = block_elisadmin_get_item_css_class('reportslist'); $pages[] = new menuitem('reportslist', $jasper_link_page, null, '', $jasper_link_css); } */ $pages = array_merge($pages, array(new menuitem('customfields', new menuitempage('customfieldpage', '', array('level' => 'user')), null, '', block_elisadmin_get_item_css_class('customfields')), new menuitem('clusterclassification', new menuitempage('usersetclassificationpage', 'plugins/usetclassify/usersetclassificationpage.class.php'), null, get_string('userset_classification', 'elisprogram_usetclassify'), block_elisadmin_get_item_css_class('clusterclassification')), new menuitem('users', null, 'root', '', block_elisadmin_get_item_css_class('users', true)), new menuitem('manageusers', new menuitempage('userpage'), null, '', block_elisadmin_get_item_css_class('manageusers')), new menuitem('manageclusters', new menuitempage('usersetpage'), null, '', block_elisadmin_get_item_css_class('manageclusters')), new menuitem('curr', null, 'root', get_string('curriculum', 'local_elisprogram'), block_elisadmin_get_item_css_class('curr', true)), new menuitem('certificatelist', new menuitempage('certificatelistpage'), null, '', block_elisadmin_get_item_css_class('certificatelist')), new menuitem('managecurricula', new menuitempage('curriculumpage'), null, '', block_elisadmin_get_item_css_class('managecurricula')), new menuitem('managecourses', new menuitempage('coursepage'), null, '', block_elisadmin_get_item_css_class('managecourses')), new menuitem('manageclasses', new menuitempage('pmclasspage'), null, '', block_elisadmin_get_item_css_class('manageclasses')), new menuitem('crscat', null, 'root', get_string('learningplan', 'local_elisprogram'), block_elisadmin_get_item_css_class('crscat', true)), new menuitem('currentcourses', new menuitempage('coursecatalogpage', '', array('action' => 'current')), null, '', block_elisadmin_get_item_css_class('currentcourses')), new menuitem('availablecourses', new menuitempage('coursecatalogpage', '', array('action' => 'available')), null, '', block_elisadmin_get_item_css_class('availablecourses')), new menuitem('waitlist', new menuitempage('coursecatalogpage', '', array('action' => 'waitlist')), null, get_string('waitlistcourses', 'local_elisprogram'), block_elisadmin_get_item_css_class('waitlist')), new menuitem('rept', null, 'root', get_string('reports', 'local_elisprogram'), block_elisadmin_get_item_css_class('rept', true)))); if (has_capability('moodle/course:managegroups', context_course::instance($SITE->id))) { if (elis::$config->elisprogram_usetgroups->site_course_userset_groups) { $pages[] = new menuitem('frontpagegroups', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/index.php?id={$SITE->id}"), 'admn', get_string('frontpagegroups', 'elisprogram_usetgroups'), block_elisadmin_get_item_css_class('manageclusters')); } if (elis::$config->elisprogram_usetgroups->userset_groupings) { $pages[] = new menuitem('frontpagegroupings', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/group/groupings.php?id={$SITE->id}"), 'admn', get_string('frontpagegroupings', 'elisprogram_usetgroups'), block_elisadmin_get_item_css_class('manageclusters')); } } /** * This section adds all the necessary PHP reports to the menu */ //get all report pages, including categories but not including the //topmost report element $report_pages = block_elisadmin_get_report_tree_items(); //merge in the reporting page links $pages = array_merge($pages, $report_pages); if (empty(elis::$config->local_elisprogram->userdefinedtrack)) { $pages[] = new menuitem('managetracks', new menuitempage('trackpage'), null, '', block_elisadmin_get_item_css_class('managetracks')); } $syscontext = context_system::instance(); if (has_capability('local/elisprogram:config', $syscontext)) { $pages[] = new menuitem('configmanager', new menuitempage('url_page', 'lib/menuitem.class.php', "{$CFG->wwwroot}/admin/settings.php?section=local_elisprogram_settings"), 'admn', get_string('configuration'), block_elisadmin_get_item_css_class('configuration')); } $pages[] = new menuitem('notifications', new menuitempage('notifications', 'notificationspage.class.php', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('notifications')); //$pages[] = new menuitem('dataimport', new menuitempage('dataimportpage', 'elis_ip/elis_ip_page.php', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('integrationpoint')); $pages[] = new menuitem('defaultcls', new menuitempage('configclsdefaultpage', '', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('defaultcls')); $pages[] = new menuitem('defaultcrs', new menuitempage('configcrsdefaultpage', '', array('section' => 'admn')), null, '', block_elisadmin_get_item_css_class('defaultcrs')); //turn all pages that have no children into leaf nodes menuitemlisting::flag_leaf_nodes($pages); //combine the specific entity page listing with the general CM listing $menuitemlisting = new menuitemlisting(array_merge($cm_entity_pages, $pages)); $tree = new treerepresentation($menuitemlisting); $this->content = new stdClass(); $this->content->text = $tree->convert_to_markup(); $this->content->footer = ''; $PAGE->requires->yui_module('moodle-local_elisprogram-menuitem', 'M.local_elisprogram.init_menuitem', array($tree->get_js_object(), $CFG->httpswwwroot), null, true); return $this->content; }