Skip to content

Commit

Permalink
MDL-68233 renderers/block: remove illegal uses of $PAGE and $OUTPUT
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed Mar 29, 2020
1 parent d939d6e commit 1dcd0d3
Show file tree
Hide file tree
Showing 27 changed files with 129 additions and 175 deletions.
69 changes: 32 additions & 37 deletions admin/tool/analytics/classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
defined('MOODLE_INTERNAL') || die();

use plugin_renderer_base;
use templatable;
use renderable;


/**
* Renderer class.
Expand Down Expand Up @@ -74,14 +73,12 @@ public function render_table(\table_sql $table) {
* @return string HTML
*/
public function render_evaluate_results($results, $logs = array()) {
global $OUTPUT;

$output = '';

foreach ($results as $timesplittingid => $result) {

if (!CLI_SCRIPT) {
$output .= $OUTPUT->box_start('generalbox mb-3');
$output .= $this->output->box_start('generalbox mb-3');
}

// Check that the array key is a string, not all results depend on time splitting methods (e.g. general errors).
Expand All @@ -90,47 +87,47 @@ public function render_evaluate_results($results, $logs = array()) {
$langstrdata = (object)array('name' => $timesplitting->get_name(), 'id' => $timesplittingid);

if (CLI_SCRIPT) {
$output .= $OUTPUT->heading(get_string('scheduledanalysisresultscli', 'tool_analytics', $langstrdata), 3);
$output .= $this->output->heading(get_string('scheduledanalysisresultscli', 'tool_analytics', $langstrdata), 3);
} else {
$output .= $OUTPUT->heading(get_string('scheduledanalysisresults', 'tool_analytics', $langstrdata), 3);
$output .= $this->output->heading(get_string('scheduledanalysisresults', 'tool_analytics', $langstrdata), 3);
}
}

if ($result->status == 0) {
$output .= $OUTPUT->notification(get_string('goodmodel', 'tool_analytics'),
$output .= $this->output->notification(get_string('goodmodel', 'tool_analytics'),
\core\output\notification::NOTIFY_SUCCESS);
} else if ($result->status === \core_analytics\model::NO_DATASET) {
$output .= $OUTPUT->notification(get_string('nodatatoevaluate', 'tool_analytics'),
$output .= $this->output->notification(get_string('nodatatoevaluate', 'tool_analytics'),
\core\output\notification::NOTIFY_WARNING);
}

if (isset($result->score)) {
// Score.
$output .= $OUTPUT->heading(get_string('accuracy', 'tool_analytics') . ': ' .
$output .= $this->output->heading(get_string('accuracy', 'tool_analytics') . ': ' .
round(floatval($result->score), 4) * 100 . '%', 4);
}

if (!empty($result->info)) {
foreach ($result->info as $message) {
$output .= $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING);
$output .= $this->output->notification($message, \core\output\notification::NOTIFY_WARNING);
}
}

if (!CLI_SCRIPT) {
$output .= $OUTPUT->box_end();
$output .= $this->output->box_end();
}
}

// Info logged during evaluation.
if (!empty($logs) && debugging()) {
$output .= $OUTPUT->heading(get_string('extrainfo', 'tool_analytics'), 3);
$output .= $this->output->heading(get_string('extrainfo', 'tool_analytics'), 3);
foreach ($logs as $log) {
$output .= $OUTPUT->notification($log, \core\output\notification::NOTIFY_WARNING);
$output .= $this->output->notification($log, \core\output\notification::NOTIFY_WARNING);
}
}

if (!CLI_SCRIPT) {
$output .= $OUTPUT->single_button(new \moodle_url('/admin/tool/analytics/index.php'), get_string('continue'), 'get');
$output .= $this->output->single_button(new \moodle_url('/admin/tool/analytics/index.php'), get_string('continue'), 'get');
}

return $output;
Expand All @@ -147,62 +144,60 @@ public function render_evaluate_results($results, $logs = array()) {
* @return string HTML
*/
public function render_get_predictions_results($trainresults = false, $trainlogs = array(), $predictresults = false, $predictlogs = array()) {
global $OUTPUT;

$output = '';

if ($trainresults || (!empty($trainlogs) && debugging())) {
$output .= $OUTPUT->heading(get_string('trainingresults', 'tool_analytics'), 3);
$output .= $this->output->heading(get_string('trainingresults', 'tool_analytics'), 3);
}

if ($trainresults) {
if ($trainresults->status == 0) {
$output .= $OUTPUT->notification(get_string('trainingprocessfinished', 'tool_analytics'),
$output .= $this->output->notification(get_string('trainingprocessfinished', 'tool_analytics'),
\core\output\notification::NOTIFY_SUCCESS);
} else if ($trainresults->status === \core_analytics\model::NO_DATASET ||
$trainresults->status === \core_analytics\model::NOT_ENOUGH_DATA) {
$output .= $OUTPUT->notification(get_string('nodatatotrain', 'tool_analytics'),
$output .= $this->output->notification(get_string('nodatatotrain', 'tool_analytics'),
\core\output\notification::NOTIFY_WARNING);
} else {
$output .= $OUTPUT->notification(get_string('generalerror', 'tool_analytics', $trainresults->status),
$output .= $this->output->notification(get_string('generalerror', 'tool_analytics', $trainresults->status),
\core\output\notification::NOTIFY_ERROR);
}
}

if (!empty($trainlogs) && debugging()) {
$output .= $OUTPUT->heading(get_string('extrainfo', 'tool_analytics'), 4);
$output .= $this->output->heading(get_string('extrainfo', 'tool_analytics'), 4);
foreach ($trainlogs as $log) {
$output .= $OUTPUT->notification($log, \core\output\notification::NOTIFY_WARNING);
$output .= $this->output->notification($log, \core\output\notification::NOTIFY_WARNING);
}
}

if ($predictresults || (!empty($predictlogs) && debugging())) {
$output .= $OUTPUT->heading(get_string('predictionresults', 'tool_analytics'), 3, 'main mt-3');
$output .= $this->output->heading(get_string('predictionresults', 'tool_analytics'), 3, 'main mt-3');
}

if ($predictresults) {
if ($predictresults->status == 0) {
$output .= $OUTPUT->notification(get_string('predictionprocessfinished', 'tool_analytics'),
$output .= $this->output->notification(get_string('predictionprocessfinished', 'tool_analytics'),
\core\output\notification::NOTIFY_SUCCESS);
} else if ($predictresults->status === \core_analytics\model::NO_DATASET ||
$predictresults->status === \core_analytics\model::NOT_ENOUGH_DATA) {
$output .= $OUTPUT->notification(get_string('nodatatopredict', 'tool_analytics'),
$output .= $this->output->notification(get_string('nodatatopredict', 'tool_analytics'),
\core\output\notification::NOTIFY_WARNING);
} else {
$output .= $OUTPUT->notification(get_string('generalerror', 'tool_analytics', $predictresults->status),
$output .= $this->output->notification(get_string('generalerror', 'tool_analytics', $predictresults->status),
\core\output\notification::NOTIFY_ERROR);
}
}

if (!empty($predictlogs) && debugging()) {
$output .= $OUTPUT->heading(get_string('extrainfo', 'tool_analytics'), 4);
$output .= $this->output->heading(get_string('extrainfo', 'tool_analytics'), 4);
foreach ($predictlogs as $log) {
$output .= $OUTPUT->notification($log, \core\output\notification::NOTIFY_WARNING);
$output .= $this->output->notification($log, \core\output\notification::NOTIFY_WARNING);
}
}

if (!CLI_SCRIPT) {
$output .= $OUTPUT->single_button(new \moodle_url('/admin/tool/analytics/index.php'), get_string('continue'), 'get');
$output .= $this->output->single_button(new \moodle_url('/admin/tool/analytics/index.php'), get_string('continue'), 'get');
}

return $output;
Expand Down Expand Up @@ -236,17 +231,17 @@ protected function render_invalid_analysables(\tool_analytics\output\invalid_ana
* @return string HTML
*/
public function render_analytics_disabled() {
global $OUTPUT, $PAGE, $FULLME;
global $FULLME;

$PAGE->set_url($FULLME);
$PAGE->set_title(get_string('pluginname', 'tool_analytics'));
$PAGE->set_heading(get_string('pluginname', 'tool_analytics'));
$this->page->set_url($FULLME);
$this->page->set_title(get_string('pluginname', 'tool_analytics'));
$this->page->set_heading(get_string('pluginname', 'tool_analytics'));

$output = $OUTPUT->header();
$output .= $OUTPUT->notification(get_string('analyticsdisabled', 'analytics'), \core\output\notification::NOTIFY_INFO);
$output = $this->output->header();
$output .= $this->output->notification(get_string('analyticsdisabled', 'analytics'), \core\output\notification::NOTIFY_INFO);
$output .= \html_writer::tag('a', get_string('continue'), ['class' => 'btn btn-primary',
'href' => (new \moodle_url('/'))->out()]);
$output .= $OUTPUT->footer();
$output .= $this->output->footer();

return $output;
}
Expand Down
2 changes: 1 addition & 1 deletion backup/util/ui/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public function backup_details_unknown(moodle_url $nextstageurl) {
*/
public function course_selector(moodle_url $nextstageurl, $wholecourse = true, restore_category_search $categories = null,
restore_course_search $courses = null, $currentcourse = null) {
global $CFG, $PAGE;
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');

// These variables are used to check if the form using this function was submitted.
Expand Down
4 changes: 2 additions & 2 deletions badges/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ protected function render_external_badge(\core_badges\output\external_badge $iba
* @return string
*/
protected function render_badge_user_collection(\core_badges\output\badge_user_collection $badges) {
global $CFG, $USER, $SITE, $OUTPUT;
global $CFG, $USER, $SITE;
$backpack = $badges->backpack;
$mybackpack = new moodle_url('/badges/mybackpack.php');

Expand Down Expand Up @@ -645,7 +645,7 @@ protected function render_badge_user_collection(\core_badges\output\badge_user_c
$externalhtml .= $this->output->heading_with_help(get_string('externalbadges', 'badges'), 'externalbadges', 'badges');
if (!is_null($backpack)) {
if ($backpack->backpackid != $CFG->badges_site_backpack) {
$externalhtml .= $OUTPUT->notification(get_string('backpackneedsupdate', 'badges'), 'warning');
$externalhtml .= $this->output->notification(get_string('backpackneedsupdate', 'badges'), 'warning');

}
if ($backpack->totalcollections == 0) {
Expand Down
4 changes: 2 additions & 2 deletions blocks/badges/block_badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function specialization() {
}

public function get_content() {
global $USER, $PAGE, $CFG;
global $USER, $CFG;

if ($this->content !== null) {
return $this->content;
Expand Down Expand Up @@ -105,4 +105,4 @@ public function get_content() {

return $this->content;
}
}
}
6 changes: 3 additions & 3 deletions blocks/comments/block_comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function instance_allow_multiple() {
}

function get_content() {
global $CFG, $PAGE;
global $CFG;
if ($this->content !== NULL) {
return $this->content;
}
Expand All @@ -64,10 +64,10 @@ function get_content() {
if (empty($this->instance)) {
return $this->content;
}
list($context, $course, $cm) = get_context_info_array($PAGE->context->id);
list($context, $course, $cm) = get_context_info_array($this->page->context->id);

$args = new stdClass;
$args->context = $PAGE->context;
$args->context = $this->page->context;
$args->course = $course;
$args->area = 'page_comments';
$args->itemid = 0;
Expand Down
3 changes: 1 addition & 2 deletions blocks/private_files/block_private_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function instance_allow_multiple() {
}

function get_content() {
global $CFG, $USER, $PAGE, $OUTPUT;

if ($this->content !== NULL) {
return $this->content;
Expand All @@ -62,7 +61,7 @@ function get_content() {
$this->content->text = $renderer->private_files_tree();
if (has_capability('moodle/user:manageownfiles', $this->context)) {
$this->content->footer = html_writer::link(
new moodle_url('/user/files.php', array('returnurl' => $PAGE->url->out())),
new moodle_url('/user/files.php', array('returnurl' => $this->page->url->out())),
get_string('privatefilesmanage') . '...');
}

Expand Down
4 changes: 2 additions & 2 deletions blocks/rss_client/block_rss_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ function specialization() {
* @return block_rss_client\output\footer|null The renderable footer or null if none should be displayed.
*/
protected function get_footer($feedrecords) {
global $PAGE;
$footer = null;

if ($this->config->block_rss_client_show_channel_link) {
Expand All @@ -80,7 +79,8 @@ protected function get_footer($feedrecords) {
if ($footer === null) {
$footer = new block_rss_client\output\footer();
}
$manageurl = new moodle_url('/blocks/rss_client/managefeeds.php', ['courseid' => $PAGE->course->id]);
$manageurl = new moodle_url('/blocks/rss_client/managefeeds.php',
['courseid' => $this->page->course->id]);
$footer->set_failed($manageurl);
}
}
Expand Down
3 changes: 1 addition & 2 deletions blocks/settings/block_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ function instance_can_be_docked() {
}

function get_required_javascript() {
global $PAGE;
$adminnode = $PAGE->settingsnav->find('siteadministration', navigation_node::TYPE_SITE_ADMIN);
$adminnode = $this->page->settingsnav->find('siteadministration', navigation_node::TYPE_SITE_ADMIN);
parent::get_required_javascript();
$arguments = array(
'instanceid' => $this->instance->id,
Expand Down
4 changes: 1 addition & 3 deletions course/classes/management_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,7 @@ public function category_listitem_actions(core_course_category $category, array
}

public function render_action_menu($menu) {
global $OUTPUT;

return $OUTPUT->render($menu);
return $this->output->render($menu);
}

/**
Expand Down
18 changes: 5 additions & 13 deletions course/format/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ protected function section_left_content($section, $course, $onsectionpage) {
* @return string HTML to output.
*/
protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) {
global $PAGE;

$o = '';
$currenttext = '';
$sectionstyle = '';
Expand Down Expand Up @@ -270,9 +268,7 @@ protected function section_edit_controls() {
* @return array of edit control items
*/
protected function section_edit_control_items($course, $section, $onsectionpage = false) {
global $PAGE;

if (!$PAGE->user_is_editing()) {
if (!$this->page->user_is_editing()) {
return array();
}

Expand Down Expand Up @@ -743,8 +739,6 @@ protected function section_nav_selection($course, $sections, $displaysection) {
* @param int $displaysection The section number in the course which is being displayed
*/
public function print_single_section_page($course, $sections, $mods, $modnames, $modnamesused, $displaysection) {
global $PAGE;

$modinfo = get_fast_modinfo($course);
$course = course_get_format($course)->get_course();

Expand All @@ -759,7 +753,7 @@ public function print_single_section_page($course, $sections, $mods, $modnames,
// Copy activity clipboard..
echo $this->course_activity_clipboard($course, $displaysection);
$thissection = $modinfo->get_section_info(0);
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
if ($thissection->summary or !empty($modinfo->sections[0]) or $this->page->user_is_editing()) {
echo $this->start_section_list();
echo $this->section_header($thissection, $course, true, $displaysection);
echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection);
Expand Down Expand Up @@ -828,8 +822,6 @@ public function print_single_section_page($course, $sections, $mods, $modnames,
* @param array $modnamesused (argument not used)
*/
public function print_multiple_section_page($course, $sections, $mods, $modnames, $modnamesused) {
global $PAGE;

$modinfo = get_fast_modinfo($course);
$course = course_get_format($course)->get_course();

Expand All @@ -849,7 +841,7 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if ($section == 0) {
// 0-section is displayed a little different then the others
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
if ($thissection->summary or !empty($modinfo->sections[0]) or $this->page->user_is_editing()) {
echo $this->section_header($thissection, $course, false, 0);
echo $this->courserenderer->course_section_cm_list($course, $thissection, 0);
echo $this->courserenderer->course_section_add_cm_control($course, 0, 0);
Expand All @@ -871,7 +863,7 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
continue;
}

if (!$PAGE->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
if (!$this->page->user_is_editing() && $course->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
// Display section summary only.
echo $this->section_summary($thissection, $course, null);
} else {
Expand All @@ -884,7 +876,7 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
}
}

if ($PAGE->user_is_editing() and has_capability('moodle/course:update', $context)) {
if ($this->page->user_is_editing() and has_capability('moodle/course:update', $context)) {
// Print stealth sections if present.
foreach ($modinfo->get_section_info_all() as $section => $thissection) {
if ($section <= $numsections or empty($modinfo->sections[$section])) {
Expand Down
4 changes: 1 addition & 3 deletions course/format/topics/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ public function section_title_without_link($section, $course) {
* @return array of edit control items
*/
protected function section_edit_control_items($course, $section, $onsectionpage = false) {
global $PAGE;

if (!$PAGE->user_is_editing()) {
if (!$this->page->user_is_editing()) {
return array();
}

Expand Down
Loading

0 comments on commit 1dcd0d3

Please sign in to comment.