Skip to content

Commit f224723

Browse files
authored
Merge pull request #207 from learnweb/feature/limitedanswermode
Feature/limitedanswermode
2 parents 2e91aeb + 4ac62c7 commit f224723

15 files changed

+447
-80
lines changed

Diff for: .github/workflows/config.json

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"main-moodle": "MOODLE_405_STABLE",
33
"main-php": "8.3",
44
"moodle-php": {
5-
"MOODLE_401_STABLE": ["7.4", "8.1"],
65
"MOODLE_403_STABLE": ["8.0", "8.2"],
76
"MOODLE_404_STABLE": ["8.1", "8.3"],
87
"MOODLE_405_STABLE": ["8.1", "8.2", "8.3"]

Diff for: 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

Diff for: classes/output/helpicon.php

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.svg';
46+
$iconstyle = ['style' =>
47+
'max-width: 20px; max-height: 20px; margin: 0; padding: 0; box-sizing: content-box; margin-right: .5rem;'];
48+
$icon = \html_writer::img($iconurl, $content, $iconstyle);
49+
50+
$class = $htmlclass;
51+
$iconattributes = ['role' => 'button',
52+
'style' => 'display: inline;',
53+
'data-container' => 'body',
54+
'data-toggle' => 'popover',
55+
'data-placement' => 'right',
56+
'data-action' => 'showhelpicon',
57+
'data-html' => 'true',
58+
'data-trigger' => 'focus',
59+
'tabindex' => '0',
60+
'data-content' => '<div class=&quot;no-overflow&quot;><p>' . $content . '</p> </div>', ];
61+
$this->helpobject = \html_writer::span($icon, $class, $iconattributes);
62+
}
63+
64+
/**
65+
* Returns the Helpicon, so that it can be used.
66+
*
67+
* @return object The Helpicon
68+
*/
69+
public function get_helpicon() {
70+
return $this->helpobject;
71+
}
72+
}

Diff for: classes/tables/userstats_table.php

+5-20
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
@@ -151,27 +152,11 @@ public function get_usertable() {
151152
* Setup the help icon for amount of activity
152153
*/
153154
public function set_helpactivity() {
154-
global $CFG;
155+
$htmlclass = 'helpactivityclass btn btn-link';
156+
$content = get_string('helpamountofactivity', 'moodleoverflow');
157+
$helpobject = new helpicon($htmlclass, $content);
155158
$this->helpactivity = new \stdClass();
156-
$this->helpactivity->iconurl = $CFG->wwwroot . '/pix/a/help.png';
157-
$this->helpactivity->icon = \html_writer::img($this->helpactivity->iconurl,
158-
get_string('helpamountofactivity', 'moodleoverflow'));
159-
$this->helpactivity->class = 'helpactivityclass btn btn-link';
160-
$this->helpactivity->iconattributes = ['role' => 'button',
161-
'data-container' => 'body',
162-
'data-toggle' => 'popover',
163-
'data-placement' => 'right',
164-
'data-action' => 'showhelpicon',
165-
'data-html' => 'true',
166-
'data-trigger' => 'focus',
167-
'tabindex' => '0',
168-
'data-content' => '<div class=&quot;no-overflow&quot;><p>' .
169-
get_string('helpamountofactivity', 'moodleoverflow') .
170-
'</p> </div>', ];
171-
172-
$this->helpactivity->object = \html_writer::span($this->helpactivity->icon,
173-
$this->helpactivity->class,
174-
$this->helpactivity->iconattributes);
159+
$this->helpactivity->object = $helpobject->get_helpicon();
175160
}
176161

177162
// Functions that show the data.

Diff for: 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"/>

Diff for: db/upgrade.php

+17
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,22 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
300300
upgrade_mod_savepoint(true, 2024072600, 'moodleoverflow');
301301
}
302302

303+
if ($oldversion < 2025031200) {
304+
// Define table moodleoverflow to be edited.
305+
$table = new xmldb_table('moodleoverflow');
306+
307+
// Create the field fot the start time for the limited answer mode.
308+
$field = new xmldb_field('la_starttime', XMLDB_TYPE_INTEGER, '10', null, null, null, 0, 'allowmultiplemarks');
309+
if (!$dbman->field_exists($table, $field)) {
310+
$dbman->add_field($table, $field);
311+
}
312+
// Create the field for the end time for the limited answer mode.
313+
$field = new xmldb_field('la_endtime', XMLDB_TYPE_INTEGER, '10', null, null, null, 0, 'la_starttime');
314+
if (!$dbman->field_exists($table, $field)) {
315+
$dbman->add_field($table, $field);
316+
}
317+
upgrade_mod_savepoint(true, 2025031200, 'moodleoverflow');
318+
}
319+
303320
return true;
304321
}

Diff for: 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();

Diff for: lang/en/moodleoverflow.php

+14
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,21 @@
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'] = 'Time at which students can no longer answer';
176+
$string['la_endtime_help'] = 'Students can not answer to qustions after the set up date';
177+
$string['la_endtime_ruleerror'] = 'End time must be in the future';
178+
$string['la_sequence_error'] = 'The end time must be after the start time';
179+
$string['la_starttime'] = 'Time at which students can start to answer';
180+
$string['la_starttime_help'] = 'Students can not answer to questions until the set up date';
181+
$string['la_starttime_ruleerror'] = 'Start time must be in the future';
175182
$string['lastpost'] = 'Last post';
183+
$string['limitedanswer_helpicon_teacher'] = 'This can be changed in the settings of the Moodleoverflow.';
184+
$string['limitedanswer_info_endtime'] = 'Posts can not be answered after {$a->limitedanswerdate}.';
185+
$string['limitedanswer_info_start'] = 'This Moodleoverflow is in a limited answer mode.';
186+
$string['limitedanswer_info_starttime'] = 'Posts can not be answered until {$a->limitedanswerdate}.';
187+
$string['limitedanswerheading'] = 'Limited Answer Mode';
188+
$string['limitedanswerwarning_answers'] = 'There are already answered posts in this Moodleoverflow.';
189+
$string['limitedanswerwarning_conclusion'] = 'You can only set a time until students are able to answer';
176190
$string['mailindexlink'] = 'Change your forum preferences: {$a}';
177191
$string['manydiscussions'] = 'Discussions per page';
178192
$string['markallread'] = 'Mark all posts in this discussion as read';

0 commit comments

Comments
 (0)