Пример #1
0
/**
 * 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;
}