Skip to content

Commit

Permalink
Merge pull request #130 from learnweb/update/Moodle_402
Browse files Browse the repository at this point in the history
Update/moodle 402
  • Loading branch information
NinaHerrmann committed May 22, 2023
2 parents 32d4422 + 8e761b3 commit 65eef2b
Show file tree
Hide file tree
Showing 31 changed files with 1,275 additions and 227 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ jobs:

strategy:
matrix:
php: ['8.0']
moodle-branch: ['MOODLE_401_STABLE']
php: ['8.1']
moodle-branch: ['MOODLE_402_STABLE']
database: ['pgsql']

steps:
Expand Down Expand Up @@ -110,8 +110,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.0']
moodle-branch: ['MOODLE_311_STABLE', 'MOODLE_400_STABLE', 'MOODLE_401_STABLE']
php: ['8.0', '8.1']
moodle-branch: ['MOODLE_401_STABLE', 'MOODLE_402_STABLE']
database: ['mariadb', 'pgsql']
include:
- php: '7.4'
Expand All @@ -120,6 +120,18 @@ jobs:
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'

steps:
- name: Start MariaDB
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/moodle-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
--data-urlencode "altdownloadurl=${ZIPURL}" \
--data-urlencode "releasenotes=${BODY}" \
--data-urlencode "releasenotesformat=4")
echo "::set-output name=response::${RESPONSE}"
echo "response=${RESPONSE}" >> $GITHUB_OUTPUT
- name: Evaluate the response
id: evaluate-response
env:
Expand Down
2 changes: 1 addition & 1 deletion amd/build/rating.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/rating.min.js.map

Large diffs are not rendered by default.

67 changes: 61 additions & 6 deletions amd/src/rating.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ async function sendVote(postid, rating, userid) {
* Init function.
*
* @param {int} userid
* @param {boolean} allowmultiplemarks // true means allowed, false means not allowed.
*
*/
export function init(userid) {
export function init(userid, allowmultiplemarks) {
Prefetch.prefetchStrings('mod_moodleoverflow',
['marksolved', 'marknotsolved', 'markhelpful', 'marknothelpful',
'action_remove_upvote', 'action_upvote', 'action_remove_downvote', 'action_downvote']);
Expand Down Expand Up @@ -104,22 +106,75 @@ export function init(userid) {
case 'helpful':
case 'solved': {
const isHelpful = action === 'helpful';
const htmlclass = isHelpful ? 'statusstarter' : 'statusteacher';
const htmlclass = isHelpful ? 'markedhelpful' : 'markedsolution';
const shouldRemove = postElement.classList.contains(htmlclass);
const baseRating = isHelpful ? RATING_HELPFUL : RATING_SOLVED;
const rating = shouldRemove ? baseRating * 10 : baseRating;
await sendVote(postid, rating, userid);
for (const el of root.querySelectorAll('.moodleoverflowpost.' + htmlclass)) {
el.classList.remove(htmlclass);
el.querySelector(`[data-moodleoverflow-action="${action}"]`).textContent =
await getString(`mark${action}`, 'mod_moodleoverflow');

/* If multiplemarks are not allowed (that is the default mode): delete all marks.
else: only delete the mark if the post is being unmarked.
Add a mark, if the post is being marked.
*/
if (!allowmultiplemarks) {
// Delete all marks in the discussion
for (const el of root.querySelectorAll('.moodleoverflowpost.' + htmlclass)) {
el.classList.remove(htmlclass);
el.querySelector(`[data-moodleoverflow-action="${action}"]`).textContent =
await getString(`mark${action}`, 'mod_moodleoverflow');
}
} else {
// Remove only the mark of the unmarked post.
if (shouldRemove) {
postElement.classList.remove(htmlclass);
actionElement.textContent = await getString(`mark${action}`, 'mod_moodleoverflow');
changeStrings(htmlclass, action);
}
}
// If the post is being marked, mark it.
if (!shouldRemove) {
postElement.classList.add(htmlclass);
actionElement.textContent = await getString(`marknot${action}`, 'mod_moodleoverflow');
if (allowmultiplemarks) {
changeStrings(htmlclass, action);
}
}

}
}
};

}

/**
* Function to change the String of the post data-action button.
* Only used if mulitplemarks are allowed.
* @param {string} htmlclass the class where the String is being updated
* @param {string} action helpful or solved mark
*/
async function changeStrings(htmlclass, action) {
Prefetch.prefetchStrings('mod_moodleoverflow',
['marksolved', 'alsomarksolved', 'markhelpful', 'alsomarkhelpful',]);

// 1. Step: Are there other posts in the Discussion, that are solved/helpful?
var othermarkedposts = false;
for (const el of root.querySelectorAll('.moodleoverflowpost')) {
if (el.classList.contains(htmlclass)) {
othermarkedposts = true;
break;
}
}
// 2. Step: Change the strings of the action Button of the unmarked posts.
for (const el of root.querySelectorAll('.moodleoverflowpost')) {
if (!el.classList.contains(htmlclass) && el.querySelector(`[data-moodleoverflow-action="${action}"]`)) {
if (othermarkedposts) {
el.querySelector(`[data-moodleoverflow-action="${action}"]`).textContent =
await getString(`alsomark${action}`, 'mod_moodleoverflow');
} else {
el.querySelector(`[data-moodleoverflow-action="${action}"]`).textContent =
await getString(`mark${action}`, 'mod_moodleoverflow');
}
}
}
}
35 changes: 35 additions & 0 deletions classes/capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,57 @@
*/
class capabilities {

/** capability add instance */
const ADD_INSTANCE = 'mod/moodleoverflow:addinstance';

/** capability view discussions*/
const VIEW_DISCUSSION = 'mod/moodleoverflow:viewdiscussion';

/** capability reply in discussions*/
const REPLY_POST = 'mod/moodleoverflow:replypost';

/** capability start discussions*/
const START_DISCUSSION = 'mod/moodleoverflow:startdiscussion';

/** capability edit post from other course participants*/
const EDIT_ANY_POST = 'mod/moodleoverflow:editanypost';

/** capability delete your post*/
const DELETE_OWN_POST = 'mod/moodleoverflow:deleteownpost';

/** capability delete post from any course participant*/
const DELETE_ANY_POST = 'mod/moodleoverflow:deleteanypost';

/** capability rate a post*/
const RATE_POST = 'mod/moodleoverflow:ratepost';

/** capability mark a post as a solution for a questions*/
const MARK_SOLVED = 'mod/moodleoverflow:marksolved';

/** capability manage the subscription of a moodleoverflow instance */
const MANAGE_SUBSCRIPTIONS = 'mod/moodleoverflow:managesubscriptions';

/** capability force the subscription of participants */
const ALLOW_FORCE_SUBSCRIBE = 'mod/moodleoverflow:allowforcesubscribe';

/** capability attach files to posts */
const CREATE_ATTACHMENT = 'mod/moodleoverflow:createattachment';

/** capability review post to be published*/
const REVIEW_POST = 'mod/moodleoverflow:reviewpost';

/** @var array cache capabilities*/
private static $cache = [];

/**
* Saves the cache from has_capability.
*
* @param string $capability The capability that is being checked.
* @param context $context The context.
* @param int|null $userid The user ID.
*
* @return bool true or false
*/
public static function has(string $capability, context $context, $userid = null): bool {
global $USER;
if (!$userid) {
Expand Down
20 changes: 10 additions & 10 deletions classes/output/moodleoverflow_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ public function export_for_template(\renderer_base $renderer, $plaintext = false
protected function export_for_template_text(\mod_moodleoverflow_renderer $renderer) {

return array(
'id' => html_entity_decode($this->post->id),
'coursename' => html_entity_decode($this->get_coursename()),
'courselink' => html_entity_decode($this->get_courselink()),
'moodleoverflowname' => html_entity_decode($this->get_moodleoverflowname()),
'showdiscussionname' => html_entity_decode($this->has_showdiscussionname()),
'discussionname' => html_entity_decode($this->get_discussionname()),
'subject' => html_entity_decode($this->get_subject()),
'authorfullname' => html_entity_decode($this->get_author_fullname()),
'postdate' => html_entity_decode($this->get_postdate()),
'id' => html_entity_decode($this->post->id, ENT_COMPAT),
'coursename' => html_entity_decode($this->get_coursename(), ENT_COMPAT),
'courselink' => html_entity_decode($this->get_courselink(), ENT_COMPAT),
'moodleoverflowname' => html_entity_decode($this->get_moodleoverflowname(), ENT_COMPAT),
'showdiscussionname' => html_entity_decode($this->has_showdiscussionname(), ENT_COMPAT),
'discussionname' => html_entity_decode($this->get_discussionname(), ENT_COMPAT),
'subject' => html_entity_decode($this->get_subject(), ENT_COMPAT),
'authorfullname' => html_entity_decode($this->get_author_fullname(), ENT_COMPAT),
'postdate' => html_entity_decode($this->get_postdate(), ENT_COMPAT),
'firstpost' => $this->is_firstpost(),
'canreply' => $this->canreply,
'permalink' => $this->get_permalink(),
Expand All @@ -179,7 +179,7 @@ protected function export_for_template_text(\mod_moodleoverflow_renderer $render
'grouppicture' => $this->get_group_picture(),

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

Expand Down
Loading

0 comments on commit 65eef2b

Please sign in to comment.