Merge branch 'MDL-50322-master' of git://github.com/mastnym/moodle

This commit is contained in:
Dan Poltawski 2015-06-01 13:49:57 +01:00
commit 918950d0cd
3 changed files with 75 additions and 29 deletions

View File

@ -0,0 +1,61 @@
<?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/>.
/**
* This file provides form for splitting discussions
*
* @package mod_forum
* @copyright 2015 Martin Mastny <mastnym@vscht.cz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.');
}
require_once("$CFG->libdir/formslib.php");
/**
* Form which displays fields for splitting forum post to a separate threads.
*
* @package mod_forum
* @copyright 2015 Martin Mastny <mastnym@vscht.cz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_forum_prune_form extends moodleform {
/**
* Form constructor.
*
*/
public function definition() {
$mform = $this->_form;
$mform->addElement('text', 'name', get_string('discussionname', 'forum'), array('size' => '60', 'maxlength' => '255'));
$mform->setType('name', PARAM_TEXT);
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$this->add_action_buttons(true, get_string('prune', 'forum'));
$mform->addElement('hidden', 'prune');
$mform->setType('prune', PARAM_INT);
$mform->setConstant('prune', $this->_customdata['prune']);
$mform->addElement('hidden', 'confirm');
$mform->setType('confirm', PARAM_INT);
$mform->setConstant('confirm', $this->_customdata['confirm']);
}
}

View File

@ -458,8 +458,16 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
print_error('cannotsplit', 'forum');
}
if (!empty($name) && confirm_sesskey()) { // User has confirmed the prune
$PAGE->set_cm($cm);
$PAGE->set_context($modcontext);
$prunemform = new mod_forum_prune_form(null, array('prune' => $prune, 'confirm' => $prune));
if ($prunemform->is_cancelled()) {
redirect(forum_go_back_to("discuss.php?d=$post->discussion"));
} else if ($fromform = $prunemform->get_data()) {
// User submits the data.
$newdiscussion = new stdClass();
$newdiscussion->course = $discussion->course;
$newdiscussion->forum = $discussion->forum;
@ -483,7 +491,7 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
forum_change_discussionid($post->id, $newid);
// update last post in each discussion
// Update last post in each discussion.
forum_discussion_update_last_post($discussion->id);
forum_discussion_update_last_post($newid);
@ -523,12 +531,9 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
redirect(forum_go_back_to("discuss.php?d=$newid"));
} else { // User just asked to prune something
} else {
// Display the prune form.
$course = $DB->get_record('course', array('id' => $forum->course));
$PAGE->set_cm($cm);
$PAGE->set_context($modcontext);
$PAGE->navbar->add(format_string($post->subject, true), new moodle_url('/mod/forum/discuss.php', array('d'=>$discussion->id)));
$PAGE->navbar->add(get_string("prune", "forum"));
$PAGE->set_title(format_string($discussion->name).": ".format_string($post->subject));
@ -536,13 +541,12 @@ if (!empty($forum)) { // User is starting a new discussion in a forum
echo $OUTPUT->header();
echo $OUTPUT->heading(format_string($forum->name), 2);
echo $OUTPUT->heading(get_string('pruneheading', 'forum'), 3);
echo '<center>';
include('prune.html');
$prunemform->display();
forum_print_post($post, $discussion, $forum, $cm, $course, false, false, false);
echo '</center>';
}
echo $OUTPUT->footer();
die;
} else {

View File

@ -1,19 +0,0 @@
<form id="pruneform" method="get" action="post.php">
<table border="0" cellpadding="5">
<tr valign="top">
<td align="right"><b><?php print_string("discussionname", "forum"); ?>:</b></td>
<td>
<input type="text" name="name" size="60" value="<?php p($post->subject) ?>" />
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="hidden" name="prune" value="<?php p($prune) ?>" />
<input type="hidden" name="confirm" value="<?php p($prune) ?>" />
<input type="hidden" name="sesskey" value="<?php echo sesskey() ?>" />
<input type="submit" value="<?php print_string('prune', 'forum'); ?>" />
</td>
</tr>
</table>
</form>