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,
null,
null,
$statusFilter
$statusToFilter
);
switch ($action) {

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

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

@ -443,8 +443,8 @@ class Category implements GradebookItem
return $cats;
}
$tbl_grade_categories = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'SELECT * FROM '.$tbl_grade_categories;
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'SELECT * FROM '.$table;
$paramcount = 0;
if (isset($id)) {
$sql .= ' WHERE id = '.intval($id);
@ -808,9 +808,9 @@ class Category implements GradebookItem
$name = $this->name;
$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
FROM $tbl_grade_categories
FROM $table
WHERE name = '".Database::escape_string($name)."'";
if (api_is_allowed_to_edit()) {
@ -836,7 +836,6 @@ class Category implements GradebookItem
} else {
$sql .= ' AND parent_id = '.intval($parent);
}
$result = Database::query($sql);
$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);
$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);
$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()) {
$sql .= ' AND visible = 1';
@ -1481,6 +1480,7 @@ class Category implements GradebookItem
WHERE
cc.id = cu.c_id AND
cu.status = '.COURSEMANAGER;
if (!api_is_platform_admin()) {
$sql .= ' AND cu.user_id = '.$user_id;
}
@ -1662,17 +1662,6 @@ class Category implements GradebookItem
$session_id = 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
if (isset($studentId)) {
// Special case: this is the root

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

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

@ -425,13 +425,12 @@ function api_get_utc_datetime(
$returnObj = false
) {
$from_timezone = api_get_timezone();
$to_timezone = 'UTC';
if (is_null($time) || empty($time) || $time === '0000-00-00 00:00:00') {
if ($return_null_if_invalid_date) {
return null;
}
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');
@ -445,7 +444,7 @@ function api_get_utc_datetime(
}
try {
$date = new DateTime($time, new DateTimezone($from_timezone));
$date->setTimezone(new DateTimeZone($to_timezone));
$date->setTimezone(new DateTimeZone('UTC'));
if ($returnObj) {
return $date;
} 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_A9ED106212469DE2 FOREIGN KEY (category_id) REFERENCES portfolio_category (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;
// 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
*
* @return bool false on failure (no bad consequences anyway, just ignoring profile)
* @throws \Doctrine\DBAL\DBALException
*
* @return bool false on failure (no bad consequences anyway, just ignoring profile)
*/
function installProfileSettings($installationProfile = '')
{
@ -3104,8 +3105,9 @@ function rrmdir($dir)
* @param bool $preview
* @param bool $anonymous
*
* @return array
* @throws \Doctrine\DBAL\DBALException
*
* @return array
*/
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 bool $processFiles
*
* @return bool Always returns true except if the process is broken
* @throws \Doctrine\DBAL\DBALException
*
* @return bool Always returns true except if the process is broken
*/
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