Skip to content

Commit

Permalink
Merge branch 'update/M4.4' of github.com:learnweb/moodle-mod_moodleov…
Browse files Browse the repository at this point in the history
…erflow into feature/limitedanswermode
  • Loading branch information
TamaroWalter committed May 28, 2024
2 parents f0ff660 + 9bb30d1 commit 438bffe
Show file tree
Hide file tree
Showing 27 changed files with 173 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/moodle-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
--data-urlencode "vcstag=${TAGNAME}" \
--data-urlencode "changelogurl=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/commits/${TAGNAME}" \
--data-urlencode "altdownloadurl=${ZIPURL}" \
--data-urlencode "releasenotes=${BODY}" \
--data-urlencode "releasenotes=${BODY@Q}" \
--data-urlencode "releasenotesformat=4")
echo "response=${RESPONSE}" >> $GITHUB_OUTPUT
- name: Evaluate the response
Expand Down
14 changes: 7 additions & 7 deletions backup/moodle2/backup_moodleoverflow_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@ protected function define_structure() {
$moodleoverflow = new backup_nested_element('moodleoverflow', ['id'], [
'name', 'intro', 'introformat', 'maxbytes', 'maxattachments',
'forcesubscribe', 'trackingtype', 'timecreated', 'timemodified',
'ratingpreference', 'coursewidereputation', 'allownegativereputation']);
'ratingpreference', 'coursewidereputation', 'allownegativereputation', ]);

// Define each element separated.
$discussions = new backup_nested_element('discussions');
$discussion = new backup_nested_element('discussion', ['id'], [
'name', 'firstpost', 'userid', 'timemodified', 'usermodified', 'timestart']);
'name', 'firstpost', 'userid', 'timemodified', 'usermodified', 'timestart', ]);

$posts = new backup_nested_element('posts');

$post = new backup_nested_element('post', ['id'], [
'parent', 'userid', 'created', 'modified',
'mailed', 'message', 'messageformat', 'attachment']);
'mailed', 'message', 'messageformat', 'attachment', ]);

$ratings = new backup_nested_element('ratings');

$rating = new backup_nested_element('rating', ['id'], [
'userid', 'rating', 'firstrated', 'lastchanged']);
'userid', 'rating', 'firstrated', 'lastchanged', ]);

$discussionsubs = new backup_nested_element('discuss_subs');

Expand All @@ -75,18 +75,18 @@ protected function define_structure() {
$subscriptions = new backup_nested_element('subscriptions');

$subscription = new backup_nested_element('subscription', ['id'], [
'userid']);
'userid', ]);

$readposts = new backup_nested_element('readposts');

$read = new backup_nested_element('read', ['id'], [
'userid', 'discussionid', 'postid', 'firstread',
'lastread']);
'lastread', ]);

$tracking = new backup_nested_element('tracking');

$track = new backup_nested_element('track', ['id'], [
'userid']);
'userid', ]);

// Build the tree.
$moodleoverflow->add_child($discussions);
Expand Down
6 changes: 3 additions & 3 deletions classes/manager/mail_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

use context_course;
use context_module;
use core\context\course;
use core_php_time_limit;
use mod_moodleoverflow\anonymous;
use mod_moodleoverflow\output\moodleoverflow_email;
Expand Down Expand Up @@ -406,7 +407,7 @@ private static function send_post($userto, $post, array &$coursemodules, array &
['userid' => $dataobject->userid,
'courseid' => $dataobject->courseid,
'forumid' => $dataobject->forumid,
'forumdiscussionid' => $dataobject->forumdiscussionid],
'forumdiscussionid' => $dataobject->forumdiscussionid, ],
'numberofposts, id');
if (is_object($record)) {
$dataset = $record;
Expand Down Expand Up @@ -496,8 +497,7 @@ private static function send_post($userto, $post, array &$coursemodules, array &

// Preapare to actually send the post now. Build up the content.
$cleanname = str_replace('"', "'", strip_tags(format_string($moodleoverflow->name)));
$coursecontext = context_course::instance($course->id);
$shortname = format_string($course->shortname, true, ['context' => $coursecontext]);
$shortname = format_string($course->shortname, true, ['context' => context_course::instance($course->id)]);

// Define a header to make mails easier to track.
$emailmessageid = generate_email_messageid('moodlemoodleoverflow' . $moodleoverflow->id);
Expand Down
2 changes: 1 addition & 1 deletion classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static function role_assigned(\core\event\role_assigned $event) {
WHERE m.course = :courseid AND m.forcesubscribe = :initial AND mo.name = 'moodleoverflow' AND ms.id IS NULL";
$params = ['courseid' => $context->instanceid,
'userid' => $userid,
'initial' => MOODLEOVERFLOW_INITIALSUBSCRIBE];
'initial' => MOODLEOVERFLOW_INITIALSUBSCRIBE, ];
$moodleoverflows = $DB->get_records_sql($sql, $params);

// Loop through all moodleoverflows.
Expand Down
4 changes: 2 additions & 2 deletions classes/privacy/data_export_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function export_discussion_data($userid, array $mappings) {
FROM {moodleoverflow} mof
INNER JOIN {moodleoverflow_discussions} d ON d.moodleoverflow = mof.id
LEFT JOIN {moodleoverflow_discuss_subs} dsub ON dsub.discussion = d.id
WHERE mof.id ${foruminsql}
WHERE mof.id {$foruminsql}
AND (
d.userid = :discussionuserid OR
d.usermodified = :dmuserid OR
Expand Down Expand Up @@ -113,7 +113,7 @@ public static function export_all_posts($userid, array $mappings) {
INNER JOIN {moodleoverflow_posts} p ON p.discussion = d.id
LEFT JOIN {moodleoverflow_read} fr ON fr.postid = p.id
LEFT JOIN {moodleoverflow_ratings} rat ON rat.postid = p.id
WHERE mof.id ${foruminsql} AND
WHERE mof.id {$foruminsql} AND
(
p.userid = :postuserid OR
fr.userid = :readuserid OR
Expand Down
10 changes: 5 additions & 5 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,22 +324,22 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {

$DB->delete_records('moodleoverflow_read', [
'moodleoverflowid' => $forum->id,
'userid' => $userid]);
'userid' => $userid, ]);

$DB->delete_records('moodleoverflow_subscriptions', [
'moodleoverflow' => $forum->id,
'userid' => $userid]);
'userid' => $userid, ]);

$DB->delete_records('moodleoverflow_discuss_subs', [
'moodleoverflow' => $forum->id,
'userid' => $userid]);
'userid' => $userid, ]);

$DB->delete_records('moodleoverflow_tracking', [
'moodleoverflowid' => $forum->id,
'userid' => $userid]);
'userid' => $userid, ]);
$DB->delete_records('moodleoverflow_grades', [
'moodleoverflowid' => $forum->id,
'userid' => $userid]);
'userid' => $userid, ]);

// Do not delete ratings but reset userid.
$ratingsql = "userid = :userid AND discussionid IN
Expand Down
2 changes: 1 addition & 1 deletion classes/ratings.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function moodleoverflow_add_rating($moodleoverflow, $postid, $rati
// Is the submitted rating valid?
$possibleratings = [RATING_NEUTRAL, RATING_DOWNVOTE, RATING_UPVOTE, RATING_SOLVED,
RATING_HELPFUL, RATING_REMOVE_DOWNVOTE, RATING_REMOVE_UPVOTE,
RATING_REMOVE_SOLVED, RATING_REMOVE_HELPFUL];
RATING_REMOVE_SOLVED, RATING_REMOVE_HELPFUL, ];
if (!in_array($rating, $possibleratings)) {
throw new moodle_exception('invalidratingid', 'moodleoverflow');
}
Expand Down
4 changes: 2 additions & 2 deletions classes/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ public static function get_unsubscribable_moodleoverflows() {
WHERE m.forcesubscribe <> :forcesubscribe AND ms.id IS NOT NULL AND cm.course $coursesql";
$params = ['modulename' => 'moodleoverflow',
'userid' => $USER->id,
'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE];
'forcesubscribe' => MOODLEOVERFLOW_FORCESUBSCRIBE, ];
$mergedparams = array_merge($courseparams, $params);
$moodleoverflows = $DB->get_recordset_sql($sql, $mergedparams);

Expand Down Expand Up @@ -670,7 +670,7 @@ public static function subscribe_user($userid, $moodleoverflow, $context, $userr
$params = [
'userid' => $userid,
'moodleoverflowid' => $moodleoverflow->id,
'preference' => self::MOODLEOVERFLOW_DISCUSSION_UNSUBSCRIBED];
'preference' => self::MOODLEOVERFLOW_DISCUSSION_UNSUBSCRIBED, ];
$where = 'userid = :userid AND moodleoverflow = :moodleoverflowid AND preference <> :preference';
$DB->delete_records_select('moodleoverflow_discuss_subs', $where, $params);

Expand Down
10 changes: 5 additions & 5 deletions classes/tables/userstats_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public function __construct($uniqueid, $courseid, $moodleoverflow, $url) {
'forumactivity',
'courseactivity',
'forumreputation',
'coursereputation']);
'coursereputation', ]);
$this->define_baseurl($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('userstatsforumreputation', 'moodleoverflow'),
get_string('userstatscoursereputation', 'moodleoverflow')]);
get_string('userstatscoursereputation', 'moodleoverflow'), ]);
$this->get_table_data();
$this->sortable(true, 'coursereputation', SORT_DESC);
$this->no_sorting('username');
Expand Down Expand Up @@ -281,7 +281,7 @@ public function set_helpactivity() {
'tabindex' => '0',
'data-content' => '<div class=&quot;no-overflow&quot;><p>' .
get_string('helpamountofactivity', 'moodleoverflow') .
'</p> </div>'];
'</p> </div>', ];

$this->helpactivity->object = \html_writer::span($this->helpactivity->icon,
$this->helpactivity->class,
Expand Down Expand Up @@ -360,10 +360,10 @@ public function col_coursereputation($row) {
*/
private function badge_render($number) {
if ($number > 0) {
return \html_writer::tag('h5', \html_writer::start_span('badge badge-success') .
return \html_writer::tag('h5', \html_writer::start_span('badge bg-success') .
$number . \html_writer::end_span());
} else {
return \html_writer::tag('h5', \html_writer::start_span('badge badge-warning') .
return \html_writer::tag('h5', \html_writer::start_span('badge bg-warning') .
$number . \html_writer::end_span());
}
}
Expand Down
4 changes: 2 additions & 2 deletions classes/task/send_daily_mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function execute() {
$mail = [];
// Fill the $mail array.
foreach ($userdata as $row) {
$currentcourse = $DB->get_record('course', array('id' => $row->courseid), 'fullname, id');
$currentcourse = $DB->get_record('course', ['id' => $row->courseid], 'fullname, id');
// Check if the user is enrolled in the course, if not, go to the next row.
if (!is_enrolled(\context_course::instance($row->courseid), $user->userid, '', true)) {
continue;
}

$currentforum = $DB->get_record('moodleoverflow', array('id' => $row->forumid), 'name, id');
$currentforum = $DB->get_record('moodleoverflow', ['id' => $row->forumid], 'name, id');
$coursemoduleid = get_coursemodule_from_instance('moodleoverflow', $row->forumid);
$discussion = $DB->get_record('moodleoverflow_discussions', ['id' => $row->forumdiscussionid], 'name, id');
$unreadposts = $row->numberofposts;
Expand Down
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/

// Require needed files.
use core\context\course;

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
require_once(dirname(__FILE__) . '/locallib.php');
require_once($CFG->dirroot . '/course/lib.php');
Expand Down
4 changes: 3 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core\context\course;

defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__) . '/locallib.php');

Expand Down Expand Up @@ -788,7 +790,7 @@ function moodleoverflow_send_mails() {
['userid' => $dataobject->userid,
'courseid' => $dataobject->courseid,
'forumid' => $dataobject->forumid,
'forumdiscussionid' => $dataobject->forumdiscussionid],
'forumdiscussionid' => $dataobject->forumdiscussionid, ],
'numberofposts, id');
if (is_object($record)) {
$dataset = $record;
Expand Down
19 changes: 6 additions & 13 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @copyright 2017 Kennet Winter <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use mod_moodleoverflow\anonymous;
use mod_moodleoverflow\capabilities;
use mod_moodleoverflow\event\post_deleted;
Expand Down Expand Up @@ -157,7 +156,7 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = -
$userstatsbuttontext = get_string('seeuserstats', 'moodleoverflow');
$userstatsbuttonurl = new moodle_url('/mod/moodleoverflow/userstats.php', ['id' => $cm->id,
'courseid' => $moodleoverflow->course,
'mid' => $moodleoverflow->id]);
'mid' => $moodleoverflow->id, ]);
$userstatsbutton = new single_button($userstatsbuttonurl, $userstatsbuttontext, 'get');
$userstatsbutton->class = 'singlebutton align-middle m-2';
echo $OUTPUT->render($userstatsbutton);
Expand Down Expand Up @@ -325,7 +324,7 @@ function moodleoverflow_print_latest_discussions($moodleoverflow, $cm, $page = -
} else {
// Get his picture, his name and the link to his profile.
$preparedarray[$i]['picture'] = $OUTPUT->user_picture($startuser, ['courseid' => $moodleoverflow->course,
'link' => false]);
'link' => false, ]);
$preparedarray[$i]['username'] = fullname($startuser, has_capability('moodle/site:viewfullnames', $context));
$preparedarray[$i]['userlink'] = $CFG->wwwroot . '/user/view.php?id=' .
$discussion->userid . '&course=' . $moodleoverflow->course;
Expand Down Expand Up @@ -1484,12 +1483,6 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co
}
$mustachedata->questioner = $post->userid == $discussion->userid ? 'questioner' : '';

// Set options for the post.
$options = new stdClass();
$options->para = false;
$options->trusted = false;
$options->context = $modulecontext;

$reviewdelay = get_config('moodleoverflow', 'reviewpossibleaftertime');
$mustachedata->reviewdelay = format_time($reviewdelay);
$mustachedata->needsreview = !$post->reviewed;
Expand All @@ -1498,7 +1491,7 @@ function moodleoverflow_print_post($post, $discussion, $moodleoverflow, $cm, $co
$mustachedata->withinreviewperiod = $reviewable;

// Prepare the post.
$mustachedata->postcontent = format_text($post->message, $post->messageformat, $options, $course->id);
$mustachedata->postcontent = format_text($post->message, $post->messageformat, ['context' => $modulecontext]);

// Load the attachments.
$mustachedata->attachments = get_attachments($post, $cm);
Expand Down Expand Up @@ -1915,10 +1908,10 @@ function moodleoverflow_delete_post($post, $deletechildren, $cm, $moodleoverflow
$attachments = $fs->get_area_files($context->id, 'mod_moodleoverflow', 'attachment',
$post->id, "filename", true);
foreach ($attachments as $attachment) {
// Get file
// Get file.
$file = $fs->get_file($context->id, 'mod_moodleoverflow', 'attachment', $post->id,
$attachment->get_filepath(), $attachment->get_filename());
// Delete it if it exists
// Delete it if it exists.
if ($file) {
$file->delete();
}
Expand Down Expand Up @@ -2120,7 +2113,7 @@ function moodleoverflow_update_user_grade_on_db($moodleoverflow, $postuserrating
if ($DB->record_exists('moodleoverflow_grades', ['userid' => $userid, 'moodleoverflowid' => $moodleoverflow->id])) {

$DB->set_field('moodleoverflow_grades', 'grade', $grade, ['userid' => $userid,
'moodleoverflowid' => $moodleoverflow->id]);
'moodleoverflowid' => $moodleoverflow->id, ]);

} else {

Expand Down
11 changes: 7 additions & 4 deletions post.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// TODO refactor this. For more readability, and to avoid security issues.

// Include config and locallib.
use mod_moodleoverflow\anonymous;
use mod_moodleoverflow\review;

require_once(dirname(dirname(dirname(__FILE__))) . '/config.php');
Expand Down Expand Up @@ -506,7 +507,9 @@
empty($post->id) ? null : $post->id,
mod_moodleoverflow_post_form::attachment_options($moodleoverflow));

if ($draftitemid && $edit && \mod_moodleoverflow\anonymous::is_post_anonymous($discussion, $moodleoverflow, $post->userid) && $post->userid != $USER->id) {
if ($draftitemid && $edit && anonymous::is_post_anonymous($discussion, $moodleoverflow, $post->userid)
&& $post->userid != $USER->id) {

$usercontext = context_user::instance($USER->id);
$anonymousstr = get_string('anonymous', 'moodleoverflow');
foreach (get_file_storage()->get_area_files($usercontext->id, 'user', 'draft', $draftitemid) as $file) {
Expand Down Expand Up @@ -650,7 +653,7 @@
if ($realpost->userid == $USER->id) {
$message .= get_string('postupdated', 'moodleoverflow');
} else {
if (\mod_moodleoverflow\anonymous::is_post_anonymous($discussion, $moodleoverflow, $realpost->userid)) {
if (anonymous::is_post_anonymous($discussion, $moodleoverflow, $realpost->userid)) {
$name = get_string('anonymous', 'moodleoverflow');
} else {
$realuser = $DB->get_record('user', ['id' => $realpost->userid]);
Expand All @@ -669,7 +672,7 @@
'other' => [
'discussionid' => $discussion->id,
'moodleoverflowid' => $moodleoverflow->id,
]];
], ];

// If the editing user is not the original author, add the original author to the params.
if ($realpost->userid != $USER->id) {
Expand Down Expand Up @@ -721,7 +724,7 @@
'other' => [
'discussionid' => $discussion->id,
'moodleoverflowid' => $moodleoverflow->id,
]];
], ];
$event = \mod_moodleoverflow\event\post_created::create($params);
$event->trigger();
redirect(
Expand Down
Loading

0 comments on commit 438bffe

Please sign in to comment.