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

@ -35,5 +35,7 @@ $modulename = required_param('module', PARAM_PLUGIN);
$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.
$PAGE->set_url('/course/dndupload.php');
$dndproc = new dndupload_ajax_processor($courseid, $section, $type, $modulename);
$dndproc->process($displayname, $contents);

View file

@ -665,7 +665,8 @@ class dndupload_ajax_processor {
* @param cm_info $mod details of the mod just created
*/
protected function send_response($mod) {
global $OUTPUT;
global $OUTPUT, $PAGE;
$courserenderer = $PAGE->get_renderer('core', 'course');
$resp = new stdClass();
$resp->error = self::ERROR_OK;
@ -673,7 +674,8 @@ class dndupload_ajax_processor {
$resp->name = $mod->name;
$resp->link = $mod->get_url()->out();
$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();
// if using groupings, then display grouping name

View file

@ -125,7 +125,7 @@ class core_course_external extends external_api {
$sectioncontents = array();
//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];
// 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 {
/** @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
* @return string HTML to output.
@ -544,7 +558,6 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
$modinfo = get_fast_modinfo($course);
$course = course_get_format($course)->get_course();
$courserenderer = $this->page->get_renderer('core', 'course');
// Can we view the section in question?
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()) {
echo $this->start_section_list();
echo $this->section_header($thissection, $course, true, $displaysection);
print_section($course, $thissection, null, null, true, "100%", false, $displaysection);
echo $courserenderer->course_section_add_cm_control($course, 0, $displaysection);
echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection);
echo $this->courserenderer->course_section_add_cm_control($course, 0, $displaysection);
echo $this->section_footer();
echo $this->end_section_list();
}
@ -604,8 +617,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
$completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon();
print_section($course, $thissection, null, null, true, '100%', false, $displaysection);
echo $courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection);
echo $this->courserenderer->course_section_cm_list($course, $thissection, $displaysection);
echo $this->courserenderer->course_section_add_cm_control($course, $displaysection, $displaysection);
echo $this->section_footer();
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();
$context = context_course::instance($course->id);
$courserenderer = $this->page->get_renderer('core', 'course');
// Title with completion help icon.
$completioninfo = new completion_info($course);
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
if ($thissection->summary or !empty($modinfo->sections[0]) or $PAGE->user_is_editing()) {
echo $this->section_header($thissection, $course, false, 0);
print_section($course, $thissection, null, null, true, "100%", false, 0);
echo $courserenderer->course_section_add_cm_control($course, 0);
echo $this->courserenderer->course_section_cm_list($course, $thissection);
echo $this->courserenderer->course_section_add_cm_control($course, 0);
echo $this->section_footer();
}
continue;
@ -686,8 +698,8 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
} else {
echo $this->section_header($thissection, $course, false, 0);
if ($thissection->uservisible) {
print_section($course, $thissection, null, null, true, "100%", false, 0);
echo $courserenderer->course_section_add_cm_control($course, $section);
echo $this->courserenderer->course_section_cm_list($course, $thissection);
echo $this->courserenderer->course_section_add_cm_control($course, $section);
}
echo $this->section_footer();
}
@ -701,7 +713,7 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
continue;
}
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();
}

View file

@ -1301,75 +1301,6 @@ function set_section_visible($courseid, $sectionnumber, $visibility) {
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
*
@ -2656,33 +2587,6 @@ function moveto_module($mod, $section, $beforemod=NULL) {
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
*