Merge branch 'MDL-32771-2' of git://github.com/danpoltawski/moodle

This commit is contained in:
Sam Hemelryk 2012-05-09 09:14:20 +12:00
commit b34e00c197
4 changed files with 49 additions and 14 deletions

View File

@ -15,23 +15,43 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This script allows the number of sections in a course to be increased
* or decreased, redirecting to the course page.
*
* @package core_course
* @copyright 2012 Dan Poltawski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.3
*/
require_once(dirname(__FILE__).'/../config.php');
require_once($CFG->dirroot.'/course/lib.php');
$courseid = required_param('courseid', PARAM_INT);
$increase = optional_param('increase', true, PARAM_BOOL);
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$PAGE->set_url('/course/addsection.php', array('courseid' => $courseid));
$PAGE->set_url('/course/changenumsections.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);
if ($increase) {
// Add an additional section.
$course->numsections++;
} else {
// Remove a section.
$course->numsections--;
}
// Don't go less than 0, intentionally redirect silently (for the case of
// double clicks).
if ($course->numsections >= 0) {
$DB->update_record('course', $course);
}
// Redirect to where we were..
redirect(course_get_url($course));

View File

@ -560,15 +560,28 @@ abstract class format_section_renderer_base extends plugin_renderer_base {
echo $this->end_section_list();
// Print the add section link
$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::start_tag('div', array('class' => 'mdl-right'));
// Increase number of sections.
$straddsection = get_string('increasesections', 'moodle');
$url = new moodle_url('/course/changenumsections.php',
array('courseid' => $course->id,
'increase' => true,
'sesskey' => sesskey()));
$icon = $this->output->pix_icon('t/switch_plus', $straddsection);
echo html_writer::link($url, $icon.get_accesshide($straddsection), array('class' => 'increase-sections'));
if ($course->numsections > 0) {
// Reduce number of sections sections.
$strremovesection = get_string('reducesections', 'moodle');
$url = new moodle_url('/course/changenumsections.php',
array('courseid' => $course->id,
'increase' => false,
'sesskey' => sesskey()));
$icon = $this->output->pix_icon('t/switch_minus', $strremovesection);
echo html_writer::link($url, $icon.get_accesshide($strremovesection), array('class' => 'reduce-sections'));
}
echo html_writer::end_tag('div');
} else {
echo $this->end_section_list();

View File

@ -43,7 +43,6 @@ $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';
@ -879,6 +878,7 @@ $string['includenoneusers'] = 'Include no users';
$string['includeroleassignments'] = 'Include role assignments';
$string['includesitefiles'] = 'Include site files used in this course';
$string['includeuserfiles'] = 'Include user files';
$string['increasesections'] = 'Increase the number of sections';
$string['info'] = 'Information';
$string['institution'] = 'Institution';
$string['instudentview'] = 'in student view';
@ -1314,6 +1314,7 @@ $string['recentactivityreport'] = 'Full report of recent activity...';
$string['recipientslist'] = 'Recipients list';
$string['recreatedcategory'] = 'Recreated category {$a}';
$string['redirect'] = 'Redirect';
$string['reducesections'] = 'Reduce the number of sections';
$string['refresh'] = 'Refresh';
$string['refreshingevents'] = 'Refreshing events';
$string['registration'] = 'Moodle registration';

View File

@ -18,6 +18,7 @@
#page-site-index .headingblock {margin-bottom: 9px;}
#page-site-index .clearfloat {float: none;clear: both; height:0px;}
.path-course-view a.reduce-sections {padding-left: 0.2em;}
.path-course-view .headingblock {margin-bottom: 9px;}
.path-course-view .subscribelink {text-align:right;}
.path-course-view .unread {margin-left: 3em;}