Skip to content

Commit

Permalink
Merge branch 'bugfix/settingsreset' of github.com:learnweb/moodle-mod…
Browse files Browse the repository at this point in the history
…_moodleoverflow into bugfix/settingsreset
  • Loading branch information
TamaroWalter committed Mar 15, 2024
2 parents f39560d + bc38222 commit 7e13b11
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 117 deletions.
19 changes: 10 additions & 9 deletions backup/moodle2/backup_moodleoverflow_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,26 @@ protected function define_structure() {

// Define the root element describing the moodleoverflow instance.
$moodleoverflow = new backup_nested_element('moodleoverflow', ['id'], [
'name', 'intro', 'introformat', 'maxbytes', 'maxattachments',
'forcesubscribe', 'trackingtype', 'timecreated', 'timemodified',
'ratingpreference', 'coursewidereputation', 'allownegativereputation']);
'name', 'intro', 'introformat', 'maxbytes', 'maxattachments', 'timecreated', 'timemodified',
'forcesubscribe', 'trackingtype', 'ratingpreference', 'coursewidereputation', 'allowrating',
'allowreputation', 'allownegativereputation', 'grademaxgrade', 'gradescalefactor', 'gradecat',
'anonymous', 'needsreview', 'allowmultiplemarks', ]);

// 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 +76,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
2 changes: 1 addition & 1 deletion classes/manager/mail_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,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
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
6 changes: 3 additions & 3 deletions classes/tables/userstats_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,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 @@ -277,7 +277,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
2 changes: 1 addition & 1 deletion classes/task/send_daily_mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function execute() {
$string = get_string('digestunreadpost', 'mod_moodleoverflow', ['linktocourse' => $linktocourse,
'linktoforum' => $linktoforum,
'linktodiscussion' => $linktodiscussion,
'unreadposts' => $unreadposts]);
'unreadposts' => $unreadposts, ]);
array_push($mail, $string);
}
// Build the final message and send it to user. Then remove the sent records.
Expand Down
4 changes: 1 addition & 3 deletions discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@

echo '<div id="moodleoverflow-posts"><div id="moodleoverflow-root">';

//moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discussion, $post, $multiplemarks);
$processingdata = get_moduleinfo_data($cm, $course);
var_dump($processingdata);
moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discussion, $post, $multiplemarks);
echo '</div></div>';

echo $OUTPUT->footer();
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,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
17 changes: 6 additions & 11 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,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 +325,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 @@ -928,12 +928,7 @@ function moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discuss

// Retrieve all posts of the discussion.
$posts = moodleoverflow_get_all_discussion_posts($discussion->id, $istracked, $modulecontext);
/*$newpost = [];
foreach($posts as $posti) {
$newpost[] = $posti->message;
}
var_dump($newpost);
*/$usermapping = anonymous::get_userid_mapping($moodleoverflow, $discussion->id);
$usermapping = anonymous::get_userid_mapping($moodleoverflow, $discussion->id);

// Start with the parent post.
$post = $posts[$post->id];
Expand Down Expand Up @@ -1856,10 +1851,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 @@ -2061,7 +2056,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
7 changes: 4 additions & 3 deletions post.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,8 @@
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 && \mod_moodleoverflow\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 @@ -653,7 +654,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 @@ -705,7 +706,7 @@
'other' => [
'discussionid' => $discussion->id,
'moodleoverflowid' => $moodleoverflow->id,
]];
], ];
$event = \mod_moodleoverflow\event\post_created::create($params);
$event->trigger();
redirect(
Expand Down
2 changes: 1 addition & 1 deletion tests/behat/behat_mod_moodleoverflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected function add_new_discussion($moodleoverflowname, TableNode $table, $bu

// Navigate to moodleoverflow.
$this->execute('behat_navigation::i_am_on_page_instance', [$this->escape($moodleoverflowname),
'moodleoverflow activity']);
'moodleoverflow activity', ]);
$this->execute('behat_forms::press_button', $buttonstr);

// Fill form and post.
Expand Down
8 changes: 4 additions & 4 deletions tests/dailymail_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function helper_run_send_mails() {
* Test if the task send_daily_mail sends a mail to the user.
* @covers \send_daily_mail::execute
*/
public function test_mail_delivery() {
public function test_mail_delivery(): void {

// Create user with maildigest = on.
$this->helper_create_user_and_discussion('1');
Expand All @@ -154,7 +154,7 @@ public function test_mail_delivery() {
* Test if the content of the mail matches the supposed content.
* @covers \send_daily_mail::execute
*/
public function test_content_of_mail_delivery() {
public function test_content_of_mail_delivery(): void {

// Create user with maildigest = on.
$this->helper_create_user_and_discussion('1');
Expand Down Expand Up @@ -189,7 +189,7 @@ public function test_content_of_mail_delivery() {
* Test if the task does not send a mail when maildigest = 0
* @covers \send_daily_mail::execute
*/
public function test_mail_not_send() {
public function test_mail_not_send(): void {
// Creat user with daily_mail = off.
$this->helper_create_user_and_discussion('0');

Expand All @@ -205,7 +205,7 @@ public function test_mail_not_send() {
* Test if database is updated after sending a mail
* @covers \send_daily_mail::execute
*/
public function test_records_removed() {
public function test_records_removed(): void {
global $DB;
// Create user with maildigest = on.
$this->helper_create_user_and_discussion('1');
Expand Down
8 changes: 4 additions & 4 deletions tests/locallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function tearDown(): void {
* Test subscription using automatic subscription on create.
* @covers \mod_moodleoverflow\subscriptions Subscription of users as default.
*/
public function test_moodleoverflow_auto_subscribe_on_create() {
public function test_moodleoverflow_auto_subscribe_on_create(): void {
global $DB;

$this->resetAfterTest();
Expand Down Expand Up @@ -83,7 +83,7 @@ public function test_moodleoverflow_auto_subscribe_on_create() {
* Test subscription using forced subscription on create.
* @covers \mod_moodleoverflow\subscriptions sorced Subscription of users.
*/
public function test_moodleoverflow_forced_subscribe_on_create() {
public function test_moodleoverflow_forced_subscribe_on_create(): void {
global $DB;

$this->resetAfterTest();
Expand Down Expand Up @@ -115,7 +115,7 @@ public function test_moodleoverflow_forced_subscribe_on_create() {
* Test subscription using optional subscription on create.
* @covers \mod_moodleoverflow\subscriptions optional subscription.
*/
public function test_moodleoverflow_optional_subscribe_on_create() {
public function test_moodleoverflow_optional_subscribe_on_create(): void {
global $DB;

$this->resetAfterTest();
Expand Down Expand Up @@ -146,7 +146,7 @@ public function test_moodleoverflow_optional_subscribe_on_create() {
* Test subscription using disallow subscription on create.
* @covers \mod_moodleoverflow\subscriptions prohibit Subscription of users.
*/
public function test_moodleoverflow_disallow_subscribe_on_create() {
public function test_moodleoverflow_disallow_subscribe_on_create(): void {
global $DB;

$this->resetAfterTest();
Expand Down
Loading

0 comments on commit 7e13b11

Please sign in to comment.