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

pull/2459/head
Angel Fernando Quiroz Campos 8 years ago
commit d7b1f27854
  1. 2
      main/gradebook/gradebook_display_summary.php
  2. 43
      main/gradebook/index.php
  3. 4
      main/gradebook/lib/be/abstractlink.class.php
  4. 25
      main/gradebook/lib/be/category.class.php
  5. 92
      main/gradebook/lib/fe/gradebooktable.class.php
  6. 34
      main/gradebook/lib/gradebook_data_generator.class.php
  7. 5
      main/inc/lib/internationalization.lib.php
  8. 4
      main/install/configuration.dist.php
  9. 9
      main/install/install.lib.php
  10. 15
      tests/datafiller/generate_users.php

@ -29,7 +29,7 @@ $userList = CourseManager::get_user_list_from_course_code(
$sessionId, $sessionId,
null, null,
null, null,
$statusFilter $statusToFilter
); );
switch ($action) { switch ($action) {

@ -666,7 +666,6 @@ if (isset($_GET['studentoverview'])) {
//if $category = 0 (which happens when GET['selectcat'] is undefined) //if $category = 0 (which happens when GET['selectcat'] is undefined)
// then Category::load() will create a new 'root' category with empty // then Category::load() will create a new 'root' category with empty
// course and session fields in memory (Category::create_root_category()) // course and session fields in memory (Category::create_root_category())
if ($_in_course === true) { if ($_in_course === true) {
// When *inside* a course, we want to make sure there is one (and only // When *inside* a course, we want to make sure there is one (and only
// one) category for this course or for this session. // one) category for this course or for this session.
@ -692,8 +691,8 @@ if (isset($_GET['studentoverview'])) {
// There is no category for this course+session, so create one // There is no category for this course+session, so create one
$cat = new Category(); $cat = new Category();
if (!empty($session_id)) { if (!empty($session_id)) {
$s_name = api_get_session_name($session_id); $sessionName = api_get_session_name($session_id);
$cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name); $cat->set_name($course_code.' - '.get_lang('Session').' '.$sessionName);
$cat->set_session_id($session_id); $cat->set_session_id($session_id);
} else { } else {
$cat->set_name($course_code); $cat->set_name($course_code);
@ -895,6 +894,7 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)
$i = 0; $i = 0;
$allcat = []; $allcat = [];
/** @var Category $cat */ /** @var Category $cat */
foreach ($cats as $cat) { foreach ($cats as $cat) {
$allcat = $cat->get_subcategories($stud_id, $course_code, $session_id); $allcat = $cat->get_subcategories($stud_id, $course_code, $session_id);
@ -934,13 +934,24 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)
$exportToPdf = true; $exportToPdf = true;
} }
$teacher = api_is_allowed_to_edit(null, true);
if ($teacher) {
$loadStats = false;
} else {
$loadStats = api_get_configuration_value('disable_gradebook_stats') === false;
}
$gradebookTable = new GradebookTable( $gradebookTable = new GradebookTable(
$cat, $cat,
$allcat, $allcat,
$alleval, $alleval,
$alllink, $alllink,
$addparams, $addparams,
$exportToPdf $exportToPdf,
null,
null,
[],
$loadStats
); );
$model = ExerciseLib::getCourseScoreModel(); $model = ExerciseLib::getCourseScoreModel();
@ -951,13 +962,23 @@ if (isset($first_time) && $first_time == 1 && api_is_allowed_to_edit(null, true)
]; ];
} else { } else {
if (empty($model)) { if (empty($model)) {
$gradebookTable->td_attributes = [ if ($loadStats) {
3 => 'class="text-right"', $gradebookTable->td_attributes = [
4 => 'class="text-center"', 3 => 'class="text-right"',
5 => 'class="text-center"', 4 => 'class="text-center"',
6 => 'class="text-center"', 5 => 'class="text-center"',
7 => 'class="text-center"', 6 => 'class="text-center"',
]; 7 => 'class="text-center"',
];
} else {
$gradebookTable->td_attributes = [
3 => 'class="text-right"',
4 => 'class="text-center"',
5 => 'class="text-center"',
//6 => 'class="text-center"',
//7 => 'class="text-center"',
];
}
} else { } else {
$gradebookTable->td_attributes = [ $gradebookTable->td_attributes = [
3 => 'class="text-right"', 3 => 'class="text-right"',

@ -214,6 +214,10 @@ abstract class AbstractLink implements GradebookItem
public function getStudentList() public function getStudentList()
{ {
if (empty($this->studentList)) {
return [];
}
return $this->studentList; return $this->studentList;
} }

@ -443,8 +443,8 @@ class Category implements GradebookItem
return $cats; return $cats;
} }
$tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'SELECT * FROM '.$tbl_grade_categories; $sql = 'SELECT * FROM '.$table;
$paramcount = 0; $paramcount = 0;
if (isset($id)) { if (isset($id)) {
$sql .= ' WHERE id = '.intval($id); $sql .= ' WHERE id = '.intval($id);
@ -808,9 +808,9 @@ class Category implements GradebookItem
$name = $this->name; $name = $this->name;
$parent = $this->parent; $parent = $this->parent;
} }
$tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = "SELECT count(id) AS number $sql = "SELECT count(id) AS number
FROM $tbl_grade_categories FROM $table
WHERE name = '".Database::escape_string($name)."'"; WHERE name = '".Database::escape_string($name)."'";
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
@ -836,7 +836,6 @@ class Category implements GradebookItem
} else { } else {
$sql .= ' AND parent_id = '.intval($parent); $sql .= ' AND parent_id = '.intval($parent);
} }
$result = Database::query($sql); $result = Database::query($sql);
$number = Database::fetch_row($result); $number = Database::fetch_row($result);
@ -1193,12 +1192,12 @@ class Category implements GradebookItem
) { ) {
$main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER); $main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE); $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$course_code = Database::escape_string($course_code); $course_code = Database::escape_string($course_code);
$session_id = (int) $session_id; $session_id = (int) $session_id;
$sql = "SELECT * FROM $tbl_grade_categories WHERE parent_id = 0"; $sql = "SELECT * FROM $table WHERE parent_id = 0";
if (!api_is_allowed_to_edit()) { if (!api_is_allowed_to_edit()) {
$sql .= ' AND visible = 1'; $sql .= ' AND visible = 1';
@ -1481,6 +1480,7 @@ class Category implements GradebookItem
WHERE WHERE
cc.id = cu.c_id AND cc.id = cu.c_id AND
cu.status = '.COURSEMANAGER; cu.status = '.COURSEMANAGER;
if (!api_is_platform_admin()) { if (!api_is_platform_admin()) {
$sql .= ' AND cu.user_id = '.$user_id; $sql .= ' AND cu.user_id = '.$user_id;
} }
@ -1662,17 +1662,6 @@ class Category implements GradebookItem
$session_id = null, $session_id = null,
$order = null $order = null
) { ) {
if (!empty($session_id)) {
/*$tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'SELECT id FROM '.$tbl_grade_categories. ' WHERE session_id = '.$session_id;
$result_session = Database::query($sql);
if (Database::num_rows($result_session) > 0) {
$data_session = Database::fetch_array($result_session);
$parent_id = $data_session['id'];
return self::load(null, null, null, $parent_id, null, null, $order);
}*/
}
// 1 student // 1 student
if (isset($studentId)) { if (isset($studentId)) {
// Special case: this is the root // Special case: this is the root

@ -25,6 +25,7 @@ class GradebookTable extends SortableTable
private $datagen; private $datagen;
private $evals_links; private $evals_links;
private $dataForGraph; private $dataForGraph;
private $loadStats = true;
/** /**
* GradebookTable constructor. * GradebookTable constructor.
@ -48,7 +49,8 @@ class GradebookTable extends SortableTable
$exportToPdf = false, $exportToPdf = false,
$showTeacherView = null, $showTeacherView = null,
$userId = null, $userId = null,
$studentList = [] $studentList = [],
$loadStats = true
) { ) {
$this->teacherView = is_null($showTeacherView) ? api_is_allowed_to_edit(null, true) : $showTeacherView; $this->teacherView = is_null($showTeacherView) ? api_is_allowed_to_edit(null, true) : $showTeacherView;
$this->userId = is_null($userId) ? api_get_user_id() : $userId; $this->userId = is_null($userId) ? api_get_user_id() : $userId;
@ -67,6 +69,7 @@ class GradebookTable extends SortableTable
$this->evals_links = array_merge($evals, $links); $this->evals_links = array_merge($evals, $links);
$this->currentcat = $currentcat; $this->currentcat = $currentcat;
$this->cats = $cats; $this->cats = $cats;
$this->loadStats = $loadStats;
$this->datagen = new GradebookDataGenerator($cats, $evals, $links); $this->datagen = new GradebookDataGenerator($cats, $evals, $links);
if (!empty($userId)) { if (!empty($userId)) {
@ -104,9 +107,13 @@ class GradebookTable extends SortableTable
$this->set_header($column++, get_lang('Weight'), false); $this->set_header($column++, get_lang('Weight'), false);
$this->set_header($column++, get_lang('Result'), false); $this->set_header($column++, get_lang('Result'), false);
if (empty($model)) { if (empty($model)) {
$this->set_header($column++, get_lang('Ranking'), false); if ($this->loadStats) {
$this->set_header($column++, get_lang('Ranking'), false);
}
$this->set_header($column++, get_lang('BestScore'), false); $this->set_header($column++, get_lang('BestScore'), false);
$this->set_header($column++, get_lang('Average'), false); if ($this->loadStats) {
$this->set_header($column++, get_lang('Average'), false);
}
} }
if (!empty($cats)) { if (!empty($cats)) {
@ -214,13 +221,12 @@ class GradebookTable extends SortableTable
$course_code = api_get_course_id(); $course_code = api_get_course_id();
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$statusToFilter = 0;
if (empty($session_id)) { if (empty($session_id)) {
$statusToFilter = STUDENT; $statusToFilter = STUDENT;
} else {
$statusToFilter = 0;
} }
if (empty($this->studentList)) { if (empty($this->studentList) && $this->loadStats) {
$studentList = CourseManager::get_user_list_from_course_code( $studentList = CourseManager::get_user_list_from_course_code(
$course_code, $course_code,
$session_id, $session_id,
@ -237,7 +243,8 @@ class GradebookTable extends SortableTable
$from, $from,
$this->per_page, $this->per_page,
false, false,
$this->studentList $this->studentList,
$this->loadStats
); );
// generate the data to display // generate the data to display
@ -348,14 +355,13 @@ class GradebookTable extends SortableTable
} }
} else { } else {
$score = $item->calc_score($this->userId); $score = $item->calc_score($this->userId);
$scoreToDisplay = '-';
if (!empty($score[1])) { if (!empty($score[1])) {
$completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT); $completeScore = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
$score = $score[0] / $score[1] * $item->get_weight(); $score = $score[0] / $score[1] * $item->get_weight();
$score = $scoredisplay->display_score([$score, null], SCORE_SIMPLE); $score = $scoredisplay->display_score([$score, null], SCORE_SIMPLE);
$scoreToDisplay = Display::tip($score, $completeScore); $scoreToDisplay = Display::tip($score, $completeScore);
} else { } else {
$scoreToDisplay = '-';
$categoryScore = null; $categoryScore = null;
} }
@ -407,11 +413,17 @@ class GradebookTable extends SortableTable
if (empty($model)) { if (empty($model)) {
// Ranking // Ranking
$row[] = $ranking; if ($this->loadStats) {
$row[] = $ranking;
}
// Best // Best
$row[] = $best; $row[] = $best;
// Average // Average
$row[] = $average; if ($this->loadStats) {
$row[] = $average;
}
} }
if (get_class($item) == 'Category') { if (get_class($item) == 'Category') {
@ -454,7 +466,6 @@ class GradebookTable extends SortableTable
$sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink); $sub_cat_info = new GradebookDataGenerator($allcat, $alleval, $alllink);
$sub_cat_info->userId = $user_id; $sub_cat_info->userId = $user_id;
$data_array2 = $sub_cat_info->get_data( $data_array2 = $sub_cat_info->get_data(
$sorting, $sorting,
$from, $from,
@ -488,7 +499,7 @@ class GradebookTable extends SortableTable
$row[] = $this->build_type_column($item, ['style' => 'padding-left:5px']); $row[] = $this->build_type_column($item, ['style' => 'padding-left:5px']);
// Name. // Name.
$row[] = $invisibility_span_open."    ". $row[] = $invisibility_span_open."    ".
$this->build_name_link($item, $type).$invisibility_span_close; $this->build_name_link($item, $type).$invisibility_span_close;
// Description. // Description.
@ -528,9 +539,6 @@ class GradebookTable extends SortableTable
if (count($eval_n_links) > 0) { if (count($eval_n_links) > 0) {
$value_data = isset($data[4]) ? $data[4] : null; $value_data = isset($data[4]) ? $data[4] : null;
if (!is_null($value_data)) { if (!is_null($value_data)) {
//$score = $item->calc_score(api_get_user_id());
//$new_score = $data[3] * $score[0] / $score[1];
//$new_score = floatval(number_format($new_score, api_get_setting('gradebook_number_decimals')));
// Result // Result
$row[] = $value_data; $row[] = $value_data;
@ -538,12 +546,18 @@ class GradebookTable extends SortableTable
$average = isset($data['average']) ? $data['average'] : null; $average = isset($data['average']) ? $data['average'] : null;
$ranking = isset($data['ranking']) ? $data['ranking'] : null; $ranking = isset($data['ranking']) ? $data['ranking'] : null;
// Ranking if ($this->loadStats) {
$row[] = $ranking; // Ranking
$row[] = $ranking;
}
// Best // Best
$row[] = $best; $row[] = $best;
// Average // Average
$row[] = $average; if ($this->loadStats) {
$row[] = $average;
}
} }
} }
@ -709,16 +723,29 @@ class GradebookTable extends SortableTable
$totalAverage, $totalAverage,
]; ];
} else { } else {
$row = [ if ($this->loadStats) {
null, $row = [
'<h3>'.get_lang('Total').'</h3>', null,
null, '<h3>'.get_lang('Total').'</h3>',
$main_weight, null,
$totalResult, $main_weight,
$totalRanking, $totalResult,
$totalBest, $totalRanking,
$totalAverage, $totalBest,
]; $totalAverage,
];
} else {
$row = [
null,
'<h3>'.get_lang('Total').'</h3>',
null,
$main_weight,
$totalResult,
//$totalRanking,
$totalBest,
//$totalAverage,
];
}
} }
$sortable_data[] = $row; $sortable_data[] = $row;
@ -824,12 +851,13 @@ class GradebookTable extends SortableTable
SCORE_DIV_PERCENT_WITH_CUSTOM SCORE_DIV_PERCENT_WITH_CUSTOM
); );
$rowTotal[] = ' '; $rowTotal[] = ' ';
$rowTotal[] = ' '; if ($this->loadStats) {
$rowTotal[] = ' '; $rowTotal[] = ' ';
$rowTotal[] = ' ';
}
$sortable_data[] = $rowTotal; $sortable_data[] = $rowTotal;
} }
return $sortable_data; return $sortable_data;
} }

@ -90,7 +90,8 @@ class GradebookDataGenerator
$start = 0, $start = 0,
$count = null, $count = null,
$ignore_score_color = false, $ignore_score_color = false,
$studentList = [] $studentList = [],
$loadStats = true
) { ) {
// do some checks on count, redefine if invalid value // do some checks on count, redefine if invalid value
if (!isset($count)) { if (!isset($count)) {
@ -107,7 +108,7 @@ class GradebookDataGenerator
// Get selected items // Get selected items
$visibleItems = array_slice($allitems, $start, $count); $visibleItems = array_slice($allitems, $start, $count);
$userCount = count($studentList); $userCount = !empty($studentList) ? count($studentList) : 0;
// Generate the data to display // Generate the data to display
$data = []; $data = [];
@ -154,6 +155,7 @@ class GradebookDataGenerator
$ranking = $this->buildRankingColumn($item, $userId, $userCount); $ranking = $this->buildRankingColumn($item, $userId, $userCount);
$row['ranking'] = $ranking['display']; $row['ranking'] = $ranking['display'];
$row['ranking_score'] = $ranking['score']; $row['ranking_score'] = $ranking['score'];
$row[] = $item; $row[] = $item;
} }
} else { } else {
@ -173,28 +175,32 @@ class GradebookDataGenerator
$row['best'] = $best['display']; $row['best'] = $best['display'];
$row['best_score'] = $best['score']; $row['best_score'] = $best['score'];
$rankingStudentList = [];
$invalidateResults = true;
// Average // Average
$average = $this->buildAverageResultColumn($item); $average = $this->buildAverageResultColumn($item);
$row['average'] = $average['display']; $row['average'] = $average['display'];
$row['average_score'] = $average['score']; $row['average_score'] = $average['score'];
// Ranking // Ranking
$rankingStudentList = []; if (!empty($studentList)) {
$invalidateResults = true; foreach ($studentList as $user) {
foreach ($studentList as $user) { $score = $this->build_result_column(
$score = $this->build_result_column( $user['user_id'],
$user['user_id'], $item,
$item, $ignore_score_color,
$ignore_score_color, true
true );
);
if (!empty($score['score'][0])) { if (!empty($score['score'][0])) {
$invalidateResults = false; $invalidateResults = false;
}
$rankingStudentList[$user['user_id']] = $score['score'][0];
} }
$rankingStudentList[$user['user_id']] = $score['score'][0];
} }
$scoreDisplay = ScoreDisplay::instance(); $scoreDisplay = ScoreDisplay::instance();
$score = AbstractLink::getCurrentUserRanking($userId, $rankingStudentList); $score = AbstractLink::getCurrentUserRanking($userId, $rankingStudentList);
$row['ranking'] = $scoreDisplay->display_score( $row['ranking'] = $scoreDisplay->display_score(

@ -425,13 +425,12 @@ function api_get_utc_datetime(
$returnObj = false $returnObj = false
) { ) {
$from_timezone = api_get_timezone(); $from_timezone = api_get_timezone();
$to_timezone = 'UTC';
if (is_null($time) || empty($time) || $time === '0000-00-00 00:00:00') { if (is_null($time) || empty($time) || $time === '0000-00-00 00:00:00') {
if ($return_null_if_invalid_date) { if ($return_null_if_invalid_date) {
return null; return null;
} }
if ($returnObj) { if ($returnObj) {
return $date = new DateTime(gmdate('Y-m-d H:i:s')); return $date = new DateTime(gmdate('Y-m-d H:i:s'), new DateTimeZone('UTC'));
} }
return gmdate('Y-m-d H:i:s'); return gmdate('Y-m-d H:i:s');
@ -445,7 +444,7 @@ function api_get_utc_datetime(
} }
try { try {
$date = new DateTime($time, new DateTimezone($from_timezone)); $date = new DateTime($time, new DateTimezone($from_timezone));
$date->setTimezone(new DateTimeZone($to_timezone)); $date->setTimezone(new DateTimeZone('UTC'));
if ($returnObj) { if ($returnObj) {
return $date; return $date;
} else { } else {

@ -804,5 +804,9 @@ ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED106291D79BD3 FOREIGN KEY (c_id) REFE
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062613FECDF FOREIGN KEY (session_id) REFERENCES session (id); ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062613FECDF FOREIGN KEY (session_id) REFERENCES session (id);
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED106212469DE2 FOREIGN KEY (category_id) REFERENCES portfolio_category (id); ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED106212469DE2 FOREIGN KEY (category_id) REFERENCES portfolio_category (id);
ALTER TABLE portfolio_category ADD CONSTRAINT FK_7AC64359A76ED395 FOREIGN KEY (user_id) REFERENCES user (id); ALTER TABLE portfolio_category ADD CONSTRAINT FK_7AC64359A76ED395 FOREIGN KEY (user_id) REFERENCES user (id);
INSERT INTO settings_current(variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES('course_create_active_tools','portfolio','checkbox','Tools','true','CourseCreateActiveToolsTitle','CourseCreateActiveToolsComment',NULL,'Portfolio', 0);
*/ */
//$_configuration['allow_portfolio_tool'] = false; //$_configuration['allow_portfolio_tool'] = false;
// Disable average and best columns in gradebook see BT#
//$_configuration['disable_gradebook_stats'] = false;

@ -3030,8 +3030,9 @@ function getVersionTable()
* *
* @param string $installationProfile The name of the JSON file in main/install/profiles/ folder * @param string $installationProfile The name of the JSON file in main/install/profiles/ folder
* *
* @return bool false on failure (no bad consequences anyway, just ignoring profile)
* @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\DBAL\DBALException
*
* @return bool false on failure (no bad consequences anyway, just ignoring profile)
*/ */
function installProfileSettings($installationProfile = '') function installProfileSettings($installationProfile = '')
{ {
@ -3104,8 +3105,9 @@ function rrmdir($dir)
* @param bool $preview * @param bool $preview
* @param bool $anonymous * @param bool $anonymous
* *
* @return array
* @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\DBAL\DBALException
*
* @return array
*/ */
function get_group_picture_path_by_id($id, $type = 'web', $preview = false, $anonymous = false) function get_group_picture_path_by_id($id, $type = 'web', $preview = false, $anonymous = false)
{ {
@ -3165,8 +3167,9 @@ function get_group_picture_path_by_id($id, $type = 'web', $preview = false, $ano
* @param EntityManager $manager * @param EntityManager $manager
* @param bool $processFiles * @param bool $processFiles
* *
* @return bool Always returns true except if the process is broken
* @throws \Doctrine\DBAL\DBALException * @throws \Doctrine\DBAL\DBALException
*
* @return bool Always returns true except if the process is broken
*/ */
function migrateSwitch($fromVersion, $manager, $processFiles = true) function migrateSwitch($fromVersion, $manager, $processFiles = true)
{ {

@ -0,0 +1,15 @@
<?php
/**
* Use this script (uncommenting the die(); line) to generate a file in
* /tmp/data_users.php to replace the data_users.php file here with a much
* larger number of (less realistic) users for testing purposes
*/
die();
$string = "\$users[] = array('username' => 'aaaX', 'pass' => 'aaaX', 'firstname' => 'AAAX', 'lastname' => 'BBBX', 'status' => 5, 'auth_source' => 'platform', 'email' => 'aaaX@example.com', 'creator_id' => 1, 'active' => 1);\n";
$output = '';
$outputFile = '/tmp/data_users.php';
$fh = fopen($outputFile, 'a+');
for ($i=1; $i < 5000; $i++) {
fwrite($fh, str_replace('X', $i, $string));
}
fclose($fh);
Loading…
Cancel
Save