Skip to content

Commit 81c3e1e

Browse files
New feature: restricted time for participation for moodleoverflow forums (#138)
* add setting to enable a limited mode * Update upgrade.php * answer button functionality updated, new helpicon class * functionality is finished, testing missing * code cleaning with code/phpdoc checker * github workflow error fixed, difference between student and teacher * github workflows error fixed * last workflow errors fixed * workflow errors fixed * workflow behat errors fixed * add global cfg statement * adapt workflow to update branch * codecleaning * change the version as it has been increased since the last merge * fixed proken SQL Statement * behat test for limitedanswer feature * codecleaning * add limitedanswer time to backup * added a endtime adjusting settings, locallib, post, langfiles * adjusted behat * review * adjusted the mod_form to show warning in case answers exists * add m4.5 check --------- Co-authored-by: NinaHerrmann <[email protected]>
1 parent 5be9889 commit 81c3e1e

21 files changed

+369
-62
lines changed

.github/workflows/moodle-ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
php: ['8.3']
12-
moodle-branch: ['MOODLE_404_STABLE']
12+
moodle-branch: ['MOODLE_405_STABLE']
1313
database: ['pgsql']
1414

1515
steps:
@@ -111,17 +111,17 @@ jobs:
111111
fail-fast: false
112112
matrix:
113113
php: ['8.0', '8.1', '8.2', '8.3']
114-
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE']
114+
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_403_STABLE', 'MOODLE_404_STABLE', 'MOODLE_405_STABLE']
115115
database: ['mariadb', 'pgsql']
116116
exclude:
117117
- php: '8.0'
118118
moodle-branch: 'MOODLE_404_STABLE'
119+
- php: '8.0'
120+
moodle-branch: 'MOODLE_405_STABLE'
119121
- php: '8.2'
120122
moodle-branch: 'MOODLE_401_STABLE'
121123
- php: '8.3'
122124
moodle-branch: 'MOODLE_401_STABLE'
123-
- php: '8.3'
124-
moodle-branch: 'MOODLE_402_STABLE'
125125
- php: '8.3'
126126
moodle-branch: 'MOODLE_403_STABLE'
127127
include:

backup/moodle2/backup_moodleoverflow_stepslib.php

+14-11
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,41 @@ class backup_moodleoverflow_activity_structure_step extends backup_activity_stru
3939
* @return backup_nested_element
4040
*/
4141
protected function define_structure() {
42+
4243
// To know if we are including userinfo.
4344
$userinfo = $this->get_setting_value('userinfo');
4445

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

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

5658
$posts = new backup_nested_element('posts');
57-
$post = new backup_nested_element('post', ['id'], ['parent', 'userid', 'created', 'modified', 'message',
58-
'messageformat', 'attachment', 'mailed', 'reviewed', 'timereviewed', ]);
59+
$post = new backup_nested_element('post', ['id'], [
60+
'parent', 'userid', 'created', 'modified',
61+
'message', 'messageformat', 'attachment', 'mailed', 'reviewed', 'timereviewed', ]);
5962

6063
$ratings = new backup_nested_element('ratings');
61-
$rating = new backup_nested_element('rating', ['id'], ['userid', 'rating', 'firstrated', 'lastchanged']);
64+
$rating = new backup_nested_element('rating', ['id'], [
65+
'userid', 'rating', 'firstrated', 'lastchanged', ]);
6266

6367
$discussionsubs = new backup_nested_element('discuss_subs');
64-
$discussionsub = new backup_nested_element('discuss_sub', ['id'], ['userid', 'preference']);
68+
$discussionsub = new backup_nested_element('discuss_sub', ['id'], [
69+
'userid', 'preference', ]);
6570

6671
$subscriptions = new backup_nested_element('subscriptions');
6772
$subscription = new backup_nested_element('subscription', ['id'], ['userid']);
6873

6974
$readposts = new backup_nested_element('readposts');
70-
$read = new backup_nested_element('read', ['id'], ['userid', 'discussionid', 'postid', 'firstread', 'lastread']);
75+
$read = new backup_nested_element('read', ['id'], [
76+
'userid', 'discussionid', 'postid', 'firstread', 'lastread', ]);
7177

7278
$grades = new backup_nested_element('grades');
7379
$grade = new backup_nested_element('grade', ['id'], ['userid', 'grade']);
@@ -94,9 +100,6 @@ protected function define_structure() {
94100
$moodleoverflow->add_child($readposts);
95101
$readposts->add_child($read);
96102

97-
$moodleoverflow->add_child($grades);
98-
$grades->add_child($grade);
99-
100103
$moodleoverflow->add_child($tracking);
101104
$tracking->add_child($track);
102105

classes/output/helpicon.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Use of the Helpicon from Moodle core.
19+
* @package mod_moodleoverflow
20+
* @copyright 2023 Tamaro Walter
21+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22+
*/
23+
24+
namespace mod_moodleoverflow\output;
25+
26+
/**
27+
* Builds a Helpicon, that shows a String when hovering over it.
28+
* @package mod_moodleoverflow
29+
* @copyright 2023 Tamaro Walter
30+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31+
*/
32+
class helpicon {
33+
34+
/** @var object The Helpicon*/
35+
private $helpobject;
36+
37+
/**
38+
* Builds a Helpicon and stores it in helpobject.
39+
*
40+
* @param string $htmlclass The classname in which the icon will be.
41+
* @param string $content A string that shows the information that the icon has.
42+
*/
43+
public function __construct($htmlclass, $content) {
44+
global $CFG;
45+
$iconurl = $CFG->wwwroot . '/pix/a/help.png';
46+
$icon = \html_writer::img($iconurl, $content);
47+
$class = $htmlclass;
48+
$iconattributes = ['role' => 'button',
49+
'data-container' => 'body',
50+
'data-toggle' => 'popover',
51+
'data-placement' => 'right',
52+
'data-action' => 'showhelpicon',
53+
'data-html' => 'true',
54+
'data-trigger' => 'focus',
55+
'tabindex' => '0',
56+
'data-content' => '<div class=&quot;no-overflow&quot;><p>' . $content . '</p> </div>', ];
57+
$this->helpobject = \html_writer::span($icon, $class, $iconattributes);
58+
}
59+
60+
/**
61+
* Returns the Helpicon, so that it can be used.
62+
*
63+
* @return object The Helpicon
64+
*/
65+
public function get_helpicon() {
66+
return $this->helpobject;
67+
}
68+
}

classes/tables/userstats_table.php

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
require_once($CFG->dirroot . '/mod/moodleoverflow/lib.php');
3131
require_once($CFG->dirroot . '/mod/moodleoverflow/locallib.php');
3232
require_once($CFG->libdir . '/tablelib.php');
33+
use mod_moodleoverflow\output\helpicon;
3334

3435
/**
3536
* Table listing all user statistics of a course
@@ -152,6 +153,9 @@ public function get_usertable() {
152153
*/
153154
public function set_helpactivity() {
154155
global $CFG;
156+
$htmlclass = 'helpactivityclass btn btn-link';
157+
$content = get_string('helpamountofactivity', 'moodleoverflow');
158+
$helpobject = new helpicon($htmlclass, $content);
155159
$this->helpactivity = new \stdClass();
156160
$this->helpactivity->iconurl = $CFG->wwwroot . '/pix/a/help.png';
157161
$this->helpactivity->icon = \html_writer::img($this->helpactivity->iconurl,

db/install.xml

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
<FIELD NAME="anonymous" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
2929
<FIELD NAME="needsreview" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
3030
<FIELD NAME="allowmultiplemarks" TYPE="int" LENGTH="1" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
31+
<FIELD NAME="la_starttime" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
32+
<FIELD NAME="la_endtime" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
3133
</FIELDS>
3234
<KEYS>
3335
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>

db/upgrade.php

+17
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,23 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
292292
upgrade_mod_savepoint(true, 2023040400, 'moodleoverflow');
293293
}
294294

295+
if ($oldversion < 2024061700) {
296+
// Define table moodleoverflow to be edited.
297+
$table = new xmldb_table('moodleoverflow');
298+
299+
// Create the field fot the start time for the limited answer mode.
300+
$field = new xmldb_field('la_starttime', XMLDB_TYPE_INTEGER, '10', null, null, null, 0, 'allowmultiplemarks');
301+
if (!$dbman->field_exists($table, $field)) {
302+
$dbman->add_field($table, $field);
303+
}
304+
// Create the field for the end time for the limited answer mode.
305+
$field = new xmldb_field('la_endtime', XMLDB_TYPE_INTEGER, '10', null, null, null, 0, 'la_starttime');
306+
if (!$dbman->field_exists($table, $field)) {
307+
$dbman->add_field($table, $field);
308+
}
309+
upgrade_mod_savepoint(true, 2024061700, 'moodleoverflow');
310+
}
311+
295312
if ($oldversion < 2024072600) {
296313
require_once($CFG->dirroot . '/mod/moodleoverflow/db/upgradelib.php');
297314

discussion.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
if ($marksetting->allowmultiplemarks == 1) {
5656
$multiplemarks = true;
5757
}
58+
// Setting of limitedanswer. Limitedanswertime saves the timestamp, until the limitedanswer is on (0 if off).
59+
$limitedanswersetting = $DB->get_record('moodleoverflow', ['id' => $moodleoverflow->id], 'la_starttime, la_endtime');
5860

5961
// Get the related coursemodule and its context.
6062
if (!$cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id, $course->id)) {
@@ -156,7 +158,7 @@
156158

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

159-
moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discussion, $post, $multiplemarks);
161+
moodleoverflow_print_discussion($course, $cm, $moodleoverflow, $discussion, $post, $multiplemarks, $limitedanswersetting);
160162
echo '</div></div>';
161163

162164
echo $OUTPUT->footer();

lang/en/moodleoverflow.php

+11
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,18 @@
172172
$string['invalidpostid'] = 'Invalid post ID - {$a}';
173173
$string['invalidratingid'] = 'The submitted rating is neither an upvote nor a downvote.';
174174
$string['jump_to_next_post_needing_review'] = 'Jump to next post needing to be reviewed.';
175+
$string['la_endtime'] = 'End time students can answer';
176+
$string['la_endtime_help'] = 'Students can not answer to qustions after the set up date';
177+
$string['la_starttime'] = 'Start time students can answer';
178+
$string['la_starttime_help'] = 'Students can not answer to questions until the set up date';
175179
$string['lastpost'] = 'Last post';
180+
$string['limitedanswer_helpicon_teacher'] = 'This can be changed in the settings of the Moodleoverflow.';
181+
$string['limitedanswer_info_endtime'] = 'Posts can not be answered after {$a->limitedanswerdate}.';
182+
$string['limitedanswer_info_start'] = 'This Moodleoverflow is in a limited answer mode.';
183+
$string['limitedanswer_info_starttime'] = 'Posts can not be answered until {$a->limitedanswerdate}.';
184+
$string['limitedanswerheading'] = 'Limited Answer Mode';
185+
$string['limitedanswerwarning_answers'] = 'There are already answered posts in this Moodleoverflow.';
186+
$string['limitedanswerwarning_conclusion'] = 'Activating or changing limited answer mode might confuse users.';
176187
$string['mailindexlink'] = 'Change your forum preferences: {$a}';
177188
$string['manydiscussions'] = 'Discussions per page';
178189
$string['markallread'] = 'Mark all posts in this discussion as read';

0 commit comments

Comments
 (0)