Skip to content

Commit

Permalink
Merge branch 'MDL-50322-28' of git://github.com/mastnym/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_28_STABLE
  • Loading branch information
danpoltawski committed Jun 1, 2015
2 parents d0be17a + 183c831 commit 2fef754
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 29 deletions.
61 changes: 61 additions & 0 deletions mod/forum/classes/prune_form.php
Original file line number Diff line number Diff line change
@@ -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']);
}
}
24 changes: 14 additions & 10 deletions mod/forum/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,16 @@
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;
Expand All @@ -479,7 +487,7 @@

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);

Expand Down Expand Up @@ -519,26 +527,22 @@

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));
$PAGE->set_heading($course->fullname);
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 {
Expand Down
19 changes: 0 additions & 19 deletions mod/forum/prune.html

This file was deleted.

0 comments on commit 2fef754

Please sign in to comment.