/**
* Makes the pop up contents for the grading interface
*
* @param array $params
* @param $coursemodule
* @global moodle_database $DB
* @global $PAGE
* @global stdClass $CFG
* @global $SESSION
* @global $USER
* @global $OUTPUT
* @params object $coursemodule
* @return string HTML
*/
public function grading_popup($params, $coursemodule)
{
global $DB, $PAGE, $CFG, $SESSION, $USER, $OUTPUT;
$output = '';
// Lifted from /mod/forum/discuss.php...
/*
$parent = $params['parent']; // If set, then display this post and all children.
$mode = $params['mode']; // If set, changes the layout of the thread
$move = $params['move']; // If set, moves this discussion to another forum
$mark = $params['mark']; // Used for tracking read posts if user initiated.
$postid = $params['postid']; // Used for tracking read posts if user initiated.
*/
$discussion = $DB->get_record('forum_discussions', array('id' => $params['discussionid']), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $discussion->course), '*', MUST_EXIST);
$forum = $DB->get_record('forum', array('id' => $discussion->forum), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('forum', $forum->id, $course->id, false, MUST_EXIST);
$modcontext = context_module::instance($cm->id);
// Security - cmid is used to check context permissions earlier on, so it must match when
// derived from the discussion.
if (!($cm->id == $params['coursemoduleid'])) {
print_error('Bad params!');
return false;
}
// Add ajax-related libs.
$PAGE->requires->yui2_lib('event');
$PAGE->requires->yui2_lib('connection');
$PAGE->requires->yui2_lib('json');
// Move this down fix for MDL-6926.
require_once $CFG->dirroot . '/mod/forum/lib.php';
// Restrict news forums - should not be graded.
if ($forum->type == 'news') {
print_error('invaliddiscussionid', 'forum', "{$CFG->wwwroot}/mod/forum/view.php?f={$forum->id}");
}
unset($SESSION->fromdiscussion);
// In case the user has used the drop-down to change from threaded to flat or something.
if (isset($params['mode'])) {
set_user_preference('forum_displaymode', $params['mode']);
}
$displaymode = get_user_preferences('forum_displaymode', $CFG->forum_displaymode);
$parent = $discussion->firstpost;
$post = forum_get_post_full($parent);
if (!$post) {
print_error("notexists", 'forum', "{$CFG->wwwroot}/mod/forum/view.php?f={$forum->id}");
}
if (!forum_user_can_view_post($post, $course, $cm, $forum, $discussion)) {
print_error('nopermissiontoview', 'forum', "{$CFG->wwwroot}/mod/forum/view.php?id={$forum->id}");
}
// For now, restrict to rating only.
$canreply = false;
// Without this, the nesting doesn't work properly as the css isn't picked up.
$output .= html_writer::start_tag('div', array('class' => 'path-mod-forum'));
$output .= html_writer::start_tag('div', array('class' => 'discussioncontrols clearfix'));
$output .= html_writer::start_tag('div', array('class' => 'discussioncontrol displaymode'));
// We don't want to have the current mode returned in the url as well as the new one.
unset($params['mode']);
$newurl = new moodle_url('/blocks/ajax_marking/actions/grading_popup.php', $params);
$select = new single_select($newurl, 'mode', forum_get_layout_modes(), $displaymode, null, "mode");
$output .= $OUTPUT->render($select);
$output .= html_writer::end_tag('div');
// If user has not already posted and it's a Q & A forum...
$forumisqanda = $forum->type == 'qanda';
$noviewwithoutposting = !has_capability('mod/forum:viewqandawithoutposting', $modcontext);
$hasnotposted = !forum_user_has_posted($forum->id, $discussion->id, $USER->id);
if ($forumisqanda && $noviewwithoutposting && $hasnotposted) {
$output .= $OUTPUT->notification(get_string('qandanotify', 'forum'));
}
$canrate = has_capability('mod/forum:rate', $modcontext);
ob_start();
forum_print_discussion($course, $cm, $forum, $discussion, $post, $displaymode, $canreply, $canrate);
$output .= ob_get_contents();
ob_end_clean();
$output .= html_writer::end_tag('div');
$output .= html_writer::end_tag('div');
return $output;
}
请发表评论