/** * This function returns the reports an user has access to * * @param stdClass $course The course to object for the report * @param stdClass $context Current context * @param stdClass $user The currrent user */ function report_configreports_get_my_reports($course, $context) { global $CFG, $DB, $USER; require_once $CFG->dirroot . "/report/configreports/locallib.php"; $reports = $DB->get_records('report_configreports', array('courseid' => $course->id), 'name ASC'); $myreports = array(); if ($reports) { foreach ($reports as $report) { if ($report->visible && cr_check_report_permissions($report, $USER->id, $context)) { $rname = format_string($report->name); $url = new moodle_url('/report/configreports/viewreport.php', array('id' => $report->id, 'courseid' => $course->id)); $myreports[] = array('name' => $rname, 'url' => $url); } } } if (has_capability('report/configreports:managereports', $context) || has_capability('report/configreports:manageownreports', $context)) { $url = new moodle_url('/report/configreports/managereport.php', array('courseid' => $course->id)); $myreports[] = array('name' => get_string('managereports', 'report_configreports'), 'url' => $url); } return $myreports; }
/** * Gets the contents of the block (course view) * * @return object An object with the contents **/ public function get_content() { global $DB, $USER, $CFG, $COURSE; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->footer = ''; $this->content->icons = array(); if (!isloggedin()) { return $this->content; } require_once $CFG->dirroot . "/blocks/configurable_reports/locallib.php"; $course = $DB->get_record('course', array('id' => $COURSE->id)); if (!$course) { print_error('coursedoesnotexists'); } if ($course->id == SITEID) { $context = context_system::instance(); } else { $context = context_course::instance($course->id); } // Site (Shared) reports. if (!empty($this->config->displayglobalreports)) { $reports = $DB->get_records('block_configurable_reports', array('global' => 1), 'name ASC'); if ($reports) { foreach ($reports as $report) { if ($report->visible && cr_check_report_permissions($report, $USER->id, $context)) { $rname = format_string($report->name); $this->content->items[] = '<a href= "' . $CFG->wwwroot . '/blocks/configurable_reports/viewreport.php?id=' . $report->id . '&courseid=' . $course->id . '" alt="' . $rname . '">' . $rname . '</a>'; } } if (!empty($this->content->items)) { $this->content->items[] = '========'; } } } // Course reports. if (!property_exists($this, 'config') or !isset($this->config->displayreportslist) or $this->config->displayreportslist) { $reports = $DB->get_records('block_configurable_reports', array('courseid' => $course->id), 'name ASC'); if ($reports) { foreach ($reports as $report) { if (!$report->global && $report->visible && cr_check_report_permissions($report, $USER->id, $context)) { $rname = format_string($report->name); $this->content->items[] = '<a href= "' . $CFG->wwwroot . '/blocks/configurable_reports/viewreport.php?id=' . $report->id . '&courseid=' . $course->id . '" alt="' . $rname . '">' . $rname . '</a>'; } } if (!empty($this->content->items)) { $this->content->items[] = '========'; } } } if (has_capability('block/configurable_reports:managereports', $context) || has_capability('block/configurable_reports:manageownreports', $context)) { $this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/configurable_reports/managereport.php?courseid=' . $course->id . '">' . get_string('managereports', 'block_configurable_reports') . '</a>'; } return $this->content; }
/** *Gets the contents of the block (course view) * * @return object An object with the contents **/ function get_content() { global $DB, $USER, $CFG, $COURSE; if ($this->content !== NULL) { return $this->content; } $this->content = new stdClass(); $this->content->footer = ''; $this->content->icons = array(); if (!isloggedin()) { return $this->content; } require_once $CFG->dirroot . "/report/configreports/locallib.php"; $course = $DB->get_record('course', array('id' => $COURSE->id)); if (!$course) { print_error('coursedoesnotexists'); } if ($course->id == SITEID) { $context = get_context_instance(CONTEXT_SYSTEM); } else { $context = get_context_instance(CONTEXT_COURSE, $course->id); } $reports = $DB->get_records('report_configreports', array('courseid' => $course->id), 'name ASC'); if ($reports) { foreach ($reports as $report) { if ($report->visible && cr_check_report_permissions($report, $USER->id, $context)) { $rname = format_string($report->name); $this->content->items[] = '<a href= "' . $CFG->wwwroot . '/report/configreports/viewreport.php?id=' . $report->id . '&courseid=' . $course->id . '" alt="' . $rname . '">' . $rname . '</a>'; } } } if (has_capability('report/configreports:managereports', $context) || has_capability('report/configreports:manageownreports', $context)) { $this->content->items[] = '<a href="' . $CFG->wwwroot . '/report/configreports/managereport.php?courseid=' . $course->id . '">' . get_string('managereports', 'report_configreports') . '</a>'; } return $this->content; }
$PAGE->set_url('/report/configurablereports/index.php', array('id' => $id)); //setting page layout to report $PAGE->set_pagelayout('report'); if ($course->id == SITEID) { $context = context_system::instance(); } else { $context = context_course::instance($course->id); } //checking if user is capable of viewing this report in $context require_capability('report/configurablereports:view', $context); //global $DB, $USER, $CFG ,$COURSE; require_once $CFG->dirroot . "/blocks/configurable_reports/locallib.php"; $reports = $DB->get_records('block_configurable_reports', array('courseid' => $course->id), 'name ASC'); if ($reports) { foreach ($reports as $report) { if ($report->visible && cr_check_report_permissions($report, $USER->id, $context)) { $rname = format_string($report->name); $items[] = '<a href= "' . $CFG->wwwroot . '/blocks/configurable_reports/viewreport.php?id=' . $report->id . '&courseid=' . $course->id . '" alt="' . $rname . '">' . $rname . '</a>'; } } } if (has_capability('block/configurable_reports:managereports', $context) || has_capability('block/configurable_reports:manageownreports', $context)) { $items[] = '<hr/><a href="' . $CFG->wwwroot . '/blocks/configurable_reports/managereport.php?courseid=' . $course->id . '">' . get_string('managereports', 'block_configurable_reports') . '</a>'; } //making log entry add_to_log($course->id, 'course', 'report configurablereports', "report/configurablereports/index.php?id={$course->id}", $course->id); //setting page title and page heading $PAGE->set_title($course->shortname . ': ' . get_string('pluginname', 'block_configurable_reports')); $PAGE->set_heading($course->fullname); //Displaying header and heading echo $OUTPUT->header();