Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion amd/build/functions.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/notification', 'core/conf
// Update user reputation.
templates.replaceNode($('.user-details,.author').find('a[href*="id=' + userid + '"]')
.siblings('span'), '<span>' + response.raterreputation + '</span>', "");
if (userid !== response.ownerid) {
if (response.ownerid && userid !== response.ownerid) {
templates.replaceNode($('.user-details,.author').find('a[href*="id=' + response.ownerid + '"]')
.siblings('span'), '<span>' + response.ownerreputation + '</span>', "");
}
Expand Down
58 changes: 58 additions & 0 deletions classes/anonymous.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
// This file is part of a plugin for Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Moodleoverflow anonymous related class.
*
* @package mod_moodleoverflow
* @copyright 2021 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace mod_moodleoverflow;

defined('MOODLE_INTERNAL') || die();

/**
* Class for Moodleoverflow anonymity
*
* @package mod_moodleoverflow
* @copyright 2021 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class anonymous {

const NOT_ANONYMOUS = 0;
const QUESTION_ANONYMOUS = 1;
const EVERYTHING_ANONYMOUS = 2;

public static function is_post_anonymous($post, $moodleoverflow, $postinguserid): bool {
if ($postinguserid == 0) {
return true;
}

if ($moodleoverflow->anonymous == self::EVERYTHING_ANONYMOUS) {
return true;
}

if ($moodleoverflow->anonymous == self::QUESTION_ANONYMOUS) {
return $post->parent == 0;
}

return false;
}

}
19 changes: 18 additions & 1 deletion classes/output/moodleoverflow_email.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

namespace mod_moodleoverflow\output;

use mod_moodleoverflow\anonymous;

defined('MOODLE_INTERNAL') || die();

/**
Expand Down Expand Up @@ -357,7 +359,11 @@ public function get_discussionname() {
* @return string
*/
public function get_author_fullname() {
return fullname($this->author, $this->viewfullnames);
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
return get_string('privacy:anonym_user_name', 'mod_moodleoverflow');
} else {
return fullname($this->author, $this->viewfullnames);
}
}

/**
Expand Down Expand Up @@ -515,6 +521,10 @@ public function get_moodleoverflowviewlink() {
* @return string
*/
public function get_authorlink() {
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
return null;
}

$link = new \moodle_url(
'/user/view.php', array(
'id' => $this->post->userid,
Expand All @@ -532,6 +542,9 @@ public function get_authorlink() {
*/
public function get_author_picture() {
global $OUTPUT;
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
return '';
}

return $OUTPUT->user_picture($this->author, array('courseid' => $this->course->id));
}
Expand All @@ -542,6 +555,10 @@ public function get_author_picture() {
* @return string
*/
public function get_group_picture() {
if (anonymous::is_post_anonymous($this->post, $this->moodleoverflow, $this->author->id)) {
return '';
}

if (isset($this->userfrom->groups)) {
$groups = $this->userfrom->groups[$this->moodleoverflow->id];
} else {
Expand Down
79 changes: 44 additions & 35 deletions classes/ratings.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,51 +465,60 @@ private static function moodleoverflow_get_reputation_instance($moodleoverflowid
print_error('invalidmoodleoverflowid', 'moodleoverflow');
}

// Get all posts of this user in this module.
// Do not count votes for own posts.
$sql = "SELECT r.id, r.postid as post, r.rating
// Initiate a variable.
$reputation = 0;

if ($moodleoverflow->anonymous != anonymous::EVERYTHING_ANONYMOUS) {

// Get all posts of this user in this module.
// Do not count votes for own posts.
$sql = "SELECT r.id, r.postid as post, r.rating
FROM {moodleoverflow_posts} p
JOIN {moodleoverflow_ratings} r ON p.id = r.postid
WHERE p.userid = ? AND NOT r.userid = ? AND r.moodleoverflowid = ?
ORDER BY r.postid ASC";
$params = array($userid, $userid, $moodleoverflowid);
$records = $DB->get_records_sql($sql, $params);
WHERE p.userid = ? AND NOT r.userid = ? AND r.moodleoverflowid = ? ";

// Check if there are results.
$records = (isset($records)) ? $records : array();
if ($moodleoverflow->anonymous == anonymous::QUESTION_ANONYMOUS) {
$sql .= " AND p.parent <> 0 ";
}

// Initiate a variable.
$reputation = 0;
$sql .= "ORDER BY r.postid ASC";

// Iterate through all ratings.
foreach ($records as $record) {
$params = array($userid, $userid, $moodleoverflowid);
$records = $DB->get_records_sql($sql, $params);

// The rating is a downvote.
if ($record->rating == RATING_DOWNVOTE) {
$reputation += get_config('moodleoverflow', 'votescaledownvote');
continue;
}
// Check if there are results.
$records = (isset($records)) ? $records : array();

// The rating is an upvote.
if ($record->rating == RATING_UPVOTE) {
$reputation += get_config('moodleoverflow', 'votescaleupvote');
continue;
}
// Iterate through all ratings.
foreach ($records as $record) {

// The post has been marked as helpful by the question owner.
if ($record->rating == RATING_HELPFUL) {
$reputation += get_config('moodleoverflow', 'votescalehelpful');
continue;
}
// The rating is a downvote.
if ($record->rating == RATING_DOWNVOTE) {
$reputation += get_config('moodleoverflow', 'votescaledownvote');
continue;
}

// The post has been marked as solved by a teacher.
if ($record->rating == RATING_SOLVED) {
$reputation += get_config('moodleoverflow', 'votescalesolved');
// The rating is an upvote.
if ($record->rating == RATING_UPVOTE) {
$reputation += get_config('moodleoverflow', 'votescaleupvote');
continue;
}

// The post has been marked as helpful by the question owner.
if ($record->rating == RATING_HELPFUL) {
$reputation += get_config('moodleoverflow', 'votescalehelpful');
continue;
}

// The post has been marked as solved by a teacher.
if ($record->rating == RATING_SOLVED) {
$reputation += get_config('moodleoverflow', 'votescalesolved');
continue;
}

// Another rating should not exist.
continue;
}

// Another rating should not exist.
continue;
}

// Get votes this user made.
Expand Down Expand Up @@ -806,4 +815,4 @@ private static function moodleoverflow_user_can_rate($moodleoverflow, $cm = null
return has_capability('mod/moodleoverflow:ratepost', $modulecontext, $userid);
}

}
}
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<FIELD NAME="grademaxgrade" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="gradescalefactor" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="gradecat" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="anonymous" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
Expand Down
17 changes: 17 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,22 @@ function xmldb_moodleoverflow_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2019052600, 'moodleoverflow');
}

if ($oldversion < 2021060800) {

// Define table moodleoverflow to be edited
$table = new xmldb_table('moodleoverflow');

// Define field anonymous to be added to moodleoverflow.
$field = new xmldb_field('anonymous', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, 0, 'gradecat');

// Conditionally launch add field grademaxgrade.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Moodleoverflow savepoint reached.
upgrade_mod_savepoint(true, 2021060800, 'moodleoverflow');
}

return true;
}
Loading