Skip to content

Commit

Permalink
Merge pull request #3 from willianmano/VERSION2
Browse files Browse the repository at this point in the history
Version2.1
  • Loading branch information
willianmano committed Aug 13, 2015
2 parents 456667f + b719460 commit 041e74d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 14 deletions.
21 changes: 18 additions & 3 deletions classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,25 @@ class block_ranking_helper {
* @return void
*/
public static function observer(\core\event\base $event) {
global $DB;


if (!self::is_student($event->relateduserid)) {
return;
}

if ($event->eventname == '\mod_quiz\event\attempt_submitted') {

$enablemultipleattempts = $DB->get_record('config_plugins', array('plugin' => 'block_ranking', 'name' => 'enable_multiple_quizz_attempts'));

if (isset($enablemultipleattempts) && $enablemultipleattempts->value == 0) {
$isrepeated = self::is_completion_repeated($event->courseid, $event->relateduserid, $event->contextinstanceid);

if ($isrepeated) {
return;
}
}

$objectid = self::get_coursemodule_instance($event->contextinstanceid, $event->relateduserid);

if ($objectid) {
Expand All @@ -64,7 +77,7 @@ public static function observer(\core\event\base $event) {
return;
}

if (self::is_completion_repeated($event->courseid, $event->relateduserid, $event->objectid)) {
if (self::is_completion_repeated($event->courseid, $event->relateduserid, $event->contextinstanceid)) {
return;
}

Expand Down Expand Up @@ -145,7 +158,7 @@ protected static function is_completion_repeated($courseid, $userid, $cmcid) {
global $DB;

$sql = "SELECT
*
count(*) as qtd
FROM {ranking_points} p
INNER JOIN {ranking_logs} l ON l.rankingid = p.id
WHERE p.courseid = :courseid
Expand All @@ -156,6 +169,8 @@ protected static function is_completion_repeated($courseid, $userid, $cmcid) {
$params['userid'] = $userid;
$params['cmcid'] = $cmcid;

return $DB->get_record_sql($sql, $params);
$qtd = $DB->get_record_sql($sql, $params);

return (int) $qtd->qtd;
}
}
18 changes: 10 additions & 8 deletions classes/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class block_ranking_manager {
*
* @return void
*/
public static function add_user_points($cmcid, $grade) {
public static function add_user_points($cmcid, $grade = null) {

$usercompletion = self::get_module_completion($cmcid);

Expand Down Expand Up @@ -116,27 +116,29 @@ protected static function get_module_completion($cmcid) {
*
* @return void
*/
protected static function add_default_points($completion, $points = null, $grade) {
protected static function add_default_points($completion, $points = null, $grade = null) {

if (!isset($points) || trim($points) != '') {
$points = self::DEFAULT_POINTS;
}

if (!empty($completion->completiongradeitemnumber)) {
$activitygrade = self::get_activity_finalgrade($completion->modulename, $completion->instance, $completion->userid);
$points += $activitygrade;
} else if (!empty($grade)) {

if (!empty($grade)) {
if ($grade > 10) {
$grade = $grade / 10;
}

$points += $grade;
} else {
$activitygrade = self::get_activity_finalgrade($completion->modulename, $completion->instance, $completion->userid);

if ($activitygrade) {
$points += $activitygrade;
}
}

$rankingid = self::add_or_update_user_points($completion->userid, $completion->course, $points);

self::add_ranking_log($rankingid, $completion->course, $completion->id, $points);
self::add_ranking_log($rankingid, $completion->course, $completion->coursemoduleid, $points);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion lang/en/block_ranking.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@

$string['monthly'] = 'Monthly';
$string['weekly'] = 'Weekly';
$string['general'] = 'General';
$string['general'] = 'General';

$string['yes'] = 'Yes';
$string['no'] = 'No';

$string['enable_multiple_quizz_attempts'] = 'Enable multiple quizz attempts';
$string['enable_multiple_quizz_attempts_help'] = 'Enable studens to add points in every quizz attempt. If this options is marked as NO, the student only will receive the points of the first attempt.';
8 changes: 7 additions & 1 deletion lang/pt_br/block_ranking.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,10 @@

$string['monthly'] = 'Mensal';
$string['weekly'] = 'Semanal';
$string['general'] = 'Geral';
$string['general'] = 'Geral';

$string['yes'] = 'Sim';
$string['no'] = 'Não';

$string['enable_multiple_quizz_attempts'] = 'Habilitar mútiplas tentativas no quizz';
$string['enable_multiple_quizz_attempts_help'] = 'Possibilita que os estudantes ganhem pontos em todas as tentativa no quizz. Se essa opção for marcada como não, o estudante só receberá os pontos da primeira tentativa.';
3 changes: 3 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@

$settings->add(new admin_setting_configtext('block_ranking/defaultpoints', get_string('defaultpoints', 'block_ranking'),
'', 2, PARAM_INT));

$settings->add(new admin_setting_configselect('block_ranking/enable_multiple_quizz_attempts', get_string('enable_multiple_quizz_attempts', 'block_ranking'),
get_string('enable_multiple_quizz_attempts_help', 'block_ranking'), '1', array('1' => get_string('yes', 'block_ranking'), '0' => get_string('no', 'block_ranking'))));
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

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

$plugin->version = 2015051800;
$plugin->version = 2015081300;
$plugin->requires = 2011120511;
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Version for Moodle 2.9 onwards';
Expand Down

0 comments on commit 041e74d

Please sign in to comment.