Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions .github/workflows/config.json

This file was deleted.

7 changes: 5 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
CHANGELOG
=========

5.0 (2025-06-24)
v5.0-r1 (2025-08-01)
------------------

- Fixes Issues [#216](https://github.com/learnweb/moodle-mod_moodleoverflow/issues/216),
[#211](https://github.com/learnweb/moodle-mod_moodleoverflow/issues/211),
[#202](https://github.com/learnweb/moodle-mod_moodleoverflow/issues/202)
- Adaption to Moodle 5.0

4.5.1 (2025-05-19)
------------------
Expand Down
9 changes: 4 additions & 5 deletions classes/discussion/discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class discussion {

// Not Database-related attributes.

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

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

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

// Delete the read-records for the discussion.
readtracking::moodleoverflow_delete_read_records(-1, -1, $this->id);
Expand Down
72 changes: 0 additions & 72 deletions classes/output/helpicon.php

This file was deleted.

31 changes: 23 additions & 8 deletions classes/post/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use mod_moodleoverflow\review;
use mod_moodleoverflow\readtracking;
use mod_moodleoverflow\discussion\discussion;
use mod_moodleoverflow_post_form;
use moodle_exception;

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

/** @var object The discussion where the post is located */
public $discussionobject;
/** @var discussion The discussion where the post is located */
public discussion $discussionobject;

/** @var object The Moodleoverflow where the post is located*/
public $moodleoverflowobject;
Expand Down Expand Up @@ -154,9 +155,9 @@ public function __construct($id, $discussion, $parent, $userid, $created, $modif
* Builds a Post from a DB record.
* Look up database structure for standard values.
* @param object $record Data object.
* @return object post instance
* @return post post instance
*/
public static function from_record($record) {
public static function from_record($record): post {
$id = null;
if (object_property_exists($record, 'id') && $record->id) {
$id = $record->id;
Expand Down Expand Up @@ -259,6 +260,15 @@ public function moodleoverflow_add_new_post() {

// Add post to the database.
$this->id = $DB->insert_record('moodleoverflow_posts', $this->build_db_object());

// Save draft files to permanent file area.
$context = \context_module::instance($this->get_coursemodule()->id);
$draftid = file_get_submitted_draft_itemid('introeditor');
$this->message = file_save_draft_area_files($draftid, $context->id, 'mod_moodleoverflow', 'post',
$this->id, mod_moodleoverflow_post_form::editor_options($context, $this->id), $this->message);
$DB->update_record('moodleoverflow_posts', $this->build_db_object());

// Update the attachments. This happens after the DB update call, as this function changes the DB record as well.
$this->moodleoverflow_add_attachment();

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

// Update the attributes.
$this->modified = $time;
$this->message = $postmessage;
$this->messageformat = $messageformat;
$this->formattachments = $formattachments;

// Update the message and save draft files to permanent file area.
$context = \context_module::instance($this->get_coursemodule()->id);
$draftid = file_get_submitted_draft_itemid('introeditor');
$this->message = file_save_draft_area_files($draftid, $context->id, 'mod_moodleoverflow', 'post',
$this->id, mod_moodleoverflow_post_form::editor_options($context, $this->id), $postmessage);

// Update the record in the database.
$DB->update_record('moodleoverflow_posts', $this->build_db_object());

Expand Down Expand Up @@ -546,9 +561,9 @@ public function get_moodleoverflow() {
/**
* Returns the discussion where the post is located.
*
* @return object $discussionobject.
* @return discussion $discussionobject.
*/
public function get_discussion() {
public function get_discussion(): discussion {
global $DB;
$this->existence_check();

Expand Down Expand Up @@ -631,7 +646,7 @@ public function get_db_object() {
public function moodleoverflow_get_post_ratings() {
$this->existence_check();

$discussionid = $this->get_discussion()->id;
$discussionid = $this->get_discussion()->get_id();
$postratings = \mod_moodleoverflow\ratings::moodleoverflow_get_ratings_by_discussion($discussionid, $this->id);

$ratingsobject = new \stdClass();
Expand Down
8 changes: 4 additions & 4 deletions classes/post/post_control.php
Original file line number Diff line number Diff line change
Expand Up @@ -796,11 +796,11 @@ private function check_moodleoverflow_exists(int $moodleoverflowid): object {
/**
* Checks if the related discussion exists.
* @param int $discussionid
* @return object $discussion
* @return discussion $discussion
* @throws dml_exception
* @throws moodle_exception
*/
private function check_discussion_exists(int $discussionid): object {
private function check_discussion_exists(int $discussionid): discussion {
global $DB;
if (!$discussionrecord = $DB->get_record('moodleoverflow_discussions', ['id' => $discussionid])) {
throw new moodle_exception('invaliddiscussionid', 'moodleoverflow');
Expand All @@ -811,11 +811,11 @@ private function check_discussion_exists(int $discussionid): object {
/**
* Checks if a post exists.
* @param int $postid
* @return object $post
* @return post $post
* @throws dml_exception
* @throws moodle_exception
*/
private function check_post_exists(int $postid): object {
private function check_post_exists(int $postid): post {
global $DB;
if (!$postrecord = $DB->get_record('moodleoverflow_posts', ['id' => $postid])) {
throw new moodle_exception('invalidpostid', 'moodleoverflow');
Expand Down
2 changes: 1 addition & 1 deletion classes/post_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public static function editor_options(context_module $context, $postid) {
'maxbytes' => $maxbytes,
'trusttext' => true,
'return_types' => FILE_INTERNAL | FILE_EXTERNAL,
'subdirs' => file_area_contains_subdirs($context, 'mod_forum', 'post', $postid),
'subdirs' => file_area_contains_subdirs($context, 'mod_moodleoverflow', 'post', $postid),
];
}
}
23 changes: 4 additions & 19 deletions classes/tables/userstats_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
require_once($CFG->dirroot . '/mod/moodleoverflow/lib.php');
require_once($CFG->dirroot . '/mod/moodleoverflow/locallib.php');
require_once($CFG->libdir . '/tablelib.php');
use mod_moodleoverflow\output\helpicon;

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

/** @var \stdClass Help icon for amountofactivity-column.*/
private $helpactivity;

/**
* Constructor for workflow_table.
*
Expand All @@ -62,13 +58,13 @@ class userstats_table extends \flexible_table {
* @param string $url The url of the table
*/
public function __construct($uniqueid, $courseid, $moodleoverflow, $url) {
global $PAGE;
global $PAGE, $OUTPUT;
parent::__construct($uniqueid);
$PAGE->requires->js_call_amd('mod_moodleoverflow/activityhelp', 'init');

$this->courseid = $courseid;
$this->moodleoverflowid = $moodleoverflow;
$this->set_helpactivity();
$helpactivity = $OUTPUT->help_icon('helpamountofactivity', 'moodleoverflow');

$this->set_attribute('class', 'moodleoverflow-statistics-table');
$this->set_attribute('id', $uniqueid);
Expand All @@ -78,8 +74,8 @@ public function __construct($uniqueid, $courseid, $moodleoverflow, $url) {
$this->define_headers([get_string('fullnameuser'),
get_string('userstatsupvotes', 'moodleoverflow'),
get_string('userstatsdownvotes', 'moodleoverflow'),
(get_string('userstatsforumactivity', 'moodleoverflow') . $this->helpactivity->object),
(get_string('userstatscourseactivity', 'moodleoverflow') . $this->helpactivity->object),
(get_string('userstatsforumactivity', 'moodleoverflow') . $helpactivity),
(get_string('userstatscourseactivity', 'moodleoverflow') . $helpactivity),
get_string('userstatsforumreputation', 'moodleoverflow'),
get_string('userstatscoursereputation', 'moodleoverflow'), ]);
$this->get_table_data();
Expand Down Expand Up @@ -148,17 +144,6 @@ public function get_usertable() {
return $this->userstatsdata;
}

/**
* Setup the help icon for amount of activity
*/
public function set_helpactivity() {
$htmlclass = 'helpactivityclass btn btn-link';
$content = get_string('helpamountofactivity', 'moodleoverflow');
$helpobject = new helpicon($htmlclass, $content);
$this->helpactivity = new \stdClass();
$this->helpactivity->object = $helpobject->get_helpicon();
}

// Functions that show the data.

/**
Expand Down
25 changes: 15 additions & 10 deletions lang/en/moodleoverflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@
$string['grademaxgradeerror'] = 'Maximum grade must be a positive integer different than 0';
$string['gradesreport'] = 'Grades report';
$string['gradesupdated'] = 'Grades updated';
$string['helpamountofactivity'] = 'Each activity like writing a post, starting a discussion or giving a rating gives 1 point';
$string['helpamountofactivity'] = 'Help icon for activity';
$string['helpamountofactivity_help'] = 'Each activity like writing a post, starting a discussion or giving a rating gives 1 point';
$string['hiddenmoodleoverflowpost'] = 'Hidden forum post';
$string['invaliddiscussionid'] = 'Discussion ID was incorrect';
$string['invalidforcesubscribe'] = 'Invalid force subscription mode';
Expand All @@ -177,20 +178,24 @@
$string['invalidratingid'] = 'The submitted rating is neither an upvote nor a downvote.';
$string['jump_to_next_post_needing_review'] = 'Jump to next post needing to be reviewed.';
$string['la_endtime'] = 'Time at which students can no longer answer';
$string['la_endtime_help'] = 'Students can not answer to qustions after the set up date';
$string['la_endtime_help'] = 'Students can not answer questions after the set up date';
$string['la_endtime_ruleerror'] = 'End time must be in the future';
$string['la_heading'] = 'Limited Answer Mode';
$string['la_helpicon_teacher'] = 'This can be changed in the settings of the Moodleoverflow.';
$string['la_info_endtime'] = 'Posts can not be answered after {$a->limitedanswerdate}.';
$string['la_info_start'] = 'This Moodleoverflow is in a limited answer mode.';
$string['la_info_starttime'] = 'Posts can not be answered until {$a->limitedanswerdate}.';
$string['la_sequence_error'] = 'The end time must be after the start time';
$string['la_starttime'] = 'Time at which students can start to answer';
$string['la_starttime_help'] = 'Students can not answer to questions until the set up date';
$string['la_starttime_help'] = 'Students can start to answer questions after the set up date';
$string['la_starttime_ruleerror'] = 'Start time must be in the future';
$string['la_student_helpicon'] = "limited answer help icon";
$string['la_student_helpicon_help'] = "This moodleoveroverflow is currently in a restricted mode. You can answer as soon as the teacher allows it.";
$string['la_teacher_helpicon'] = "limited answer help icon";
$string['la_teacher_helpicon_help'] = "This moodleoverflow is currently in a restricted mode. This can be changed in the settings of this acticity.";
$string['la_warning_answers'] = 'There are already answered posts in this Moodleoverflow.';
$string['la_warning_conclusion'] = 'You can only set a time until students are able to answer';
$string['lastpost'] = 'Last post';
$string['limitedanswer_helpicon_teacher'] = 'This can be changed in the settings of the Moodleoverflow.';
$string['limitedanswer_info_endtime'] = 'Posts can not be answered after {$a->limitedanswerdate}.';
$string['limitedanswer_info_start'] = 'This Moodleoverflow is in a limited answer mode.';
$string['limitedanswer_info_starttime'] = 'Posts can not be answered until {$a->limitedanswerdate}.';
$string['limitedanswerheading'] = 'Limited Answer Mode';
$string['limitedanswerwarning_answers'] = 'There are already answered posts in this Moodleoverflow.';
$string['limitedanswerwarning_conclusion'] = 'You can only set a time until students are able to answer';
$string['mailindexlink'] = 'Change your forum preferences: {$a}';
$string['manydiscussions'] = 'Discussions per page';
$string['markallread'] = 'Mark all posts in this discussion as read';
Expand Down
Loading
Loading