Skip to content

Commit 7db0839

Browse files
authored
Merge pull request #244 from learnweb/fix/edited_link
Fix link to profile in edited message
2 parents 4ac0d67 + 892b8f1 commit 7db0839

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

classes/post/post_control.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,10 @@ private function build_prepost_edit(int $editpostid): void {
299299
// as the review class should be refactored with the new way of working with posts.
300300
$alreadyreviewed = review::should_post_be_reviewed($this->info->relatedpost->get_db_object(), $this->info->moodleoverflow)
301301
&& $this->info->relatedpost->reviewed;
302-
if (
303-
($beyondtime || $alreadyreviewed) && !has_capability(
304-
'mod/moodleoverflow:editanypost',
305-
$this->info->modulecontext
306-
)
307-
) {
308-
throw new moodle_exception(
309-
'maxtimehaspassed',
310-
'moodleoverflow',
311-
'',
312-
format_time(get_config('moodleoverflow', 'maxeditingtime'))
313-
);
302+
$capability = has_capability('mod/moodleoverflow:editanypost', $this->info->modulecontext);
303+
if (($beyondtime || $alreadyreviewed) && !$capability) {
304+
$formattime = format_time(get_config('moodleoverflow', 'maxeditingtime'));
305+
throw new moodle_exception('maxtimehaspassed', 'moodleoverflow', '', $formattime);
314306
}
315307

316308
// If the current user is not the one who posted this post.
@@ -593,9 +585,10 @@ public function confirm_delete(): void {
593585
* @param array $pageparams An object that the post.php created.
594586
* @return mod_moodleoverflow_post_form a mod_moodleoverflow_post_form object.
595587
* @throws coding_exception
588+
* @throws \core\exception\moodle_exception
596589
*/
597-
public function build_postform(array $pageparams) {
598-
global $USER, $CFG;
590+
public function build_postform(array $pageparams): mod_moodleoverflow_post_form {
591+
global $USER;
599592
// Require that the user is logged in properly and enrolled to the course.
600593
require_login($this->info->course, false, $this->info->cm);
601594

@@ -644,13 +637,12 @@ public function build_postform(array $pageparams) {
644637
$data->date = userdate(time());
645638
$this->prepost->messageformat = editors_get_preferred_format();
646639
if ($this->prepost->messageformat == FORMAT_HTML) {
647-
$data->name = html_writer::tag('a', $CFG->wwwroot . '/user/view.php?id' . $USER->id .
648-
'&course=' . $this->prepost->courseid . '">' . fullname($USER));
649-
$this->prepost->message .= html_writer::tag('p', html_writer::tag(
650-
'span',
651-
get_string('editedby', 'moodleoverflow', $data),
652-
["class" => "edited"]
653-
));
640+
$profileurl = new moodle_url('/user/view.php', ['id' => $USER->id, 'course' => $this->prepost->courseid]);
641+
$data->name = html_writer::link($profileurl, fullname($USER));
642+
$this->prepost->message .= html_writer::tag(
643+
'p',
644+
html_writer::tag('span', get_string('editedby', 'moodleoverflow', $data), ['class' => 'edited'])
645+
);
654646
} else {
655647
$data->name = fullname($USER);
656648
$this->prepost->message .= "\n\n(" . get_string('editedby', 'moodleoverflow', $data) . ')';

0 commit comments

Comments
 (0)