Fix gradebook score update BT#17403

pull/3312/head
Julio Montoya 5 years ago
parent 0dc3c359c5
commit 2aa0a6318d
  1. 14
      main/gradebook/gradebook_scoring_system.php
  2. 53
      main/gradebook/lib/scoredisplay.class.php

@ -40,14 +40,18 @@ $interbreadcrumb[] = [
'name' => get_lang('ToolGradebook'), 'name' => get_lang('ToolGradebook'),
]; ];
$select_cat = (int) $_GET['selectcat']; $categoryId = (int) $_GET['selectcat'];
$displayScore = ScoreDisplay::instance(); if (empty($categoryId)) {
api_not_allowed(true);
}
$displayScore = ScoreDisplay::instance($categoryId);
$customdisplays = $displayScore->get_custom_score_display_settings(); $customdisplays = $displayScore->get_custom_score_display_settings();
$nr_items = count($customdisplays) != '0' ? count($customdisplays) : '1'; $nr_items = count($customdisplays) != '0' ? count($customdisplays) : '1';
$scoreform = new ScoreDisplayForm( $scoreform = new ScoreDisplayForm(
'scoring_system_form', 'scoring_system_form',
api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq() api_get_self().'?selectcat='.$categoryId.'&'.api_get_cidreq()
); );
if ($scoreform->validate()) { if ($scoreform->validate()) {
@ -83,7 +87,7 @@ if ($scoreform->validate()) {
false false
) )
); );
header('Location: '.api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq()); header('Location: '.api_get_self().'?selectcat='.$categoryId.'&'.api_get_cidreq());
exit; exit;
} }
@ -100,7 +104,7 @@ if ($scoreform->validate()) {
Display::return_message(get_lang('ScoringUpdated'), 'confirm', false) Display::return_message(get_lang('ScoringUpdated'), 'confirm', false)
); );
header('Location:'.api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq()); header('Location:'.api_get_self().'?selectcat='.$categoryId.'&'.api_get_cidreq());
exit; exit;
} }

@ -93,15 +93,15 @@ class ScoreDisplay
/** /**
* Get the instance of this class. * Get the instance of this class.
* *
* @param int $category_id * @param int $categoryId
* *
* @return ScoreDisplay * @return ScoreDisplay
*/ */
public static function instance($category_id = 0) public static function instance($categoryId = 0)
{ {
static $instance; static $instance;
if (!isset($instance)) { if (!isset($instance)) {
$instance = new ScoreDisplay($category_id); $instance = new ScoreDisplay($categoryId);
} }
return $instance; return $instance;
@ -114,18 +114,20 @@ class ScoreDisplay
{ {
if (!isset($score1)) { if (!isset($score1)) {
return isset($score2) ? 1 : 0; return isset($score2) ? 1 : 0;
} elseif (!isset($score2)) { }
if (!isset($score2)) {
return -1; return -1;
} else {
$scoreDisplay = self::instance();
$custom1 = $scoreDisplay->display_custom($score1);
$custom2 = $scoreDisplay->display_custom($score2);
if ($custom1 == $custom2) {
return 0;
} else {
return ($score1[0] / $score1[1]) < ($score2[0] / $score2[1]) ? -1 : 1;
}
} }
$scoreDisplay = self::instance();
$custom1 = $scoreDisplay->display_custom($score1);
$custom2 = $scoreDisplay->display_custom($score2);
if ($custom1 == $custom2) {
return 0;
}
return ($score1[0] / $score1[1]) < ($score2[0] / $score2[1]) ? -1 : 1;
} }
/** /**
@ -346,25 +348,20 @@ class ScoreDisplay
private function get_current_gradebook_category_id() private function get_current_gradebook_category_id()
{ {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$curr_course_code = api_get_course_id(); $courseCode = api_get_course_id();
$curr_session_id = api_get_session_id(); $sessionId = api_get_session_id();
$sessionCondition = api_get_session_condition($sessionId, true);
if (empty($curr_session_id)) { $sql = "SELECT id FROM $table
$session_condition = ' AND session_id is null '; WHERE course_code = '$courseCode' $sessionCondition";
} else {
$session_condition = ' AND session_id = '.$curr_session_id;
}
$sql = 'SELECT id FROM '.$table.'
WHERE course_code = "'.$curr_course_code.'" '.$session_condition;
$rs = Database::query($sql); $rs = Database::query($sql);
$category_id = 0; $categoryId = 0;
if (Database::num_rows($rs) > 0) { if (Database::num_rows($rs) > 0) {
$row = Database::fetch_row($rs); $row = Database::fetch_row($rs);
$category_id = $row[0]; $categoryId = $row[0];
} }
return $category_id; return $categoryId;
} }
/** /**
@ -524,7 +521,7 @@ class ScoreDisplay
{ {
$tbl_display = Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY); $tbl_display = Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY);
if (isset($category_id)) { if (isset($category_id)) {
$category_id = intval($category_id); $category_id = (int) $category_id;
} else { } else {
$category_id = $this->get_current_gradebook_category_id(); $category_id = $this->get_current_gradebook_category_id();
} }
@ -553,7 +550,7 @@ class ScoreDisplay
{ {
$tbl_display = Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY); $tbl_display = Database::get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY);
if (isset($category_id)) { if (isset($category_id)) {
$category_id = intval($category_id); $category_id = (int) $category_id;
} else { } else {
$category_id = $this->get_current_gradebook_category_id(); $category_id = $this->get_current_gradebook_category_id();
} }

Loading…
Cancel
Save