Internal - Add gradebook to psalm checks, add szymach/c-pchart lib

pull/3543/head
Julio Montoya 5 years ago
parent d89cd9ac5a
commit c9546d79b5
  1. 5
      composer.json
  2. 7
      psalm.xml
  3. 2
      public/main/gradebook/certificate_report.php
  4. 10
      public/main/gradebook/gradebook.php
  5. 2
      public/main/gradebook/gradebook_display_certificate.php
  6. 5
      public/main/gradebook/index.php
  7. 2
      public/main/gradebook/lib/GradebookUtils.php
  8. 34
      public/main/gradebook/lib/be/category.class.php
  9. 4
      public/main/gradebook/lib/be/evallink.class.php
  10. 22
      public/main/gradebook/lib/be/evaluation.class.php
  11. 26
      public/main/gradebook/lib/be/exerciselink.class.php
  12. 12
      public/main/gradebook/lib/be/forumthreadlink.class.php
  13. 2
      public/main/gradebook/lib/be/gradebookitem.class.php
  14. 13
      public/main/gradebook/lib/be/learnpathlink.class.php
  15. 8
      public/main/gradebook/lib/be/linkfactory.class.php
  16. 14
      public/main/gradebook/lib/be/studentpublicationlink.class.php
  17. 9
      public/main/gradebook/lib/be/surveylink.class.php
  18. 6
      public/main/gradebook/lib/fe/catform.class.php
  19. 4
      public/main/gradebook/lib/fe/dataform.class.php
  20. 2
      public/main/gradebook/lib/fe/displaygradebook.php
  21. 19
      public/main/gradebook/lib/fe/evalform.class.php
  22. 1
      public/main/gradebook/lib/fe/exportgradebook.php
  23. 2
      public/main/gradebook/lib/fe/gradebooktable.class.php
  24. 13
      public/main/gradebook/lib/fe/linkaddeditform.class.php
  25. 5
      public/main/gradebook/lib/fe/linkform.class.php
  26. 14
      public/main/gradebook/lib/fe/userform.class.php
  27. 1
      public/main/gradebook/lib/gradebook_data_generator.class.php
  28. 6
      public/main/gradebook/lib/gradebook_result.class.php
  29. 2
      public/main/gradebook/user_stats.php

@ -58,7 +58,6 @@
"ext-zip": "*", "ext-zip": "*",
"ext-zlib": "*", "ext-zlib": "*",
"a2lix/translation-form-bundle": "^3.0", "a2lix/translation-form-bundle": "^3.0",
"stof/doctrine-extensions-bundle": "~1.4",
"api-platform/api-pack": "^1.2", "api-platform/api-pack": "^1.2",
"beberlei/doctrineextensions": "^1.2", "beberlei/doctrineextensions": "^1.2",
"brumann/polyfill-unserialize": "^1.0", "brumann/polyfill-unserialize": "^1.0",
@ -118,6 +117,7 @@
"sensio/framework-extra-bundle": "~5.0", "sensio/framework-extra-bundle": "~5.0",
"sensiolabs/security-checker": "~6.0", "sensiolabs/security-checker": "~6.0",
"sonata-project/exporter": "^2.2", "sonata-project/exporter": "^2.2",
"stof/doctrine-extensions-bundle": "~1.4",
"sunra/php-simple-html-dom-parser": "~1.5", "sunra/php-simple-html-dom-parser": "~1.5",
"symfony/apache-pack": "^1.0", "symfony/apache-pack": "^1.0",
"symfony/asset": "^5.0", "symfony/asset": "^5.0",
@ -141,9 +141,10 @@
"symfony/webpack-encore-bundle": "^1.7", "symfony/webpack-encore-bundle": "^1.7",
"symfony/yaml": "^5.0", "symfony/yaml": "^5.0",
"symfonycasts/reset-password-bundle": "^1.1", "symfonycasts/reset-password-bundle": "^1.1",
"szymach/c-pchart": "^3.0",
"tgalopin/html-sanitizer-bundle": "^1.1", "tgalopin/html-sanitizer-bundle": "^1.1",
"twig/intl-extra": "^3.0",
"twig/extensions": "^1.5", "twig/extensions": "^1.5",
"twig/intl-extra": "^3.0",
"vich/uploader-bundle": "^1.13", "vich/uploader-bundle": "^1.13",
"webit/eval-math": "~1.0" "webit/eval-math": "~1.0"
}, },

@ -25,16 +25,14 @@
<file name="public/main/exercise/exercise.class.php"/> <file name="public/main/exercise/exercise.class.php"/>
<directory name="public/main/group"/> <directory name="public/main/group"/>
<!-- <directory name="public/main/gradebook/lib/fe"/>--> <directory name="public/main/gradebook"/>
<!-- <directory name="public/main/forum"/>--> <!-- <directory name="public/main/forum"/>-->
<directory name="public/main/link" /> <directory name="public/main/link" />
<!-- <directory name="public/main/lp"/>--> <!-- <directory name="public/main/lp"/>-->
<!-- <directory name="public/main/session" />--> <!-- <directory name="public/main/session" />-->
<!-- <directory name="public/main/inc/ajax" />--> <!-- <directory name="public/main/inc/ajax" />-->
<directory name="public/main/work" /> <directory name="public/main/work" />
<file name="public/main/inc/lib/access_url_edit_courses_to_url_functions.lib.php"/> <file name="public/main/inc/lib/access_url_edit_courses_to_url_functions.lib.php"/>
@ -136,6 +134,7 @@
<directory name="src/GraphQlBundle"/> <directory name="src/GraphQlBundle"/>
<directory name="src/LtiBundle"/> <directory name="src/LtiBundle"/>
<file name="public/main/forum/forumfunction.inc.php"/>
<file name="public/main/admin/index.php"/> <file name="public/main/admin/index.php"/>
<file name="public/main/admin/db.php"/> <file name="public/main/admin/db.php"/>
<file name="public/main/admin/settings.php"/> <file name="public/main/admin/settings.php"/>

@ -50,6 +50,8 @@ foreach ($sessionsList as $session) {
$sessions[$session['id']] = $session['name']; $sessions[$session['id']] = $session['name'];
} }
$selfUrl = api_get_self();
if ($selectedSession > 0) { if ($selectedSession > 0) {
if (!SessionManager::isValidId($selectedSession)) { if (!SessionManager::isValidId($selectedSession)) {
Display::addFlash(Display::return_message(get_lang('The session could not be found'))); Display::addFlash(Display::return_message(get_lang('The session could not be found')));

@ -506,6 +506,8 @@ if (!empty($keyword)) {
foreach ($data_array as $data) { foreach ($data_array as $data) {
$newarray[] = array_slice($data, 1); $newarray[] = array_slice($data, 1);
} }
/* @todo use pdf.lib.php
$pdf = new Cezpdf(); $pdf = new Cezpdf();
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm'); $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
$pdf->ezSetMargins(30, 30, 50, 30); $pdf->ezSetMargins(30, 30, 50, 30);
@ -526,7 +528,7 @@ if (!empty($keyword)) {
'width' => 500, 'width' => 500,
] ]
); );
$pdf->ezStream(); $pdf->ezStream();*/
exit; exit;
} }
} elseif (!empty($_GET['export_certificate'])) { } elseif (!empty($_GET['export_certificate'])) {
@ -564,8 +566,8 @@ with a grade of
\'%s\''), $organization_name, $stud_fn.' '.$stud_ln, $category[0]->get_name(), $scorecourse_display); \'%s\''), $organization_name, $stud_fn.' '.$stud_ln, $category[0]->get_name(), $scorecourse_display);
$certif_text = str_replace("\\n", "\n", $certif_text); $certif_text = str_replace("\\n", "\n", $certif_text);
$date = api_convert_and_format_date(null, DATE_FORMAT_SHORT); $date = api_convert_and_format_date(null, DATE_FORMAT_SHORT);
// @todo use pdf.lib.php
$pdf = new Cezpdf('a4', 'landscape'); /*$pdf = new Cezpdf('a4', 'landscape');
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm'); $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
$pdf->ezSetMargins(30, 30, 50, 50); $pdf->ezSetMargins(30, 30, 50, 50);
//line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom) //line Y coordinates in landscape mode are upside down (500 is on top, 10 is on the bottom)
@ -581,7 +583,7 @@ with a grade of
$pdf->ezText($organization_name, 22, ['justification' => 'left']); $pdf->ezText($organization_name, 22, ['justification' => 'left']);
$pdf->ezSetY(580); $pdf->ezSetY(580);
$pdf->ezText($portal_name, 22, ['justification' => 'right']); $pdf->ezText($portal_name, 22, ['justification' => 'right']);
$pdf->ezStream(); $pdf->ezStream();*/
} }
exit; exit;
} else { } else {

@ -48,7 +48,7 @@ if ('true' === $filter) {
'POST', 'POST',
api_get_self().'?'.api_get_cidreq().'&cat_id='.$categoryId api_get_self().'?'.api_get_cidreq().'&cat_id='.$categoryId
); );
$form->addElement('select', 'filter', get_lang('Code'), $options); $form->addSelect('filter', get_lang('Code'), $options);
$form->addButton('submit', get_lang('Submit')); $form->addButton('submit', get_lang('Submit'));
$filterForm = '<br />'.$form->returnForm(); $filterForm = '<br />'.$form->returnForm();

@ -694,7 +694,8 @@ if (isset($_GET['studentoverview'])) {
foreach ($data_array as $data) { foreach ($data_array as $data) {
$newarray[] = array_slice($data, 1); $newarray[] = array_slice($data, 1);
} }
$pdf = new Cezpdf(); // @todo use pdf.lib.php
/*$pdf = new Cezpdf();
$pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm'); $pdf->selectFont(api_get_path(LIBRARY_PATH).'ezpdf/fonts/Courier.afm');
$pdf->ezSetMargins(30, 30, 50, 30); $pdf->ezSetMargins(30, 30, 50, 30);
$pdf->ezSetY(810); $pdf->ezSetY(810);
@ -722,7 +723,7 @@ if (isset($_GET['studentoverview'])) {
] ]
); );
$pdf->ezStream(); $pdf->ezStream();
exit; exit;*/
} }
} else { } else {
// Student view // Student view

@ -1141,7 +1141,7 @@ class GradebookUtils
* *
* @param string $courseCode * @param string $courseCode
* *
* @deprecated use CourseManager * @todo use CourseManager
* *
* @return array * @return array
*/ */

@ -873,7 +873,7 @@ class Category implements GradebookItem
/** /**
* Calculate the score of this category. * Calculate the score of this category.
* *
* @param int $stud_id student id (default: all students - then the average is returned) * @param int $studentId student id (default: all students - then the average is returned)
* @param $type * @param $type
* @param string $course_code * @param string $course_code
* @param int $session_id * @param int $session_id
@ -882,12 +882,12 @@ class Category implements GradebookItem
* or null if no scores available * or null if no scores available
*/ */
public function calc_score( public function calc_score(
$stud_id = null, $studentId = null,
$type = null, $type = null,
$course_code = '', $course_code = '',
$session_id = null $session_id = null
) { ) {
$key = 'category:'.$this->id.'student:'.(int) $stud_id.'type:'.$type.'course:'.$course_code.'session:'.(int) $session_id; $key = 'category:'.$this->id.'student:'.(int) $studentId.'type:'.$type.'course:'.$course_code.'session:'.(int) $session_id;
$useCache = api_get_configuration_value('gradebook_use_apcu_cache'); $useCache = api_get_configuration_value('gradebook_use_apcu_cache');
$cacheAvailable = api_get_configuration_value('apc') && $useCache; $cacheAvailable = api_get_configuration_value('apc') && $useCache;
@ -898,19 +898,19 @@ class Category implements GradebookItem
} }
} }
// Classic // Classic
if (!empty($stud_id) && '' == $type) { if (!empty($studentId) && '' == $type) {
if (!empty($course_code)) { if (!empty($course_code)) {
$cats = $this->get_subcategories( $cats = $this->get_subcategories(
$stud_id, $studentId,
$course_code, $course_code,
$session_id $session_id
); );
$evals = $this->get_evaluations($stud_id, false, $course_code); $evals = $this->get_evaluations($studentId, false, $course_code);
$links = $this->get_links($stud_id, false, $course_code); $links = $this->get_links($studentId, false, $course_code);
} else { } else {
$cats = $this->get_subcategories($stud_id); $cats = $this->get_subcategories($studentId);
$evals = $this->get_evaluations($stud_id); $evals = $this->get_evaluations($studentId);
$links = $this->get_links($stud_id); $links = $this->get_links($studentId);
} }
// Calculate score // Calculate score
@ -925,7 +925,7 @@ class Category implements GradebookItem
$cat->set_course_code($course_code); $cat->set_course_code($course_code);
$cat->setStudentList($this->getStudentList()); $cat->setStudentList($this->getStudentList());
$score = $cat->calc_score( $score = $cat->calc_score(
$stud_id, $studentId,
null, null,
$course_code, $course_code,
$session_id $session_id
@ -947,7 +947,7 @@ class Category implements GradebookItem
/** @var Evaluation $eval */ /** @var Evaluation $eval */
foreach ($evals as $eval) { foreach ($evals as $eval) {
$eval->setStudentList($this->getStudentList()); $eval->setStudentList($this->getStudentList());
$evalres = $eval->calc_score($stud_id); $evalres = $eval->calc_score($studentId);
if (isset($evalres) && 0 != $eval->get_weight()) { if (isset($evalres) && 0 != $eval->get_weight()) {
$evalweight = $eval->get_weight(); $evalweight = $eval->get_weight();
$weightsum += $evalweight; $weightsum += $evalweight;
@ -972,7 +972,7 @@ class Category implements GradebookItem
$link->set_session_id($session_id); $link->set_session_id($session_id);
} }
$linkres = $link->calc_score($stud_id, null); $linkres = $link->calc_score($studentId, null);
if (!empty($linkres) && 0 != $link->get_weight()) { if (!empty($linkres) && 0 != $link->get_weight()) {
$linkweight = $link->get_weight(); $linkweight = $link->get_weight();
$link_res_denom = 0 == $linkres[1] ? 1 : $linkres[1]; $link_res_denom = 0 == $linkres[1] ? 1 : $linkres[1];
@ -1104,7 +1104,7 @@ class Category implements GradebookItem
$link->set_session_id($session_id); $link->set_session_id($session_id);
} }
$linkres = $link->calc_score($stud_id, $type); $linkres = $link->calc_score($studentId, $type);
if (!empty($linkres) && 0 != $link->get_weight()) { if (!empty($linkres) && 0 != $link->get_weight()) {
$linkweight = $link->get_weight(); $linkweight = $link->get_weight();
@ -1154,7 +1154,7 @@ class Category implements GradebookItem
// function get_data // function get_data
return null; return null;
return AbstractLink::getCurrentUserRanking($stud_id, []); return AbstractLink::getCurrentUserRanking($studentId, []);
break; break;
default: default:
if ($cacheAvailable) { if ($cacheAvailable) {
@ -1548,7 +1548,7 @@ class Category implements GradebookItem
* *
* @return array 2-dimensional array - every element contains 2 subelements (code, title) * @return array 2-dimensional array - every element contains 2 subelements (code, title)
*/ */
public function get_all_courses($user_id) public static function get_all_courses($user_id)
{ {
$tbl_main_courses = Database::get_main_table(TABLE_MAIN_COURSE); $tbl_main_courses = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_main_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); $tbl_main_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
@ -2013,7 +2013,7 @@ class Category implements GradebookItem
* *
* @return array category objects matching the search criterium * @return array category objects matching the search criterium
*/ */
public function find_category($name_mask, $allcat) public static function find_category($name_mask, $allcat)
{ {
$categories = []; $categories = [];
foreach ($allcat as $search_cat) { foreach ($allcat as $search_cat) {

@ -27,11 +27,11 @@ abstract class EvalLink extends AbstractLink
* *
* @return array * @return array
*/ */
public function calc_score($userId = null, $type = null) public function calc_score($studentId = null, $type = null)
{ {
$eval = $this->get_evaluation(); $eval = $this->get_evaluation();
return $eval->calc_score($userId, $type); return $eval->calc_score($studentId, $type);
} }
public function get_link() public function get_link()

@ -512,14 +512,14 @@ class Evaluation implements GradebookItem
/** /**
* Calculate the score of this evaluation. * Calculate the score of this evaluation.
* *
* @param int $stud_id (default: all students who have results for this eval - then the average is returned) * @param int $studentId (default: all students who have results for this eval - then the average is returned)
* @param string $type (best, average, ranking) * @param string $type (best, average, ranking)
* *
* @return array (score, max) if student is given * @return array (score, max) if student is given
* array (sum of scores, number of scores) otherwise * array (sum of scores, number of scores) otherwise
* or null if no scores available * or null if no scores available
*/ */
public function calc_score($stud_id = null, $type = null) public function calc_score($studentId = null, $type = null)
{ {
$allowStats = api_get_configuration_value('allow_gradebook_stats'); $allowStats = api_get_configuration_value('allow_gradebook_stats');
if ($allowStats) { if ($allowStats) {
@ -547,17 +547,17 @@ class Evaluation implements GradebookItem
return $result; return $result;
break; break;
case 'ranking': case 'ranking':
$ranking = AbstractLink::getCurrentUserRanking($stud_id, $evaluation->getUserScoreList()); $ranking = AbstractLink::getCurrentUserRanking($studentId, $evaluation->getUserScoreList());
return $ranking; return $ranking;
break; break;
default: default:
$weight = $evaluation->getMax(); $weight = $evaluation->getMax();
if (!empty($stud_id)) { if (!empty($studentId)) {
$scoreList = $evaluation->getUserScoreList(); $scoreList = $evaluation->getUserScoreList();
$result = [0, $weight]; $result = [0, $weight];
if (isset($scoreList[$stud_id])) { if (isset($scoreList[$studentId])) {
$result = [$scoreList[$stud_id], $weight]; $result = [$scoreList[$studentId], $weight];
} }
return $result; return $result;
@ -574,8 +574,8 @@ class Evaluation implements GradebookItem
} }
$useSession = true; $useSession = true;
if (isset($stud_id) && empty($type)) { if (isset($studentId) && empty($type)) {
$key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$studentId;
$data = Session::read('calc_score'); $data = Session::read('calc_score');
$results = isset($data[$key]) ? $data[$key] : null; $results = isset($data[$key]) ? $data[$key] : null;
@ -584,7 +584,7 @@ class Evaluation implements GradebookItem
} }
$results = null; $results = null;
if (empty($results)) { if (empty($results)) {
$results = Result::load(null, $stud_id, $this->id); $results = Result::load(null, $studentId, $this->id);
Session::write('calc_score', [$key => $results]); Session::write('calc_score', [$key => $results]);
} }
@ -649,7 +649,7 @@ class Evaluation implements GradebookItem
$students[$res->get_user_id()] = $score; $students[$res->get_user_id()] = $score;
} }
return AbstractLink::getCurrentUserRanking($stud_id, $students); return AbstractLink::getCurrentUserRanking($studentId, $students);
break; break;
default: default:
return [$sum, $count]; return [$sum, $count];
@ -783,7 +783,7 @@ class Evaluation implements GradebookItem
* *
* @todo can be written more efficiently using a new (but very complex) sql query * @todo can be written more efficiently using a new (but very complex) sql query
*/ */
public function findEvaluations($name_mask, $selectcat) public static function findEvaluations($name_mask, $selectcat)
{ {
$rootcat = Category::load($selectcat); $rootcat = Category::load($selectcat);
$evals = $rootcat[0]->get_evaluations( $evals = $rootcat[0]->get_evaluations(

@ -116,7 +116,7 @@ class ExerciseLink extends AbstractLink
/** /**
* Get the score of this exercise. Only the first attempts are taken into account. * Get the score of this exercise. Only the first attempts are taken into account.
* *
* @param int $stud_id student id (default: all students who have results - * @param int $studentId student id (default: all students who have results -
* then the average is returned) * then the average is returned)
* @param string $type * @param string $type
* *
@ -124,7 +124,7 @@ class ExerciseLink extends AbstractLink
* array (sum of scores, number of scores) otherwise * array (sum of scores, number of scores) otherwise
* or null if no scores available * or null if no scores available
*/ */
public function calc_score($stud_id = null, $type = null) public function calc_score($studentId = null, $type = null)
{ {
$allowStats = api_get_configuration_value('allow_gradebook_stats'); $allowStats = api_get_configuration_value('allow_gradebook_stats');
@ -156,11 +156,11 @@ class ExerciseLink extends AbstractLink
return [null, null]; return [null, null];
break; break;
default: default:
if (!empty($stud_id)) { if (!empty($studentId)) {
$scoreList = $link->getUserScoreList(); $scoreList = $link->getUserScoreList();
$result = [0, $weight]; $result = [0, $weight];
if (isset($scoreList[$stud_id])) { if (isset($scoreList[$studentId])) {
$result = [$scoreList[$stud_id], $weight]; $result = [$scoreList[$studentId], $weight];
} }
return $result; return $result;
@ -186,7 +186,7 @@ class ExerciseLink extends AbstractLink
$courseId = $this->getCourseId(); $courseId = $this->getCourseId();
$exerciseData = $this->get_exercise_data(); $exerciseData = $this->get_exercise_data();
$exerciseId = isset($exerciseData['id']) ? (int) $exerciseData['id'] : 0; $exerciseId = isset($exerciseData['id']) ? (int) $exerciseData['id'] : 0;
$stud_id = (int) $stud_id; $studentId = (int) $studentId;
if (empty($exerciseId)) { if (empty($exerciseId)) {
return null; return null;
@ -194,7 +194,7 @@ class ExerciseLink extends AbstractLink
$key = 'exercise_link_id:'. $key = 'exercise_link_id:'.
$this->get_id(). $this->get_id().
'exerciseId:'.$exerciseId.'student:'.$stud_id.'session:'.$sessionId.'courseId:'.$courseId.'type:'.$type; 'exerciseId:'.$exerciseId.'student:'.$studentId.'session:'.$sessionId.'courseId:'.$courseId.'type:'.$type;
$useCache = api_get_configuration_value('gradebook_use_apcu_cache'); $useCache = api_get_configuration_value('gradebook_use_apcu_cache');
$cacheAvailable = api_get_configuration_value('apc') && $useCache; $cacheAvailable = api_get_configuration_value('apc') && $useCache;
@ -243,8 +243,8 @@ class ExerciseLink extends AbstractLink
c_id = $courseId "; c_id = $courseId ";
} }
if (!empty($stud_id) && 'ranking' !== $type) { if (!empty($studentId) && 'ranking' !== $type) {
$sql .= " AND exe_user_id = $stud_id "; $sql .= " AND exe_user_id = $studentId ";
} }
$sql .= ' ORDER BY exe_id DESC'; $sql .= ' ORDER BY exe_id DESC';
} else { } else {
@ -255,14 +255,14 @@ class ExerciseLink extends AbstractLink
hp.c_id = $courseId AND hp.c_id = $courseId AND
doc.iid = $exerciseId"; doc.iid = $exerciseId";
if (!empty($stud_id)) { if (!empty($studentId)) {
$sql .= " AND hp.exe_user_id = $stud_id "; $sql .= " AND hp.exe_user_id = $studentId ";
} }
} }
$scores = Database::query($sql); $scores = Database::query($sql);
if (isset($stud_id) && empty($type)) { if (isset($studentId) && empty($type)) {
// for 1 student // for 1 student
if ($data = Database::fetch_array($scores, 'ASSOC')) { if ($data = Database::fetch_array($scores, 'ASSOC')) {
$attempts = Database::query($sql); $attempts = Database::query($sql);
@ -357,7 +357,7 @@ class ExerciseLink extends AbstractLink
return $result; return $result;
break; break;
case 'ranking': case 'ranking':
$ranking = AbstractLink::getCurrentUserRanking($stud_id, $students); $ranking = AbstractLink::getCurrentUserRanking($studentId, $students);
if ($cacheAvailable) { if ($cacheAvailable) {
$cacheDriver->save($key, $ranking); $cacheDriver->save($key, $ranking);
} }

@ -99,12 +99,12 @@ class ForumThreadLink extends AbstractLink
} }
/** /**
* @param int $stud_id * @param int $studentId
* @param string $type * @param string $type
* *
* @return array|null * @return array|null
*/ */
public function calc_score($stud_id = null, $type = null) public function calc_score($studentId = null, $type = null)
{ {
require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php';
$threadInfo = get_thread_information('', $this->get_ref_id()); $threadInfo = get_thread_information('', $this->get_ref_id());
@ -133,8 +133,8 @@ class ForumThreadLink extends AbstractLink
iid = ".$this->get_ref_id()." iid = ".$this->get_ref_id()."
$sessionCondition $sessionCondition
"; ";
if (isset($stud_id)) { if (isset($studentId)) {
$sql .= ' AND user_id = '.intval($stud_id); $sql .= ' AND user_id = '.intval($studentId);
} }
// order by id, that way the student's first attempt is accessed first // order by id, that way the student's first attempt is accessed first
@ -142,7 +142,7 @@ class ForumThreadLink extends AbstractLink
$scores = Database::query($sql); $scores = Database::query($sql);
// for 1 student // for 1 student
if (isset($stud_id)) { if (isset($studentId)) {
if (0 == $threadInfo['thread_peer_qualify']) { if (0 == $threadInfo['thread_peer_qualify']) {
// Classic way of calculate score // Classic way of calculate score
if ($data = Database::fetch_array($scores)) { if ($data = Database::fetch_array($scores)) {
@ -207,7 +207,7 @@ class ForumThreadLink extends AbstractLink
return [$sumResult / $counter, $weight]; return [$sumResult / $counter, $weight];
break; break;
case 'ranking': case 'ranking':
return AbstractLink::getCurrentUserRanking($stud_id, $students); return AbstractLink::getCurrentUserRanking($studentId, $students);
break; break;
default: default:
return [$sum, $counter]; return [$sum, $counter];

@ -30,5 +30,5 @@ interface GradebookItem
public function setStudentList($list); public function setStudentList($list);
public function calc_score($stud_id = null, $type = null); public function calc_score($studentId = null, $type = null);
} }

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
@ -69,14 +70,14 @@ class LearnpathLink extends AbstractLink
/** /**
* Get the progress of this learnpath. Only the last attempt are taken into account. * Get the progress of this learnpath. Only the last attempt are taken into account.
* *
* @param $stud_id student id (default: all students who have results - then the average is returned) * @param $studentId student id (default: all students who have results - then the average is returned)
* @param $type The type of score we want to get: best|average|ranking * @param $type The type of score we want to get: best|average|ranking
* *
* @return array (score, max) if student is given * @return array (score, max) if student is given
* array (sum of scores, number of scores) otherwise * array (sum of scores, number of scores) otherwise
* or null if no scores available * or null if no scores available
*/ */
public function calc_score($stud_id = null, $type = null) public function calc_score($studentId = null, $type = null)
{ {
$tbl_stats = Database::get_course_table(TABLE_LP_VIEW); $tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
$session_id = $this->get_session_id(); $session_id = $this->get_session_id();
@ -90,8 +91,8 @@ class LearnpathLink extends AbstractLink
lp_id = ".$this->get_ref_id()." AND lp_id = ".$this->get_ref_id()." AND
session_id = $session_id "; session_id = $session_id ";
if (isset($stud_id)) { if (isset($studentId)) {
$sql .= ' AND user_id = '.intval($stud_id); $sql .= ' AND user_id = '.intval($studentId);
} }
// order by id, that way the student's first attempt is accessed first // order by id, that way the student's first attempt is accessed first
@ -99,7 +100,7 @@ class LearnpathLink extends AbstractLink
$scores = Database::query($sql); $scores = Database::query($sql);
// for 1 student // for 1 student
if (isset($stud_id)) { if (isset($studentId)) {
if ($data = Database::fetch_assoc($scores)) { if ($data = Database::fetch_assoc($scores)) {
return [$data['progress'], 100]; return [$data['progress'], 100];
} else { } else {
@ -137,7 +138,7 @@ class LearnpathLink extends AbstractLink
return [$sumResult / $rescount, 100]; return [$sumResult / $rescount, 100];
break; break;
case 'ranking': case 'ranking':
return AbstractLink::getCurrentUserRanking($stud_id, $students); return AbstractLink::getCurrentUserRanking($studentId, $students);
break; break;
default: default:
return [$sum, $rescount]; return [$sum, $rescount];

@ -45,7 +45,7 @@ class LinkFactory
/** /**
* Get the link object referring to an evaluation. * Get the link object referring to an evaluation.
*/ */
public function get_evaluation_link($eval_id) public static function get_evaluation_link($eval_id)
{ {
$links = AbstractLink::load(null, null, $eval_id); $links = AbstractLink::load(null, null, $eval_id);
foreach ($links as $link) { foreach ($links as $link) {
@ -60,13 +60,13 @@ class LinkFactory
/** /**
* Find links by name. * Find links by name.
* *
* @param string $name_mask search string * @param string $name search string
* *
* @return array link objects matching the search criterium * @return array link objects matching the search criterium
*/ */
public function find_links($name_mask, $selectcat) public static function find_links($name, $selectcat)
{ {
return AbstractLink::find_links($name_mask, $selectcat); return AbstractLink::find_links($name, $selectcat);
} }
/** /**

@ -147,13 +147,13 @@ class StudentPublicationLink extends AbstractLink
} }
/** /**
* @param null $stud_id * @param null $studentId
* *
* @return array * @return array
*/ */
public function calc_score($stud_id = null, $type = null) public function calc_score($studentId = null, $type = null)
{ {
$stud_id = (int) $stud_id; $studentId = (int) $studentId;
$em = Database::getManager(); $em = Database::getManager();
$data = $this->get_exercise_data(); $data = $this->get_exercise_data();
@ -206,9 +206,9 @@ class StudentPublicationLink extends AbstractLink
]; ];
} }
if (!empty($stud_id)) { if (!empty($studentId)) {
$dql .= ' AND a.userId = :student '; $dql .= ' AND a.userId = :student ';
$params['student'] = $stud_id; $params['student'] = $studentId;
} }
$order = api_get_setting('student_publication_to_take_in_gradebook'); $order = api_get_setting('student_publication_to_take_in_gradebook');
@ -228,7 +228,7 @@ class StudentPublicationLink extends AbstractLink
$scores = $em->createQuery($dql)->execute($params); $scores = $em->createQuery($dql)->execute($params);
// for 1 student // for 1 student
if (!empty($stud_id)) { if (!empty($studentId)) {
if (!count($scores)) { if (!count($scores)) {
return [null, null]; return [null, null];
} }
@ -279,7 +279,7 @@ class StudentPublicationLink extends AbstractLink
return [$sumResult / $rescount, $weight]; return [$sumResult / $rescount, $weight];
break; break;
case 'ranking': case 'ranking':
return AbstractLink::getCurrentUserRanking($stud_id, $students); return AbstractLink::getCurrentUserRanking($studentId, $students);
break; break;
default: default:
return [$sum, $rescount]; return [$sum, $rescount];

@ -1,4 +1,5 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
@ -129,12 +130,12 @@ class SurveyLink extends AbstractLink
/** /**
* Calculate score for a student (to show in the gradebook). * Calculate score for a student (to show in the gradebook).
* *
* @param int $stud_id * @param int $studentId
* @param string $type Type of result we want (best|average|ranking) * @param string $type Type of result we want (best|average|ranking)
* *
* @return array|null * @return array|null
*/ */
public function calc_score($stud_id = null, $type = null) public function calc_score($studentId = null, $type = null)
{ {
// Note: Max score is assumed to be always 1 for surveys, // Note: Max score is assumed to be always 1 for surveys,
// only student's participation is to be taken into account. // only student's participation is to be taken into account.
@ -144,7 +145,7 @@ class SurveyLink extends AbstractLink
$courseId = $this->getCourseId(); $courseId = $this->getCourseId();
$tbl_survey = Database::get_course_table(TABLE_SURVEY); $tbl_survey = Database::get_course_table(TABLE_SURVEY);
$tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION); $tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
$get_individual_score = !is_null($stud_id); $get_individual_score = !is_null($studentId);
$sql = "SELECT i.answered $sql = "SELECT i.answered
FROM $tbl_survey AS s FROM $tbl_survey AS s
@ -158,7 +159,7 @@ class SurveyLink extends AbstractLink
"; ";
if ($get_individual_score) { if ($get_individual_score) {
$sql .= ' AND i.user = '.intval($stud_id); $sql .= ' AND i.user = '.intval($studentId);
} }
$sql_result = Database::query($sql); $sql_result = Database::query($sql);

@ -190,8 +190,7 @@ class CatForm extends FormValidator
*/ */
protected function build_select_course_form() protected function build_select_course_form()
{ {
$select = $this->addElement( $select = $this->addSelect(
'select',
'select_course', 'select_course',
[get_lang('Pick a course'), 'test'], [get_lang('Pick a course'), 'test'],
null null
@ -253,8 +252,7 @@ class CatForm extends FormValidator
if ($allowSkillEdit) { if ($allowSkillEdit) {
if (Skill::isToolAvailable()) { if (Skill::isToolAvailable()) {
$skillSelect = $this->addElement( $skillSelect = $this->addSelectAjax(
'select_ajax',
'skills', 'skills',
[ [
get_lang('Skills'), get_lang('Skills'),

@ -51,9 +51,9 @@ class DataForm extends FormValidator
parent::display(); parent::display();
} }
public function setDefaults($defaults = [], $filter = null) public function setDefaults($defaultValues = [], $filter = null)
{ {
parent::setDefaults($defaults, $filter); parent::setDefaults($defaultValues, $filter);
} }
protected function build_pdf_export_form() protected function build_pdf_export_form()

@ -249,7 +249,7 @@ class DisplayGradebook
* @param $selectcat * @param $selectcat
* @param bool $is_course_admin * @param bool $is_course_admin
* @param bool $is_platform_admin * @param bool $is_platform_admin
* @param bool $simple_search_form * @param FormValidator $simple_search_form
* @param bool $show_add_qualification Whether to show or not the link to add a new qualification * @param bool $show_add_qualification Whether to show or not the link to add a new qualification
* (we hide it in case of the course-embedded tool where we have only one * (we hide it in case of the course-embedded tool where we have only one
* per course or session) * per course or session)

@ -27,7 +27,7 @@ class EvalForm extends FormValidator
* *
* @param int $form_type 1=add, 2=edit,3=move,4=result_add * @param int $form_type 1=add, 2=edit,3=move,4=result_add
* @param Evaluation $evaluation_object the category object * @param Evaluation $evaluation_object the category object
* @param obj $result_object the result object * @param $result_object the result object
* @param string $form_name * @param string $form_name
* @param string $method * @param string $method
* @param string $action * @param string $action
@ -85,9 +85,9 @@ class EvalForm extends FormValidator
parent::display(); parent::display();
} }
public function setDefaults($defaults = [], $filter = null) public function setDefaults($defaultValues = [], $filter = null)
{ {
parent::setDefaults($defaults, $filter); parent::setDefaults($defaultValues, $filter);
} }
public function sort_by_user($item1, $item2) public function sort_by_user($item1, $item2)
@ -114,9 +114,8 @@ class EvalForm extends FormValidator
*/ */
protected function build_add_user_to_eval() protected function build_add_user_to_eval()
{ {
$this->addElement('header', get_lang('Choose users for this evaluation')); $this->addHeader(get_lang('Choose users for this evaluation'));
$select = $this->addElement( $select = $this->addSelect(
'select',
'firstLetterUser', 'firstLetterUser',
get_lang('First letter'), get_lang('First letter'),
null, null,
@ -133,8 +132,7 @@ class EvalForm extends FormValidator
$select->addOption($letter, $letter); $select->addOption($letter, $letter);
} }
} }
$select = $this->addElement( $select = $this->addSelect(
'select',
'add_users', 'add_users',
null, null,
null, null,
@ -290,7 +288,7 @@ class EvalForm extends FormValidator
$renderer->setCustomElementTemplate('<span>{element}</span> '); $renderer->setCustomElementTemplate('<span>{element}</span> ');
$this->addElement('static', null, null, '"'.$this->evaluation_object->get_name().'" '); $this->addElement('static', null, null, '"'.$this->evaluation_object->get_name().'" ');
$this->addElement('static', null, null, get_lang('Move to').' : '); $this->addElement('static', null, null, get_lang('Move to').' : ');
$select = $this->addElement('select', 'move_cat', null, null); $select = $this->addSelect('move_cat', null, null);
$line = ''; $line = '';
foreach ($this->evaluation_object->get_target_categories() as $cat) { foreach ($this->evaluation_object->get_target_categories() as $cat) {
for ($i = 0; $i < $cat[2]; $i++) { for ($i = 0; $i < $cat[2]; $i++) {
@ -558,8 +556,7 @@ class EvalForm extends FormValidator
if (1 == count($all_categories)) { if (1 == count($all_categories)) {
$this->addElement('hidden', 'hid_category_id', $cat_id); $this->addElement('hidden', 'hid_category_id', $cat_id);
} else { } else {
$select_gradebook = $this->addElement( $select_gradebook = $this->addSelect(
'select',
'hid_category_id', 'hid_category_id',
get_lang('Select assessment'), get_lang('Select assessment'),
[], [],

@ -136,6 +136,7 @@ function export_pdf_with_html($headers_table, $data_table, $headers_pdf, $footer
} }
$items_per_page = 30; $items_per_page = 30;
$count_pages = ceil(count($data_table) / $items_per_page); $count_pages = ceil(count($data_table) / $items_per_page);
$content_table = '';
for ($x = 0; $x < $count_pages; $x++) { for ($x = 0; $x < $count_pages; $x++) {
$content_table .= '<table width="100%" border="1" style="border-collapse:collapse">'; $content_table .= '<table width="100%" border="1" style="border-collapse:collapse">';
// header table // header table

@ -1165,7 +1165,7 @@ class GradebookTable extends SortableTable
$categoryId = $item->getCategory()->get_id(); $categoryId = $item->getCategory()->get_id();
$cat = new Category(); $cat = new Category();
$is_student = api_is_student();
switch ($item->get_item_type()) { switch ($item->get_item_type()) {
case 'C': case 'C':
// Category // Category

@ -50,10 +50,10 @@ class LinkAddEditForm extends FormValidator
if ($link->needs_name_and_description()) { if ($link->needs_name_and_description()) {
$this->addText('name', get_lang('Name'), true, ['size' => '40', 'maxlength' => '40']); $this->addText('name', get_lang('Name'), true, ['size' => '40', 'maxlength' => '40']);
} else { } else {
$select = $this->addElement('select', 'select_link', get_lang('ChooseItem')); $select = $this->addSelect('select_link', get_lang('ChooseItem'));
foreach ($link->get_all_links() as $newlink) { foreach ($link->get_all_links() as $newlink) {
$name = strip_tags(Exercise::get_formated_title_variable($newlink[1])); $name = strip_tags(Exercise::get_formated_title_variable($newlink[1]));
$select->addoption($name, $newlink[0]); $select->addOption($name, $newlink[0]);
} }
} }
} else { } else {
@ -74,8 +74,7 @@ class LinkAddEditForm extends FormValidator
if (1 == count($category_object)) { if (1 == count($category_object)) {
$this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id()); $this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id());
} else { } else {
$select_gradebook = $this->addElement( $select_gradebook = $this->addSelect(
'select',
'select_gradebook', 'select_gradebook',
get_lang('Select assessment'), get_lang('Select assessment'),
[], [],
@ -90,12 +89,12 @@ class LinkAddEditForm extends FormValidator
if (empty($grade_model_id)) { if (empty($grade_model_id)) {
if (0 == $my_cat->get_parent_id()) { if (0 == $my_cat->get_parent_id()) {
$default_weight = $my_cat->get_weight(); $default_weight = $my_cat->get_weight();
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id()); $select_gradebook->addOption(get_lang('Default'), $my_cat->get_id());
} else { } else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id()); $select_gradebook->addOption($my_cat->get_name(), $my_cat->get_id());
} }
} else { } else {
$select_gradebook->addoption(get_lang('Select'), 0); $select_gradebook->addOption(get_lang('Select'), 0);
} }
if ($link->get_category_id() == $my_cat->get_id()) { if ($link->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight(); $default_weight = $my_cat->get_weight();

@ -68,7 +68,7 @@ class LinkForm extends FormValidator
'"'.$this->link_object->get_name().'" ' '"'.$this->link_object->get_name().'" '
); );
$this->addElement('static', null, null, get_lang('Move to').' : '); $this->addElement('static', null, null, get_lang('Move to').' : ');
$select = $this->addElement('select', 'move_cat', null, null); $select = $this->addSelect('move_cat', null, null);
$line = ''; $line = '';
foreach ($this->link_object->get_target_categories() as $cat) { foreach ($this->link_object->get_target_categories() as $cat) {
for ($i = 0; $i < $cat[2]; $i++) { for ($i = 0; $i < $cat[2]; $i++) {
@ -86,8 +86,7 @@ class LinkForm extends FormValidator
protected function build_create() protected function build_create()
{ {
$this->addHeader(get_lang('Add online activity')); $this->addHeader(get_lang('Add online activity'));
$select = $this->addElement( $select = $this->addSelect(
'select',
'select_link', 'select_link',
get_lang('Choose type of activity to assess'), get_lang('Choose type of activity to assess'),
null, null,

@ -15,9 +15,9 @@ class UserForm extends FormValidator
/** /**
* Builds a form containing form items based on a given parameter. * Builds a form containing form items based on a given parameter.
* *
* @param int form_type 1 = user_info * @param int $form_type 1 = user_info
* @param user array * @param array $user
* @param string form name * @param string $form_name
* @param string $method * @param string $method
* @param string $action * @param string $action
*/ */
@ -28,9 +28,9 @@ class UserForm extends FormValidator
if (isset($user)) { if (isset($user)) {
$this->user_info = $user; $this->user_info = $user;
} }
if (isset($result_object)) { /*if (isset($result_object)) {
$this->result_object = $result_object; $this->result_object = $result_object;
} }*/
if (self::TYPE_USER_INFO == $this->form_type) { if (self::TYPE_USER_INFO == $this->form_type) {
$this->build_user_info_form(); $this->build_user_info_form();
} elseif (self::TYPE_SIMPLE_SEARCH == $this->form_type) { } elseif (self::TYPE_SIMPLE_SEARCH == $this->form_type) {
@ -44,9 +44,9 @@ class UserForm extends FormValidator
parent::display(); parent::display();
} }
public function setDefaults($defaults = [], $filter = null) public function setDefaults($defaultValues = [], $filter = null)
{ {
parent::setDefaults($defaults, $filter); parent::setDefaults($defaultValues, $filter);
} }
protected function build_simple_search() protected function build_simple_search()

@ -245,6 +245,7 @@ class GradebookDataGenerator
$evals = []; $evals = [];
$links = []; $links = [];
if ('C' === $item->get_item_type()) { if ('C' === $item->get_item_type()) {
/** @var Category $item */
$evals = $item->get_evaluations(null); $evals = $item->get_evaluations(null);
$links = $item->get_links(null); $links = $item->get_links(null);
} }

@ -21,7 +21,7 @@ class GradeBookResult
/** /**
* Exports the complete report as a CSV file. * Exports the complete report as a CSV file.
* *
* @param string $dato Document path inside the document tool * @param array $dato Document path inside the document tool
* *
* @return bool False on error * @return bool False on error
*/ */
@ -32,7 +32,6 @@ class GradeBookResult
$data = ''; $data = '';
//build the results //build the results
//titles //titles
foreach ($dato[0] as $header_col) { foreach ($dato[0] as $header_col) {
if (!empty($header_col)) { if (!empty($header_col)) {
if (is_array($header_col)) { if (is_array($header_col)) {
@ -82,9 +81,6 @@ class GradeBookResult
* Exports the complete report as an XLS file. * Exports the complete report as an XLS file.
* *
* @param array $data * @param array $data
*
* @throws PHPExcel_Exception
* @throws PHPExcel_Writer_Exception
*/ */
public function exportCompleteReportXLS($data) public function exportCompleteReportXLS($data)
{ {

@ -54,7 +54,7 @@ if (isset($_GET['exportpdf'])) {
$newarray[] = array_slice($data, 1); $newarray[] = array_slice($data, 1);
} }
$userInfo = api_get_user_info($userId); $userInfo = api_get_user_info($userId);
$html .= get_lang('Results and feedback').' : '.$userInfo['complete_name_with_username'].' ('.api_get_local_time().')'; $html = get_lang('Results and feedback').' : '.$userInfo['complete_name_with_username'].' ('.api_get_local_time().')';
if ($displayscore->is_custom()) { if ($displayscore->is_custom()) {
$header_names = [ $header_names = [

Loading…
Cancel
Save