Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/moodle 402 #130

Merged
merged 39 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
03d29fb
setting for multiplemarks added
TamaroWalter Apr 4, 2023
a357fd4
1. feature added, multiple marks are now possible, feature not comple…
TamaroWalter Apr 5, 2023
b98a9de
comment added for marks setting in discussion.php
TamaroWalter Apr 6, 2023
d2d9d2c
multiplemarks-checkbox bug fixed
TamaroWalter Apr 6, 2023
5b04f0e
WIP: change button string if posts are marked
TamaroWalter Apr 17, 2023
f08df49
WIP: change button strings is not working
TamaroWalter Apr 18, 2023
0c6855d
feature problems solved, multiple marks are now really possible
TamaroWalter Apr 24, 2023
e3f2beb
merge conflicts fixed
TamaroWalter Apr 24, 2023
865c60f
revert problems fixed
TamaroWalter Apr 24, 2023
fe52f57
Revert "WIP: change button string if posts are marked"
TamaroWalter Apr 24, 2023
68609d6
Revert "comment added for marks setting in discussion.php"
TamaroWalter Apr 24, 2023
a781f29
mark button strings update on reload, only js still needed
TamaroWalter Apr 24, 2023
6671a63
js added to change action button strings. Feature ready for pull request
TamaroWalter Apr 25, 2023
5e11d7d
update 4.2
TamaroWalter May 8, 2023
5d3ccad
phpUnit issues fixed for 402 update
TamaroWalter May 8, 2023
32e14fb
phpdoc issues fixed
TamaroWalter May 8, 2023
8f94ae0
Merge branch 'master' into feature/multipleratings
NinaHerrmann May 9, 2023
08fd0f8
Merge branch 'feature/multipleratings' into update/Moodle_402
NinaHerrmann May 9, 2023
58fcc2f
new build
NinaHerrmann May 9, 2023
3c79050
Update capabilities.php
NinaHerrmann May 12, 2023
723cdce
Update ratings.php
NinaHerrmann May 12, 2023
656420b
Update dailymail_test.php
NinaHerrmann May 12, 2023
cdf2085
Update userstats_test.php
NinaHerrmann May 12, 2023
565c6dc
post sorting updated1
TamaroWalter May 15, 2023
8c8086b
Merge branch 'update/Moodle_402' of github.com:learnweb/moodle-mod_mo…
TamaroWalter May 15, 2023
0951e8d
WIP: sort of posts by rating
TamaroWalter May 15, 2023
82e7ff7
minor changes
NinaHerrmann May 15, 2023
a161e7a
rename statusteacher and statusstarter in markedhelpful and markedsol…
NinaHerrmann May 15, 2023
f278128
grunt build
NinaHerrmann May 15, 2023
5294e80
WIP - var_dumps to check missing post in ratings.php sorting
NinaHerrmann May 16, 2023
4145d3c
sorting error fixed in ratings.php
TamaroWalter May 16, 2023
c76720f
WIP: write test cases for rating.php
TamaroWalter May 16, 2023
bf93575
coding style
NinaHerrmann May 16, 2023
97f2258
WIP: write test cases for ratings.php
TamaroWalter May 16, 2023
cac514b
test cases completed for ratings.php
TamaroWalter May 22, 2023
3003623
force encoding to ENT_COMPAT (default in php < 8.1)
NinaHerrmann May 22, 2023
fdfec0e
code checking and cleaning
TamaroWalter May 22, 2023
d7cb0d8
last changes on version number for release
TamaroWalter May 22, 2023
8e761b3
behat problems fixed
TamaroWalter May 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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