MDL-32508 course: Add basic 'add a section' button at the bottom of the course page
authorDan Poltawski <dan@moodle.com>
Mon, 21 Nov 2011 15:11:35 +0000 (15:11 +0000)
committerDan Poltawski <dan@moodle.com>
Fri, 4 May 2012 02:53:01 +0000 (10:53 +0800)
With thanks to LUNS who provided this code from when I did it working
there.

course/addsection.php [new file with mode: 0644]
course/format/renderer.php
lang/en/moodle.php

diff --git a/course/addsection.php b/course/addsection.php
new file mode 100644 (file)
index 0000000..d414527
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+
+require_once(dirname(__FILE__).'/../config.php');
+require_once($CFG->dirroot.'/course/lib.php');
+
+$courseid = required_param('courseid', PARAM_INT);
+$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+
+$PAGE->set_url('/course/addsection.php', array('courseid' => $courseid));
+
+// Authorisation checks.
+require_login($course);
+require_capability('moodle/course:update', context_course::instance($course->id));
+require_sesskey();
+
+// Add an additional section.
+$course->numsections++;
+$DB->update_record('course', $course);
+
+// Redirect to where we were..
+redirect(course_get_url($course));
index dcace50..082c66e 100644 (file)
@@ -507,8 +507,19 @@ abstract class format_renderer_base extends plugin_renderer_base {
                 print_section($course, $thissection, $mods, $modnamesused);
                 echo $this->stealth_section_footer();
             }
+
+            $straddsection = get_string('addanadditionalsection', 'moodle');
+            echo html_writer::start_tag('div', array('class' => 'mdl-align'));
+            echo $this->output->action_link(
+                new moodle_url('/course/addsection.php',
+                    array('courseid' => $course->id, 'sesskey' => sesskey())
+                ), $this->output->pix_icon('t/add', $straddsection).$straddsection, null,
+                    array('class' => 'addsectionlink')
+            );
+            echo html_writer::end_tag('div');
         }
 
         echo $this->end_section_list();
+
     }
 }
index 9a3803a..0a9a09b 100644 (file)
@@ -43,6 +43,7 @@ $string['activityweighted'] = 'Activity per user';
 $string['add'] = 'Add';
 $string['addactivity'] = 'Add an activity...';
 $string['addadmin'] = 'Add admin';
+$string['addanadditionalsection'] = 'Add an additional section';
 $string['addblock'] = 'Add a block';
 $string['addcomment'] = 'Add a comment...';
 $string['addcountertousername'] = 'Create user by adding number to username';