/** * Dynamically loads child menu items for a cluster entity (similar to block_curr_admin_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 curr_admin tree, or 0 if none * @param int $parent_curriculum_id The last curriculum passed going down the curr_admin 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_curr_admin_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_curr_admin_get_menu_item('cluster', $item, 'root', $cluster_css_class, $item->id, $parent_curriculum_id, $params, $isLeaf, $parent_path); } } return $result_items; }
function get_content() { global $CFG, $ADMIN, $USER, $CURMAN, $HTTPSPAGEREQUIRED; require_once $CFG->libdir . '/adminlib.php'; require_once $CFG->dirroot . '/my/pagelib.php'; // dependencies on page classes require_once $CFG->dirroot . '/curriculum/clusterpage.class.php'; require_once $CFG->dirroot . '/curriculum/curriculumpage.class.php'; require_once $CFG->dirroot . '/curriculum/coursepage.class.php'; require_once $CFG->dirroot . '/curriculum/trackpage.class.php'; // ELIS-1251 - Don't display a useless message if in the center column // if ($this->instance->position == BLOCK_POS_CENTRE) { // $this->content = new stdClass; // $output = "This is content to display if in the middle..."; // $this->content->text = $output; // $this->content->footer = ''; // return $this->content; // } /// Display a link to the admin interface if on the main site index page and the current user has /// admin or developer access. // if ($this->instance->pageid == SITEID && // has_capability('block/curr_admin:config', get_context_instance(CONTEXT_SYSTEM, SITEID))) { // // $this->content = new stdClass; // $this->content->text = '<a href="' . $CFG->wwwroot . '/curriculum/index.php">' . // get_string('accesscurriculumadmin', 'block_curr_admin') . '</a>'; // $this->content->footer = ''; // } /// Determine the users CM access level. $access = cm_determine_access($USER->id); $this->title = get_string("blocktitle{$access}", 'block_curr_admin'); if (empty($access) || $this->content !== NULL) { return $this->content; } //if we are not on a CM "newpage", disable the expansion of //entities in the curr admin tree (logic in curriculum/index.php) if (!isset($CURMAN->page)) { unset($USER->currentitypath); } //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 if (!empty($HTTPSPAGEREQUIRED)) { $wwwroot = $CFG->httpswwwroot; } else { $wwwroot = $CFG->wwwroot; } require_js($wwwroot . '/curriculum/js/menuitem.js'); //CM entities for placement at the top of the menu $cm_entity_pages = array(); $cm_entity_pages[] = new menuitem('root'); $num_block_icons = isset($CURMAN->config->num_block_icons) ? $CURMAN->config->num_block_icons : 5; /***************************************** * Clusters *****************************************/ if (!isset($CURMAN->config->display_clusters_at_top_level) || !empty($CURMAN->config->display_clusters_at_top_level)) { $manageclusters_css_class = block_curr_admin_get_item_css_class('manageclusters'); $cluster_css_class = block_curr_admin_get_item_css_class('cluster_instance'); require_once CURMAN_DIRLOCATION . '/lib/contexts.php'; $context_result = cm_context_set::for_user_with_capability('cluster', 'block/curr_admin:cluster: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' => clusterpage::get_contexts('block/curr_admin:cluster:view'), 'parent' => $cluster->id); $cluster_count = cluster_count_records('', '', $cluster_filter); // count associated curricula $curriculum_filter = array('contexts' => curriculumpage::get_contexts('block/curr_admin:curriculum:view')); $curriculum_count = clustercurriculum::count_curricula($cluster->id, $curriculum_filter); $isLeaf = empty($cluster_count) && empty($curriculum_count); $cm_entity_pages[] = block_curr_admin_get_menu_item('cluster', $cluster, 'root', $manageclusters_css_class, $cluster->id, 0, $params, $isLeaf); } } if ($num_block_icons < $num_records) { $cm_entity_pages[] = block_curr_admin_get_menu_summary_item('cluster', $cluster_css_class, $num_records - $num_block_icons); } } /***************************************** * Curricula *****************************************/ if (!empty($CURMAN->config->display_curricula_at_top_level)) { $managecurricula_css_class = block_curr_admin_get_item_css_class('managecurricula'); $curriculum_css_class = block_curr_admin_get_item_css_class('curriculum_instance'); require_once CURMAN_DIRLOCATION . '/curriculumpage.class.php'; $num_records = curriculum_count_records('', '', curriculumpage::get_contexts('block/curr_admin:curriculum:view')); if ($curricula = get_records(CURTABLE, '', '', '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('block/curr_admin:course:view')); $course_count = curriculumcourse_count_records($curriculum->id, '', '', $course_filter); // count associated tracks $track_contexts = trackpage::get_contexts('block/curr_admin:track:view'); $track_count = track_count_records('', '', $curriculum->id, 0, $track_contexts); // count associated clusters $cluster_filter = array('contexts' => clusterpage::get_contexts('block/curr_admin:cluster: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_curr_admin_get_menu_item('curriculum', $curriculum, 'root', $managecurricula_css_class, 0, $curriculum->id, $params, $isLeaf); } } if ($num_block_icons < $num_records) { $cm_entity_pages[] = block_curr_admin_get_menu_summary_item('curriculum', $curriculum_css_class, $num_records - $num_block_icons); } } global $SITE; //general cm pages $pages = array(new menuitem('dashboard', new menuitempage('dashboardpage'), 'root', '', block_curr_admin_get_item_css_class('dashboard')), new menuitem('admn', null, 'root', get_string('admin'), block_curr_admin_get_item_css_class('admn', true)), new menuitem('bulkuser', new menuitempage('bulkuserpage'), null, get_string('userbulk', 'admin'), block_curr_admin_get_item_css_class('bulkuser'))); //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_curr_admin_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_curr_admin_get_item_css_class('customfields')), new menuitem('clusterclassification', new menuitempage('clusterclassificationpage', 'plugins/cluster_classification/clusterclassificationpage.class.php'), null, get_string('cluster_classification', 'crlm_cluster_classification'), block_curr_admin_get_item_css_class('clusterclassification')), new menuitem('info', null, 'root', get_string('informationalelements', 'block_curr_admin'), block_curr_admin_get_item_css_class('info', true)), new menuitem('managetags', new menuitempage('tagpage'), null, '', block_curr_admin_get_item_css_class('managetags')), new menuitem('manageenvironments', new menuitempage('envpage'), null, '', block_curr_admin_get_item_css_class('manageenvironments')), new menuitem('users', null, 'root', '', block_curr_admin_get_item_css_class('users', true)), new menuitem('manageusers', new menuitempage('usermanagementpage'), null, '', block_curr_admin_get_item_css_class('manageusers')), new menuitem('manageclusters', new menuitempage('clusterpage'), null, '', block_curr_admin_get_item_css_class('manageclusters')), new menuitem('curr', null, 'root', get_string('curriculum', 'block_curr_admin'), block_curr_admin_get_item_css_class('curr', true)), new menuitem('certificatelist', new menuitempage('certificatelistpage'), null, '', block_curr_admin_get_item_css_class('certificatelist')), new menuitem('managecurricula', new menuitempage('curriculumpage'), null, '', block_curr_admin_get_item_css_class('managecurricula')), new menuitem('managecourses', new menuitempage('coursepage'), null, '', block_curr_admin_get_item_css_class('managecourses')), new menuitem('manageclasses', new menuitempage('cmclasspage'), null, '', block_curr_admin_get_item_css_class('manageclasses')), new menuitem('crscat', null, 'root', get_string('learningplan', 'block_curr_admin'), block_curr_admin_get_item_css_class('crscat', true)), new menuitem('currentcourses', new menuitempage('coursecatalogpage', '', array('action' => 'current')), null, '', block_curr_admin_get_item_css_class('currentcourses')), new menuitem('availablecourses', new menuitempage('coursecatalogpage', '', array('action' => 'available')), null, '', block_curr_admin_get_item_css_class('availablecourses')), new menuitem('waitlist', new menuitempage('coursecatalogpage', '', array('action' => 'waitlist')), null, get_string('waitlistcourses', 'block_curr_admin'), block_curr_admin_get_item_css_class('waitlist')), new menuitem('rept', null, 'root', get_string('reports', 'block_curr_admin'), block_curr_admin_get_item_css_class('rept', true)))); if (has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $SITE->id))) { if ($CURMAN->config->site_course_cluster_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', 'crlm_cluster_groups'), block_curr_admin_get_item_css_class('manageclusters')); } if ($CURMAN->config->cluster_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', 'crlm_cluster_groups'), block_curr_admin_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_curr_admin_get_report_tree_items(); //merge in the reporting page links $pages = array_merge($pages, $report_pages); if (empty($CURMAN->config->userdefinedtrack)) { $pages[] = new menuitem('managetracks', new menuitempage('trackpage'), null, '', block_curr_admin_get_item_css_class('managetracks')); } $access = cm_determine_access($USER->id); switch ($access) { case 'admin': case 'developer': $pages[] = new menuitem('configmanager', new menuitempage('configpage', '', array('section' => 'admn')), null, get_string('configuration'), block_curr_admin_get_item_css_class('configuration')); $pages[] = new menuitem('notifications', new menuitempage('notifications', 'notificationspage.class.php', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('notifications')); $pages[] = new menuitem('dataimport', new menuitempage('dataimportpage', 'elis_ip/elis_ip_page.php', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('integrationpoint')); $pages[] = new menuitem('defaultcls', new menuitempage('configclsdefaultpage', '', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('defaultcls')); $pages[] = new menuitem('defaultcrs', new menuitempage('configcrsdefaultpage', '', array('section' => 'admn')), null, '', block_curr_admin_get_item_css_class('defaultcrs')); break; default: break; } //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 = ''; return $this->content; }
/** * 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>'); } }
/** * 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_curr_admin_get_report_tree_items() { global $CFG; //if the reports block is not installed, no entries will be displayed if (!record_exists('block', 'name', 'php_report')) { return array(); } //get the category-level links $items = block_curr_admin_get_report_category_items(); //path to library file for scheduling classes $schedulelib_path = $CFG->dirroot . '/blocks/php_report/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 $test_permissions_page = new scheduling_page(); //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 . '/blocks/php_report/schedule.php?action=list'); //convert to a menu item $css_class = block_curr_admin_get_item_css_class('schedulereports'); $schedule_reports_item = new menuitem('schedule_reports', $schedule_reports_page, 'rept', get_string('schedule_reports', 'block_php_report'), $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 ($handle = opendir($CFG->dirroot . '/blocks/php_report/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 . '/blocks/php_report/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_curr_admin_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_curr_admin_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; }