mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 17:36:38 +02:00
MDL-65069 mod_forum: inline 'add discussion' form
This commit is contained in:
parent
4962446a44
commit
9ff7cae7c0
2 changed files with 47 additions and 1 deletions
|
@ -185,6 +185,7 @@ class discussion_list {
|
||||||
$forumview,
|
$forumview,
|
||||||
[
|
[
|
||||||
'pagination' => $this->renderer->render(new \paging_bar($alldiscussionscount, $pageno, $pagesize, $PAGE->url, 'p')),
|
'pagination' => $this->renderer->render(new \paging_bar($alldiscussionscount, $pageno, $pagesize, $PAGE->url, 'p')),
|
||||||
|
'newdiscussionhtml' => $this->get_discussion_form($user, $cm, $groupid)
|
||||||
],
|
],
|
||||||
$exportedposts
|
$exportedposts
|
||||||
);
|
);
|
||||||
|
@ -192,6 +193,48 @@ class discussion_list {
|
||||||
return $this->renderer->render_from_template($this->template, $forumview);
|
return $this->renderer->render_from_template($this->template, $forumview);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function get_discussion_form(stdClass $user, \cm_info $cm, ?int $groupid) {
|
||||||
|
global $PAGE;
|
||||||
|
|
||||||
|
$forum = $this->forum;
|
||||||
|
$forumrecord = $this->legacydatamapperfactory->get_forum_data_mapper()->to_legacy_object($forum);
|
||||||
|
$modcontext = \context_module::instance($cm->id);
|
||||||
|
$post = new stdClass();
|
||||||
|
$post->course = $forum->get_course_id();
|
||||||
|
$post->forum = $forum->get_id();
|
||||||
|
$post->discussion = 0; // Ie discussion # not defined yet.
|
||||||
|
$post->parent = 0;
|
||||||
|
$post->subject = '';
|
||||||
|
$post->userid = $user->id;
|
||||||
|
$post->message = '';
|
||||||
|
$post->messageformat = editors_get_preferred_format();
|
||||||
|
$post->messagetrust = 0;
|
||||||
|
$post->groupid = $groupid;
|
||||||
|
|
||||||
|
$thresholdwarning = forum_check_throttling($forum, $cm);
|
||||||
|
//$forumrecord = $DB->get_record('forum', array('id' => $forum->get_id()));
|
||||||
|
$mformpost = new \mod_forum_post_form('post.php', array('course' => $forum->get_course_record(),
|
||||||
|
'cm' => $cm,
|
||||||
|
'coursecontext' => $forum->get_context(),
|
||||||
|
'modcontext' => $modcontext,
|
||||||
|
'forum' => $forumrecord,
|
||||||
|
'post' => $post,
|
||||||
|
'subscribe' => \mod_forum\subscriptions::is_subscribed($user->id, $forumrecord,
|
||||||
|
null, $cm),
|
||||||
|
'thresholdwarning' => $thresholdwarning,
|
||||||
|
'edit' => 0), 'post', '', array('id' => 'mformforum'));
|
||||||
|
// Setup the file related components.
|
||||||
|
$draftitemid = file_get_submitted_draft_itemid('attachments');
|
||||||
|
$attachoptions = \mod_forum_post_form::attachment_options($forumrecord);
|
||||||
|
file_prepare_draft_area($draftitemid, $modcontext->id, 'mod_forum', 'attachment', null, $attachoptions);
|
||||||
|
|
||||||
|
$params = array('reply' => 0, 'forum' => $forumrecord->id, 'edit' => 0) +
|
||||||
|
(isset($post->groupid) ? array('groupid' => $post->groupid) : array());
|
||||||
|
$mformpost->set_data($params);
|
||||||
|
|
||||||
|
return $mformpost->render();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the list of groups to show based on the current user and requested groupid.
|
* Get the list of groups to show based on the current user and requested groupid.
|
||||||
*
|
*
|
||||||
|
|
|
@ -41,11 +41,14 @@
|
||||||
|
|
||||||
{{#forum.capabilities.create}}
|
{{#forum.capabilities.create}}
|
||||||
<div class="p-t-1 p-b-1">
|
<div class="p-t-1 p-b-1">
|
||||||
<a href="{{forum.urls.create}}" class="btn btn-primary">
|
<a class="btn btn-primary" data-toggle="collapse" href="#collapseAddForm">
|
||||||
{{$discussion_create_text}}
|
{{$discussion_create_text}}
|
||||||
{{#str}}addanewdiscussion, forum{{/str}}
|
{{#str}}addanewdiscussion, forum{{/str}}
|
||||||
{{/discussion_create_text}}
|
{{/discussion_create_text}}
|
||||||
</a>
|
</a>
|
||||||
|
<div class="collapse" id="collapseAddForm">
|
||||||
|
{{{newdiscussionhtml}}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/forum.capabilities.create}}
|
{{/forum.capabilities.create}}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue