Skip to content

Commit 990bfe5

Browse files
authored
Merge pull request #218 from learnweb/hotfix/M500
Last Changes for Moodle 5.0
2 parents 6f1d450 + fe9b687 commit 990bfe5

File tree

16 files changed

+254
-169
lines changed

16 files changed

+254
-169
lines changed

.github/workflows/config.json

Lines changed: 0 additions & 22 deletions
This file was deleted.

CHANGES.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
CHANGELOG
22
=========
33

4-
5.0 (2025-06-24)
4+
v5.0-r1 (2025-08-01)
55
------------------
6-
6+
- Fixes Issues [#216](https://github.com/learnweb/moodle-mod_moodleoverflow/issues/216),
7+
[#211](https://github.com/learnweb/moodle-mod_moodleoverflow/issues/211),
8+
[#202](https://github.com/learnweb/moodle-mod_moodleoverflow/issues/202)
9+
- Adaption to Moodle 5.0
710

811
4.5.1 (2025-05-19)
912
------------------

classes/discussion/discussion.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class discussion {
8181

8282
// Not Database-related attributes.
8383

84-
/** @var array an Array of posts that belong to this discussion */
84+
/** @var post[] an Array of posts that belong to this discussion */
8585
public $posts;
8686

8787
/** @var bool a variable for checking if this instance has all its posts */
@@ -126,7 +126,7 @@ public function __construct($id, $course, $moodleoverflow, $name, $firstpost,
126126
* Builds a Discussion from a DB record.
127127
*
128128
* @param object $record Data object.
129-
* @return object discussion instance
129+
* @return discussion discussion instance
130130
*/
131131
public static function from_record($record) {
132132
$id = null;
@@ -258,9 +258,8 @@ public function moodleoverflow_delete_discussion($prepost) {
258258
$transaction = $DB->start_delegated_transaction();
259259

260260
// Delete every post of this discussion.
261-
foreach ($this->posts as $post) {
262-
$post->moodleoverflow_delete_post(false);
263-
}
261+
$firstpost = $this->posts[$this->firstpost];
262+
$firstpost->moodleoverflow_delete_post(true);
264263

265264
// Delete the read-records for the discussion.
266265
readtracking::moodleoverflow_delete_read_records(-1, -1, $this->id);

classes/output/helpicon.php

Lines changed: 0 additions & 72 deletions
This file was deleted.

classes/post/post.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use mod_moodleoverflow\review;
3232
use mod_moodleoverflow\readtracking;
3333
use mod_moodleoverflow\discussion\discussion;
34+
use mod_moodleoverflow_post_form;
3435
use moodle_exception;
3536

3637
defined('MOODLE_INTERNAL') || die();
@@ -103,8 +104,8 @@ class post {
103104
/** @var string The subject/title of the Discussion */
104105
public $subject;
105106

106-
/** @var object The discussion where the post is located */
107-
public $discussionobject;
107+
/** @var discussion The discussion where the post is located */
108+
public discussion $discussionobject;
108109

109110
/** @var object The Moodleoverflow where the post is located*/
110111
public $moodleoverflowobject;
@@ -154,9 +155,9 @@ public function __construct($id, $discussion, $parent, $userid, $created, $modif
154155
* Builds a Post from a DB record.
155156
* Look up database structure for standard values.
156157
* @param object $record Data object.
157-
* @return object post instance
158+
* @return post post instance
158159
*/
159-
public static function from_record($record) {
160+
public static function from_record($record): post {
160161
$id = null;
161162
if (object_property_exists($record, 'id') && $record->id) {
162163
$id = $record->id;
@@ -259,6 +260,15 @@ public function moodleoverflow_add_new_post() {
259260

260261
// Add post to the database.
261262
$this->id = $DB->insert_record('moodleoverflow_posts', $this->build_db_object());
263+
264+
// Save draft files to permanent file area.
265+
$context = \context_module::instance($this->get_coursemodule()->id);
266+
$draftid = file_get_submitted_draft_itemid('introeditor');
267+
$this->message = file_save_draft_area_files($draftid, $context->id, 'mod_moodleoverflow', 'post',
268+
$this->id, mod_moodleoverflow_post_form::editor_options($context, $this->id), $this->message);
269+
$DB->update_record('moodleoverflow_posts', $this->build_db_object());
270+
271+
// Update the attachments. This happens after the DB update call, as this function changes the DB record as well.
262272
$this->moodleoverflow_add_attachment();
263273

264274
if ($this->reviewed) {
@@ -375,10 +385,15 @@ public function moodleoverflow_edit_post($time, $postmessage, $messageformat, $f
375385

376386
// Update the attributes.
377387
$this->modified = $time;
378-
$this->message = $postmessage;
379388
$this->messageformat = $messageformat;
380389
$this->formattachments = $formattachments;
381390

391+
// Update the message and save draft files to permanent file area.
392+
$context = \context_module::instance($this->get_coursemodule()->id);
393+
$draftid = file_get_submitted_draft_itemid('introeditor');
394+
$this->message = file_save_draft_area_files($draftid, $context->id, 'mod_moodleoverflow', 'post',
395+
$this->id, mod_moodleoverflow_post_form::editor_options($context, $this->id), $postmessage);
396+
382397
// Update the record in the database.
383398
$DB->update_record('moodleoverflow_posts', $this->build_db_object());
384399

@@ -546,9 +561,9 @@ public function get_moodleoverflow() {
546561
/**
547562
* Returns the discussion where the post is located.
548563
*
549-
* @return object $discussionobject.
564+
* @return discussion $discussionobject.
550565
*/
551-
public function get_discussion() {
566+
public function get_discussion(): discussion {
552567
global $DB;
553568
$this->existence_check();
554569

@@ -631,7 +646,7 @@ public function get_db_object() {
631646
public function moodleoverflow_get_post_ratings() {
632647
$this->existence_check();
633648

634-
$discussionid = $this->get_discussion()->id;
649+
$discussionid = $this->get_discussion()->get_id();
635650
$postratings = \mod_moodleoverflow\ratings::moodleoverflow_get_ratings_by_discussion($discussionid, $this->id);
636651

637652
$ratingsobject = new \stdClass();

classes/post/post_control.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -796,11 +796,11 @@ private function check_moodleoverflow_exists(int $moodleoverflowid): object {
796796
/**
797797
* Checks if the related discussion exists.
798798
* @param int $discussionid
799-
* @return object $discussion
799+
* @return discussion $discussion
800800
* @throws dml_exception
801801
* @throws moodle_exception
802802
*/
803-
private function check_discussion_exists(int $discussionid): object {
803+
private function check_discussion_exists(int $discussionid): discussion {
804804
global $DB;
805805
if (!$discussionrecord = $DB->get_record('moodleoverflow_discussions', ['id' => $discussionid])) {
806806
throw new moodle_exception('invaliddiscussionid', 'moodleoverflow');
@@ -811,11 +811,11 @@ private function check_discussion_exists(int $discussionid): object {
811811
/**
812812
* Checks if a post exists.
813813
* @param int $postid
814-
* @return object $post
814+
* @return post $post
815815
* @throws dml_exception
816816
* @throws moodle_exception
817817
*/
818-
private function check_post_exists(int $postid): object {
818+
private function check_post_exists(int $postid): post {
819819
global $DB;
820820
if (!$postrecord = $DB->get_record('moodleoverflow_posts', ['id' => $postid])) {
821821
throw new moodle_exception('invalidpostid', 'moodleoverflow');

classes/post_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public static function editor_options(context_module $context, $postid) {
159159
'maxbytes' => $maxbytes,
160160
'trusttext' => true,
161161
'return_types' => FILE_INTERNAL | FILE_EXTERNAL,
162-
'subdirs' => file_area_contains_subdirs($context, 'mod_forum', 'post', $postid),
162+
'subdirs' => file_area_contains_subdirs($context, 'mod_moodleoverflow', 'post', $postid),
163163
];
164164
}
165165
}

classes/tables/userstats_table.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
require_once($CFG->dirroot . '/mod/moodleoverflow/lib.php');
3131
require_once($CFG->dirroot . '/mod/moodleoverflow/locallib.php');
3232
require_once($CFG->libdir . '/tablelib.php');
33-
use mod_moodleoverflow\output\helpicon;
3433

3534
/**
3635
* Table listing all user statistics of a course
@@ -50,9 +49,6 @@ class userstats_table extends \flexible_table {
5049
/** @var array table that will have objects with every user and his statistics. */
5150
private $userstatsdata = [];
5251

53-
/** @var \stdClass Help icon for amountofactivity-column.*/
54-
private $helpactivity;
55-
5652
/**
5753
* Constructor for workflow_table.
5854
*
@@ -62,13 +58,13 @@ class userstats_table extends \flexible_table {
6258
* @param string $url The url of the table
6359
*/
6460
public function __construct($uniqueid, $courseid, $moodleoverflow, $url) {
65-
global $PAGE;
61+
global $PAGE, $OUTPUT;
6662
parent::__construct($uniqueid);
6763
$PAGE->requires->js_call_amd('mod_moodleoverflow/activityhelp', 'init');
6864

6965
$this->courseid = $courseid;
7066
$this->moodleoverflowid = $moodleoverflow;
71-
$this->set_helpactivity();
67+
$helpactivity = $OUTPUT->help_icon('helpamountofactivity', 'moodleoverflow');
7268

7369
$this->set_attribute('class', 'moodleoverflow-statistics-table');
7470
$this->set_attribute('id', $uniqueid);
@@ -78,8 +74,8 @@ public function __construct($uniqueid, $courseid, $moodleoverflow, $url) {
7874
$this->define_headers([get_string('fullnameuser'),
7975
get_string('userstatsupvotes', 'moodleoverflow'),
8076
get_string('userstatsdownvotes', 'moodleoverflow'),
81-
(get_string('userstatsforumactivity', 'moodleoverflow') . $this->helpactivity->object),
82-
(get_string('userstatscourseactivity', 'moodleoverflow') . $this->helpactivity->object),
77+
(get_string('userstatsforumactivity', 'moodleoverflow') . $helpactivity),
78+
(get_string('userstatscourseactivity', 'moodleoverflow') . $helpactivity),
8379
get_string('userstatsforumreputation', 'moodleoverflow'),
8480
get_string('userstatscoursereputation', 'moodleoverflow'), ]);
8581
$this->get_table_data();
@@ -148,17 +144,6 @@ public function get_usertable() {
148144
return $this->userstatsdata;
149145
}
150146

151-
/**
152-
* Setup the help icon for amount of activity
153-
*/
154-
public function set_helpactivity() {
155-
$htmlclass = 'helpactivityclass btn btn-link';
156-
$content = get_string('helpamountofactivity', 'moodleoverflow');
157-
$helpobject = new helpicon($htmlclass, $content);
158-
$this->helpactivity = new \stdClass();
159-
$this->helpactivity->object = $helpobject->get_helpicon();
160-
}
161-
162147
// Functions that show the data.
163148

164149
/**

lang/en/moodleoverflow.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@
167167
$string['grademaxgradeerror'] = 'Maximum grade must be a positive integer different than 0';
168168
$string['gradesreport'] = 'Grades report';
169169
$string['gradesupdated'] = 'Grades updated';
170-
$string['helpamountofactivity'] = 'Each activity like writing a post, starting a discussion or giving a rating gives 1 point';
170+
$string['helpamountofactivity'] = 'Help icon for activity';
171+
$string['helpamountofactivity_help'] = 'Each activity like writing a post, starting a discussion or giving a rating gives 1 point';
171172
$string['hiddenmoodleoverflowpost'] = 'Hidden forum post';
172173
$string['invaliddiscussionid'] = 'Discussion ID was incorrect';
173174
$string['invalidforcesubscribe'] = 'Invalid force subscription mode';
@@ -177,20 +178,24 @@
177178
$string['invalidratingid'] = 'The submitted rating is neither an upvote nor a downvote.';
178179
$string['jump_to_next_post_needing_review'] = 'Jump to next post needing to be reviewed.';
179180
$string['la_endtime'] = 'Time at which students can no longer answer';
180-
$string['la_endtime_help'] = 'Students can not answer to qustions after the set up date';
181+
$string['la_endtime_help'] = 'Students can not answer questions after the set up date';
181182
$string['la_endtime_ruleerror'] = 'End time must be in the future';
183+
$string['la_heading'] = 'Limited Answer Mode';
184+
$string['la_helpicon_teacher'] = 'This can be changed in the settings of the Moodleoverflow.';
185+
$string['la_info_endtime'] = 'Posts can not be answered after {$a->limitedanswerdate}.';
186+
$string['la_info_start'] = 'This Moodleoverflow is in a limited answer mode.';
187+
$string['la_info_starttime'] = 'Posts can not be answered until {$a->limitedanswerdate}.';
182188
$string['la_sequence_error'] = 'The end time must be after the start time';
183189
$string['la_starttime'] = 'Time at which students can start to answer';
184-
$string['la_starttime_help'] = 'Students can not answer to questions until the set up date';
190+
$string['la_starttime_help'] = 'Students can start to answer questions after the set up date';
185191
$string['la_starttime_ruleerror'] = 'Start time must be in the future';
192+
$string['la_student_helpicon'] = "limited answer help icon";
193+
$string['la_student_helpicon_help'] = "This moodleoveroverflow is currently in a restricted mode. You can answer as soon as the teacher allows it.";
194+
$string['la_teacher_helpicon'] = "limited answer help icon";
195+
$string['la_teacher_helpicon_help'] = "This moodleoverflow is currently in a restricted mode. This can be changed in the settings of this acticity.";
196+
$string['la_warning_answers'] = 'There are already answered posts in this Moodleoverflow.';
197+
$string['la_warning_conclusion'] = 'You can only set a time until students are able to answer';
186198
$string['lastpost'] = 'Last post';
187-
$string['limitedanswer_helpicon_teacher'] = 'This can be changed in the settings of the Moodleoverflow.';
188-
$string['limitedanswer_info_endtime'] = 'Posts can not be answered after {$a->limitedanswerdate}.';
189-
$string['limitedanswer_info_start'] = 'This Moodleoverflow is in a limited answer mode.';
190-
$string['limitedanswer_info_starttime'] = 'Posts can not be answered until {$a->limitedanswerdate}.';
191-
$string['limitedanswerheading'] = 'Limited Answer Mode';
192-
$string['limitedanswerwarning_answers'] = 'There are already answered posts in this Moodleoverflow.';
193-
$string['limitedanswerwarning_conclusion'] = 'You can only set a time until students are able to answer';
194199
$string['mailindexlink'] = 'Change your forum preferences: {$a}';
195200
$string['manydiscussions'] = 'Discussions per page';
196201
$string['markallread'] = 'Mark all posts in this discussion as read';

0 commit comments

Comments
 (0)