Add new columns see BT#9427

1.10.x
Julio Montoya 10 years ago
parent 487d6f06a8
commit 046210ce12
  1. 7
      main/gradebook/lib/be/abstractlink.class.php
  2. 33
      main/gradebook/lib/be/attendancelink.class.php
  3. 3
      main/gradebook/lib/be/dropboxlink.class.php
  4. 2
      main/gradebook/lib/be/evallink.class.php
  5. 46
      main/gradebook/lib/be/evaluation.class.php
  6. 16
      main/gradebook/lib/be/exerciselink.class.php
  7. 30
      main/gradebook/lib/be/forumthreadlink.class.php
  8. 2
      main/gradebook/lib/be/gradebookitem.class.php
  9. 42
      main/gradebook/lib/be/learnpathlink.class.php
  10. 8
      main/gradebook/lib/be/linkfactory.class.php
  11. 39
      main/gradebook/lib/be/result.class.php
  12. 18
      main/gradebook/lib/be/studentpublicationlink.class.php
  13. 15
      main/gradebook/lib/be/surveylink.class.php
  14. 76
      main/gradebook/lib/fe/gradebooktable.class.php
  15. 203
      main/gradebook/lib/gradebook_data_generator.class.php

@ -451,13 +451,6 @@ abstract class AbstractLink implements GradebookItem
abstract function get_link();
abstract function is_valid_link();
abstract function get_type_name();
// The following methods are already defined in GradebookItem,
// and must be implemented by the subclass as well !
// abstract function get_name();
// abstract function get_description();
// abstract function calc_score($stud_id = null);
abstract function needs_name_and_description();
abstract function needs_max();
abstract function needs_results();

@ -19,11 +19,17 @@ class AttendanceLink extends AbstractLink
$this->set_type(LINK_ATTENDANCE);
}
/**
* @return string
*/
public function get_type_name()
{
return get_lang('Attendance');
}
/**
* @return bool
*/
public function is_allowed_to_change_name()
{
return false;
@ -100,7 +106,6 @@ class AttendanceLink extends AbstractLink
return $my_cats;
}
/**
* Has anyone done this exercise yet ?
*/
@ -119,7 +124,7 @@ class AttendanceLink extends AbstractLink
* @param int $stud_id
* @return array|null
*/
public function calc_score($stud_id = null)
public function calc_score($stud_id = null, $type = null)
{
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
$session_id = api_get_session_id();
@ -146,23 +151,37 @@ class AttendanceLink extends AbstractLink
return array (0, $attendance['attendance_qualify_max']);
}
} else {// all students -> get average
$students=array(); // user list, needed to make sure we only
$students = array(); // user list, needed to make sure we only
// take first attempts into account
$rescount = 0;
$sum = 0;
while ($data=Database::fetch_array($scores)) {
if (!(array_key_exists($data['user_id'],$students))) {
$sumResult = 0;
$bestResult = 0;
while ($data = Database::fetch_array($scores)) {
if (!(array_key_exists($data['user_id'], $students))) {
if ($attendance['attendance_qualify_max'] != 0) {
$students[$data['user_id']] = $data['score'];
$rescount++;
$sum += ($data['score'] / $attendance['attendance_qualify_max']);
$sum += $data['score'] / $attendance['attendance_qualify_max'];
$sumResult += $data['score'];
if ($data['score'] > $bestResult) {
$bestResult = $data['score'];
}
$weight = $attendance['attendance_qualify_max'];
}
}
}
if ($rescount == 0) {
return null;
} else {
return array ($sum , $rescount);
if ($type == 'best') {
return array($bestResult, $weight);
}
if ($type == 'average') {
return array($sumResult/$rescount, $weight);
}
return array($sum , $rescount);
}
}
}

@ -19,13 +19,12 @@ class DropboxLink extends EvalLink
$this->set_type(LINK_DROPBOX);
}
/**
*
* Returns the URL of a document
* This function is loaded when using a gradebook as a tab (gradebook = -1) see issue #2705
*/
public function get_view_url ($stud_id)
public function get_view_url($stud_id)
{
// find a file uploaded by the given student,
// with the same title as the evaluation name

@ -165,7 +165,7 @@ abstract class EvalLink extends AbstractLink
/**
* Lazy load function to get the linked evaluation
*/
protected function get_evaluation ()
protected function get_evaluation()
{
if (!isset($this->evaluation)) {
if (isset($this->ref_id)) {

@ -19,6 +19,9 @@ class Evaluation implements GradebookItem
private $visible;
private $sessionId;
/**
* Construct
*/
public function __construct()
{
}
@ -309,6 +312,9 @@ class Evaluation implements GradebookItem
}
}
/**
* @param $idevaluation
*/
public function add_evaluation_log($idevaluation)
{
if (!empty($idevaluation)) {
@ -466,26 +472,40 @@ class Evaluation implements GradebookItem
* array (sum of scores, number of scores) otherwise
* or null if no scores available
*/
public function calc_score($stud_id = null)
public function calc_score($stud_id = null, $type = null)
{
$results = Result::load(null, $stud_id, $this->id);
$rescount = 0;
$sum = 0;
$bestResult = 0;
$weight = 0;
$sumResult = 0;
foreach ($results as $res) {
$score = $res->get_score();
if ((!empty ($score)) || ($score == '0')) {
$rescount++;
$sum += ($score / $this->get_max());
$sum += $score / $this->get_max();
$sumResult += $score;
if ($score > $bestResult) {
$bestResult = $score;
}
$weight = $this->get_max();
}
}
if ($rescount == 0) {
return null;
}
else if (isset($stud_id)) {
return array ($score, $this->get_max());
} else if (isset($stud_id)) {
return array($score, $this->get_max());
} else {
return array ($sum, $rescount);
if ($type == 'best') {
return array($bestResult, $weight);
}
if ($type == 'average') {
return array($sumResult/$rescount, $weight);
}
return array($sum, $rescount);
}
}
@ -495,7 +515,8 @@ class Evaluation implements GradebookItem
* to disable this element.
* @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
*/
public function get_target_categories() {
public function get_target_categories()
{
// - course independent evaluation
// -> movable to root or other course independent categories
// - evaluation inside a course
@ -537,7 +558,6 @@ class Evaluation implements GradebookItem
return $targets;
}
/**
* Move this evaluation to the given category.
* If this evaluation moves from inside a course to outside,
@ -579,13 +599,14 @@ class Evaluation implements GradebookItem
$result = Database::query($sql);
$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
return $alleval;
}
/**
* Get a list of students that do not have a result record for this evaluation
*/
public function get_not_subscribed_students ($first_letter_user = '')
public function get_not_subscribed_students($first_letter_user = '')
{
$tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
@ -600,8 +621,9 @@ class Evaluation implements GradebookItem
.' ORDER BY lastname';
$result = Database::query($sql);
$db_users = Database::store_result($result);
return $db_users;
$users = Database::store_result($result);
return $users;
}
/**
@ -610,7 +632,7 @@ class Evaluation implements GradebookItem
* @return array evaluation objects matching the search criterium
* @todo can be written more efficiently using a new (but very complex) sql query
*/
public function find_evaluations ($name_mask,$selectcat)
public function find_evaluations($name_mask,$selectcat)
{
$rootcat = Category::load($selectcat);
$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);

@ -184,7 +184,7 @@ class ExerciseLink extends AbstractLink
* array (sum of scores, number of scores) otherwise
* or null if no scores available
*/
public function calc_score($stud_id = null)
public function calc_score($stud_id = null, $type = null)
{
$tblStats = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
$tblHp = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
@ -234,18 +234,32 @@ class ExerciseLink extends AbstractLink
// take first attempts into account
$student_count = 0;
$sum = 0;
$bestResult = 0;
$weight = 0;
$sumResult = 0;
while ($data = Database::fetch_array($scores, 'ASSOC')) {
if (!in_array($data['exe_user_id'], $students)) {
if ($data['exe_weighting'] != 0) {
$students[] = $data['exe_user_id'];
$student_count++;
if ($data['exe_result'] > $bestResult) {
$bestResult = $data['exe_result'];
}
$sum += $data['exe_result'] / $data['exe_weighting'];
$sumResult += $data['exe_result'];
$weight = $data['exe_weighting'];
}
}
}
if ($student_count == 0) {
return null;
} else {
if ($type == 'best') {
return array($bestResult, $weight);
}
if ($type == 'average') {
return array($sumResult/$student_count, $weight);
}
return array($sum, $student_count);
}
}

@ -10,6 +10,9 @@ class ForumThreadLink extends AbstractLink
private $forum_thread_table = null;
private $itemprop_table = null;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
@ -118,7 +121,7 @@ class ForumThreadLink extends AbstractLink
* @param int $stud_id
* @return array|null
*/
public function calc_score($stud_id = null)
public function calc_score($stud_id = null, $type = null)
{
$thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
@ -127,7 +130,8 @@ class ForumThreadLink extends AbstractLink
$query = Database::query($sql);
$assignment = Database::fetch_array($query);
$sql = "SELECT * FROM $thread_qualify WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id();
$sql = "SELECT * FROM $thread_qualify
WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id();
if (isset($stud_id)) {
$sql .= ' AND user_id = '."'".intval($stud_id)."'";
}
@ -149,17 +153,25 @@ class ForumThreadLink extends AbstractLink
}
} else {
// all students -> get average
$students=array(); // user list, needed to make sure we only
$students = array(); // user list, needed to make sure we only
// take first attempts into account
$rescount = 0;
$sum = 0;
$bestResult = 0;
$weight = 0;
$sumResult = 0;
while ($data=Database::fetch_array($scores)) {
while ($data = Database::fetch_array($scores)) {
if (!(array_key_exists($data['user_id'],$students))) {
if ($assignment['thread_qualify_max'] != 0) {
$students[$data['user_id']] = $data['qualify'];
$rescount++;
$sum += ($data['qualify'] / $assignment['thread_qualify_max']);
$sum += $data['qualify'] / $assignment['thread_qualify_max'];
$sumResult += $data['qualify'];
if ($data['qualify'] > $bestResult) {
$bestResult = $data['qualify'];
}
$weight = $assignment['thread_qualify_max'];
}
}
}
@ -167,7 +179,13 @@ class ForumThreadLink extends AbstractLink
if ($rescount == 0) {
return null;
} else {
return array ($sum , $rescount);
if ($type == 'average') {
return array($sumResult/$rescount, $weight);
}
if ($type == 'best') {
return array($bestResult, $weight);
}
return array($sum , $rescount);
}
}
}

@ -17,5 +17,5 @@ interface GradebookItem
public function get_date();
public function is_visible();
public function get_icon_name();
public function calc_score($stud_id = null);
public function calc_score($stud_id = null, $type = null);
}

@ -102,21 +102,23 @@ class LearnpathLink extends AbstractLink
* array (sum of scores, number of scores) otherwise
* or null if no scores available
*/
public function calc_score($stud_id = null)
public function calc_score($stud_id = null, $type = null)
{
$tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
$session_id = api_get_session_id();
$sql = "SELECT * FROM $tbl_stats
WHERE c_id = ".$this->course_id." AND
lp_id = ".$this->get_ref_id()." AND
session_id = $session_id ";
WHERE
c_id = ".$this->course_id." AND
lp_id = ".$this->get_ref_id()." AND
session_id = $session_id ";
if (isset($stud_id))
$sql .= ' AND user_id = '.intval($stud_id);
// order by id, that way the student's first attempt is accessed first
$sql .= ' ORDER BY view_count DESC';
$scores = Database::query($sql);
// for 1 student
if (isset($stud_id)) {
@ -124,26 +126,38 @@ class LearnpathLink extends AbstractLink
return array ($data['progress'], 100);
} else
return null;
}
// all students -> get average
else {
$students=array(); // user list, needed to make sure we only
} else {
// all students -> get average
$students = array(); // user list, needed to make sure we only
// take first attempts into account
$rescount = 0;
$sum = 0;
while ($data=Database::fetch_array($scores)) {
$bestResult = 0;
$sumResult = 0;
while ($data = Database::fetch_array($scores)) {
if (!(array_key_exists($data['user_id'], $students))) {
$students[$data['user_id']] = $data['progress'];
$rescount++;
$sum += ($data['progress'] / 100);
$sum += $data['progress'] / 100;
$sumResult += $data['progress'];
if ($data['progress'] > $bestResult) {
$bestResult = $data['progress'];
}
}
}
if ($rescount == 0)
if ($rescount == 0) {
return null;
else
return array ($sum , $rescount);
} else {
if ($type == 'average') {
return array($sumResult/$rescount, 100);
}
if ($type == 'best') {
return array($bestResult, 100);
}
return array($sum, $rescount);
}
}
}

@ -42,7 +42,7 @@ class LinkFactory
/**
* Get the link object referring to an evaluation
*/
public function get_evaluation_link ($eval_id)
public function get_evaluation_link($eval_id)
{
$links = AbstractLink :: load(null, null, $eval_id);
foreach ($links as $link) {
@ -58,7 +58,7 @@ class LinkFactory
* @param string $name_mask search string
* @return array link objects matching the search criterium
*/
public function find_links ($name_mask,$selectcat)
public function find_links($name_mask,$selectcat)
{
return AbstractLink::find_links($name_mask, $selectcat);
}
@ -67,7 +67,7 @@ class LinkFactory
* Static method to create specific link objects
* @param $type link type
*/
public static function create ($type)
public static function create($type)
{
$type = intval($type);
switch ($type) {
@ -95,7 +95,7 @@ class LinkFactory
* Return an array of all known link types
* @return array
*/
public static function get_all_types ()
public static function get_all_types()
{
//LINK_DROPBOX,
return array (

@ -1,5 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Defines a gradebook Result object
* @author Bert Steppé, Stijn Konings
@ -82,24 +83,32 @@ class Result
$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
$tbl_course_rel_course = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_session_rel_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$sessionId = api_get_session_id();
if (is_null($id) && is_null($user_id) && !is_null($evaluation_id)) {
// Verified_if_exist_evaluation
$sql = 'SELECT COUNT(*) AS count FROM ' . $tbl_grade_results . '
WHERE evaluation_id="' . Database::escape_string($evaluation_id) . '";';
$result = Database::query($sql);
$existEvaluation = Database::result($result, 0, 0);
$sql_verified_if_exist_evaluation = 'SELECT COUNT(*) AS count FROM ' . $tbl_grade_results . ' WHERE evaluation_id="' . Database::escape_string($evaluation_id) . '";';
$res_verified_if_exist_evaluation = Database::query($sql_verified_if_exist_evaluation);
$info_verified_if_exist_evaluation = Database::result($res_verified_if_exist_evaluation, 0, 0);
if ($info_verified_if_exist_evaluation != 0) {
if ($existEvaluation != 0) {
$sql_course_rel_user = '';
if (api_get_session_id()) {
$sql_course_rel_user = 'SELECT course_code, id_user as user_id, status FROM ' . $tbl_session_rel_course_user . '
WHERE status=0 AND course_code="' . api_get_course_id() . '" AND id_session=' . api_get_session_id();
if ($sessionId) {
$sql = 'SELECT course_code, id_user as user_id, status
FROM ' . $tbl_session_rel_course_user . '
WHERE
status=0 AND
course_code="' . api_get_course_id() . '" AND
id_session=' . $sessionId;
} else {
$sql_course_rel_user = 'SELECT course_code,user_id,status FROM ' . $tbl_course_rel_course . ' WHERE status ="' . STUDENT . '" AND course_code="' . api_get_course_id() . '" ';
$sql = 'SELECT course_code,user_id,status
FROM ' . $tbl_course_rel_course . '
WHERE status ="' . STUDENT . '" AND course_code="' . api_get_course_id() . '" ';
}
$res_course_rel_user = Database::query($sql_course_rel_user);
$res_course_rel_user = Database::query($sql);
$list_user_course_list = array();
while ($row_course_rel_user = Database::fetch_array($res_course_rel_user, 'ASSOC')) {
@ -107,12 +116,16 @@ class Result
}
$current_date = api_get_utc_datetime();
for ($i = 0; $i < count($list_user_course_list); $i++) {
$sql_verified = 'SELECT COUNT(*) AS count FROM ' . $tbl_grade_results . ' WHERE user_id="' . intval($list_user_course_list[$i]['user_id']) . '" AND evaluation_id="' . intval($evaluation_id) . '";';
$sql_verified = 'SELECT COUNT(*) AS count
FROM ' . $tbl_grade_results . '
WHERE
user_id="' . intval($list_user_course_list[$i]['user_id']) . '" AND
evaluation_id="' . intval($evaluation_id) . '";';
$res_verified = Database::query($sql_verified);
$info_verified = Database::result($res_verified, 0, 0);
if ($info_verified == 0) {
$sql_insert = 'INSERT INTO ' . $tbl_grade_results . '(user_id,evaluation_id,created_at,score)
VALUES ("' . intval($list_user_course_list[$i]['user_id']) . '","' . intval($evaluation_id) . '","' . $current_date . '",0);';
VALUES ("' . intval($list_user_course_list[$i]['user_id']) . '","' . intval($evaluation_id) . '","' . $current_date . '",0);';
$res_insert = Database::query($sql_insert);
}
}
@ -191,7 +204,6 @@ class Result
*/
public function add_result__log($userid, $evaluationid)
{
if (isset($userid) && isset($evaluationid)) {
$tbl_grade_results_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT_LOG);
$result = new Result();
@ -247,5 +259,4 @@ class Result
$sql = 'DELETE FROM ' . $tbl_grade_results . ' WHERE id = ' . $this->id;
Database::query($sql);
}
}

@ -152,7 +152,7 @@ class StudentPublicationLink extends AbstractLink
* @param null $stud_id
* @return array|null
*/
public function calc_score($stud_id = null)
public function calc_score($stud_id = null, $type = null)
{
$stud_id = intval($stud_id);
$table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
@ -216,12 +216,22 @@ class StudentPublicationLink extends AbstractLink
// take first attempts into account
$rescount = 0;
$sum = 0;
$bestResult = 0;
$weight = 0;
$sumResult = 0;
while ($data = Database::fetch_array($scores)) {
if (!(array_key_exists($data['user_id'], $students))) {
if ($assignment['qualification'] != 0) {
$students[$data['user_id']] = $data['qualification'];
$rescount++;
$sum += $data['qualification'] / $assignment['qualification'];
$sumResult += $data['qualification'];
if ($data['qualification'] > $bestResult) {
$bestResult = $data['qualification'];
}
$weight = $assignment['qualification'];
}
}
}
@ -229,6 +239,12 @@ class StudentPublicationLink extends AbstractLink
if ($rescount == 0) {
return null;
} else {
if ($type == 'best') {
return array($bestResult, $weight);
}
if ($type == 'average') {
return array($sumResult/$rescount, $weight);
}
return array($sum, $rescount);
}
}

@ -139,7 +139,7 @@ class SurveyLink extends AbstractLink
* @param int $stud_id
* @return array|null
*/
public function calc_score($stud_id = null)
public function calc_score($stud_id = null, $type = null)
{
// Note: Max score is assumed to be always 1 for surveys,
// only student's participation is to be taken into account.
@ -179,14 +179,27 @@ class SurveyLink extends AbstractLink
// for all the students -> get average
$rescount = 0;
$sum = 0;
$bestResult = 0;
$weight = 0;
while ($data = Database::fetch_array($sql_result)) {
$sum += $data['answered'] ? $max_score : 0;
$rescount++;
if ($data['answered'] > $bestResult) {
$bestResult = $data['answered'];
$weight = $assignment['qualification'];
}
}
$sum = $sum / $max_score;
if ($rescount == 0) {
return null;
}
if ($type == 'best') {
return array($bestResult, $rescount);
}
if ($type == 'average') {
return array($sum, $rescount);
}
return array($sum, $rescount);
}
}

@ -23,7 +23,7 @@ class GradebookTable extends SortableTable
* @param array $links
* @param null $addparams
*/
public function GradebookTable($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null)
public function __construct($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null)
{
parent::__construct('gradebooklist', null, null, (api_is_allowed_to_edit()?1:0));
$this->evals_links = array_merge($evals, $links);
@ -54,6 +54,9 @@ class GradebookTable extends SortableTable
} else {
$this->set_header($column++, get_lang('Weight'), false);
$this->set_header($column++, get_lang('Result'), false);
$this->set_header($column++, get_lang('Global'), false);
$this->set_header($column++, get_lang('Best'), false);
$this->set_header($column++, get_lang('Average'), false);
if (!empty($cats)) {
$this->set_header($column++, get_lang('Actions'), false);
@ -215,6 +218,7 @@ class GradebookTable extends SortableTable
}
$category_weight = $item->get_weight();
$mainCategoryWeight = $main_cat[0]->get_weight();
if (api_is_allowed_to_edit(null, true)) {
$weight_total_links += $data[3];
@ -232,25 +236,43 @@ class GradebookTable extends SortableTable
$row[] = $this->build_edit_column($item);
}
} else {
//students get the results and certificates columns
$score = $item->calc_score(api_get_user_id());
if (!empty($score[1])) {
$completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
$score = $score[0]/$score[1]*$item->get_weight();
$score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE);
$categoryScore = $scoredisplay->display_score(array($score, $mainCategoryWeight), SCORE_DIV);
$scoreToDisplay = Display::tip($score, $completeScore);
} else {
$scoreToDisplay = '-';
$categoryScore = null;
}
// Students get the results and certificates columns
if (count($this->evals_links) > 0 && $status_user != 1) {
$value_data = isset($data[4]) ? $data[4] : null;
if (!is_null($value_data)) {
$best = isset($data['best']) ? $data['best'] : null;
$average = isset($data['average']) ? $data['average'] : null;
//if (!is_null($value_data)) {
// Student result
$row[] = Display::tag('h4', $value_data);
} else {
// Global
$row[] = Display::tag('h4', $categoryScore);
// Best
$row[] = Display::tag('h4', $best);
// Average
$row[] = Display::tag('h4', $average);
$row[] = $this->build_edit_column($item);
}
} else {
$score = $item->calc_score(api_get_user_id());
if (!empty($score[1])) {
$complete_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
$score = $score[0]/$score[1]*$item->get_weight();
$score = $scoredisplay->display_score(array($score, null), SCORE_SIMPLE);
$row[] = Display::tip($score, $complete_score);
} else {
$row[] = '-';
}
/*} else {
}*/
} else {
$row[] = $scoreToDisplay;
if (!empty($this->cats)) {
$row[] = $this->build_edit_column($item);
@ -275,9 +297,12 @@ class GradebookTable extends SortableTable
$alllink = $cats[0]->get_links($stud_id);
$sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink);
$data_array = $sub_cat_info->get_data($sorting, $from, $this->per_page);
$data_array = $sub_cat_info->get_data($sorting, $from, $this->per_page);
$total_weight = 0;
//$score = $cats[0]->calc_score(api_get_user_id());
//$categoryScore = $scoredisplay->display_score(array($score, $cats[0]->get_weight()), SCORE_DIV);
// Links.
foreach ($data_array as $data) {
$row = array();
@ -310,7 +335,7 @@ class GradebookTable extends SortableTable
if (api_is_allowed_to_edit(null, true)) {
//$weight_total_links += intval($data[3]);
} else {
$cattotal = Category::load($_GET['selectcat']);
$cattotal = Category::load($_GET['selectcat']);
$scoretotal = $cattotal[0]->calc_score(api_get_user_id());
$item_value = $scoretotal[0];
}
@ -332,7 +357,22 @@ class GradebookTable extends SortableTable
$score = $item->calc_score(api_get_user_id());
$new_score = $data[3] * $score[0] / $score[1];
$new_score = floatval(number_format($new_score, api_get_setting('gradebook_number_decimals')));
$row[] = Display::tip($new_score, $data[4]);
//$row[] = Display::tip($new_score, $data[4]);
$row[] = $value_data;
$best = isset($data['best']) ? $data['best'] : null;
$average = isset($data['average']) ? $data['average'] : null;
// Global
$categoryScore = $scoredisplay->display_score(
array($new_score, $cattotal[0]->get_weight()),
SCORE_DIV
);
$row[] = Display::tag('h4', $categoryScore);
// Best
$row[] = Display::tag('h4', $best);
// Average
$row[] = Display::tag('h4', $average);
}
}
if (!empty($cats)) {

@ -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);
}
}
}
}

Loading…
Cancel
Save