Skip to content

Commit 1e47368

Browse files
committed
display original post when replying
1 parent e5fdce0 commit 1e47368

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

classes/post/post_control.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
// Import namespace from the locallib, needs a check later which namespaces are really needed.
2929
use coding_exception;
30+
use context_module;
3031
use core\notification;
3132
use dml_exception;
3233
use html_writer;
@@ -671,6 +672,27 @@ public function build_postform(array $pageparams): mod_moodleoverflow_post_form
671672
return $mformpost;
672673
}
673674

675+
/**
676+
* Display the original post when a user replies to it.
677+
*
678+
* @throws moodle_exception|dml_exception
679+
*/
680+
public function display_original_post(): string {
681+
global $PAGE, $DB;
682+
if ($this->interaction == 'reply') {
683+
$post = post::from_record($DB->get_record('moodleoverflow_posts', ['id' => $this->info->relatedpost->get_id()]));
684+
$data = (object) [
685+
'postid' => $post->get_id(),
686+
'postcontent' => $post->get_message_formatted(),
687+
'attachments' => $post->moodleoverflow_get_attachments(),
688+
'byname' => $post->get_userlink(),
689+
'byshortdate' => userdate($post->modified, get_string('strftimedatetimeshort', 'core_langconfig')),
690+
];
691+
return $PAGE->get_renderer('mod_moodleoverflow')->render_post_original($data);
692+
}
693+
return '';
694+
}
695+
674696
// Helper functions.
675697

676698
// Error handling functions.

post.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,5 +168,6 @@
168168

169169
// Display all.
170170
echo $OUTPUT->header();
171+
echo $postcontrol->display_original_post();
171172
$mformpost->display();
172173
echo $OUTPUT->footer();

renderer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ public function render_post($data) {
7979
return $this->render_from_template('mod_moodleoverflow/post', $data);
8080
}
8181

82+
/**
83+
* Renders a simplified version of any post. Used to display the post a reply is referring to.
84+
*
85+
* @param object $data The submitted variables.
86+
*
87+
* @return bool|string
88+
*/
89+
public function render_post_original(object $data): bool|string {
90+
return $this->render_from_template('mod_moodleoverflow/post_original', $data);
91+
}
92+
8293
/**
8394
* Display a moodleoverflow post in the relevant context.
8495
*

templates/post_original.mustache

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{!
2+
This file is part of Moodle - http://moodle.org/
3+
4+
Moodle is free software: you can redistribute it and/or modify
5+
it under the terms of the GNU General Public License as published by
6+
the Free Software Foundation, either version 3 of the License, or
7+
(at your option) any later version.
8+
9+
Moodle is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
}}
17+
{{!
18+
@template mod_moodleoverflow/post_original
19+
20+
Moodleoverflow post original template.
21+
In the post.php this template is used to show the post that a new answer post is referring to.
22+
It's a simpler version of the post template.
23+
24+
Example context (json):
25+
{
26+
}
27+
}}
28+
29+
{{! Start the post. Mark it read or unread. }}
30+
<h2>Reply to discussion</h2>
31+
<div id="p{{postid}}" class="moodleoverflowpost bg-light moodleoverflowcomment
32+
border" role="region" data-moodleoverflow-postid="{{postid}}">
33+
<div class="d-flex p-2 w-100">
34+
<div class="answercell d-flex flex-column">
35+
<div class="post-text">
36+
{{{ postcontent }}}
37+
</div>
38+
<div class="attachments flex-grow-1">
39+
{{#attachments}}
40+
{{#image}}
41+
<img src="{{filepath}}" alt=""/>
42+
<br>
43+
{{/image}}
44+
{{^image}}
45+
<a class="icon-size-6" href="{{filepath}}">
46+
{{{icon}}}
47+
</a>
48+
<a href="{{filepath}}">
49+
{{filename}}
50+
</a>
51+
{{/image}}
52+
<br>
53+
{{/attachments}}
54+
</div>
55+
<div class="post-info">
56+
<div class="leftbox {{questioner}}">
57+
<span class="text-muted">{{{ byname }}} - {{ byshortdate }}</span>
58+
</div>
59+
</div>
60+
</div>
61+
</div>
62+
</div>

0 commit comments

Comments
 (0)