|
|
|
@ -1,10 +1,8 @@ |
|
|
|
|
<?php |
|
|
|
|
/* For licensing terms, see /license.txt */ |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Script |
|
|
|
|
* @package chamilo.gradebook |
|
|
|
|
*/ |
|
|
|
|
/** |
|
|
|
|
* Class UserDataGenerator |
|
|
|
|
* Class to select, sort and transform object data into array data, |
|
|
|
|
* used for a student's general view |
|
|
|
|
* @author Bert Steppé |
|
|
|
@ -12,7 +10,6 @@ |
|
|
|
|
*/ |
|
|
|
|
class UserDataGenerator |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
// Sorting types constants |
|
|
|
|
const UDG_SORT_TYPE = 1; |
|
|
|
|
const UDG_SORT_NAME = 2; |
|
|
|
@ -33,7 +30,8 @@ class UserDataGenerator |
|
|
|
|
private $scorecache; |
|
|
|
|
private $avgcache; |
|
|
|
|
|
|
|
|
|
function UserDataGenerator($userid, $evals = array(), $links = array()) { |
|
|
|
|
public function UserDataGenerator($userid, $evals = array(), $links = array()) |
|
|
|
|
{ |
|
|
|
|
$this->userid = $userid; |
|
|
|
|
$evals_filtered = array(); |
|
|
|
|
foreach ($evals as $eval) { |
|
|
|
@ -66,7 +64,8 @@ class UserDataGenerator |
|
|
|
|
/** |
|
|
|
|
* Get total number of items (rows) |
|
|
|
|
*/ |
|
|
|
|
public function get_total_items_count() { |
|
|
|
|
public function get_total_items_count() |
|
|
|
|
{ |
|
|
|
|
return count($this->items); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -81,7 +80,8 @@ class UserDataGenerator |
|
|
|
|
* 5: student's score |
|
|
|
|
* 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 |
|
|
|
|
if (!isset($count)) { |
|
|
|
|
$count = count ($this->items) - $start; |
|
|
|
@ -157,7 +157,8 @@ class UserDataGenerator |
|
|
|
|
// Sort functions |
|
|
|
|
// Make sure to only use functions as defined in the GradebookItem interface ! |
|
|
|
|
|
|
|
|
|
function sort_by_type($item1, $item2) { |
|
|
|
|
function sort_by_type($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
if ($item1->get_item_type() == $item2->get_item_type()) { |
|
|
|
|
return $this->sort_by_name($item1,$item2); |
|
|
|
|
} else { |
|
|
|
@ -165,13 +166,15 @@ class UserDataGenerator |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function sort_by_course($item1, $item2) { |
|
|
|
|
function sort_by_course($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
$name1 = api_strtolower($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); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function sort_by_category($item1, $item2) { |
|
|
|
|
function sort_by_category($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
$cat1 = $this->get_category_cached($item1->get_category_id()); |
|
|
|
|
$cat2 = $this->get_category_cached($item2->get_category_id()); |
|
|
|
|
$name1 = api_strtolower($this->get_category_name_to_display($cat1)); |
|
|
|
@ -179,31 +182,34 @@ class UserDataGenerator |
|
|
|
|
return api_strnatcmp($name1, $name2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sort_by_name($item1, $item2) { |
|
|
|
|
function sort_by_name($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
return api_strnatcmp($item1->get_name(),$item2->get_name()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sort_by_average($item1, $item2) { |
|
|
|
|
function sort_by_average($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
$score1 = $this->avgcache[$item1->get_item_type() . $item1->get_id()]; |
|
|
|
|
$score2 = $this->avgcache[$item2->get_item_type() . $item2->get_id()]; |
|
|
|
|
return $this->compare_scores($score1, $score2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function sort_by_score($item1, $item2) { |
|
|
|
|
function sort_by_score($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
$score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()]; |
|
|
|
|
$score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()]; |
|
|
|
|
return $this->compare_scores($score1, $score2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function sort_by_mask($item1, $item2) { |
|
|
|
|
function sort_by_mask($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
$score1 = $this->scorecache[$item1->get_item_type() . $item1->get_id()]; |
|
|
|
|
$score2 = $this->scorecache[$item2->get_item_type() . $item2->get_id()]; |
|
|
|
|
return ScoreDisplay :: compare_scores_by_custom_display($score1, $score2); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function compare_scores ($score1, $score2) { |
|
|
|
|
function compare_scores ($score1, $score2) |
|
|
|
|
{ |
|
|
|
|
if (!isset($score1)) { |
|
|
|
|
return (isset($score2) ? 1 : 0); |
|
|
|
|
} elseif (!isset($score2)) { |
|
|
|
@ -213,22 +219,22 @@ class UserDataGenerator |
|
|
|
|
} else { |
|
|
|
|
return (($score1[0]/$score1[1]) < ($score2[0]/$score2[1]) ? -1 : 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Other functions |
|
|
|
|
private function build_course_name ($item) { |
|
|
|
|
private function build_course_name ($item) |
|
|
|
|
{ |
|
|
|
|
return $this->get_course_name_from_code_cached($item->get_course_code()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function build_category_name ($item) { |
|
|
|
|
private function build_category_name ($item) |
|
|
|
|
{ |
|
|
|
|
$cat = $this->get_category_cached($item->get_category_id()); |
|
|
|
|
|
|
|
|
|
return $this->get_category_name_to_display($cat); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function build_average_column ($item, $ignore_score_color) { |
|
|
|
|
private function build_average_column ($item, $ignore_score_color) |
|
|
|
|
{ |
|
|
|
|
if (isset($this->avgcache)) { |
|
|
|
|
$avgscore = $this->avgcache[$item->get_item_type() . $item->get_id()]; |
|
|
|
|
} else { |
|
|
|
@ -243,7 +249,8 @@ class UserDataGenerator |
|
|
|
|
return $scoredisplay->display_score($avgscore, $displaytype); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function build_result_column ($item, $ignore_score_color) { |
|
|
|
|
private function build_result_column ($item, $ignore_score_color) |
|
|
|
|
{ |
|
|
|
|
$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; |
|
|
|
|
$scoredisplay = ScoreDisplay :: instance(); |
|
|
|
|
$displaytype = SCORE_DIV_PERCENT; |
|
|
|
@ -253,7 +260,8 @@ class UserDataGenerator |
|
|
|
|
return $scoredisplay->display_score($studscore, $displaytype, SCORE_ONLY_DEFAULT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function build_mask_column ($item, $ignore_score_color) { |
|
|
|
|
private function build_mask_column($item, $ignore_score_color) |
|
|
|
|
{ |
|
|
|
|
$studscore = $this->scorecache[$item->get_item_type() . $item->get_id()]; |
|
|
|
|
$scoredisplay = ScoreDisplay :: instance(); |
|
|
|
|
$displaytype = SCORE_DIV_PERCENT; |
|
|
|
|