Skip to content

Commit 65eef2b

Browse files
authored
Merge pull request #130 from learnweb/update/Moodle_402
Update/moodle 402
2 parents 32d4422 + 8e761b3 commit 65eef2b

31 files changed

+1275
-227
lines changed

.github/workflows/moodle-ci.yml

+16-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: ['8.0']
12-
moodle-branch: ['MOODLE_401_STABLE']
11+
php: ['8.1']
12+
moodle-branch: ['MOODLE_402_STABLE']
1313
database: ['pgsql']
1414

1515
steps:
@@ -110,8 +110,8 @@ jobs:
110110
strategy:
111111
fail-fast: false
112112
matrix:
113-
php: ['8.0']
114-
moodle-branch: ['MOODLE_311_STABLE', 'MOODLE_400_STABLE', 'MOODLE_401_STABLE']
113+
php: ['8.0', '8.1']
114+
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE']
115115
database: ['mariadb', 'pgsql']
116116
include:
117117
- php: '7.4'
@@ -120,6 +120,18 @@ jobs:
120120
- php: '7.4'
121121
moodle-branch: 'MOODLE_39_STABLE'
122122
database: 'pgsql'
123+
- php: '8.0'
124+
moodle-branch: 'MOODLE_311_STABLE'
125+
database: 'mariadb'
126+
- php: '8.0'
127+
moodle-branch: 'MOODLE_311_STABLE'
128+
database: 'pgsql'
129+
- php: '8.0'
130+
moodle-branch: 'MOODLE_400_STABLE'
131+
database: 'mariadb'
132+
- php: '8.0'
133+
moodle-branch: 'MOODLE_400_STABLE'
134+
database: 'pgsql'
123135

124136
steps:
125137
- name: Start MariaDB

.github/workflows/moodle-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
--data-urlencode "altdownloadurl=${ZIPURL}" \
4545
--data-urlencode "releasenotes=${BODY}" \
4646
--data-urlencode "releasenotesformat=4")
47-
echo "::set-output name=response::${RESPONSE}"
47+
echo "response=${RESPONSE}" >> $GITHUB_OUTPUT
4848
- name: Evaluate the response
4949
id: evaluate-response
5050
env:

amd/build/rating.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/rating.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/rating.js

+61-6
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ async function sendVote(postid, rating, userid) {
6565
* Init function.
6666
*
6767
* @param {int} userid
68+
* @param {boolean} allowmultiplemarks // true means allowed, false means not allowed.
69+
*
6870
*/
69-
export function init(userid) {
71+
export function init(userid, allowmultiplemarks) {
7072
Prefetch.prefetchStrings('mod_moodleoverflow',
7173
['marksolved', 'marknotsolved', 'markhelpful', 'marknothelpful',
7274
'action_remove_upvote', 'action_upvote', 'action_remove_downvote', 'action_downvote']);
@@ -104,22 +106,75 @@ export function init(userid) {
104106
case 'helpful':
105107
case 'solved': {
106108
const isHelpful = action === 'helpful';
107-
const htmlclass = isHelpful ? 'statusstarter' : 'statusteacher';
109+
const htmlclass = isHelpful ? 'markedhelpful' : 'markedsolution';
108110
const shouldRemove = postElement.classList.contains(htmlclass);
109111
const baseRating = isHelpful ? RATING_HELPFUL : RATING_SOLVED;
110112
const rating = shouldRemove ? baseRating * 10 : baseRating;
111113
await sendVote(postid, rating, userid);
112-
for (const el of root.querySelectorAll('.moodleoverflowpost.' + htmlclass)) {
113-
el.classList.remove(htmlclass);
114-
el.querySelector(`[data-moodleoverflow-action="${action}"]`).textContent =
115-
await getString(`mark${action}`, 'mod_moodleoverflow');
114+
115+
/* If multiplemarks are not allowed (that is the default mode): delete all marks.
116+
else: only delete the mark if the post is being unmarked.
117+
118+
Add a mark, if the post is being marked.
119+
*/
120+
if (!allowmultiplemarks) {
121+
// Delete all marks in the discussion
122+
for (const el of root.querySelectorAll('.moodleoverflowpost.' + htmlclass)) {
123+
el.classList.remove(htmlclass);
124+
el.querySelector(`[data-moodleoverflow-action="${action}"]`).textContent =
125+
await getString(`mark${action}`, 'mod_moodleoverflow');
126+
}
127+
} else {
128+
// Remove only the mark of the unmarked post.
129+
if (shouldRemove) {
130+
postElement.classList.remove(htmlclass);
131+
actionElement.textContent = await getString(`mark${action}`, 'mod_moodleoverflow');
132+
changeStrings(htmlclass, action);
133+
}
116134
}
135+
// If the post is being marked, mark it.
117136
if (!shouldRemove) {
118137
postElement.classList.add(htmlclass);
119138
actionElement.textContent = await getString(`marknot${action}`, 'mod_moodleoverflow');
139+
if (allowmultiplemarks) {
140+
changeStrings(htmlclass, action);
141+
}
120142
}
143+
121144
}
122145
}
123146
};
124147

148+
}
149+
150+
/**
151+
* Function to change the String of the post data-action button.
152+
* Only used if mulitplemarks are allowed.
153+
* @param {string} htmlclass the class where the String is being updated
154+
* @param {string} action helpful or solved mark
155+
*/
156+
async function changeStrings(htmlclass, action) {
157+
Prefetch.prefetchStrings('mod_moodleoverflow',
158+
['marksolved', 'alsomarksolved', 'markhelpful', 'alsomarkhelpful',]);
159+
160+
// 1. Step: Are there other posts in the Discussion, that are solved/helpful?
161+
var othermarkedposts = false;
162+
for (const el of root.querySelectorAll('.moodleoverflowpost')) {
163+
if (el.classList.contains(htmlclass)) {
164+
othermarkedposts = true;
165+
break;
166+
}
167+
}
168+
// 2. Step: Change the strings of the action Button of the unmarked posts.
169+
for (const el of root.querySelectorAll('.moodleoverflowpost')) {
170+
if (!el.classList.contains(htmlclass) && el.querySelector(`[data-moodleoverflow-action="${action}"]`)) {
171+
if (othermarkedposts) {
172+
el.querySelector(`[data-moodleoverflow-action="${action}"]`).textContent =
173+
await getString(`alsomark${action}`, 'mod_moodleoverflow');
174+
} else {
175+
el.querySelector(`[data-moodleoverflow-action="${action}"]`).textContent =
176+
await getString(`mark${action}`, 'mod_moodleoverflow');
177+
}
178+
}
179+
}
125180
}

classes/capabilities.php

+35
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,57 @@
3535
*/
3636
class capabilities {
3737

38+
/** capability add instance */
3839
const ADD_INSTANCE = 'mod/moodleoverflow:addinstance';
40+
41+
/** capability view discussions*/
3942
const VIEW_DISCUSSION = 'mod/moodleoverflow:viewdiscussion';
43+
44+
/** capability reply in discussions*/
4045
const REPLY_POST = 'mod/moodleoverflow:replypost';
46+
47+
/** capability start discussions*/
4148
const START_DISCUSSION = 'mod/moodleoverflow:startdiscussion';
49+
50+
/** capability edit post from other course participants*/
4251
const EDIT_ANY_POST = 'mod/moodleoverflow:editanypost';
52+
53+
/** capability delete your post*/
4354
const DELETE_OWN_POST = 'mod/moodleoverflow:deleteownpost';
55+
56+
/** capability delete post from any course participant*/
4457
const DELETE_ANY_POST = 'mod/moodleoverflow:deleteanypost';
58+
59+
/** capability rate a post*/
4560
const RATE_POST = 'mod/moodleoverflow:ratepost';
61+
62+
/** capability mark a post as a solution for a questions*/
4663
const MARK_SOLVED = 'mod/moodleoverflow:marksolved';
64+
65+
/** capability manage the subscription of a moodleoverflow instance */
4766
const MANAGE_SUBSCRIPTIONS = 'mod/moodleoverflow:managesubscriptions';
67+
68+
/** capability force the subscription of participants */
4869
const ALLOW_FORCE_SUBSCRIBE = 'mod/moodleoverflow:allowforcesubscribe';
70+
71+
/** capability attach files to posts */
4972
const CREATE_ATTACHMENT = 'mod/moodleoverflow:createattachment';
73+
74+
/** capability review post to be published*/
5075
const REVIEW_POST = 'mod/moodleoverflow:reviewpost';
5176

77+
/** @var array cache capabilities*/
5278
private static $cache = [];
5379

80+
/**
81+
* Saves the cache from has_capability.
82+
*
83+
* @param string $capability The capability that is being checked.
84+
* @param context $context The context.
85+
* @param int|null $userid The user ID.
86+
*
87+
* @return bool true or false
88+
*/
5489
public static function has(string $capability, context $context, $userid = null): bool {
5590
global $USER;
5691
if (!$userid) {

classes/output/moodleoverflow_email.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,15 @@ public function export_for_template(\renderer_base $renderer, $plaintext = false
155155
protected function export_for_template_text(\mod_moodleoverflow_renderer $renderer) {
156156

157157
return array(
158-
'id' => html_entity_decode($this->post->id),
159-
'coursename' => html_entity_decode($this->get_coursename()),
160-
'courselink' => html_entity_decode($this->get_courselink()),
161-
'moodleoverflowname' => html_entity_decode($this->get_moodleoverflowname()),
162-
'showdiscussionname' => html_entity_decode($this->has_showdiscussionname()),
163-
'discussionname' => html_entity_decode($this->get_discussionname()),
164-
'subject' => html_entity_decode($this->get_subject()),
165-
'authorfullname' => html_entity_decode($this->get_author_fullname()),
166-
'postdate' => html_entity_decode($this->get_postdate()),
158+
'id' => html_entity_decode($this->post->id, ENT_COMPAT),
159+
'coursename' => html_entity_decode($this->get_coursename(), ENT_COMPAT),
160+
'courselink' => html_entity_decode($this->get_courselink(), ENT_COMPAT),
161+
'moodleoverflowname' => html_entity_decode($this->get_moodleoverflowname(), ENT_COMPAT),
162+
'showdiscussionname' => html_entity_decode($this->has_showdiscussionname(), ENT_COMPAT),
163+
'discussionname' => html_entity_decode($this->get_discussionname(), ENT_COMPAT),
164+
'subject' => html_entity_decode($this->get_subject(), ENT_COMPAT),
165+
'authorfullname' => html_entity_decode($this->get_author_fullname(), ENT_COMPAT),
166+
'postdate' => html_entity_decode($this->get_postdate(), ENT_COMPAT),
167167
'firstpost' => $this->is_firstpost(),
168168
'canreply' => $this->canreply,
169169
'permalink' => $this->get_permalink(),
@@ -179,7 +179,7 @@ protected function export_for_template_text(\mod_moodleoverflow_renderer $render
179179
'grouppicture' => $this->get_group_picture(),
180180

181181
// Format some components according to the renderer.
182-
'message' => html_entity_decode($renderer->format_message_text($this->cm, $this->post)),
182+
'message' => html_entity_decode($renderer->format_message_text($this->cm, $this->post), ENT_COMPAT),
183183
);
184184
}
185185

0 commit comments

Comments
 (0)