Skip to content

Commit 0114dbf

Browse files
authored
Merge branch 'master' into enhancement/postform
2 parents a48c809 + 3032b86 commit 0114dbf

File tree

13 files changed

+222
-38
lines changed

13 files changed

+222
-38
lines changed

backup/moodle2/backup_moodleoverflow_stepslib.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -45,48 +45,41 @@ protected function define_structure() {
4545

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

5253
// Define each element separated.
5354
$discussions = new backup_nested_element('discussions');
5455
$discussion = new backup_nested_element('discussion', ['id'], [
55-
'name', 'firstpost', 'userid', 'timemodified', 'usermodified', 'timestart', ]);
56+
'name', 'firstpost', 'userid', 'timestart', 'timemodified', 'usermodified', ]);
5657

5758
$posts = new backup_nested_element('posts');
58-
5959
$post = new backup_nested_element('post', ['id'], [
6060
'parent', 'userid', 'created', 'modified',
61-
'mailed', 'message', 'messageformat', 'attachment', ]);
61+
'message', 'messageformat', 'attachment', 'mailed', 'reviewed', 'timereviewed', ]);
6262

6363
$ratings = new backup_nested_element('ratings');
64-
6564
$rating = new backup_nested_element('rating', ['id'], [
6665
'userid', 'rating', 'firstrated', 'lastchanged', ]);
6766

6867
$discussionsubs = new backup_nested_element('discuss_subs');
69-
7068
$discussionsub = new backup_nested_element('discuss_sub', ['id'], [
71-
'userid',
72-
'preference',
73-
]);
69+
'userid', 'preference', ]);
7470

7571
$subscriptions = new backup_nested_element('subscriptions');
76-
77-
$subscription = new backup_nested_element('subscription', ['id'], [
78-
'userid', ]);
72+
$subscription = new backup_nested_element('subscription', ['id'], ['userid']);
7973

8074
$readposts = new backup_nested_element('readposts');
81-
8275
$read = new backup_nested_element('read', ['id'], [
83-
'userid', 'discussionid', 'postid', 'firstread',
84-
'lastread', ]);
76+
'userid', 'discussionid', 'postid', 'firstread', 'lastread', ]);
8577

86-
$tracking = new backup_nested_element('tracking');
78+
$grades = new backup_nested_element('grades');
79+
$grade = new backup_nested_element('grade', ['id'], ['userid', 'grade']);
8780

88-
$track = new backup_nested_element('track', ['id'], [
89-
'userid', ]);
81+
$tracking = new backup_nested_element('tracking');
82+
$track = new backup_nested_element('track', ['id'], ['userid']);
9083

9184
// Build the tree.
9285
$moodleoverflow->add_child($discussions);

discussion.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@
161161
echo '<div id="moodleoverflow-posts"><div id="moodleoverflow-root">';
162162

163163
moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discussion, $post, $multiplemarks);
164-
165164
echo '</div></div>';
166165

167166
echo $OUTPUT->footer();

lang/en/moodleoverflow.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@
353353
$string['action_remove_downvote'] = 'Click to remove downvote';
354354
$string['downvotenotchangeable'] = 'Cannot downvote';
355355
$string['action_downvote'] = 'Click to downvote';
356-
$string['movetopicicon'] = 'The icon to move a topic';
357-
$string['movetopictoforum'] = 'The icon to move a selected topic to another forum';
356+
$string['movetopicicon'] = 'Move this discussion to another moodleoverflow';
357+
$string['movetopictoforum'] = 'Move discussion to {$a->forumname}';
358358

359359
// Privacy.
360360
$string['privacy:metadata:core_files'] = 'Moodleoverflow stores files which have been uploaded by the user to form part of a forum post.';

lib.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ function moodleoverflow_add_instance(stdClass $moodleoverflow, mod_moodleoverflo
137137
$moodleoverflow->timecreated = time();
138138

139139
// You may have to add extra stuff in here.
140-
141140
$moodleoverflow->id = $DB->insert_record('moodleoverflow', $moodleoverflow);
142141

143142
return $moodleoverflow->id;

locallib.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,25 @@ function moodleoverflow_print_forum_list($course, $cm, $movetopopup) {
451451
$forumarray = [[]];
452452
$currentforum = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup], 'moodleoverflow');
453453
$currentdiscussion = $DB->get_record('moodleoverflow_discussions', ['id' => $movetopopup], 'name');
454-
$forums = $DB->get_records('moodleoverflow', ['course' => $course->id]);
454+
455+
// If the currentforum is anonymous, only show forums that have a higher anonymous setting.
456+
$anonymoussetting = $DB->get_field('moodleoverflow', 'anonymous', ['id' => $currentforum->moodleoverflow]);
457+
if ($anonymoussetting == anonymous::QUESTION_ANONYMOUS || $anonymoussetting == anonymous::EVERYTHING_ANONYMOUS) {
458+
$params = ['course' => $course->id, 'anonymous' => $anonymoussetting,
459+
'currentforumid' => $currentforum->moodleoverflow, ];
460+
$sql = "SELECT *
461+
FROM {moodleoverflow}
462+
WHERE course = :course
463+
AND anonymous >= :anonymous
464+
AND id != :currentforumid";
465+
$forums = $DB->get_records_sql($sql, $params);
466+
} else {
467+
$forums = $DB->get_records('moodleoverflow', ['course' => $course->id]);
468+
}
469+
455470
$amountforums = count($forums);
456471

457-
if ($amountforums > 1) {
472+
if ($amountforums >= 1) {
458473
// Write the moodleoverflow-names in an array.
459474
$i = 0;
460475
foreach ($forums as $forum) {

pix/monologo.svg

Lines changed: 1 addition & 1 deletion
Loading

templates/forum_list.mustache

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@
3737
{{#forums}}
3838
<tr class="discussion">
3939
<td class="topic starter">
40-
{{name}}
41-
<a href='{{ movetoforum }}'>{{#pix}} i/arrow-right, core, {{#str}}movetopictoforum, moodleoverflow{{/str}} {{/pix}}</a>
40+
{{name}}
41+
<a href='{{ movetoforum }}'>
42+
{{#pix}} i/arrow-right, core,
43+
{{#str}} movetopictoforum, mod_moodleoverflow, {"forumname": {{#quote}} {{name}} {{/quote}} }
44+
{{/str}}
45+
{{/pix}}
46+
</a>
4247
</td>
4348
</tr>
4449
{{/forums}}

tests/behat/topicmove.feature

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
@mod @mod_moodleoverflow @javascript
2+
Feature: Teachers can move a discussion in one moodleoverflow forum to another moodleoverflow.
3+
4+
5+
Background:
6+
Given the following "users" exist:
7+
| username | firstname | lastname | email |
8+
| student1 | Student | 1 | student1@example.com |
9+
And the following "courses" exist:
10+
| fullname | shortname | category |
11+
| Course 1 | C1 | 0 |
12+
And the following "course enrolments" exist:
13+
| user | course | role |
14+
| student1 | C1 | student |
15+
And the following "activities" exist:
16+
| activity | name | intro | course | anonymous | idnumber |
17+
| moodleoverflow | public moodleoverflow one | Test moodleoverflow description | C1 | 0 | 1 |
18+
| moodleoverflow | public moodleoverflow two | Test moodleoverflow description | C1 | 0 | 2 |
19+
| moodleoverflow | question anonymous | Test moodleoverflow description | C1 | 1 | 3 |
20+
| moodleoverflow | everything anonymous | Test moodleoverflow description | C1 | 2 | 4 |
21+
And I log in as "admin"
22+
23+
24+
Scenario: Move topic from public forum
25+
Given I am on "Course 1" course homepage
26+
And I add a new discussion to "public moodleoverflow one" moodleoverflow with:
27+
| Subject | Public Message |
28+
| Message | This is the public message |
29+
And I follow "public moodleoverflow one"
30+
And I click on "Move this discussion to another moodleoverflow" "link"
31+
Then I should see "public moodleoverflow two"
32+
And I should see "question anonymous"
33+
And I should see "everything anonymous"
34+
And I should not see "Move discussion to public moodleoverflow one"
35+
When I click on "Move discussion to public moodleoverflow two" "link"
36+
And I am on "Course 1" course homepage
37+
And I follow "public moodleoverflow two"
38+
Then I should see "Public Message"
39+
40+
Scenario: Move topic from question anonymous forum
41+
Given I am on "Course 1" course homepage
42+
And I add a new discussion to "question anonymous" moodleoverflow with:
43+
| Subject | Question Message |
44+
| Message | This is the question anonymous message |
45+
And I follow "question anonymous"
46+
And I click on "Move this discussion to another moodleoverflow" "link"
47+
And I should not see "Move discussion to public moodleoverflow one"
48+
And I should not see "Move discussion to public moodleoverflow two"
49+
And I should see "question anonymous"
50+
And I should see "everything anonymous"
51+
When I click on "Move discussion to everything anonymous" "link"
52+
And I am on "Course 1" course homepage
53+
And I follow "everything anonymous"
54+
Then I should see "Question Message"
55+
56+
Scenario: Move topic from question anonymous forum
57+
Given I am on "Course 1" course homepage
58+
And I add a new discussion to "everything anonymous" moodleoverflow with:
59+
| Subject | Everything Message |
60+
| Message | This is the everything anonymous message |
61+
And I follow "everything anonymous"
62+
And I click on "Move this discussion to another moodleoverflow" "link"
63+
And I should not see "Move discussion to public moodleoverflow one"
64+
And I should not see "Move discussion to public moodleoverflow two"
65+
And I should not see "Move discussion to question anonymous"
66+
And I should not see "Move discussion to everything anonymous"
67+
68+

tests/behat/userstats.feature

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@mod @mod_moodleoverflow @javascript
2+
Feature: If the admin enabled user statistics, the teacher can see the activity of students in the course
3+
4+
Background:
5+
Given the following "users" exist:
6+
| username | firstname | lastname | email |
7+
| teacher1 | Teacher | 1 | teacher1@example.com |
8+
| student1 | Student | 1 | student1@example.com |
9+
And the following "courses" exist:
10+
| fullname | shortname | category |
11+
| Course 1 | C1 | 0 |
12+
And the following "course enrolments" exist:
13+
| user | course | role |
14+
| teacher1 | C1 | editingteacher |
15+
| student1 | C1 | student |
16+
And the following "activities" exist:
17+
| activity | name | intro | course | idnumber |
18+
| moodleoverflow | Test Moodleoverflow | Test moodleoverflow description | C1 | 1 |
19+
And I log in as "teacher1"
20+
And I am on "Course 1" course homepage
21+
And I add a new discussion to "Test Moodleoverflow" moodleoverflow with:
22+
| Subject | Topic question |
23+
| Message | This is a question |
24+
25+
Scenario: Userstats are not enabled per default. The teacher should not see the user statistics
26+
And I follow "Test Moodleoverflow"
27+
Then I should not see "View user statistics"
28+
29+
Scenario: Userstats are enabled. The teacher should see the user statistics. The teacher should already have an acitivty point
30+
for writing a post.
31+
Given the following config values are set as admin:
32+
| showuserstats | 1 | moodleoverflow |
33+
And I follow "Test Moodleoverflow"
34+
Then I should see "View user statistics"
35+
When I press "View user statistics"
36+
Then the following should exist in the "statisticstable" table:
37+
| User full name | Received upvotes | Received downvotes | Activity (this forum) | Activity (coursewide) |
38+
| Teacher 1 | 0 | 0 | 1 | 1 |
39+
| Student 1 | 0 | 0 | 0 | 0 |
40+
41+
42+
Scenario: Test if reputation appears in the user statistics
43+
Given the following config values are set as admin:
44+
| showuserstats | 1 | moodleoverflow |
45+
And I log in as "student1"
46+
And I am on "Course 1" course homepage
47+
And I follow "Test Moodleoverflow"
48+
And I follow "Topic question"
49+
And I click on "Answer" "link"
50+
And I set the following fields to these values:
51+
| Message | This is an answer |
52+
And I press "Post to forum"
53+
And I log out
54+
And I log in as "teacher1"
55+
And I am on "Course 1" course homepage
56+
And I follow "Test Moodleoverflow"
57+
And I follow "Topic question"
58+
And I click on "Mark as solution" "text"
59+
And I follow "Test Moodleoverflow"
60+
And I press "View user statistics"
61+
Then the following should exist in the "statisticstable" table:
62+
| User full name | Received upvotes | Received downvotes | Activity (this forum) | Activity (coursewide) | Reputation (this forum) |
63+
| Teacher 1 | 0 | 0 | 2 | 2 | 0 |
64+
| Student 1 | 0 | 0 | 1 | 1 | 30 |

tests/phpunit.xml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="lib/phpunit/phpunit.xsd"
5+
bootstrap="lib/phpunit/bootstrap.php"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
backupGlobals="false"
11+
backupStaticAttributes="false"
12+
cacheResult="false"
13+
stopOnError="false"
14+
stopOnFailure="false"
15+
stopOnIncomplete="false"
16+
stopOnSkipped="false"
17+
beStrictAboutTestsThatDoNotTestAnything="false"
18+
beStrictAboutOutputDuringTests="true"
19+
>
20+
21+
<php>
22+
<!--<const name="PHPUNIT_LONGTEST" value="1"/> uncomment to execute also slow or otherwise expensive tests-->
23+
<const name="PHPUNIT_SEQUENCE_START" value="195000"/>
24+
25+
<!--Following constants instruct tests to fetch external test files from alternative location
26+
or skip tests if empty, clone https://github.com/moodlehq/moodle-exttests to local web server-->
27+
<!--<const name="TEST_EXTERNAL_FILES_HTTP_URL" value="http://download.moodle.org/unittest"/>
28+
uncomment and alter to fetch external test files from alternative location-->
29+
<!--<const name="TEST_EXTERNAL_FILES_HTTPS_URL" value="https://download.moodle.org/unittest"/>
30+
uncomment and alter to fetch external test files from alternative location-->
31+
</php>
32+
33+
<testsuites>
34+
<testsuite name="mod_moodleoverflow_testsuite">
35+
<directory suffix="_test.php">mod/moodleoverflow/tests</directory>
36+
</testsuite>
37+
</testsuites>
38+
39+
</phpunit>

0 commit comments

Comments
 (0)