Merge branch '1.10.x' of github.com:chamilo/chamilo-lms into 1.10.x

1.10.x
Yannick Warnier 9 years ago
commit bb5b99ea22
  1. 10
      main/admin/settings.lib.php
  2. 9
      main/course_info/download.php
  3. 28
      main/coursecopy/classes/CourseRestorer.class.php
  4. 14
      main/exercice/MatchingDraggable.php
  5. 19
      main/exercice/answer.class.php
  6. 8
      main/exercice/exercise.class.php
  7. 14
      main/exercice/matching.class.php
  8. 2
      main/exercice/question.class.php
  9. 56
      main/gradebook/gradebook_display_summary.php
  10. 47
      main/gradebook/index.php
  11. 62
      main/gradebook/lib/GradebookUtils.php
  12. 12
      main/gradebook/lib/be/abstractlink.class.php
  13. 286
      main/gradebook/lib/be/category.class.php
  14. 103
      main/gradebook/lib/be/evaluation.class.php
  15. 20
      main/gradebook/lib/be/exerciselink.class.php
  16. 2
      main/gradebook/lib/be/gradebookitem.class.php
  17. 2
      main/gradebook/lib/be/learnpathlink.class.php
  18. 22
      main/gradebook/lib/be/result.class.php
  19. 147
      main/gradebook/lib/fe/gradebooktable.class.php
  20. 3
      main/gradebook/lib/flatview_data_generator.class.php
  21. 92
      main/gradebook/lib/gradebook_data_generator.class.php
  22. 47
      main/inc/lib/pdf.lib.php
  23. 8
      main/inc/lib/userportal.lib.php
  24. 49
      main/template/default/export/table_pdf.tpl

@ -349,15 +349,17 @@ function handle_stylesheets()
}
if (isset($_POST['download'])) {
$arch = api_get_path(SYS_ARCHIVE_PATH).$safe_style_dir.'.zip';
$dir = api_get_path(SYS_CODE_PATH).'css/'.$safe_style_dir;
$dir = api_get_path(SYS_CSS_PATH).'themes/'.$safe_style_dir;
if (is_dir($dir)) {
$zip = new PclZip($arch);
// Remove path prefix except the style name and put file on disk
$zip->create($dir, PCLZIP_OPT_REMOVE_PATH, substr($dir,0,-strlen($safe_style_dir)));
//@TODO: use more generic script to download.
$str = '<a class="btn btn-primary btn-large" href="' . api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive=' . str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch) . '">'.get_lang('ClickHereToDownloadTheFile').'</a>';
Display::display_normal_message($str, false);
} else {
Display::addFlash(Display::return_message(get_lang('FileNotFound'), 'warning'));
}
//@TODO: use more generic script to download.
$str = '<a class="btn btn-primary btn-large" href="' . api_get_path(WEB_CODE_PATH) . 'course_info/download.php?archive=' . str_replace(api_get_path(SYS_ARCHIVE_PATH), '', $arch) . '">'.get_lang('ClickHereToDownloadTheFile').'</a>';
Display::display_normal_message($str,false);
}
}

@ -40,14 +40,7 @@ if (empty($content_type)) {
}
if (Security::check_abs_path($archive_path.$archive_file, $archive_path)) {
header('Expires: Wed, 01 Jan 1990 00:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: public');
header('Pragma: no-cache');
header('Content-Type: '.$content_type);
header('Content-Length: '.filesize($archive_path.$archive_file));
header('Content-Disposition: attachment; filename='.$archive_file);
readfile($archive_path.$archive_file);
DocumentManager::file_send_for_download($archive_path.$archive_file, true, $archive_file);
exit;
} else {
api_not_allowed(true);

@ -1959,17 +1959,25 @@ class CourseRestorer
//Question copied from the current platform
if ($question_option_list) {
$old_option_ids = array();
foreach ($question_option_list as $item) {
foreach ($question_option_list as $item) {
$old_id = $item['id'];
unset($item['id']);
if (isset($item['iid'])) {
unset($item['iid']);
}
$item['question_id'] = $new_id;
$item['c_id'] = $this->destination_course_id;
$question_option_id = Database::insert($table_options, $item);
$old_option_ids[$old_id] = $question_option_id;
if ($question_option_id) {
$old_option_ids[$old_id] = $question_option_id;
$sql = "UPDATE $table_options SET id = iid WHERE iid = $question_option_id";
Database::query($sql);
}
}
if ($old_option_ids) {
$new_answers = Database::select(
'id, correct',
'iid, correct',
$table_ans,
array(
'WHERE' => array(
@ -1984,12 +1992,12 @@ class CourseRestorer
foreach ($new_answers as $answer_item) {
$params = array();
$params['correct'] = $old_option_ids[$answer_item['correct']];
$question_option_id = Database::update(
Database::update(
$table_ans,
$params,
array(
'id = ? AND c_id = ? AND question_id = ? ' => array(
$answer_item['id'],
'iid = ? AND c_id = ? AND question_id = ? ' => array(
$answer_item['iid'],
$this->destination_course_id,
$new_id
)
@ -2009,7 +2017,12 @@ class CourseRestorer
$item['position'] = $obj->obj->position;
$question_option_id = Database::insert($table_options, $item);
$new_options[$obj->obj->id] = $question_option_id;
if ($question_option_id) {
$new_options[$obj->obj->id] = $question_option_id;
$sql = "UPDATE $table_options SET id = iid WHERE iid = $question_option_id";
Database::query($sql);
}
}
foreach($correct_answers as $answer_id => $correct_answer) {
@ -2029,7 +2042,6 @@ class CourseRestorer
);
}
}
}
}
$this->course->resources[RESOURCE_QUIZQUESTION][$id]->destination_id = $new_id;

@ -53,16 +53,12 @@ class MatchingDraggable extends Question
if ($form->isSubmitted()) {
$nb_matches = $form->getSubmitValue('nb_matches');
$nb_options = $form->getSubmitValue('nb_options');
if (isset($_POST['lessMatches'])) {
$nb_matches--;
}
if (isset($_POST['moreMatches'])) {
$nb_matches++;
}
if (isset($_POST['lessOptions'])) {
$nb_matches--;
$nb_options--;
}
if (isset($_POST['moreOptions'])) {
$nb_matches++;
$nb_options++;
}
} else if (!empty($this->id)) {
@ -152,12 +148,6 @@ class MatchingDraggable extends Question
$form->addHtml('</tbody></table>');
$group = array();
$renderer->setElementTemplate('<div class="form-group"><div class="col-sm-offset-2">{element}', 'lessMatches');
$renderer->setElementTemplate('{element}</div></div>', 'moreMatches');
$group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessMatches', true);
$group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreMatches', true);
$form->addGroup($group);
// DISPLAY OPTIONS

@ -621,6 +621,25 @@ class Answer
if ($autoId) {
$sql = "UPDATE $answerTable SET id = iid, id_auto = iid WHERE iid = $autoId";
Database::query($sql);
$questionType = $this->getQuestionType();
if (in_array(
$questionType,
[MATCHING, MATCHING_DRAGGABLE]
)) {
$answer = new Answer($this->questionId);
$answer->read();
$correctAnswerId = $answer->selectAnswerIdByPosition($correct);
$correctAnswerAutoId = $answer->selectAutoId($correctAnswerId);
Database::update(
$answerTable,
['correct' => $correctAnswerAutoId ? $correctAnswerAutoId : 0],
['iid = ?' => $autoId]
);
}
}
} else {
// https://support.chamilo.org/issues/6558

@ -2452,10 +2452,12 @@ class Exercise
if ($studentChoice == $answerCorrect) {
$questionScore += $true_score;
} else {
if ($quiz_question_options[$studentChoice]['name'] != "Don't know") {
$questionScore += $false_score;
} else {
if ($quiz_question_options[$studentChoice]['name'] == "Don't know" ||
$quiz_question_options[$studentChoice]['name'] == "DoubtScore"
) {
$questionScore += $doubt_score;
} else {
$questionScore += $false_score;
}
}
} else {

@ -58,16 +58,12 @@ class Matching extends Question
if ($form->isSubmitted()) {
$nb_matches = $form->getSubmitValue('nb_matches');
$nb_options = $form->getSubmitValue('nb_options');
if (isset($_POST['lessMatches'])) {
$nb_matches--;
}
if (isset($_POST['moreMatches'])) {
$nb_matches++;
}
if (isset($_POST['lessOptions'])) {
$nb_matches--;
$nb_options--;
}
if (isset($_POST['moreOptions'])) {
$nb_matches++;
$nb_options++;
}
} else if (!empty($this->id)) {
@ -160,12 +156,6 @@ class Matching extends Question
$form->addHtml('</tbody></table>');
$group = array();
$renderer->setElementTemplate('<div class="form-group"><div class="col-sm-offset-2">{element}', 'lessMatches');
$renderer->setElementTemplate('{element}</div></div>', 'moreMatches');
$group[] = $form->addButtonDelete(get_lang('DelElem'), 'lessMatches', true);
$group[] = $form->addButtonCreate(get_lang('AddElem'), 'moreMatches', true);
$form->addGroup($group);
// DISPLAY OPTIONS

@ -1326,9 +1326,9 @@ abstract class Question
$item['question_id'] = $new_question_id;
$item['c_id'] = $course_id;
unset($item['id']);
unset($item['iid']);
$id = Database::insert($TBL_QUESTION_OPTIONS, $item);
if ($id) {
$sql = "UPDATE $TBL_QUESTION_OPTIONS SET id = iid
WHERE iid = $id";
Database::query($sql);

@ -6,7 +6,7 @@
* @package chamilo.gradebook
*/
$language_file = 'gradebook';
use ChamiloSession as Session;
require_once '../inc/global.inc.php';
$current_course_tool = TOOL_GRADEBOOK;
@ -36,32 +36,78 @@ switch ($action) {
$pdf = new PDF('A4', 'P', $params);
$pdfList = array();
$cats = Category::load($cat_id, null, null, null, null, null, false);
$session_id = api_get_session_id();
if (empty($session_id)) {
$statusToFilter = STUDENT;
} else {
$statusToFilter = 0;
}
$studentList = CourseManager::get_user_list_from_course_code(
api_get_course_id(),
$session_id,
null,
null,
$statusToFilter
);
$tpl = new Template('', false, false, false);
$courseInfo = api_get_course_info();
$params = array(
'pdf_title' => sprintf(get_lang('GradeFromX'), $courseInfo['department_name']),
'session_info' => '',
'course_info' => '',
'pdf_date' => '',
'course_code' => api_get_course_id(),
'add_signatures' => false,
'student_info' => null,
'show_grade_generated_date' => true,
'show_real_course_teachers' => false,
'show_teacher_as_myself' => false
);
$pdf = new PDF('A4', $params['orientation'], $params, $tpl);
foreach ($userList as $index => $value) {
$pdfList[] = GradebookUtils::generateTable(
$value['user_id'],
$cat_id,
$cats,
false,
true
true,
$studentList,
$pdf
);
}
if (!empty($pdfList)) {
// Print certificates (without the common header/footer/watermark
// stuff) and return as one multiple-pages PDF
$address = api_get_setting('institution_address');
$phone = api_get_setting('administratorTelephone');
$address = str_replace('\n', '<br />', $address);
$pdf->custom_header = array('html' => "<h5 align='right'>$address <br />$phone</h5>");
// stuff) and return as one multiple-pages PDF
$pdf->html_to_pdf(
$pdfList,
null,
null,
false,
false,
true,
true
);
}
// Delete calc_score session data
Session::erase('calc_score');
break;
case 'download':
$userId = isset($_GET['user_id']) && $_GET['user_id'] ? $_GET['user_id'] : null;
GradebookUtils::generateTable($userId, $cat_id);
$cats = Category::load($cat_id, null, null, null, null, null, false);
GradebookUtils::generateTable($userId, $cats);
break;
}

@ -95,14 +95,14 @@ $tbl_attendance = Database :: get_course_table(TABLE_ATTENDANCE);
$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$filter_confirm_msg = true;
$filter_warning_msg = true;
$courseInfo = api_get_course_info();
$cats = Category :: load(null, null, $course_code, 0, null, $session_id, false);
$cats = Category :: load(null, null, $course_code, null, null, $session_id, 'ORDER By id');
$first_time = null;
if (empty($cats)) {
//first time
$cats = Category :: load(0, null, $course_code, 0, null, $session_id, false);
$cats = Category :: load(0, null, $course_code, null, null, $session_id, 'ORDER By id');
$first_time = 1;
}
@ -117,7 +117,7 @@ if (isset($_GET['isStudentView'])) {
if ((isset($_GET['selectcat']) && $_GET['selectcat']>0) &&
(isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview')
) {
Display :: display_header();
/*Display :: display_header();
//Introduction tool: student view
Display::display_introduction_section(TOOL_GRADEBOOK, array('ToolbarSet' => 'AssessmentsIntroduction'));
$category = $_GET['selectcat'];
@ -129,7 +129,7 @@ if ((isset($_GET['selectcat']) && $_GET['selectcat']>0) &&
$gradebooktable= new GradebookTable($cats[0], $allcat, $alleval,$alllink, $addparams);
$gradebooktable->display();
Display :: display_footer();
exit;
exit;*/
} else {
if (!isset($_GET['selectcat']) &&
($_SESSION['studentview']=='studentview') ||
@ -630,7 +630,7 @@ if (isset($_GET['studentoverview'])) {
//@todo this code also seems to be deprecated ...
$cats = Category :: load($category);
$stud_id= (api_is_allowed_to_edit() ? null : $stud_id);
$allcat= array ();
$allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
$alleval= $cats[0]->get_evaluations($stud_id, true);
$alllink= $cats[0]->get_links($stud_id, true);
if (isset ($_GET['exportpdf'])) {
@ -844,7 +844,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
if (!empty($grade_models)) {
$form_grade = new FormValidator('grade_model_settings');
$obj->fill_grade_model_select_in_form($form_grade, 'grade_model_id', $grade_model_id);
$form->addButtonSave(get_lang('Save'));
$form_grade->addButtonSave(get_lang('Save'));
if ($form_grade->validate()) {
$value = $form_grade->exportValue('grade_model_id');
@ -940,6 +940,10 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
6 => 'class=centered',
7 => 'class=centered'
];
if ($action == 'export_table') {
unset($gradebooktable->td_attributes[7]);
}
}
$table = $gradebooktable->return_table();
@ -947,21 +951,38 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
if ($action == 'export_table') {
ob_clean();
$sessionName = api_get_session_name(api_get_session_id());
$sessionName = !empty($sessionName) ? " - $sessionName" : '';
$params = array(
//'filename' => get_lang('FlatView') . '_' . api_get_utc_datetime(),
'pdf_title' => get_lang('Report'),
'pdf_title' => sprintf(get_lang('GradeFromX'), $courseInfo['department_name']),
'course_code' => api_get_course_id(),
'session_info' => api_get_session_info(api_get_session_id()),
'session_info' => '',
'course_info' => '',
'pdf_date' => '',
'add_signatures' => false,
'student_info' => api_get_user_info()
'student_info' => api_get_user_info(),
'show_grade_generated_date' => true,
'show_real_course_teachers' => false,
'show_teacher_as_myself' => false
);
$pdf = new PDF('A4', $params['orientation'], $params);
$pdf->html_to_pdf_with_template($table.$graph);
$address = api_get_setting('institution_address');
$phone = api_get_setting('administratorTelephone');
$address = str_replace('\n', '<br />', $address);
$pdf->custom_header = array('html' => "<h5 align='right'>$address <br />$phone</h5>");
$pdf->html_to_pdf_with_template(
$table.
$graph.
'<br />'.get_lang('Feedback').'<br />
<textarea rows="5" cols="100" ></textarea>'
);
} else {
echo $table;
echo $graph;
}
}
}
}

@ -821,8 +821,16 @@ class GradebookUtils
* @param array $params
* @param null $mainCourseCategory
*/
public static function export_pdf_flatview($flatviewtable, $cat, $users, $alleval, $alllinks, $params = array(), $mainCourseCategory = null)
{
public static function export_pdf_flatview(
$flatviewtable,
$cat,
$users,
$alleval,
$alllinks,
$params = array(),
$mainCourseCategory = null
) {
// Getting data
$printable_data = self::get_printable_data($cat[0], $users, $alleval, $alllinks, $params, $mainCourseCategory);
@ -837,7 +845,7 @@ class GradebookUtils
foreach ($customdisplays as $custom) {
$total[$custom['display']] = 0;
}
$user_results = $flatviewtable->datagen->get_data_to_graph2();
$user_results = $flatviewtable->datagen->get_data_to_graph2(false);
foreach ($user_results as $user_result) {
$total[$user_result[count($user_result) - 1][1]]++;
}
@ -882,7 +890,9 @@ class GradebookUtils
$table->setHeaderContents($row, $column, get_lang('NumberAbbreviation'));
$column++;
foreach ($printable_data[0] as $printable_data_cell) {
$printable_data_cell = strip_tags($printable_data_cell);
if (!is_array($printable_data_cell)) {
$printable_data_cell = strip_tags($printable_data_cell);
}
$table->setHeaderContents($row, $column, $printable_data_cell);
$column++;
}
@ -1302,18 +1312,25 @@ class GradebookUtils
/**
* @param int $userId
* @param int $categoryId
* @param array $cats
* @param bool $saveToFile
* @param bool $saveToHtmlFile
* @param array $studentList
* @param PDF $pdf
*
* @return string
*/
public static function generateTable($userId, $categoryId, $saveToFile = false, $saveToHtmlFile = false)
{
public static function generateTable(
$userId,
$cats,
$saveToFile = false,
$saveToHtmlFile = false,
$studentList = array(),
$pdf = null
) {
$courseInfo = api_get_course_info();
$userInfo = api_get_user_info($userId);
$cats = Category::load($categoryId, null, null, null, null, null, false);
$cat = $cats[0];
$allcat = $cats[0]->get_subcategories(
@ -1332,9 +1349,12 @@ class GradebookUtils
null, // params
true, // $exportToPdf
false, // showteacher
$userId
$userId,
$studentList
);
$gradebooktable->userId = $userId;
if (api_is_allowed_to_edit()) {
$gradebooktable->td_attributes = [
4 => 'class=centered'
@ -1354,17 +1374,27 @@ class GradebookUtils
$sessionName = api_get_session_name(api_get_session_id());
$sessionName = !empty($sessionName) ? " - $sessionName" : '';
$params = array(
//'filename' => get_lang('FlatView') . '_' . api_get_utc_datetime(),
'pdf_title' => $courseInfo['title'].$sessionName,
'pdf_title' => sprintf(get_lang('GradeFromX'), $courseInfo['department_name']),
'session_info' => '',
'course_info' => '',
'pdf_date' => '',
'course_code' => api_get_course_id(),
'session_info' => api_get_session_info(api_get_session_id()),
'add_signatures' => false,
'student_info' => $userInfo,
'show_grade_generated_date' => true,
'show_real_course_teachers' => true
'show_real_course_teachers' => false,
'show_teacher_as_myself' => false,
'orientation' => 'P'
);
if (empty($pdf)) {
$pdf = new PDF('A4', $params['orientation'], $params);
}
$pdf->params['student_info'] = $userInfo;
$file = api_get_path(SYS_ARCHIVE_PATH).uniqid().'.html';
$content =
@ -1373,7 +1403,11 @@ class GradebookUtils
'<br />'.get_lang('Feedback').'<br />
<textarea rows="5" cols="100" ></textarea>';
$pdf = new PDF('A4', $params['orientation'], $params);
$address = api_get_setting('institution_address');
$phone = api_get_setting('administratorTelephone');
$address = str_replace('\n', '<br />', $address);
$pdf->custom_header = array('html' => "<h5 align='right'>$address <br />$phone</h5>");
$result = $pdf->html_to_pdf_with_template(
$content,

@ -25,6 +25,7 @@ abstract class AbstractLink implements GradebookItem
protected $visible;
protected $session_id;
public $course_id;
public $studentList;
/**
* Constructor
@ -167,6 +168,16 @@ abstract class AbstractLink implements GradebookItem
$this->course_id = $course_info['real_id'];
}
public function getStudentList()
{
return $this->studentList;
}
public function setStudentList($list)
{
$this->studentList = $list;
}
public function set_date($date)
{
$this->created_at = $date;
@ -591,6 +602,7 @@ abstract class AbstractLink implements GradebookItem
$ranking = null;
$currentUserId = $userId;
if (!empty($studentList) && !empty($currentUserId)) {
$studentList = array_map('floatval', $studentList);
asort($studentList);
$ranking = $count = count($studentList);

@ -22,6 +22,7 @@ class Category implements GradebookItem
private $grade_model_id;
private $generateCertificates;
private $isRequirement;
public $studentList;
/**
* Consctructor
@ -645,7 +646,7 @@ class Category implements GradebookItem
$gradebookCategory->setGradeModelId($this->grade_model_id);
$gradebookCategory->setIsRequirement($this->isRequirement);
$em->persist($gradebookCategory);
$em->merge($gradebookCategory);
$em->flush();
if (!empty($this->id)) {
@ -866,109 +867,220 @@ class Category implements GradebookItem
$course_code = '',
$session_id = null
) {
// Get appropriate subcategories, evaluations and links
if (!empty($course_code)) {
$cats = $this->get_subcategories($stud_id, $course_code, $session_id);
$evals = $this->get_evaluations($stud_id, false, $course_code);
$links = $this->get_links($stud_id, false, $course_code);
} else {
$cats = $this->get_subcategories($stud_id);
$evals = $this->get_evaluations($stud_id);
$links = $this->get_links($stud_id);
}
// Calculate score
$rescount = 0;
$ressum = 0;
$weightsum = 0;
$bestResult = 0;
$students = [];
if (!empty($cats)) {
/** @var Category $cat */
foreach ($cats as $cat) {
$score = $cat->calc_score(
// Classic
if (!empty($stud_id) && $type == '') {
if (!empty($course_code)) {
$cats = $this->get_subcategories(
$stud_id,
$type,
$course_code,
$session_id
);
$evals = $this->get_evaluations($stud_id, false, $course_code);
$links = $this->get_links($stud_id, false, $course_code);
} else {
$cats = $this->get_subcategories($stud_id);
$evals = $this->get_evaluations($stud_id);
$links = $this->get_links($stud_id);
}
if ($cat->get_weight() != 0) {
$catweight = $cat->get_weight();
$rescount++;
$weightsum += $catweight;
}
// Calculate score
$count = 0;
$ressum = 0;
$weightsum = 0;
if (isset($score)) {
$ressum += $score[0]/$score[1] * $catweight;
$bestResult += $ressum;
if (!empty($cats)) {
/** @var Category $cat */
foreach ($cats as $cat) {
$cat->setStudentList($this->getStudentList());
$score = $cat->calc_score(
$stud_id,
null,
$course_code,
$session_id
);
$catweight = 0;
if ($cat->get_weight() != 0) {
$catweight = $cat->get_weight();
$weightsum += $catweight;
}
if (isset($score) && !empty($score[1]) && !empty($catweight)) {
$ressum += $score[0]/$score[1] * $catweight;
}
}
}
}
if (!empty($evals)) {
/** @var Evaluation $eval */
foreach ($evals as $eval) {
$evalres = $eval->calc_score($stud_id, $type);
$students[$stud_id] = $evalres[0];
if (isset($evalres) && $eval->get_weight() != 0) {
$evalweight = $eval->get_weight();
$weightsum += $evalweight;
$rescount++;
$ressum += $evalres[0] / $evalres[1] * $evalweight;
} else {
if ($eval->get_weight() != 0) {
$students = array();
if (!empty($evals)) {
/** @var Evaluation $eval */
foreach ($evals as $eval) {
$eval->setStudentList($this->getStudentList());
$evalres = $eval->calc_score($stud_id, null);
if (isset($evalres) && $eval->get_weight() != 0) {
$evalweight = $eval->get_weight();
$weightsum += $evalweight;
$count++;
if (!empty($evalres[1])) {
$ressum += $evalres[0] / $evalres[1] * $evalweight;
}
} else {
if ($eval->get_weight() != 0) {
$evalweight = $eval->get_weight();
$weightsum += $evalweight;
}
}
}
}
}
if (!empty($links)) {
if (!empty($links)) {
/** @var EvalLink|ExerciseLink $link */
foreach ($links as $link) {
$link->setStudentList($this->getStudentList());
$linkres = $link->calc_score($stud_id, null);
if (!empty($linkres) && $link->get_weight() != 0) {
$students[$stud_id] = $linkres[0];
$linkweight = $link->get_weight();
$link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
$count++;
$weightsum += $linkweight;
$ressum += $linkres[0] / $link_res_denom * $linkweight;
} else {
// Adding if result does not exists
if ($link->get_weight() != 0) {
$linkweight = $link->get_weight();
$weightsum += $linkweight;
}
}
}
}
} else {
if (!empty($course_code)) {
$cats = $this->get_subcategories(
null,
$course_code,
$session_id
);
$evals = $this->get_evaluations(null, false, $course_code);
$links = $this->get_links(null, false, $course_code);
} else {
$cats = $this->get_subcategories(null);
$evals = $this->get_evaluations(null);
$links = $this->get_links(null);
}
// Calculate score
$count = 0;
$ressum = 0;
$weightsum = 0;
$bestResult = 0;
$weight = 0;
/** @var EvalLink|ExerciseLink $link */
foreach ($links as $link) {
$linkres = $link->calc_score($stud_id, $type);
if (!empty($linkres) && $link->get_weight() != 0) {
$students[$stud_id] = $linkres[0];
$linkweight = $link->get_weight();
$link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
$rescount++;
$weightsum += $linkweight;
$ressum += $linkres[0] / $link_res_denom * $linkweight;
} else {
// Adding if result does not exists
if ($link->get_weight() != 0) {
if (!empty($cats)) {
/** @var Category $cat */
foreach ($cats as $cat) {
$cat->setStudentList($this->getStudentList());
$score = $cat->calc_score(
null,
$type,
$course_code,
$session_id
);
$catweight = 0;
if ($cat->get_weight() != 0) {
$catweight = $cat->get_weight();
$weightsum += $catweight;
}
if (isset($score) && !empty($score[1]) && !empty($catweight)) {
$ressum += $score[0]/$score[1] * $catweight;
if ($ressum > $bestResult) {
$bestResult = $ressum;
}
}
}
}
if (!empty($evals)) {
/** @var Evaluation $eval */
foreach ($evals as $eval) {
$evalres = $eval->calc_score(null, $type);
$eval->setStudentList($this->getStudentList());
if (isset($evalres) && $eval->get_weight() != 0) {
$evalweight = $eval->get_weight();
$weightsum += $evalweight;
$count++;
if (!empty($evalres[1])) {
$ressum += $evalres[0] / $evalres[1] * $evalweight;
}
if ($ressum > $bestResult) {
$bestResult = $ressum;
}
} else {
if ($eval->get_weight() != 0) {
$evalweight = $eval->get_weight();
$weightsum += $evalweight;
}
}
}
}
if (!empty($links)) {
/** @var EvalLink|ExerciseLink $link */
foreach ($links as $link) {
$link->setStudentList($this->getStudentList());
$linkres = $link->calc_score($stud_id, $type);
if (!empty($linkres) && $link->get_weight() != 0) {
$students[$stud_id] = $linkres[0];
$linkweight = $link->get_weight();
$link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1];
$count++;
$weightsum += $linkweight;
$ressum += $linkres[0] / $link_res_denom * $linkweight;
if ($ressum > $bestResult) {
$bestResult = $ressum;
}
} else {
// Adding if result does not exists
if ($link->get_weight() != 0) {
$linkweight = $link->get_weight();
$weightsum += $linkweight;
}
}
}
}
}
if ($rescount == 0) {
return null;
} else {
switch ($type) {
case 'best':
return array($ressum, $weightsum);
break;
case 'average':
return array($ressum, $weightsum);
break;
case 'ranking':
switch ($type) {
case 'best':
if (empty($bestResult)) {
return null;
return AbstractLink::getCurrentUserRanking($stud_id, $students);
break;
default:
return array($ressum, $weightsum);
break;
}
}
return array($bestResult, $weightsum);
break;
case 'average':
if (empty($ressum)) {
return null;
}
return array($ressum, $weightsum);
break;
case 'ranking':
// category ranking is calculated in gradebook_data_generator.class.php
// function get_data
return null;
return AbstractLink::getCurrentUserRanking($stud_id, array());
break;
default:
return array($ressum, $weightsum);
break;
}
}
@ -2169,4 +2281,20 @@ class Category implements GradebookItem
);
}
/**
* @return array
*/
public function getStudentList()
{
return $this->studentList;
}
/**
* @param array $list
*/
public function setStudentList($list)
{
$this->studentList = $list;
}
}

@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* Class Evaluation
* @package chamilo.gradebook
@ -19,6 +21,7 @@ class Evaluation implements GradebookItem
private $eval_max;
private $visible;
private $sessionId;
public $studentList;
/**
* Construct
@ -534,46 +537,84 @@ class Evaluation implements GradebookItem
*/
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;
$students = [];
/** @var Result $res */
foreach ($results as $res) {
$score = $res->get_score();
if (!empty($score) || $score == '0') {
$rescount++;
$sum += $score / $this->get_max();
$sumResult += $score;
if ($score > $bestResult) {
$bestResult = $score;
}
$weight = $this->get_max();
$useSession = true;
if (isset($stud_id) && empty($type)) {
$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id;
$data = Session::read('calc_score');
$results = isset($data[$key]) ? $data[$key] : null;
if ($useSession == false) {
$results = null;
}
if (empty($results)) {
$results = Result::load(null, $stud_id, $this->id);
Session::write('calc_score', array($key => $results));
}
$score = 0;
/** @var Result $res */
foreach ($results as $res) {
$score = $res->get_score();
}
$students[$res->get_user_id()] = $score;
}
if ($rescount == 0) {
return null;
} else if (isset($stud_id)) {
return array($score, $this->get_max());
} else {
$count = 0;
$sum = 0;
$bestResult = 0;
$weight = 0;
$sumResult = 0;
$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id;
$data = Session::read('calc_score');
$allResults = isset($data[$key]) ? $data[$key] : null;
if ($useSession == false) {
$allResults = null;
}
if (empty($allResults)) {
$allResults = Result::load(null, null, $this->id);
Session::write($key, $allResults);
}
$students = array();
/** @var Result $res */
foreach ($allResults as $res) {
$score = $res->get_score();
if (!empty($score) || $score == '0') {
$count++;
$sum += $score / $this->get_max();
$sumResult += $score;
if ($score > $bestResult) {
$bestResult = $score;
}
$weight = $this->get_max();
}
$students[$res->get_user_id()] = $score;
}
if (empty($count)) {
return null;
}
switch ($type) {
case 'best':
return array($bestResult, $weight);
break;
case 'average':
return array($sumResult/$rescount, $weight);
return array($sumResult/$count, $weight);
break;
case 'ranking':
$students = array();
/** @var Result $res */
foreach ($allResults as $res) {
$score = $res->get_score();
$students[$res->get_user_id()] = $score;
}
return AbstractLink::getCurrentUserRanking($stud_id, $students);
break;
default:
return array($sum, $rescount);
return array($sum, $count);
break;
}
}
@ -752,4 +793,14 @@ class Evaluation implements GradebookItem
{
}
public function getStudentList()
{
return $this->studentList;
}
public function setStudentList($list)
{
$this->studentList = $list;
}
}

@ -206,7 +206,9 @@ class ExerciseLink extends AbstractLink
orig_lp_id = 0 AND
orig_lp_item_id = 0 AND
status <> 'incomplete' AND
session_id = $session_id";
session_id = $session_id AND
c_id = $courseId
";
} else {
$lpId = null;
if (!empty($exercise->lpList)) {
@ -220,11 +222,13 @@ class ExerciseLink extends AbstractLink
exe_exo_id = ".intval($this->get_ref_id())." AND
orig_lp_id = $lpId AND
status <> 'incomplete' AND
session_id = $session_id";
session_id = $session_id AND
c_id = $courseId
";
}
if (isset($stud_id)) {
$sql .= " AND c_id = $courseId AND exe_user_id = $stud_id ";
if (!empty($stud_id) && $type != 'ranking') {
$sql .= " AND exe_user_id = $stud_id ";
}
$sql .= ' ORDER BY exe_id DESC';
@ -240,7 +244,7 @@ class ExerciseLink extends AbstractLink
$scores = Database::query($sql);
if (isset($stud_id)) {
if (isset($stud_id) && empty($type)) {
// for 1 student
if ($data = Database::fetch_array($scores)) {
return array($data['exe_result'], $data['exe_weighting']);
@ -281,7 +285,11 @@ class ExerciseLink extends AbstractLink
return array($bestResult, $weight);
break;
case 'average':
return array($sumResult/$student_count, $weight);
$count = count($this->getStudentList());
/*if (empty($count)) {
return null;
}*/
return array($sumResult/$count , $weight);
break;
case 'ranking':
return AbstractLink::getCurrentUserRanking($stud_id, $students);

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

@ -22,8 +22,6 @@ class LearnpathLink extends AbstractLink
$this->set_type(LINK_LEARNPATH);
}
// FUNCTIONS IMPLEMENTING ABSTRACTLINK
/**
* Generate an array of learnpaths that a teacher hasn't created a link for.
* @return array 2-dimensional array - every element contains 2 subelements (id, name)

@ -85,6 +85,7 @@ class 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();
$list_user_course_list = array();
if (is_null($id) && is_null($user_id) && !is_null($evaluation_id)) {
// Verified_if_exist_evaluation
@ -95,8 +96,6 @@ class Result
$existEvaluation = Database::result($result, 0, 0);
if ($existEvaluation != 0) {
$sql_course_rel_user = '';
if ($sessionId) {
$sql = 'SELECT c_id, user_id as user_id, status
FROM ' . $tbl_session_rel_course_user . '
@ -111,8 +110,6 @@ class Result
}
$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')) {
$list_user_course_list[] = $row_course_rel_user;
}
@ -134,9 +131,21 @@ class Result
}
}
$sql = "SELECT gr.id, gr.user_id, gr.evaluation_id, gr.created_at, gr.score
$userIdList = array();
foreach ($list_user_course_list as $data) {
$userIdList[] = $data['user_id'];
}
$userIdListToString = implode("', '", $userIdList);
$sql = "SELECT lastname, gr.id, gr.user_id, gr.evaluation_id, gr.created_at, gr.score
FROM $tbl_grade_results gr
LEFT JOIN $tbl_user u ON gr.user_id = u.user_id ";
INNER JOIN $tbl_user u
ON gr.user_id = u.user_id ";
if (!empty($userIdList)) {
$sql .= " AND u.user_id IN ('$userIdListToString')";
}
$paramcount = 0;
if (!empty($id)) {
$sql.= ' WHERE gr.id = ' . intval($id);
@ -171,6 +180,7 @@ class Result
$res->set_score($data['score']);
$allres[] = $res;
}
return $allres;
}

@ -1,6 +1,7 @@
<?php
/* For licensing terms, see license.txt */
use ChamiloSession as Session;
use CpChart\Classes\pCache as pCache;
use CpChart\Classes\pData as pData;
use CpChart\Classes\pImage as pImage;
@ -22,6 +23,7 @@ class GradebookTable extends SortableTable
public $exportToPdf;
public $teacherView;
public $userId;
public $studentList;
/**
* Constructor
@ -39,7 +41,8 @@ class GradebookTable extends SortableTable
$addparams = null,
$exportToPdf = false,
$showTeacherView = null,
$userId = null
$userId = null,
$studentList = array()
) {
$this->teacherView = is_null($showTeacherView) ? api_is_allowed_to_edit(null, true) : $showTeacherView;
$this->userId = is_null($userId) ? api_get_user_id() : $userId;
@ -113,7 +116,7 @@ class GradebookTable extends SortableTable
$this->set_form_actions(array(
'setvisible' => get_lang('SetVisible'),
'setinvisible' => get_lang('SetInvisible'),
'deleted' => get_lang('DeleteSelected'),
'deleted' => get_lang('DeleteSelected')
)
);
} else {
@ -192,7 +195,6 @@ class GradebookTable extends SortableTable
}
// Status of user in course.
//$user_id = api_get_user_id();
$user_id = $this->userId;
$course_code = api_get_course_id();
$session_id = api_get_session_id();
@ -207,13 +209,16 @@ class GradebookTable extends SortableTable
$statusToFilter = 0;
}
$studentList = CourseManager::get_user_list_from_course_code(
$course_code,
$session_id,
null,
null,
$statusToFilter
);
if (empty($this->studentList)) {
$studentList = CourseManager::get_user_list_from_course_code(
$course_code,
$session_id,
null,
null,
$statusToFilter
);
$this->studentList = $studentList;
}
$this->datagen->userId = $this->userId;
@ -222,7 +227,7 @@ class GradebookTable extends SortableTable
$from,
$this->per_page,
false,
$studentList
$this->studentList
);
// generate the data to display
@ -236,7 +241,7 @@ class GradebookTable extends SortableTable
null,
null,
$session_id,
false
'ORDER BY id'
);
$total_categories_weight = 0;
$scoredisplay = ScoreDisplay :: instance();
@ -245,7 +250,13 @@ class GradebookTable extends SortableTable
$totalBest = [0, 0];
$totalAverage = [0, 0];
$type = 'detail';
if ($this->exportToPdf) {
$type = 'simple';
}
// Categories.
if (!empty($data_array))
foreach ($data_array as $data) {
// list of items inside the gradebook (exercises, lps, forums, etc)
$row = array();
@ -271,8 +282,9 @@ class GradebookTable extends SortableTable
$row[] = $invisibility_span_open.'<h3>'.$item->get_name().'</h3>'.$invisibility_span_close;
$main_categories[$item->get_id()]['name'] = $item->get_name();
} else {
$row[] = $invisibility_span_open.$this->build_name_link($item) . $invisibility_span_close;
$main_categories[$item->get_id()]['name'] = $this->build_name_link($item);
$name = $this->build_name_link($item, $type);
$row[] = $invisibility_span_open.$name. $invisibility_span_close;
$main_categories[$item->get_id()]['name'] = $name;
}
$this->dataForGraph['categories'][] = $item->get_name();
@ -303,6 +315,7 @@ class GradebookTable extends SortableTable
}
$category_weight = $item->get_weight();
$mainCategoryWeight = $main_cat[0]->get_weight();
if ($this->teacherView) {
$weight_total_links += $data[3];
@ -334,7 +347,7 @@ class GradebookTable extends SortableTable
// Students get the results and certificates columns
//if (count($this->evals_links) > 0 && $status_user != 1) {
if ($status_user != 1) {
if (1) {
$value_data = isset($data[4]) ? $data[4] : null;
$best = isset($data['best']) ? $data['best'] : null;
$average = isset($data['average']) ? $data['average'] : null;
@ -355,11 +368,12 @@ class GradebookTable extends SortableTable
$totalAverage[1] + $data['average_score'][1],
];
$this->dataForGraph['my_result'][] = (float) $scoredisplay->display_score($totalResult, SCORE_AVERAGE);
$this->dataForGraph['average'][] = (float) $scoredisplay->display_score($totalAverage, SCORE_AVERAGE);
// Student result
$row[] = $value_data;
$totalResultAverageValue = strip_tags($scoredisplay->display_score($totalResult, SCORE_AVERAGE));
$this->dataForGraph['my_result'][] = (float) str_replace('%', '', $totalResultAverageValue);
$totalAverageValue = strip_tags($scoredisplay->display_score($totalAverage, SCORE_AVERAGE));
$this->dataForGraph['average'][] = (float) str_replace('%', '', $totalAverageValue);
// Ranking
$row[] = $ranking;
// Best
@ -407,11 +421,18 @@ class GradebookTable extends SortableTable
$sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink);
$sub_cat_info->userId = $user_id;
$data_array = $sub_cat_info->get_data($sorting, $from, $this->per_page);
$data_array2 = $sub_cat_info->get_data(
$sorting,
$from,
$this->per_page,
false,
$this->studentList
);
$total_weight = 0;
// Links.
foreach ($data_array as $data) {
foreach ($data_array2 as $data) {
$row = array();
$item = $data[0];
@ -430,11 +451,12 @@ class GradebookTable extends SortableTable
$row[] = $this->build_id_column($item);
}
}
// Type
$row[] = $this->build_type_column($item, array('style' => 'padding-left:5px'));
// Name.
$row[] = $invisibility_span_open."&nbsp;&nbsp;&nbsp; ".$this->build_name_link($item) . $invisibility_span_close;
$row[] = $invisibility_span_open."&nbsp;&nbsp;&nbsp; ".$this->build_name_link($item, $type) . $invisibility_span_close;
// Description.
if ($this->exportToPdf == false) {
@ -443,6 +465,7 @@ class GradebookTable extends SortableTable
$weight = $data[3];
$total_weight += $weight;
// Weight
$row[] = $invisibility_span_open.$weight.$invisibility_span_close;
@ -517,7 +540,7 @@ class GradebookTable extends SortableTable
$total = GradebookUtils::score_badges(
array(
$total_weight.' / '.$category_weight,
'100',
'100'
)
);
} else {
@ -533,7 +556,7 @@ class GradebookTable extends SortableTable
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<h5>".get_lang('SubTotal').'</h5>',
null,
$total.' '.$label,
'child_of' => $parent_id,
'child_of' => $parent_id
);
$sortable_data[] = $row;
}
@ -559,7 +582,10 @@ class GradebookTable extends SortableTable
if (intval($total_categories_weight) == $main_weight) {
$total = GradebookUtils::score_badges(
array($total_categories_weight.' / '.$main_weight, '100')
array(
$total_categories_weight.' / '.$main_weight,
'100'
)
);
} else {
$total = Display::badge($total_categories_weight.' / '.$main_weight, 'warning');
@ -569,7 +595,7 @@ class GradebookTable extends SortableTable
null,
'<h3>' . get_lang('Total') . '</h3>',
null,
$total,
$total
);
$sortable_data[] = $row;
}
@ -589,26 +615,49 @@ class GradebookTable extends SortableTable
);
$totalRanking = array();
foreach ($studentList as $student) {
$invalidateRanking = true;
$average = 0;
foreach ($this->studentList as $student) {
$score = $main_cat[0]->calc_score($student['user_id']);
if (!empty($score[0])) {
$invalidateRanking = false;
}
$totalRanking[$student['user_id']] = $score[0];
$average += $score[0];
}
$totalRanking = AbstractLink::getCurrentUserRanking($user_id, $totalRanking);
$totalRanking = $scoredisplay->display_score(
$totalRanking,
SCORE_DIV
SCORE_DIV,
SCORE_BOTH,
true
);
if ($invalidateRanking) {
$totalRanking = null;
}
// Overwrite main weight
$totalBest[1] = $main_weight;
$totalBest = $scoredisplay->display_score(
$totalBest,
SCORE_DIV
SCORE_DIV,
SCORE_BOTH,
true
);
// Overwrite main weight
$totalAverage[0] = $average / count($this->studentList);
$totalAverage[1] = $main_weight;
$totalAverage = $scoredisplay->display_score(
$totalAverage,
SCORE_DIV
SCORE_DIV,
SCORE_BOTH,
true
);
if ($this->exportToPdf) {
@ -883,20 +932,23 @@ class GradebookTable extends SortableTable
/**
* Generate name column
* @param unknown_type $item
* @param GradebookItem $item
* @param string $type simple|detail
* @return string
*/
private function build_name_link($item)
private function build_name_link($item, $type = 'detail')
{
$view = isset($_GET['view']) ? Security::remove_XSS($_GET['view']) : null;
$categoryId = $item->getCategory()->get_id();
switch ($item->get_item_type()) {
// category
case 'C' :
$prms_uri='?selectcat=' . $item->get_id() . '&view='.$view;
$prms_uri='?selectcat=' . $item->get_id() . '&amp;view='.$view;
if (isset($_GET['isStudentView'])) {
if ( isset($is_student) || ( isset($_SESSION['studentview']) && $_SESSION['studentview']=='studentview') ) {
$prms_uri=$prms_uri.'&isStudentView='.Security::remove_XSS($_GET['isStudentView']);
$prms_uri=$prms_uri.'&amp;isStudentView='.Security::remove_XSS($_GET['isStudentView']);
}
}
@ -909,27 +961,25 @@ class GradebookTable extends SortableTable
// evaluation
case 'E' :
$cat = new Category();
$show_message = false;
$course_id = 0;
if (isset($_GET['selectcat'])) {
$course_id = CourseManager::get_course_by_category(
$_GET['selectcat']
);
$show_message = $cat->show_message_resource_delete($course_id);
}
$course_id = CourseManager::get_course_by_category($categoryId);
$show_message = $cat->show_message_resource_delete($course_id);
// course/platform admin can go to the view_results page
if (api_is_allowed_to_edit() && $show_message===false) {
if ($item->get_type() == 'presence') {
return '&nbsp;'
. '<a href="gradebook_view_result.php?cidReq='.$course_id.'&selecteval=' . $item->get_id() . '">'
. '<a href="gradebook_view_result.php?cidReq='.$course_id.'&amp;selecteval=' . $item->get_id() . '">'
. $item->get_name()
. '</a>';
} else {
$extra = Display::label(get_lang('Evaluation'));
if ($type == 'simple') {
$extra = '';
}
return '&nbsp;'
. '<a href="gradebook_view_result.php?cidReq='.$course_id.'&selecteval=' . $item->get_id() . '">'
. '<a href="gradebook_view_result.php?cidReq='.$course_id.'&amp;selecteval=' . $item->get_id() . '">'
. $item->get_name()
. '</a>&nbsp;'.Display::label(get_lang('Evaluation'));
. '</a>&nbsp;'.$extra;
}
} elseif (ScoreDisplay :: instance()->is_custom() && $show_message===false) {
// students can go to the statistics page (if custom display enabled)
@ -949,7 +999,7 @@ class GradebookTable extends SortableTable
case 'L':
// link
$cat = new Category();
$course_id = CourseManager::get_course_by_category($_GET['selectcat']);
$course_id = CourseManager::get_course_by_category($categoryId);
$show_message = $cat->show_message_resource_delete($course_id);
$url = $item->get_link();
@ -962,7 +1012,12 @@ class GradebookTable extends SortableTable
$text = $item->get_name();
}
$text .= "&nbsp;".Display::label($item->get_type_name(), 'info').$show_message;
$extra = Display::label($item->get_type_name(), 'info');
if ($type == 'simple') {
$extra = '';
}
$text .= "&nbsp;".$extra.$show_message;
$cc = $this->currentcat->get_course_code();
if (empty($cc)) {
$text .= '&nbsp;[<a href="'.api_get_path(REL_COURSE_PATH).$item->get_course_code().'/">'.$item->get_course_code().'</a>]';

@ -110,7 +110,8 @@ class FlatViewDataGenerator
$parent_id = $this->category->get_parent_id();
if ($parent_id == 0 or
if ($parent_id == 0 ||
isset($this->params['only_subcat']) &&
$this->params['only_subcat'] == $this->category->get_id()
) {
$main_weight = $this->category->get_weight();

@ -79,8 +79,13 @@ class GradebookDataGenerator
* 4: date
* 5: student's score (if student logged in)
*/
public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false, $studentList = array())
{
public function get_data(
$sorting = 0,
$start = 0,
$count = null,
$ignore_score_color = false,
$studentList = array()
) {
//$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
// do some checks on count, redefine if invalid value
if (!isset($count)) {
@ -91,6 +96,7 @@ class GradebookDataGenerator
}
$allitems = $this->items;
/*
// sort array
if ($sorting & self :: GDG_SORT_TYPE) {
usort($allitems, array('GradebookDataGenerator', 'sort_by_type'));
@ -107,7 +113,9 @@ class GradebookDataGenerator
}
if ($sorting & self :: GDG_SORT_DESC) {
$allitems = array_reverse($allitems);
}
}*/
usort($allitems, array('GradebookDataGenerator', 'sort_by_name'));
$userId = $this->userId;
@ -120,26 +128,14 @@ class GradebookDataGenerator
api_get_course_int_id()
);
if (empty($sessionId)) {
$statusToFilter = STUDENT;
} else {
$statusToFilter = 0;
}
$userCount = CourseManager::get_user_list_from_course_code(
$course_code,
$sessionId,
null,
null,
$statusToFilter,
true
);
$userCount = count($studentList);
// Generate the data to display
$data = array();
/** @var GradebookItem $item */
$totalWeight = 0;
foreach ($visibleitems as $item) {
$row = array();
$row[] = $item;
@ -149,7 +145,10 @@ class GradebookDataGenerator
api_get_short_text_from_html($item->get_description(), 160).'</span>';
$totalWeight += $item->get_weight();
$row[] = $item->get_weight();
if (count($this->evals_links) > 0) {
$item->setStudentList($studentList);
//if (count($this->evals_links) > 0) {
if (get_class($item) == 'Evaluation') {
// Items inside a category.
if (1) {
$resultColumn = $this->build_result_column(
@ -182,8 +181,6 @@ class GradebookDataGenerator
}
} else {
// Category.
// Result
$result = $this->build_result_column($userId, $item, $ignore_score_color, true);
$row[] = $result['display'];
$row['result_score'] = $result['score'];
@ -201,6 +198,7 @@ class GradebookDataGenerator
// Ranking
$rankingStudentList = array();
$invalidateResults = true;
foreach ($studentList as $user) {
$score = $this->build_result_column(
$user['user_id'],
@ -208,12 +206,21 @@ class GradebookDataGenerator
$ignore_score_color,
true
);
$rankingStudentList[$user['user_id']] = $score['display'][0];
if (!empty($score['score'][0])) {
$invalidateResults = false;
}
$rankingStudentList[$user['user_id']] = $score['score'][0];
}
$scoreDisplay = ScoreDisplay::instance();
$scoreDisplay = ScoreDisplay::instance();
$score = AbstractLink::getCurrentUserRanking($userId, $rankingStudentList);
$row['ranking'] = $scoreDisplay->display_score($score, SCORE_DIV);
$row['ranking'] = $scoreDisplay->display_score($score, SCORE_DIV, SCORE_BOTH, true);
if ($invalidateResults) {
$row['ranking'] = null;
}
}
$data[] = $row;
}
@ -236,9 +243,14 @@ class GradebookDataGenerator
);
$scoreDisplay = ScoreDisplay :: instance();
$display = $scoreDisplay->display_score($score, SCORE_DIV, SCORE_BOTH, true);
$type = $item->get_item_type();
if ($type == 'L' && get_class($item) == 'ExerciseLink') {
$display = ExerciseLib::show_score($score[0], $score[1], false);
}
return array(
'display' => $scoreDisplay->display_score($score, SCORE_DIV),
'display' => $display,
'score' => $score
);
}
@ -252,9 +264,15 @@ class GradebookDataGenerator
{
$score = $item->calc_score(null, 'average');
$scoreDisplay = ScoreDisplay :: instance();
$display = $scoreDisplay->display_score($score, SCORE_DIV, SCORE_BOTH, true);
$type = $item->get_item_type();
if ($type == 'L' && get_class($item) == 'ExerciseLink') {
$display = ExerciseLib::show_score($score[0], $score[1], false);
}
return array(
'display' => $scoreDisplay->display_score($score, SCORE_DIV),
'display' => $display,
'score' => $score
);
}
@ -274,7 +292,7 @@ class GradebookDataGenerator
$scoreDisplay = null;
if (isset($score[0])) {
$scoreDisplay = ScoreDisplay::instance();
$scoreDisplay = $scoreDisplay->display_score($score, SCORE_DIV);
$scoreDisplay = $scoreDisplay->display_score($score, SCORE_DIV, SCORE_BOTH, true);
}
return array(
@ -296,6 +314,7 @@ class GradebookDataGenerator
$forceSimpleResult = false
) {
$scoredisplay = ScoreDisplay::instance();
$score = $item->calc_score($userId);
if (!empty($score)) {
@ -303,10 +322,6 @@ class GradebookDataGenerator
// category
case 'C' :
if ($score != null) {
$displaytype = SCORE_PERCENT;
if ($ignore_score_color) {
$displaytype |= SCORE_IGNORE_SPLIT;
}
if ($forceSimpleResult) {
return
array(
@ -342,11 +357,18 @@ class GradebookDataGenerator
];
//}
return array(
'display' => $scoredisplay->display_score($score, SCORE_DIV),
'score' => $score,
'score_weight' => $scoreWeight,
);
$display = $scoredisplay->display_score($score, SCORE_DIV);
$type = $item->get_item_type();
if ($type == 'L' && get_class($item) == 'ExerciseLink') {
$display = ExerciseLib::show_score($score[0], $score[1], false);
}
return array(
'display' => $display,
'score' => $score,
'score_weight' => $scoreWeight,
);
}
}

@ -12,18 +12,22 @@ class PDF
public $custom_header = '';
public $custom_footer = '';
public $params = array();
public $template;
/**
* Creates the mPDF object
* @param string $pageFormat format A4 A4-L see http://mpdf1.com/manual/index.php?tid=184&searchstring=format
* @param string $orientation orientation "P" = Portrait "L" = Landscape
* @param array $params
* @param Template $template
*/
public function __construct(
$pageFormat = 'A4',
$orientation = 'P',
$params = array()
$params = array(),
$template = null
) {
$this->template = $template;
/* More info @ http://mpdf1.com/manual/index.php?tid=184&searchstring=mPDF
* mPDF ([ string $mode [, mixed $format [, float $default_font_size [, string $default_font [, float $margin_left , float $margin_right , float $margin_top , float $margin_bottom , float $margin_header , float $margin_footer [, string $orientation ]]]]]])
*/
@ -47,6 +51,8 @@ class PDF
$this->params['show_real_course_teachers'] = isset($params['show_real_course_teachers']) ? $params['show_real_course_teachers'] : false;
$this->params['student_info'] = isset($params['student_info']) ? $params['student_info'] : false;
$this->params['show_grade_generated_date'] = isset($params['show_grade_generated_date']) ? $params['show_grade_generated_date'] : false;
$this->params['show_teacher_as_myself'] = isset($params['show_teacher_as_myself']) ? $params['show_teacher_as_myself'] : true;
$this->params['pdf_date'] = isset($params['pdf_date']) ? $params['pdf_date'] : api_format_date(api_get_local_time(), DATE_TIME_FORMAT_LONG);
$this->pdf = new mPDF(
'UTF-8',
@ -76,10 +82,14 @@ class PDF
*/
public function html_to_pdf_with_template($content, $saveToFile = false, $returnHtml = false)
{
Display :: display_no_header();
if (empty($this->template)) {
$tpl = new Template('', false, false, false);
} else {
$tpl = $this->template;
}
// Assignments
Display::$global_template->assign('pdf_content', $content);
// Assignments
$tpl->assign('pdf_content', $content);
$organization = api_get_setting('Institution');
$img = api_get_path(SYS_CSS_PATH).'themes/'.api_get_visual_theme().'/images/header-logo.png';
@ -106,7 +116,7 @@ class PDF
}
}
Display::$global_template->assign('organization', $organization);
$tpl->assign('organization', $organization);
//Showing only the current teacher/admin instead the all teacher list name see BT#4080
@ -128,22 +138,25 @@ class PDF
}
} else {
$user_info = api_get_user_info();
$teacher_list = $user_info['complete_name'];
if ($this->params['show_teacher_as_myself']) {
$teacher_list = $user_info['complete_name'];
}
}
Display::$global_template->assign('pdf_course', $this->params['course_code']);
Display::$global_template->assign('pdf_course_info', $this->params['course_info']);
Display::$global_template->assign('pdf_session_info', $this->params['session_info']);
Display::$global_template->assign('pdf_date', api_format_date(api_get_local_time(), DATE_TIME_FORMAT_LONG));
Display::$global_template->assign('pdf_teachers', $teacher_list);
Display::$global_template->assign('pdf_title', $this->params['pdf_title']);
Display::$global_template->assign('pdf_student_info', $this->params['student_info']);
Display::$global_template->assign('show_grade_generated_date', $this->params['show_grade_generated_date']);
Display::$global_template->assign('add_signatures', $this->params['add_signatures']);
$tpl->assign('pdf_course', $this->params['course_code']);
$tpl->assign('pdf_course_info', $this->params['course_info']);
$tpl->assign('pdf_session_info', $this->params['session_info']);
$tpl->assign('pdf_date', $this->params['pdf_date']);
$tpl->assign('pdf_teachers', $teacher_list);
$tpl->assign('pdf_title', $this->params['pdf_title']);
$tpl->assign('pdf_student_info', $this->params['student_info']);
$tpl->assign('show_grade_generated_date', $this->params['show_grade_generated_date']);
$tpl->assign('add_signatures', $this->params['add_signatures']);
// Getting template
$tpl = Display::$global_template->get_template('export/table_pdf.tpl');
$html = Display::$global_template->fetch($tpl);
$tableTemplate = $tpl->get_template('export/table_pdf.tpl');
$html = $tpl->fetch($tableTemplate);
$html = api_utf8_encode($html);
$css_file = api_get_path(TO_SYS, WEB_CSS_PATH).'/print.css';

@ -1113,16 +1113,16 @@ class IndexManager
$atLeastOneCourseIsVisible = true;
if (api_get_setting('hide_courses_in_sessions') == 'false') {
$c = CourseManager::get_logged_user_course_html(
$courseUserHtml = CourseManager::get_logged_user_course_html(
$course,
$session_id,
'session_course_item',
true,
$this->load_directories_preview
);
if (isset($c[1])) {
$course_session = $c[1];
$course_session['skill'] = $c['skill'];
if (isset($courseUserHtml[1])) {
$course_session = $courseUserHtml[1];
$course_session['skill'] = isset($courseUserHtml['skill']) ? $courseUserHtml['skill'] : '';
$html_courses_session[] = $course_session;
}
}

@ -9,65 +9,72 @@
<table align="center" width="100%">
{% if pdf_student_info %}
<tr>
<td>
<strong>{{ "Student" | get_lang }}:</strong> {{ pdf_student_info.complete_name }}
</td>
</tr>
{% endif %}
{% if pdf_teachers %}
<tr>
<td>
<strong>{{ "Student" | get_lang }}:</strong> {{ pdf_student_info.complete_name }}
<strong>{{ "Teacher" | get_lang }}:</strong> {{ pdf_teachers }}
</td>
</tr>
{% endif %}
<tr>
<td>
<strong>{{ "Teacher" | get_lang }}:</strong> {{ pdf_teachers }}
</td>
</tr>
{% if pdf_session_info %}
<tr>
<td>
<strong>{{ "Session" | get_lang }}:</strong> {{ pdf_session_info.name }}
<strong>{{ "Session" | get_lang }}:</strong> {{ pdf_session_info.name }}
</td>
{% if pdf_session_info.description %}
<td>
<strong>{{ "Description" | get_lang }}:</strong> {{ pdf_session_info.description }}
</td>
<td>
<strong>{{ "Description" | get_lang }}:</strong> {{ pdf_session_info.description }}
</td>
{% endif %}
</tr>
{% if pdf_session_info.access_start_date != '' and pdf_session_info.access_end_date != '0000-00-00' %}
<tr>
<tr>
<td>
<strong>{{ "PeriodToDisplay" | get_lang }}:</strong> {{ "FromDateXToDateY"| get_lang | format(pdf_session_info.access_start_date, pdf_session_info.access_end_date ) }}
</td>
</tr>
</tr>
{% endif %}
{% endif %}
{% if pdf_course_info %}
<tr>
<td>
<strong>{{ "Course" | get_lang }}:</strong> {{ pdf_course_info.title }} ({{ pdf_course_info.code }})
<strong>{{ "Course" | get_lang }}:</strong> {{ pdf_course_info.title }} ({{ pdf_course_info.code }})
{% if pdf_course_category %}
{% if pdf_course_category %}
<strong>{{ "Category" | get_lang }}:</strong> {{ pdf_course_category }}
{% endif %}
{% endif %}
</td>
</tr>
{% endif %}
{% if pdf_date %}
<tr>
<td>
<strong>{{ "Date" | get_lang }}:</strong> {{ pdf_date }}
<strong>{{ "Date" | get_lang }}:</strong> {{ pdf_date }}
</td>
</tr>
{% endif %}
</table>
{% if show_grade_generated_date == true %}
<h5 align="right">
{{ 'GradeGeneratedOnX' | get_lang | format(date('d/m/Y')) }}
</h5>
<h5 align="right">
{{ 'GradeGeneratedOnX' | get_lang | format("now"| date("d/m/Y")) }}
</h5>
{% endif %}
<br />
@ -89,7 +96,7 @@
_____________________________
<br />
{{ "Teacher" | get_lang }}
</td>
</td>
<td>
_____________________________
<br />

Loading…
Cancel
Save