Skip to content

Commit

Permalink
Merge branch 'MDL-33767-master' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Aparup Banerjee committed Jul 17, 2012
2 parents c1483c9 + 5946d37 commit 816ac8d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
10 changes: 3 additions & 7 deletions course/editsection.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
require_once('editsection_form.php');

$id = required_param('id',PARAM_INT); // Week/topic ID
$sectionreturn = optional_param('sectionreturn', 0, PARAM_BOOL);
$sectionreturn = optional_param('sr', 0, PARAM_INT);

$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sectionreturn'=> $sectionreturn));
$PAGE->set_url('/course/editsection.php', array('id'=>$id, 'sr'=> $sectionreturn));

$section = $DB->get_record('course_sections', array('id' => $id), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST);
Expand All @@ -61,11 +61,7 @@
'cs' => $section, 'showavailability' => $section->showavailability));
$mform->set_data($section); // set current value

if ($sectionreturn) {
$returnurl = course_get_url($course, $section->section);
} else {
$returnurl = course_get_url($course);
}
$returnurl = course_get_url($course, $sectionreturn);

/// If data submitted, then process and store.
if ($mform->is_cancelled()){
Expand Down
32 changes: 17 additions & 15 deletions course/format/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,10 @@ protected function section_left_content($section, $course, $onsectionpage) {
* @param stdClass $section The course_section entry from DB
* @param stdClass $course The course entry from DB
* @param bool $onsectionpage true if being printed on a single-section page
* @param int $sectionreturn The section to return to after an action
* @return string HTML to output.
*/
protected function section_header($section, $course, $onsectionpage) {
protected function section_header($section, $course, $onsectionpage, $sectionreturn=0) {
global $PAGE;

$o = '';
Expand All @@ -150,7 +151,13 @@ protected function section_header($section, $course, $onsectionpage) {
$o.= html_writer::tag('div', $rightcontent, array('class' => 'right side'));
$o.= html_writer::start_tag('div', array('class' => 'content'));

if (!$onsectionpage) {
// When not on a section page, we display the section titles except the general section if null
$hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name)));

// When on a section page, we only display the general section title, if title is not the default one
$hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name)));

if ($hasnamenotsecpg || $hasnamesecpg) {
$o.= $this->output->heading($this->section_title($section, $course), 3, 'sectionname');
}

Expand All @@ -159,12 +166,7 @@ protected function section_header($section, $course, $onsectionpage) {

$context = context_course::instance($course->id);
if ($PAGE->user_is_editing() && has_capability('moodle/course:update', $context)) {
$url = new moodle_url('/course/editsection.php', array('id'=>$section->id));

if ($onsectionpage) {
$url->param('sectionreturn', 1);
}

$url = new moodle_url('/course/editsection.php', array('id'=>$section->id, 'sr'=>$sectionreturn));
$o.= html_writer::link($url,
html_writer::empty_tag('img', array('src' => $this->output->pix_url('t/edit'), 'class' => 'iconsmall edit')),
array('title' => get_string('editsummary')));
Expand Down Expand Up @@ -560,10 +562,10 @@ public function print_single_section_page($course, $sections, $mods, $modnames,
$thissection = $sections[0];
if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
echo $this->start_section_list();
echo $this->section_header($thissection, $course, true);
print_section($course, $thissection, $mods, $modnamesused, true);
echo $this->section_header($thissection, $course, true, $displaysection);
print_section($course, $thissection, $mods, $modnamesused, true, "100%", false, $displaysection);
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, 0, $modnames, false, false, true);
print_section_add_menus($course, 0, $modnames, false, false, $displaysection);
}
echo $this->section_footer();
echo $this->end_section_list();
Expand Down Expand Up @@ -592,14 +594,14 @@ public function print_single_section_page($course, $sections, $mods, $modnames,

// The requested section page.
$thissection = $sections[$displaysection];
echo $this->section_header($thissection, $course, true);
echo $this->section_header($thissection, $course, true, $displaysection);
// Show completion help icon.
$completioninfo = new completion_info($course);
echo $completioninfo->display_help_icon();

print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, true);
print_section($course, $thissection, $mods, $modnamesused, true, '100%', false, $displaysection);
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, $displaysection, $modnames, false, false, true);
print_section_add_menus($course, $displaysection, $modnames, false, false, $displaysection);
}
echo $this->section_footer();
echo $this->end_section_list();
Expand Down Expand Up @@ -646,7 +648,7 @@ public function print_multiple_section_page($course, $sections, $mods, $modnames
$thissection = $sections[0];
unset($sections[0]);
if ($thissection->summary or $thissection->sequence or $PAGE->user_is_editing()) {
echo $this->section_header($thissection, $course, true);
echo $this->section_header($thissection, $course, false);
print_section($course, $thissection, $mods, $modnamesused, true);
if ($PAGE->user_is_editing()) {
print_section_add_menus($course, 0, $modnames);
Expand Down
44 changes: 25 additions & 19 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1377,8 +1377,18 @@ function get_print_section_cm_text(cm_info $cm, $course) {

/**
* Prints a section full of activity modules
*
* @param stdClass $course The course
* @param stdClass $section The section
* @param array $mods The modules in the section
* @param array $modnamesused An array containing the list of modules and their names
* @param bool $absolute All links are absolute
* @param string $width Width of the container
* @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 = false) {
function print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false, $sectionreturn=0) {
global $CFG, $USER, $DB, $PAGE, $OUTPUT;

static $initialised;
Expand Down Expand Up @@ -1638,12 +1648,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
$mod->groupmode = false;
}
echo '  ';

if ($sectionreturn) {
echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section);
} else {
echo make_editing_buttons($mod, $absolute, true, $mod->indent, 0);
}
echo make_editing_buttons($mod, $absolute, true, $mod->indent, $sectionreturn);
echo $mod->get_after_edit_icons();
}

Expand Down Expand Up @@ -1762,8 +1767,16 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,

/**
* Prints the menus to add activities and resources.
*
* @param stdClass $course The course
* @param stdClass $section The section
* @param array $modnames An array containing the list of modules and their names
* @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, $vertical=false, $return=false, $sectionreturn = false) {
function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false, $sectionreturn=0) {
global $CFG, $OUTPUT;

// check to see if user can add menus
Expand All @@ -1779,22 +1792,15 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
$activities = array();

// We need to add the section section to the link for each module
$sectionlink = '&section=' . $section;

// We need to add the section to return to
if ($sectionreturn) {
$sectionreturnlink = '&sr=' . $section;
} else {
$sectionreturnlink = '&sr=0';
}
$sectionlink = '&section=' . $section . '&sr=' . $sectionreturn;

foreach ($modules as $module) {
if (isset($module->types)) {
// This module has a subtype
// NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
$subtypes = array();
foreach ($module->types as $subtype) {
$subtypes[$subtype->link . $sectionlink . $sectionreturnlink] = $subtype->title;
$subtypes[$subtype->link . $sectionlink] = $subtype->title;
}

// Sort module subtypes into the list
Expand All @@ -1816,11 +1822,11 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
} else {
// This module has no subtypes
if ($module->archetype == MOD_ARCHETYPE_RESOURCE) {
$resources[$module->link . $sectionlink . $sectionreturnlink] = $module->title;
$resources[$module->link . $sectionlink] = $module->title;
} else if ($module->archetype === MOD_ARCHETYPE_SYSTEM) {
// System modules cannot be added by user, do not add to dropdown
} else {
$activities[$module->link . $sectionlink . $sectionreturnlink] = $module->title;
$activities[$module->link . $sectionlink] = $module->title;
}
}
}
Expand Down

0 comments on commit 816ac8d

Please sign in to comment.