Minor - format code.

pull/2487/head
jmontoyaa 8 years ago
parent e41eabf25d
commit 9df170dbc2
  1. 16
      main/gradebook/lib/GradebookUtils.php
  2. 42
      main/gradebook/lib/flatview_data_generator.class.php
  3. 7
      main/gradebook/lib/gradebook_data_generator.class.php
  4. 14
      main/gradebook/lib/results_data_generator.class.php
  5. 11
      main/gradebook/lib/scoredisplay.class.php
  6. 54
      main/gradebook/lib/user_data_generator.class.php

@ -482,8 +482,14 @@ class GradebookUtils
* @param null $mainCourseCategory * @param null $mainCourseCategory
* @return array * @return array
*/ */
public static function get_printable_data($cat, $users, $alleval, $alllinks, $params, $mainCourseCategory = null) public static function get_printable_data(
{ $cat,
$users,
$alleval,
$alllinks,
$params,
$mainCourseCategory = null
) {
$datagen = new FlatViewDataGenerator( $datagen = new FlatViewDataGenerator(
$users, $users,
$alleval, $alleval,
@ -684,8 +690,10 @@ class GradebookUtils
* @param int $cat_id The category id * @param int $cat_id The category id
* @return array * @return array
*/ */
public static function get_list_gradebook_certificates_by_user_id($user_id, $cat_id = null) public static function get_list_gradebook_certificates_by_user_id(
{ $user_id,
$cat_id = null
) {
$table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
$sql = 'SELECT $sql = 'SELECT
gc.score_certificate, gc.score_certificate,

@ -863,7 +863,14 @@ class FlatViewDataGenerator
$row[] = array( $row[] = array(
$item_value, $item_value,
trim($scoredisplay->display_score($real_score, SCORE_CUSTOM, null, true)) trim(
$scoredisplay->display_score(
$real_score,
SCORE_CUSTOM,
null,
true
)
)
); );
$item_value_total += $item_value; $item_value_total += $item_value;
$final_score += $score[0]; $final_score += $score[0];
@ -873,7 +880,14 @@ class FlatViewDataGenerator
$total_score = array($final_score, $item_total); $total_score = array($final_score, $item_total);
$row[] = array( $row[] = array(
$final_score, $final_score,
trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)) trim(
$scoredisplay->display_score(
$total_score,
SCORE_CUSTOM,
null,
true
)
)
); );
} else { } else {
for ($count = 0; $count < count($this->evals_links); $count++) { for ($count = 0; $count < count($this->evals_links); $count++) {
@ -884,7 +898,17 @@ class FlatViewDataGenerator
$item_total += $item->get_weight(); $item_total += $item->get_weight();
$score_denom = ($score[1] == 0) ? 1 : $score[1]; $score_denom = ($score[1] == 0) ? 1 : $score[1];
$score_final = ($score[0] / $score_denom) * 100; $score_final = ($score[0] / $score_denom) * 100;
$row[] = array($score_final, trim($scoredisplay->display_score($score, SCORE_CUSTOM, null, true))); $row[] = array(
$score_final,
trim(
$scoredisplay->display_score(
$score,
SCORE_CUSTOM,
null,
true
)
)
);
} }
$total_score = array($item_value, $item_total); $total_score = array($item_value, $item_total);
@ -892,7 +916,17 @@ class FlatViewDataGenerator
if ($displayWarning) { if ($displayWarning) {
echo Display::return_message($total_score[1], 'warning'); echo Display::return_message($total_score[1], 'warning');
} }
$row[] = array($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); $row[] = array(
$score_final,
trim(
$scoredisplay->display_score(
$total_score,
SCORE_CUSTOM,
null,
true
)
)
);
} }
$data[] = $row; $data[] = $row;

@ -334,7 +334,11 @@ class GradebookDataGenerator
$type = $item->get_item_type(); $type = $item->get_item_type();
if ($type == 'L' && get_class($item) == 'ExerciseLink') { if ($type == 'L' && get_class($item) == 'ExerciseLink') {
$display = ExerciseLib::show_score($score[0], $score[1], false); $display = ExerciseLib::show_score(
$score[0],
$score[1],
false
);
} }
return array( return array(
@ -374,6 +378,7 @@ class GradebookDataGenerator
* Returns the link to the certificate generation, if the score is enough, otherwise * Returns the link to the certificate generation, if the score is enough, otherwise
* returns an empty string. This only works with categories. * returns an empty string. This only works with categories.
* @param object Item * @param object Item
* @return string
*/ */
public function get_certificate_link($item) public function get_certificate_link($item)
{ {

@ -54,8 +54,13 @@ class ResultsDataGenerator
* 4 ['score'] : student's score * 4 ['score'] : student's score
* 5 ['display'] : custom score display (only if custom scoring enabled) * 5 ['display'] : custom score display (only if custom scoring enabled)
*/ */
public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false, $pdf = false) public function get_data(
{ $sorting = 0,
$start = 0,
$count = null,
$ignore_score_color = false,
$pdf = false
) {
// do some checks on count, redefine if invalid value // do some checks on count, redefine if invalid value
$number_decimals = api_get_setting('gradebook_number_decimals'); $number_decimals = api_get_setting('gradebook_number_decimals');
if (!isset($count)) { if (!isset($count)) {
@ -86,7 +91,8 @@ class ResultsDataGenerator
$ignore_score_color $ignore_score_color
); );
} }
$user['percentage_score'] = intval($scoredisplay->display_score( $user['percentage_score'] = intval(
$scoredisplay->display_score(
array($result->get_score(), $this->evaluation->get_max()), array($result->get_score(), $this->evaluation->get_max()),
SCORE_PERCENT, SCORE_PERCENT,
SCORE_BOTH, SCORE_BOTH,
@ -132,7 +138,7 @@ class ResultsDataGenerator
* @param bool Whether we want the real score (2/4 (50 %)) or the transformation (A, B, C, etc) * @param bool Whether we want the real score (2/4 (50 %)) or the transformation (A, B, C, etc)
* @param bool Whether we want to ignore the score color * @param bool Whether we want to ignore the score color
* @param boolean $realscore * @param boolean $realscore
* @result string The score as we want to show it * @return string The score as we want to show it
*/ */
private function get_score_display($score, $realscore, $ignore_score_color = false) private function get_score_display($score, $realscore, $ignore_score_color = false)
{ {

@ -24,7 +24,7 @@ class ScoreDisplay
public static function instance($category_id = 0) public static function instance($category_id = 0)
{ {
static $instance; static $instance;
if (!isset ($instance)) { if (!isset($instance)) {
$instance = new ScoreDisplay($category_id); $instance = new ScoreDisplay($category_id);
} }
@ -197,8 +197,11 @@ class ScoreDisplay
* @param int score color percent (optional) * @param int score color percent (optional)
* @param int gradebook category id (optional) * @param int gradebook category id (optional)
*/ */
public function update_custom_score_display_settings($displays, $scorecolpercent = 0, $category_id = null) public function update_custom_score_display_settings(
{ $displays,
$scorecolpercent = 0,
$category_id = null
) {
$this->custom_display = $displays; $this->custom_display = $displays;
$this->custom_display_conv = $this->convert_displays($this->custom_display); $this->custom_display_conv = $this->convert_displays($this->custom_display);
@ -448,6 +451,7 @@ class ScoreDisplay
/** /**
* Depends on the teacher's configuration of thresholds. i.e. [0 50] "Bad", [50:100] "Good" * Depends on the teacher's configuration of thresholds. i.e. [0 50] "Bad", [50:100] "Good"
* @param array $score * @param array $score
* @return string
*/ */
private function display_custom($score) private function display_custom($score)
{ {
@ -564,7 +568,6 @@ class ScoreDisplay
private function sort_display($item1, $item2) private function sort_display($item1, $item2)
{ {
if ($item1['score'] === $item2['score']) { if ($item1['score'] === $item2['score']) {
return 0; return 0;
} else { } else {
return ($item1['score'] < $item2['score'] ? -1 : 1); return ($item1['score'] < $item2['score'] ? -1 : 1);

@ -39,7 +39,6 @@ class UserDataGenerator
public function __construct($userid, $evals = array(), $links = array()) public function __construct($userid, $evals = array(), $links = array())
{ {
$this->userid = $userid; $this->userid = $userid;
$evals_filtered = array();
$result = array(); $result = array();
foreach ($evals as $eval) { foreach ($evals as $eval) {
$toadd = true; $toadd = true;
@ -87,8 +86,12 @@ class UserDataGenerator
* 5: student's score * 5: student's score
* 6: student's score as custom display (only if custom scoring enabled) * 6: student's score as custom display (only if custom scoring enabled)
*/ */
public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) public function get_data(
{ $sorting = 0,
$start = 0,
$count = null,
$ignore_score_color = false
) {
// do some checks on count, redefine if invalid value // do some checks on count, redefine if invalid value
if (!isset($count)) { if (!isset($count)) {
$count = count($this->items) - $start; $count = count($this->items) - $start;
@ -167,7 +170,7 @@ class UserDataGenerator
* @param $item2 * @param $item2
* @return int * @return int
*/ */
function sort_by_type($item1, $item2) public function sort_by_type($item1, $item2)
{ {
if ($item1->get_item_type() == $item2->get_item_type()) { if ($item1->get_item_type() == $item2->get_item_type()) {
return $this->sort_by_name($item1, $item2); return $this->sort_by_name($item1, $item2);
@ -181,10 +184,14 @@ class UserDataGenerator
* @param $item2 * @param $item2
* @return int * @return int
*/ */
function sort_by_course($item1, $item2) public function sort_by_course($item1, $item2)
{ {
$name1 = api_strtolower($this->get_course_name_from_code_cached($item1->get_course_code())); $name1 = api_strtolower(
$name2 = api_strtolower($this->get_course_name_from_code_cached($item2->get_course_code())); $this->get_course_name_from_code_cached($item1->get_course_code())
);
$name2 = api_strtolower(
$this->get_course_name_from_code_cached($item2->get_course_code())
);
return api_strnatcmp($name1, $name2); return api_strnatcmp($name1, $name2);
} }
@ -193,7 +200,7 @@ class UserDataGenerator
* @param $item2 * @param $item2
* @return int * @return int
*/ */
function sort_by_category($item1, $item2) public function sort_by_category($item1, $item2)
{ {
$cat1 = $this->get_category_cached($item1->get_category_id()); $cat1 = $this->get_category_cached($item1->get_category_id());
$cat2 = $this->get_category_cached($item2->get_category_id()); $cat2 = $this->get_category_cached($item2->get_category_id());
@ -208,7 +215,7 @@ class UserDataGenerator
* @param $item2 * @param $item2
* @return int * @return int
*/ */
function sort_by_name($item1, $item2) public function sort_by_name($item1, $item2)
{ {
return api_strnatcmp($item1->get_name(), $item2->get_name()); return api_strnatcmp($item1->get_name(), $item2->get_name());
} }
@ -218,7 +225,7 @@ class UserDataGenerator
* @param $item2 * @param $item2
* @return int * @return int
*/ */
function sort_by_average($item1, $item2) public function sort_by_average($item1, $item2)
{ {
$score1 = $this->avgcache[$item1->get_item_type().$item1->get_id()]; $score1 = $this->avgcache[$item1->get_item_type().$item1->get_id()];
$score2 = $this->avgcache[$item2->get_item_type().$item2->get_id()]; $score2 = $this->avgcache[$item2->get_item_type().$item2->get_id()];
@ -231,7 +238,7 @@ class UserDataGenerator
* @param $item2 * @param $item2
* @return int * @return int
*/ */
function sort_by_score($item1, $item2) public function sort_by_score($item1, $item2)
{ {
$score1 = $this->scorecache[$item1->get_item_type().$item1->get_id()]; $score1 = $this->scorecache[$item1->get_item_type().$item1->get_id()];
$score2 = $this->scorecache[$item2->get_item_type().$item2->get_id()]; $score2 = $this->scorecache[$item2->get_item_type().$item2->get_id()];
@ -244,7 +251,7 @@ class UserDataGenerator
* @param $item2 * @param $item2
* @return int * @return int
*/ */
function sort_by_mask($item1, $item2) public function sort_by_mask($item1, $item2)
{ {
$score1 = $this->scorecache[$item1->get_item_type().$item1->get_id()]; $score1 = $this->scorecache[$item1->get_item_type().$item1->get_id()];
$score2 = $this->scorecache[$item2->get_item_type().$item2->get_id()]; $score2 = $this->scorecache[$item2->get_item_type().$item2->get_id()];
@ -257,7 +264,7 @@ class UserDataGenerator
* @param $score2 * @param $score2
* @return int * @return int
*/ */
function compare_scores($score1, $score2) public function compare_scores($score1, $score2)
{ {
if (!isset($score1)) { if (!isset($score1)) {
return (isset($score2) ? 1 : 0); return (isset($score2) ? 1 : 0);
@ -325,7 +332,11 @@ class UserDataGenerator
$displaytype |= SCORE_IGNORE_SPLIT; $displaytype |= SCORE_IGNORE_SPLIT;
} }
return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_DEFAULT); return $scoredisplay->display_score(
$studscore,
$displaytype,
SCORE_ONLY_DEFAULT
);
} }
/** /**
@ -341,7 +352,12 @@ class UserDataGenerator
if ($ignore_score_color) { if ($ignore_score_color) {
$displaytype |= SCORE_IGNORE_SPLIT; $displaytype |= SCORE_IGNORE_SPLIT;
} }
return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_CUSTOM);
return $scoredisplay->display_score(
$studscore,
$displaytype,
SCORE_ONLY_CUSTOM
);
} }
/** /**
@ -350,7 +366,9 @@ class UserDataGenerator
*/ */
private function get_course_name_from_code_cached($coursecode) private function get_course_name_from_code_cached($coursecode)
{ {
if (isset($this->coursecodecache) && isset($this->coursecodecache[$coursecode])) { if (isset($this->coursecodecache) &&
isset($this->coursecodecache[$coursecode])
) {
return $this->coursecodecache[$coursecode]; return $this->coursecodecache[$coursecode];
} else { } else {
$name = CourseManager::getCourseNameFromCode($coursecode); $name = CourseManager::getCourseNameFromCode($coursecode);
@ -365,7 +383,9 @@ class UserDataGenerator
*/ */
private function get_category_cached($category_id) private function get_category_cached($category_id)
{ {
if (isset($this->categorycache) && isset ($this->categorycache[$category_id])) { if (isset($this->categorycache) &&
isset($this->categorycache[$category_id])
) {
return $this->categorycache[$category_id]; return $this->categorycache[$category_id];
} else { } else {
$cat = Category::load($category_id); $cat = Category::load($category_id);

Loading…
Cancel
Save