MDL-37085 Properly deprecated functions print_xxx() from course/lib.php

- get_print_section_cm_text()
- print_section_add_menus()
- print_section()
- make_editing_buttons()
This commit is contained in:
Marina Glancy 2012-12-14 11:32:21 +08:00
parent c58a25d6eb
commit 9a36be7361
10 changed files with 178 additions and 115 deletions

View file

@ -60,6 +60,7 @@ class block_site_main_menu extends block_list {
} }
/// slow & hacky editing mode /// slow & hacky editing mode
$courserenderer = $this->page->get_renderer('core', 'course');
$ismoving = ismoving($course->id); $ismoving = ismoving($course->id);
course_create_sections_if_missing($course, 0); course_create_sections_if_missing($course, 0);
$modinfo = get_fast_modinfo($course); $modinfo = get_fast_modinfo($course);
@ -87,7 +88,10 @@ class block_site_main_menu extends block_list {
continue; continue;
} }
if (!$ismoving) { if (!$ismoving) {
$editbuttons = '<div class="buttons">'.make_editing_buttons($mod, true, true).'</div>'; $actions = course_get_cm_edit_actions($mod, -1);
$editbuttons = html_writer::tag('div',
$courserenderer->course_section_cm_edit_actions($actions),
array('class' => 'buttons'));
} else { } else {
$editbuttons = ''; $editbuttons = '';
} }
@ -123,7 +127,6 @@ class block_site_main_menu extends block_list {
$this->content->icons[] = ''; $this->content->icons[] = '';
} }
$courserenderer = $this->page->get_renderer('core', 'course');
$this->content->footer = $courserenderer->course_section_add_cm_control($course, $this->content->footer = $courserenderer->course_section_add_cm_control($course,
0, null, array('inblock' => true)); 0, null, array('inblock' => true));

View file

@ -63,6 +63,7 @@ class block_social_activities extends block_list {
/// slow & hacky editing mode /// slow & hacky editing mode
$courserenderer = $this->page->get_renderer('core', 'course');
$ismoving = ismoving($course->id); $ismoving = ismoving($course->id);
$modinfo = get_fast_modinfo($course); $modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info(0); $section = $modinfo->get_section_info(0);
@ -89,7 +90,9 @@ class block_social_activities extends block_list {
continue; continue;
} }
if (!$ismoving) { if (!$ismoving) {
$editbuttons = '<br />'.make_editing_buttons($mod, true, true); $actions = course_get_cm_edit_actions($mod, -1);
$editbuttons = '<br />'.
$courserenderer->course_section_cm_edit_actions($actions);
} else { } else {
$editbuttons = ''; $editbuttons = '';
} }
@ -126,7 +129,6 @@ class block_social_activities extends block_list {
$this->content->icons[] = ''; $this->content->icons[] = '';
} }
$courserenderer = $this->page->get_renderer('core', 'course');
$this->content->footer = $courserenderer->course_section_add_cm_control($course, $this->content->footer = $courserenderer->course_section_add_cm_control($course,
0, null, array('inblock' => true)); 0, null, array('inblock' => true));

View file

@ -35,5 +35,7 @@ $modulename = required_param('module', PARAM_PLUGIN);
$displayname = optional_param('displayname', null, PARAM_TEXT); $displayname = optional_param('displayname', null, PARAM_TEXT);
$contents = optional_param('contents', null, PARAM_RAW); // It will be up to each plugin to clean this data, before saving it. $contents = optional_param('contents', null, PARAM_RAW); // It will be up to each plugin to clean this data, before saving it.
$PAGE->set_url('/course/dndupload.php');
$dndproc = new dndupload_ajax_processor($courseid, $section, $type, $modulename); $dndproc = new dndupload_ajax_processor($courseid, $section, $type, $modulename);
$dndproc->process($displayname, $contents); $dndproc->process($displayname, $contents);

View file

@ -665,7 +665,8 @@ class dndupload_ajax_processor {
* @param cm_info $mod details of the mod just created * @param cm_info $mod details of the mod just created
*/ */
protected function send_response($mod) { protected function send_response($mod) {
global $OUTPUT; global $OUTPUT, $PAGE;
$courserenderer = $PAGE->get_renderer('core', 'course');
$resp = new stdClass(); $resp = new stdClass();
$resp->error = self::ERROR_OK; $resp->error = self::ERROR_OK;
@ -673,7 +674,8 @@ class dndupload_ajax_processor {
$resp->name = $mod->name; $resp->name = $mod->name;
$resp->link = $mod->get_url()->out(); $resp->link = $mod->get_url()->out();
$resp->elementid = 'module-'.$mod->id; $resp->elementid = 'module-'.$mod->id;
$resp->commands = make_editing_buttons($mod, true, true, 0, $mod->sectionnum); $actions = course_get_cm_edit_actions($mod, 0, $mod->sectionnum);
$resp->commands = ' '. $courserenderer->course_section_cm_edit_actions($actions);
$resp->onclick = $mod->get_on_click(); $resp->onclick = $mod->get_on_click();
// if using groupings, then display grouping name // if using groupings, then display grouping name

View file

@ -125,7 +125,7 @@ class core_course_external extends external_api {
$sectioncontents = array(); $sectioncontents = array();
//for each module of the section //for each module of the section
foreach ($modinfo->sections[$section->section] as $cmid) { //matching /course/lib.php:print_section() logic foreach ($modinfo->sections[$section->section] as $cmid) {
$cm = $modinfo->cms[$cmid]; $cm = $modinfo->cms[$cmid];
// stop here if the module is not visible to the user // stop here if the module is not visible to the user

View file

@ -38,6 +38,20 @@ defined('MOODLE_INTERNAL') || die();
*/ */
abstract class format_section_renderer_base extends plugin_renderer_base { abstract class format_section_renderer_base extends plugin_renderer_base {
/** @var contains instance of core course renderer */
protected $courserenderer;
/**
* Constructor method, calls the parent constructor
*
* @param moodle_page $page
* @param string $target one of rendering target constants
*/
public function __construct(moodle_page $page, $target) {
parent::__construct($page, $target);
$this->courserenderer = $this->page->get_renderer('core', 'course');
}
/** /**
* Generate the starting container html for a list of sections * Generate the starting container html for a list of sections
* @return string HTML to output. * @return string HTML to output.
@ -544,7 +558,6 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
$modinfo = get_fast_modinfo($course); $modinfo = get_fast_modinfo($course);
$course = course_get_format($course)->get_course(); $course = course_get_format($course)->get_course();
$courserenderer = $this->page->get_renderer('core', 'course');
// Can we view the section in question? // Can we view the section in question?
if (!($sectioninfo = $modinfo->get_section_info($displaysection))) { if (!($sectioninfo = $modinfo->get_section_info($displaysection))) {
@ -569,8 +582,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) { if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
echo $this->start_section_list(); echo $this->start_section_list();
echo $this->section_header($thissection, $course, true, $displaysection); echo $this->section_header($thissection, $course, true, $displaysection);
print_section($course, $thissection, null, null, true, "100%", false, $displaysection); echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection);
echo $courserenderer->course_section_add_cm_control($course, 0, $displaysection); echo $this->courserenderer->course_section_add_cm_control($course, 0, $displaysection);
echo $this->section_footer(); echo $this->section_footer();
echo $this->end_section_list(); echo $this->end_section_list();
} }
@ -604,8 +617,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
$completioninfo = new completion_info($course); $completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon(); echo $completioninfo->display_help_icon();
print_section($course, $thissection, null, null, true, '100%', false, $displaysection); echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection);
echo $courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection); echo $this->courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection);
echo $this->section_footer(); echo $this->section_footer();
echo $this->end_section_list(); echo $this->end_section_list();
@ -639,7 +652,6 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
$course = course_get_format($course)->get_course(); $course = course_get_format($course)->get_course();
$context = context_course::instance($course->id); $context = context_course::instance($course->id);
$courserenderer = $this->page->get_renderer('core', 'course');
// Title with completion help icon. // Title with completion help icon.
$completioninfo = new completion_info($course); $completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon(); echo $completioninfo->display_help_icon();
@ -656,8 +668,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
// 0-section is displayed a little different then the others // 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 $PAGE->user_is_editing()) {
echo $this->section_header($thissection, $course, false, 0); echo $this->section_header($thissection, $course, false, 0);
print_section($course, $thissection, null, null, true, "100%", false, 0); echo $this->courserenderer->course_section_cm_list($course, $thissection);
echo $courserenderer->course_section_add_cm_control($course, 0); echo $this->courserenderer->course_section_add_cm_control($course, 0);
echo $this->section_footer(); echo $this->section_footer();
} }
continue; continue;
@ -686,8 +698,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
} else { } else {
echo $this->section_header($thissection, $course, false, 0); echo $this->section_header($thissection, $course, false, 0);
if ($thissection->uservisible) { if ($thissection->uservisible) {
print_section($course, $thissection, null, null, true, "100%", false, 0); echo $this->courserenderer->course_section_cm_list($course, $thissection);
echo $courserenderer->course_section_add_cm_control($course, $section); echo $this->courserenderer->course_section_add_cm_control($course, $section);
} }
echo $this->section_footer(); echo $this->section_footer();
} }
@ -701,7 +713,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
continue; continue;
} }
echo $this->stealth_section_header($section); echo $this->stealth_section_header($section);
print_section($course, $thissection, null, null, true, "100%", false, 0); echo $this->courserenderer->course_section_cm_list($course, $thissection);
echo $this->stealth_section_footer(); echo $this->stealth_section_footer();
} }

View file

@ -1301,75 +1301,6 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
return $resourcestotoggle; return $resourcestotoggle;
} }
/**
* Obtains shared data that is used in print_section when displaying a
* course-module entry.
*
* Calls format_text or format_string as appropriate, and obtains the correct icon.
*
* @deprecated since 2.5
*
* This data is also used in other areas of the code.
* @param cm_info $cm Course-module data (must come from get_fast_modinfo)
* @param object $course (argument not used)
* @return array An array with the following values in this order:
* $content (optional extra content for after link),
* $instancename (text of link)
*/
function get_print_section_cm_text(cm_info $cm, $course) {
return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
$cm->get_formatted_name());
}
/**
* Prints a section full of activity modules
*
* @deprecated since 2.5
*
* @param stdClass $course The course
* @param stdClass|section_info $section The section object containing properties id and section
* @param array $mods (argument not used)
* @param array $modnamesused (argument not used)
* @param bool $absolute (argument not used)
* @param string $width (argument not used)
* @param bool $hidecompletion Hide completion status
* @param int $sectionreturn The section to return to
* @return void
*/
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
global $PAGE;
$displayoptions = array('hidecompletion' => $hidecompletion);
$courserenderer = $PAGE->get_renderer('core', 'course');
echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
}
/**
* Prints the menus to add activities and resources.
*
* @deprecated since 2.5
*
* @param stdClass $course course object, must be the same as set on the page
* @param int $section relative section number (field course_sections.section)
* @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
* @param bool $vertical Vertical orientation
* @param bool $return Return the menus or send them to output
* @param int $sectionreturn The section to link back to
* @return void|string depending on $return
*/
function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
global $PAGE;
$output = '';
$courserenderer = $PAGE->get_renderer('core', 'course');
$output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
array('inblock' => $vertical));
if ($return) {
return $output;
} else {
echo $output;
return !empty($output);
}
}
/** /**
* Retrieve all metadata for the requested modules * Retrieve all metadata for the requested modules
* *
@ -2656,33 +2587,6 @@ function moveto_module($mod, $section, $beforemod=NULL) {
return true; return true;
} }
/**
* Produces the editing buttons for a module
*
* @global core_renderer $OUTPUT
* @staticvar type $str
* @param stdClass $mod The module to produce editing buttons for
* @param bool $absolute_ignored (argument ignored) - all links are absolute
* @param bool $moveselect (argument ignored)
* @param int $indent The current indenting
* @param int $section The section to link back to
* @return string XHTML for the editing buttons
*/
function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
global $PAGE;
if (!($mod instanceof cm_info)) {
$modinfo = get_fast_modinfo($mod->course);
$mod = $modinfo->get_cm($mod->id);
}
$actions = course_get_cm_edit_actions($mod, $indent, $section);
$courserenderer = $PAGE->get_renderer('core', 'course');
// The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
// and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
// the course page HTML will allow this to be removed.
return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
}
/** /**
* Returns the list of all editing actions that current user can perform on the module * Returns the list of all editing actions that current user can perform on the module
* *

View file

@ -142,7 +142,7 @@
" class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />"; " class=\"iconsmall\" alt=\"$streditsummary\" /></a><br /><br />";
} }
print_section($SITE, $section, $mods, $modnamesused, true); echo $courserenderer->course_section_cm_list($SITE, $section);
echo $courserenderer->course_section_add_cm_control($SITE, $section->section); echo $courserenderer->course_section_add_cm_control($SITE, $section->section);
echo $OUTPUT->box_end(); echo $OUTPUT->box_end();

View file

@ -3084,3 +3084,134 @@ function format_weeks_get_section_dates($section, $course) {
} }
return null; return null;
} }
/**
* Obtains shared data that is used in print_section when displaying a
* course-module entry.
*
* Deprecated. Instead of:
* list($content, $name) = get_print_section_cm_text($cm, $course);
* use:
* $content = $cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true));
* $name = $cm->get_formatted_name();
*
* @deprecated since 2.5
* @see cm_info::get_formatted_content()
* @see cm_info::get_formatted_name()
*
* This data is also used in other areas of the code.
* @param cm_info $cm Course-module data (must come from get_fast_modinfo)
* @param object $course (argument not used)
* @return array An array with the following values in this order:
* $content (optional extra content for after link),
* $instancename (text of link)
*/
function get_print_section_cm_text(cm_info $cm, $course) {
debugging('Function get_print_section_cm_text() is deprecated. Please use '.
'cm_info::get_formatted_content() and cm_info::get_formatted_name()',
DEBUG_DEVELOPER);
return array($cm->get_formatted_content(array('overflowdiv' => true, 'noclean' => true)),
$cm->get_formatted_name());
}
/**
* Prints the menus to add activities and resources.
*
* Deprecated. Please use:
* $courserenderer = $PAGE->get_renderer('core', 'course');
* $output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
* array('inblock' => $vertical));
* echo $output; // if $return argument in print_section_add_menus() set to false
*
* @deprecated since 2.5
* @see core_course_renderer::course_section_add_cm_control()
*
* @param stdClass $course course object, must be the same as set on the page
* @param int $section relative section number (field course_sections.section)
* @param null|array $modnames (argument ignored) get_module_types_names() is used instead of argument
* @param bool $vertical Vertical orientation
* @param bool $return Return the menus or send them to output
* @param int $sectionreturn The section to link back to
* @return void|string depending on $return
*/
function print_section_add_menus($course, $section, $modnames = null, $vertical=false, $return=false, $sectionreturn=null) {
global $PAGE;
debugging('Function print_section_add_menus() is deprecated. Please use course renderer '.
'function course_section_add_cm_control()', DEBUG_DEVELOPER);
$output = '';
$courserenderer = $PAGE->get_renderer('core', 'course');
$output = $courserenderer->course_section_add_cm_control($course, $section, $sectionreturn,
array('inblock' => $vertical));
if ($return) {
return $output;
} else {
echo $output;
return !empty($output);
}
}
/**
* Produces the editing buttons for a module
*
* Deprecated. Please use:
* $courserenderer = $PAGE->get_renderer('core', 'course');
* $actions = course_get_cm_edit_actions($mod, $indent, $section);
* return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
*
* @deprecated since 2.5
* @see course_get_cm_edit_actions()
* @see core_course_renderer->course_section_cm_edit_actions()
*
* @param stdClass $mod The module to produce editing buttons for
* @param bool $absolute_ignored (argument ignored) - all links are absolute
* @param bool $moveselect (argument ignored)
* @param int $indent The current indenting
* @param int $section The section to link back to
* @return string XHTML for the editing buttons
*/
function make_editing_buttons(stdClass $mod, $absolute_ignored = true, $moveselect = true, $indent=-1, $section=null) {
global $PAGE;
debugging('Function make_editing_buttons() is deprecated, please see PHPdocs in '.
'lib/deprecatedlib.php on how to replace it', DEBUG_DEVELOPER);
if (!($mod instanceof cm_info)) {
$modinfo = get_fast_modinfo($mod->course);
$mod = $modinfo->get_cm($mod->id);
}
$actions = course_get_cm_edit_actions($mod, $indent, $section);
$courserenderer = $PAGE->get_renderer('core', 'course');
// The space added before the <span> is a ugly hack but required to set the CSS property white-space: nowrap
// and having it to work without attaching the preceding text along with it. Hopefully the refactoring of
// the course page HTML will allow this to be removed.
return ' ' . $courserenderer->course_section_cm_edit_actions($actions);
}
/**
* Prints a section full of activity modules
*
* Deprecated. Please use:
* $courserenderer = $PAGE->get_renderer('core', 'course');
* echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn,
* array('hidecompletion' => $hidecompletion));
*
* @deprecated since 2.5
* @see core_course_renderer::course_section_cm_list()
*
* @param stdClass $course The course
* @param stdClass|section_info $section The section object containing properties id and section
* @param array $mods (argument not used)
* @param array $modnamesused (argument not used)
* @param bool $absolute (argument not used)
* @param string $width (argument not used)
* @param bool $hidecompletion Hide completion status
* @param int $sectionreturn The section to return to
* @return void
*/
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=null) {
global $PAGE;
debugging('Function print_section() is deprecated. Please use course renderer function '.
'course_section_cm_list() instead.', DEBUG_DEVELOPER);
$displayoptions = array('hidecompletion' => $hidecompletion);
$courserenderer = $PAGE->get_renderer('core', 'course');
echo $courserenderer->course_section_cm_list($course, $section, $sectionreturn, $displayoptions);
}

View file

@ -1,6 +1,13 @@
This files describes API changes in core lbraries and APIs, This files describes API changes in core lbraries and APIs,
information provided here is intended especially for developers. information provided here is intended especially for developers.
=== 2.5 ===
* Functions responsible for output in course/lib.php are deprecated, the code is moved to
appropriate renderers: print_section_add_menus()
See functions' phpdocs in lib/deprecatedlib.php
* Function get_print_section_cm_text() is deprecated, replaced with methods in cm_info
=== 2.4 === === 2.4 ===
* Pagelib: Numerous deprecated functions were removed as classes page_base, page_course * Pagelib: Numerous deprecated functions were removed as classes page_base, page_course