|
|
|
@ -26,7 +26,12 @@ class GradebookDataGenerator |
|
|
|
|
private $items; |
|
|
|
|
private $evals_links; |
|
|
|
|
|
|
|
|
|
public function GradebookDataGenerator($cats = array(), $evals = array(), $links = array()) |
|
|
|
|
/** |
|
|
|
|
* @param array $cats |
|
|
|
|
* @param array $evals |
|
|
|
|
* @param array $links |
|
|
|
|
*/ |
|
|
|
|
public function __construct($cats = array(), $evals = array(), $links = array()) |
|
|
|
|
{ |
|
|
|
|
$allcats = (isset($cats) ? $cats : array()); |
|
|
|
|
$allevals = (isset($evals) ? $evals : array()); |
|
|
|
@ -107,34 +112,127 @@ class GradebookDataGenerator |
|
|
|
|
// get selected items |
|
|
|
|
$visibleitems = array_slice($allitems, $start, $count); |
|
|
|
|
//status de user in course |
|
|
|
|
$user_id = api_get_user_id(); |
|
|
|
|
$course_code = api_get_course_id(); |
|
|
|
|
$status_user = api_get_status_of_user_in_course($user_id, $course_code); |
|
|
|
|
$user_id = api_get_user_id(); |
|
|
|
|
$course_code = api_get_course_id(); |
|
|
|
|
$status_user = api_get_status_of_user_in_course($user_id, $course_code); |
|
|
|
|
|
|
|
|
|
// generate the data to display |
|
|
|
|
// Generate the data to display |
|
|
|
|
$data = array(); |
|
|
|
|
|
|
|
|
|
/** @var GradebookItem $item */ |
|
|
|
|
foreach ($visibleitems as $item) { |
|
|
|
|
$row = array (); |
|
|
|
|
$row[] = $item; |
|
|
|
|
$row[] = $item->get_name(); |
|
|
|
|
// display the 2 first line of description, and all description on mouseover (https://support.chamilo.org/issues/6588) |
|
|
|
|
$row[] = '<span title="'.api_remove_tags_with_space($item->get_description()).'">'.api_get_short_text_from_html($item->get_description(), 160).'</span>'; |
|
|
|
|
$row[] = '<span title="'.api_remove_tags_with_space($item->get_description()).'">'. |
|
|
|
|
api_get_short_text_from_html($item->get_description(), 160).'</span>'; |
|
|
|
|
$row[] = $item->get_weight(); |
|
|
|
|
/*if (api_is_allowed_to_edit(null, true)) { |
|
|
|
|
$row[] = $this->build_date_column($item); |
|
|
|
|
}*/ |
|
|
|
|
if (count($this->evals_links) > 0) { |
|
|
|
|
if (!api_is_allowed_to_edit() || $status_user != 1 ) { |
|
|
|
|
$row[] = $this->build_result_column($item, $ignore_score_color); |
|
|
|
|
$row['best'] = $this->buildBestResultColumn($item); |
|
|
|
|
$row['average'] = $this->buildAverageResultColumn($item); |
|
|
|
|
$row[] = $item; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$row[] = $this->build_result_column($item, $ignore_score_color, true); |
|
|
|
|
$row['best'] = $this->buildBestResultColumn($item); |
|
|
|
|
$row['average'] = $this->buildAverageResultColumn($item); |
|
|
|
|
} |
|
|
|
|
$data[] = $row; |
|
|
|
|
} |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get best result of an item |
|
|
|
|
* @param GradebookItem $item |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
private function buildBestResultColumn(GradebookItem $item) |
|
|
|
|
{ |
|
|
|
|
$score = $item->calc_score( |
|
|
|
|
null, |
|
|
|
|
'best', |
|
|
|
|
api_get_course_id(), |
|
|
|
|
api_get_session_id() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$scoreDisplay = ScoreDisplay :: instance(); |
|
|
|
|
|
|
|
|
|
return $scoreDisplay->display_score($score, SCORE_DIV); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
private function buildAverageResultColumn(GradebookItem $item) |
|
|
|
|
{ |
|
|
|
|
$score = $item->calc_score(null, 'average'); |
|
|
|
|
$scoreDisplay = ScoreDisplay :: instance(); |
|
|
|
|
return $scoreDisplay->display_score($score, SCORE_DIV); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item |
|
|
|
|
* @param $ignore_score_color |
|
|
|
|
* @return null|string |
|
|
|
|
*/ |
|
|
|
|
private function build_result_column($item, $ignore_score_color, $forceSimpleResult = false) |
|
|
|
|
{ |
|
|
|
|
$scoredisplay = ScoreDisplay :: instance(); |
|
|
|
|
$score = $item->calc_score(api_get_user_id()); |
|
|
|
|
|
|
|
|
|
if (!empty($score)) { |
|
|
|
|
switch ($item->get_item_type()) { |
|
|
|
|
// category |
|
|
|
|
case 'C' : |
|
|
|
|
if ($score != null) { |
|
|
|
|
$displaytype = SCORE_PERCENT; |
|
|
|
|
if ($ignore_score_color) { |
|
|
|
|
$displaytype |= SCORE_IGNORE_SPLIT; |
|
|
|
|
} |
|
|
|
|
if ($forceSimpleResult) { |
|
|
|
|
return $scoredisplay->display_score($score, SCORE_DIV); |
|
|
|
|
} |
|
|
|
|
return get_lang('Total') . ' : '. $scoredisplay->display_score($score, $displaytype); |
|
|
|
|
} else { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
// evaluation and link |
|
|
|
|
case 'E' : |
|
|
|
|
case 'L' : |
|
|
|
|
/*$displaytype = SCORE_DIV_PERCENT; |
|
|
|
|
if ($ignore_score_color) { |
|
|
|
|
$displaytype |= SCORE_IGNORE_SPLIT; |
|
|
|
|
}*/ |
|
|
|
|
return $scoredisplay->display_score($score, SCORE_DIV_PERCENT_WITH_CUSTOM); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item |
|
|
|
|
* @return string |
|
|
|
|
*/ |
|
|
|
|
private function build_date_column($item) |
|
|
|
|
{ |
|
|
|
|
$date = $item->get_date(); |
|
|
|
|
if (!isset($date) || empty($date)) { |
|
|
|
|
return ''; |
|
|
|
|
} else { |
|
|
|
|
if (is_int($date)) { |
|
|
|
|
return api_convert_and_format_date($date); |
|
|
|
|
} else { |
|
|
|
|
return api_format_date($date); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the link to the certificate generation, if the score is enough, otherwise |
|
|
|
|
* returns an empty string. This only works with categories. |
|
|
|
@ -143,27 +241,40 @@ class GradebookDataGenerator |
|
|
|
|
public function get_certificate_link($item) |
|
|
|
|
{ |
|
|
|
|
if (is_a($item, 'Category')) { |
|
|
|
|
if($item->is_certificate_available(api_get_user_id())) { |
|
|
|
|
$link = '<a href="'.Security::remove_XSS($_SESSION['gradebook_dest']).'?export_certificate=1&cat='.$item->get_id().'&user='.api_get_user_id().'">'.get_lang('Certificate').'</a>'; |
|
|
|
|
if ($item->is_certificate_available(api_get_user_id())) { |
|
|
|
|
$link = '<a href="'.Security::remove_XSS($_SESSION['gradebook_dest']).'?export_certificate=1&cat='.$item->get_id().'&user='.api_get_user_id().'">'. |
|
|
|
|
get_lang('Certificate').'</a>'; |
|
|
|
|
return $link; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sort functions |
|
|
|
|
// Make sure to only use functions as defined in the GradebookItem interface ! |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item1 |
|
|
|
|
* @param GradebookItem $item2 |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
public function sort_by_name($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
return api_strnatcmp($item1->get_name(), $item2->get_name()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item1 |
|
|
|
|
* @param GradebookItem $item2 |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
public function sort_by_id($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
return api_strnatcmp($item1->get_id(), $item2->get_id()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item1 |
|
|
|
|
* @param GradebookItem $item2 |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
public function sort_by_type($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
if ($item1->get_item_type() == $item2->get_item_type()) { |
|
|
|
@ -173,6 +284,11 @@ class GradebookDataGenerator |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item1 |
|
|
|
|
* @param GradebookItem $item2 |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
public function sort_by_description($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
$result = api_strcmp($item1->get_description(), $item2->get_description()); |
|
|
|
@ -182,6 +298,11 @@ class GradebookDataGenerator |
|
|
|
|
return $result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item1 |
|
|
|
|
* @param GradebookItem $item2 |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
public function sort_by_weight($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
if ($item1->get_weight() == $item2->get_weight()) { |
|
|
|
@ -191,6 +312,11 @@ class GradebookDataGenerator |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @param GradebookItem $item1 |
|
|
|
|
* @param GradebookItem $item2 |
|
|
|
|
* @return int |
|
|
|
|
*/ |
|
|
|
|
public function sort_by_date($item1, $item2) |
|
|
|
|
{ |
|
|
|
|
if (is_int($item1->get_date())) { |
|
|
|
@ -204,7 +330,7 @@ class GradebookDataGenerator |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(is_int($item2->get_date())) { |
|
|
|
|
if (is_int($item2->get_date())) { |
|
|
|
|
$timestamp2 = $item2->get_date(); |
|
|
|
|
} else { |
|
|
|
|
$timestamp2 = api_strtotime($item2->get_date(), 'UTC'); |
|
|
|
@ -216,49 +342,4 @@ class GradebookDataGenerator |
|
|
|
|
return ($timestamp1 < $timestamp2 ? -1 : 1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function build_result_column($item, $ignore_score_color) |
|
|
|
|
{ |
|
|
|
|
$scoredisplay = ScoreDisplay :: instance(); |
|
|
|
|
$score = $item->calc_score(api_get_user_id()); |
|
|
|
|
|
|
|
|
|
if (!empty($score)) { |
|
|
|
|
switch ($item->get_item_type()) { |
|
|
|
|
// category |
|
|
|
|
case 'C' : |
|
|
|
|
if ($score != null) { |
|
|
|
|
$displaytype = SCORE_PERCENT; |
|
|
|
|
if ($ignore_score_color) { |
|
|
|
|
$displaytype |= SCORE_IGNORE_SPLIT; |
|
|
|
|
} |
|
|
|
|
return get_lang('Total') . ' : '. $scoredisplay->display_score($score, $displaytype); |
|
|
|
|
} else { |
|
|
|
|
return ''; |
|
|
|
|
} |
|
|
|
|
// evaluation and link |
|
|
|
|
case 'E' : |
|
|
|
|
case 'L' : |
|
|
|
|
$displaytype = SCORE_DIV_PERCENT; |
|
|
|
|
if ($ignore_score_color) { |
|
|
|
|
$displaytype |= SCORE_IGNORE_SPLIT; |
|
|
|
|
} |
|
|
|
|
return $scoredisplay->display_score($score, SCORE_DIV_PERCENT_WITH_CUSTOM); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function build_date_column($item) |
|
|
|
|
{ |
|
|
|
|
$date = $item->get_date(); |
|
|
|
|
if (!isset($date) || empty($date)) { |
|
|
|
|
return ''; |
|
|
|
|
} else { |
|
|
|
|
if (is_int($date)) { |
|
|
|
|
return api_convert_and_format_date($date); |
|
|
|
|
} else { |
|
|
|
|
return api_format_date($date); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|