/** * Obtains a listing of report display names, grouped by category * * @param boolean $require_exportable If true, only include reports that are considered to be exportable * in the context of scheduling * @param int|NULL $userid Id of the Moodle user who this report is being * for * @param int $execution_mode The mode in which this report is being executed * * @return string array Mapping of category shortname to mappings of * report shortnames to display names (category entries * will exist but be empty if no reports are in that category) */ function block_php_report_get_names_by_category($require_exportable = false, $userid = NULL, $execution_mode = php_report::EXECUTION_MODE_INTERACTIVE) { global $CFG; $category_members = array(); //get a listing of the different categories $categories = block_php_report_get_category_mapping(); //initialize a bucket to store a category's reports where applicable foreach ($categories as $category_key => $category_display) { $category_members[$category_key] = array(); } //go through the directories if ($handle = opendir($CFG->dirroot . '/blocks/php_report/instances')) { while (false !== ($report_shortname = readdir($handle))) { //get the report instance (this inherently checks permissions and report availability) if ($instance = php_report::get_default_instance($report_shortname, $userid, $execution_mode)) { //determine if the export action is available in the context of scheduling $export_available = true; //check permissions and make sure access is not explicitly disallowed in the current execution mode if (!$instance->can_view_report()) { $export_available = false; } //make sure there is at least one available export format $export_formats = $instance->get_export_formats(); if (count($export_formats) == 0) { $export_available = false; } if (!$require_exportable || $export_available) { $category_shortname = $instance->get_category(); $report_shortname = $instance->get_report_shortname(); $category_members[$category_shortname][$report_shortname] = $instance->get_display_name(); } } } //sort reports by display name within each category foreach ($category_members as $category_shortname => $bucket) { sort($bucket); $category_members[$category_shortname]; } } return $category_members; }
/** * List the available reports to schedule */ public function action_list() { global $CFG; require_once $CFG->dirroot . '/blocks/php_report/sharedlib.php'; //import necessary CSS $stylesheet_web_path = $CFG->wwwroot . '/blocks/php_report/styles.php'; echo '<style>@import url("' . $stylesheet_web_path . '");</style>'; $category_members = block_php_report_get_names_by_category(true, NULL, php_report::EXECUTION_MODE_SCHEDULED); //set up the basics of our table $table = new stdClass(); $table->head = array(get_string('list_report_name_header', 'block_php_report'), get_string('list_schedule_header', 'block_php_report')); $table->align = array('left', 'left'); $table->rowclass = array(); $table->data = array(); $categories = block_php_report_get_category_mapping(); //go through categories and append items foreach ($categories as $category_key => $category_display) { if (!empty($category_members[$category_key])) { //set up a row for the category header $table->data[] = array($category_display, ''); //cass class for specially styling the category header row $table->rowclass[] = 'php_report_scheduling_list_category'; //go through and add all report entries below the category header foreach ($category_members[$category_key] as $member_shortname => $member_display) { //set up a link for executing the report $execute_report_url = $CFG->wwwroot . '/blocks/php_report/render_report_page.php?report=' . $member_shortname; $execute_report_link = php_report::get_default_instance($member_shortname) ? '<a href="' . $execute_report_url . '">' . $member_display . '</a>' : $member_display; //set up a link for scheduling the report $execute_report_url_params = array('action' => 'listinstancejobs', 'report' => $member_shortname); $execute_report_url = $this->get_url($execute_report_url_params); $schedule_report_link = ''; if (php_report::get_default_instance($member_shortname, NULL, php_report::EXECUTION_MODE_SCHEDULED)) { $schedule_report_link = '<a href="' . $execute_report_url . '"> <img src="' . $CFG->wwwroot . '/blocks/php_report/pix/schedule.png"/> </a>'; } //append info to the row $table->data[] = array($execute_report_link, $schedule_report_link); $table->rowclass[] = ''; } } } if (count($table->data > 0)) { print_table($table); } else { //error case } }