Skip to content

Commit

Permalink
Merge branch 'master' into enhancement/postform
Browse files Browse the repository at this point in the history
  • Loading branch information
NinaHerrmann authored Jul 12, 2024
2 parents a48c809 + 3032b86 commit 0114dbf
Show file tree
Hide file tree
Showing 13 changed files with 222 additions and 38 deletions.
33 changes: 13 additions & 20 deletions backup/moodle2/backup_moodleoverflow_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,48 +45,41 @@ 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', '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', 'timestart', 'timemodified', 'usermodified', ]);

$posts = new backup_nested_element('posts');

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

$ratings = new backup_nested_element('ratings');

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

$discussionsubs = new backup_nested_element('discuss_subs');

$discussionsub = new backup_nested_element('discuss_sub', ['id'], [
'userid',
'preference',
]);
'userid', 'preference', ]);

$subscriptions = new backup_nested_element('subscriptions');

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

$readposts = new backup_nested_element('readposts');

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

$tracking = new backup_nested_element('tracking');
$grades = new backup_nested_element('grades');
$grade = new backup_nested_element('grade', ['id'], ['userid', 'grade']);

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

// Build the tree.
$moodleoverflow->add_child($discussions);
Expand Down
1 change: 0 additions & 1 deletion discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@
echo '<div id="moodleoverflow-posts"><div id="moodleoverflow-root">';

moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discussion, $post, $multiplemarks);

echo '</div></div>';

echo $OUTPUT->footer();
4 changes: 2 additions & 2 deletions lang/en/moodleoverflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@
$string['action_remove_downvote'] = 'Click to remove downvote';
$string['downvotenotchangeable'] = 'Cannot downvote';
$string['action_downvote'] = 'Click to downvote';
$string['movetopicicon'] = 'The icon to move a topic';
$string['movetopictoforum'] = 'The icon to move a selected topic to another forum';
$string['movetopicicon'] = 'Move this discussion to another moodleoverflow';
$string['movetopictoforum'] = 'Move discussion to {$a->forumname}';

// Privacy.
$string['privacy:metadata:core_files'] = 'Moodleoverflow stores files which have been uploaded by the user to form part of a forum post.';
Expand Down
1 change: 0 additions & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ function moodleoverflow_add_instance(stdClass $moodleoverflow, mod_moodleoverflo
$moodleoverflow->timecreated = time();

// You may have to add extra stuff in here.

$moodleoverflow->id = $DB->insert_record('moodleoverflow', $moodleoverflow);

return $moodleoverflow->id;
Expand Down
19 changes: 17 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,25 @@ function moodleoverflow_print_forum_list($course, $cm, $movetopopup) {
$forumarray = [[]];
$currentforum = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup], 'moodleoverflow');
$currentdiscussion = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup], 'name');
$forums = $DB->get_records('moodleoverflow', ['course' => $course->id]);

// If the currentforum is anonymous, only show forums that have a higher anonymous setting.
$anonymoussetting = $DB->get_field('moodleoverflow', 'anonymous', ['id' => $currentforum->moodleoverflow]);
if ($anonymoussetting == anonymous::QUESTION_ANONYMOUS || $anonymoussetting == anonymous::EVERYTHING_ANONYMOUS) {
$params = ['course' => $course->id, 'anonymous' => $anonymoussetting,
'currentforumid' => $currentforum->moodleoverflow, ];
$sql = "SELECT *
FROM {moodleoverflow}
WHERE course = :course
AND anonymous >= :anonymous
AND id != :currentforumid";
$forums = $DB->get_records_sql($sql, $params);
} else {
$forums = $DB->get_records('moodleoverflow', ['course' => $course->id]);
}

$amountforums = count($forums);

if ($amountforums > 1) {
if ($amountforums >= 1) {
// Write the moodleoverflow-names in an array.
$i = 0;
foreach ($forums as $forum) {
Expand Down
2 changes: 1 addition & 1 deletion pix/monologo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions templates/forum_list.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@
{{#forums}}
<tr class="discussion">
<td class="topic starter">
{{name}}
<a href='{{ movetoforum }}'>{{#pix}} i/arrow-right, core, {{#str}}movetopictoforum, moodleoverflow{{/str}} {{/pix}}</a>
{{name}}
<a href='{{ movetoforum }}'>
{{#pix}} i/arrow-right, core,
{{#str}} movetopictoforum, mod_moodleoverflow, {"forumname": {{#quote}} {{name}} {{/quote}} }
{{/str}}
{{/pix}}
</a>
</td>
</tr>
{{/forums}}
Expand Down
68 changes: 68 additions & 0 deletions tests/behat/topicmove.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@mod @mod_moodleoverflow @javascript
Feature: Teachers can move a discussion in one moodleoverflow forum to another moodleoverflow.


Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | anonymous | idnumber |
| moodleoverflow | public moodleoverflow one | Test moodleoverflow description | C1 | 0 | 1 |
| moodleoverflow | public moodleoverflow two | Test moodleoverflow description | C1 | 0 | 2 |
| moodleoverflow | question anonymous | Test moodleoverflow description | C1 | 1 | 3 |
| moodleoverflow | everything anonymous | Test moodleoverflow description | C1 | 2 | 4 |
And I log in as "admin"


Scenario: Move topic from public forum
Given I am on "Course 1" course homepage
And I add a new discussion to "public moodleoverflow one" moodleoverflow with:
| Subject | Public Message |
| Message | This is the public message |
And I follow "public moodleoverflow one"
And I click on "Move this discussion to another moodleoverflow" "link"
Then I should see "public moodleoverflow two"
And I should see "question anonymous"
And I should see "everything anonymous"
And I should not see "Move discussion to public moodleoverflow one"
When I click on "Move discussion to public moodleoverflow two" "link"
And I am on "Course 1" course homepage
And I follow "public moodleoverflow two"
Then I should see "Public Message"

Scenario: Move topic from question anonymous forum
Given I am on "Course 1" course homepage
And I add a new discussion to "question anonymous" moodleoverflow with:
| Subject | Question Message |
| Message | This is the question anonymous message |
And I follow "question anonymous"
And I click on "Move this discussion to another moodleoverflow" "link"
And I should not see "Move discussion to public moodleoverflow one"
And I should not see "Move discussion to public moodleoverflow two"
And I should see "question anonymous"
And I should see "everything anonymous"
When I click on "Move discussion to everything anonymous" "link"
And I am on "Course 1" course homepage
And I follow "everything anonymous"
Then I should see "Question Message"

Scenario: Move topic from question anonymous forum
Given I am on "Course 1" course homepage
And I add a new discussion to "everything anonymous" moodleoverflow with:
| Subject | Everything Message |
| Message | This is the everything anonymous message |
And I follow "everything anonymous"
And I click on "Move this discussion to another moodleoverflow" "link"
And I should not see "Move discussion to public moodleoverflow one"
And I should not see "Move discussion to public moodleoverflow two"
And I should not see "Move discussion to question anonymous"
And I should not see "Move discussion to everything anonymous"


64 changes: 64 additions & 0 deletions tests/behat/userstats.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
@mod @mod_moodleoverflow @javascript
Feature: If the admin enabled user statistics, the teacher can see the activity of students in the course

Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | name | intro | course | idnumber |
| moodleoverflow | Test Moodleoverflow | Test moodleoverflow description | C1 | 1 |
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I add a new discussion to "Test Moodleoverflow" moodleoverflow with:
| Subject | Topic question |
| Message | This is a question |

Scenario: Userstats are not enabled per default. The teacher should not see the user statistics
And I follow "Test Moodleoverflow"
Then I should not see "View user statistics"

Scenario: Userstats are enabled. The teacher should see the user statistics. The teacher should already have an acitivty point
for writing a post.
Given the following config values are set as admin:
| showuserstats | 1 | moodleoverflow |
And I follow "Test Moodleoverflow"
Then I should see "View user statistics"
When I press "View user statistics"
Then the following should exist in the "statisticstable" table:
| User full name | Received upvotes | Received downvotes | Activity (this forum) | Activity (coursewide) |
| Teacher 1 | 0 | 0 | 1 | 1 |
| Student 1 | 0 | 0 | 0 | 0 |


Scenario: Test if reputation appears in the user statistics
Given the following config values are set as admin:
| showuserstats | 1 | moodleoverflow |
And I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Test Moodleoverflow"
And I follow "Topic question"
And I click on "Answer" "link"
And I set the following fields to these values:
| Message | This is an answer |
And I press "Post to forum"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Test Moodleoverflow"
And I follow "Topic question"
And I click on "Mark as solution" "text"
And I follow "Test Moodleoverflow"
And I press "View user statistics"
Then the following should exist in the "statisticstable" table:
| User full name | Received upvotes | Received downvotes | Activity (this forum) | Activity (coursewide) | Reputation (this forum) |
| Teacher 1 | 0 | 0 | 2 | 2 | 0 |
| Student 1 | 0 | 0 | 1 | 1 | 30 |
39 changes: 39 additions & 0 deletions tests/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="lib/phpunit/phpunit.xsd"
bootstrap="lib/phpunit/bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
backupGlobals="false"
backupStaticAttributes="false"
cacheResult="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutOutputDuringTests="true"
>

<php>
<!--<const name="PHPUNIT_LONGTEST" value="1"/> uncomment to execute also slow or otherwise expensive tests-->
<const name="PHPUNIT_SEQUENCE_START" value="195000"/>

<!--Following constants instruct tests to fetch external test files from alternative location
or skip tests if empty, clone https://github.com/moodlehq/moodle-exttests to local web server-->
<!--<const name="TEST_EXTERNAL_FILES_HTTP_URL" value="http://download.moodle.org/unittest"/>
uncomment and alter to fetch external test files from alternative location-->
<!--<const name="TEST_EXTERNAL_FILES_HTTPS_URL" value="https://download.moodle.org/unittest"/>
uncomment and alter to fetch external test files from alternative location-->
</php>

<testsuites>
<testsuite name="mod_moodleoverflow_testsuite">
<directory suffix="_test.php">mod/moodleoverflow/tests</directory>
</testsuite>
</testsuites>

</phpunit>
1 change: 1 addition & 0 deletions tests/subscriptions_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,7 @@ public function is_subscribable_loggedin_provider(): array {
* @param bool $expect
*
* @dataProvider is_subscribable_loggedin_provider
* @return void
*/
public function test_is_subscribable_loggedin($options, $expect): void {
// Reset the database after testing.
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'mod_moodleoverflow';
$plugin->version = 2024061100;
$plugin->version = 2024031104;
$plugin->release = 'v4.2-r4';
$plugin->requires = 2020061500; // Requires Moodle 3.9+.
$plugin->maturity = MATURITY_STABLE;
Expand Down
17 changes: 9 additions & 8 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@
// The page should not be large, only pages containing broad tables are usually.
$PAGE->add_body_class('limitedwidth');

// If a topic is to be moved, do it.
if ($linktoforum && $movetopopup && has_capability('mod/moodleoverflow:movetopic', $context)) {
// Take the $movetopopup-id and the $linktoforum-id and move the discussion to the forum.
$topic = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup]);
$topic->moodleoverflow = $linktoforum;
$DB->update_record('moodleoverflow_discussions', $topic);
redirect($CFG->wwwroot . '/mod/moodleoverflow/view.php?id=' . $cm->id);
}

// Output starts here.
echo $OUTPUT->header();

Expand Down Expand Up @@ -130,14 +139,6 @@
moodleoverflow_print_forum_list($course, $cm, $movetopopup);
}

if ($linktoforum && $movetopopup && has_capability('mod/moodleoverflow:movetopic', $context)) {
// Take the $movetopopup-id and the $linktoforum-id and move the discussion to the forum.
$topic = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup]);
$topic->moodleoverflow = $linktoforum;
$DB->update_record('moodleoverflow_discussions', $topic);
redirect($CFG->wwwroot . '/mod/moodleoverflow/view.php?id=' . $cm->id);
}

// Return here after posting, etc.
$SESSION->fromdiscussion = qualified_me();

Expand Down

0 comments on commit 0114dbf

Please sign in to comment.