Skip to content

Commit

Permalink
MDL-37085 Properly deprecated functions print_xxx() from course/lib.php
Browse files Browse the repository at this point in the history
- get_print_section_cm_text()
- print_section_add_menus()
- print_section()
- make_editing_buttons()
  • Loading branch information
marinaglancy committed Jan 14, 2013
1 parent c58a25d commit 9a36be7
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 115 deletions.
7 changes: 5 additions & 2 deletions blocks/site_main_menu/block_site_main_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function get_content() {
}

/// slow & hacky editing mode
$courserenderer = $this->page->get_renderer('core', 'course');
$ismoving = ismoving($course->id);
course_create_sections_if_missing($course, 0);
$modinfo = get_fast_modinfo($course);
Expand Down Expand Up @@ -87,7 +88,10 @@ function get_content() {
continue;
}
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 {
$editbuttons = '';
}
Expand Down Expand Up @@ -123,7 +127,6 @@ function get_content() {
$this->content->icons[] = '';
}

$courserenderer = $this->page->get_renderer('core', 'course');
$this->content->footer = $courserenderer->course_section_add_cm_control($course,
0, null, array('inblock' => true));

Expand Down
6 changes: 4 additions & 2 deletions blocks/social_activities/block_social_activities.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function get_content() {


/// slow & hacky editing mode
$courserenderer = $this->page->get_renderer('core', 'course');
$ismoving = ismoving($course->id);
$modinfo = get_fast_modinfo($course);
$section = $modinfo->get_section_info(0);
Expand All @@ -89,7 +90,9 @@ function get_content() {
continue;
}
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 {
$editbuttons = '';
}
Expand Down Expand Up @@ -126,7 +129,6 @@ function get_content() {
$this->content->icons[] = '';
}

$courserenderer = $this->page->get_renderer('core', 'course');
$this->content->footer = $courserenderer->course_section_add_cm_control($course,
0, null, array('inblock' => true));

Expand Down
2 changes: 2 additions & 0 deletions course/dndupload.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@
$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);
6 changes: 4 additions & 2 deletions course/dnduploadlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,15 +665,17 @@ protected function finish_setup_course_module($instanceid) {
* @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;
$resp->icon = $mod->get_icon_url()->out();
$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
Expand Down
2 changes: 1 addition & 1 deletion course/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public static function get_course_contents($courseid, $options = array()) {
$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
Expand Down
34 changes: 23 additions & 11 deletions course/format/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@
*/
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.
Expand Down Expand Up @@ -544,7 +558,6 @@ public function print_single_section_page($course, $sections, $mods, $modnames,

$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))) {
Expand All @@ -569,8 +582,8 @@ public function print_single_section_page($course, $sections, $mods, $modnames,
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();
}
Expand Down Expand Up @@ -604,8 +617,8 @@ public function print_single_section_page($course, $sections, $mods, $modnames,
$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();

Expand Down Expand Up @@ -639,7 +652,6 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
$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();
Expand All @@ -656,8 +668,8 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
// 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;
Expand Down Expand Up @@ -686,8 +698,8 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
} 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();
}
Expand All @@ -701,7 +713,7 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
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();
}

Expand Down
96 changes: 0 additions & 96 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
" 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 $OUTPUT->box_end();
Expand Down
Loading

0 comments on commit 9a36be7

Please sign in to comment.