Fix gradebook general view see BT#9428

1.10.x
Julio Montoya 10 years ago
parent 07dcafb2b0
commit a6e6160cbb
  1. 2
      main/gradebook/gradebook_flatview.php
  2. 44
      main/gradebook/lib/fe/flatviewtable.class.php
  3. 60
      main/gradebook/lib/flatview_data_generator.class.php
  4. 1
      main/inc/lib/pear/HTML/Table.php
  5. 87
      main/inc/lib/pear/HTML/Table/Storage.php

@ -121,6 +121,8 @@ $flatviewtable = new FlatViewTable(
$mainCourseCategory[0] $mainCourseCategory[0]
); );
$flatviewtable->setAutoFill(false);
$parameters = array('selectcat' => intval($_GET['selectcat'])); $parameters = array('selectcat' => intval($_GET['selectcat']));
$flatviewtable->set_additional_parameters($parameters); $flatviewtable->set_additional_parameters($parameters);

@ -3,9 +3,9 @@
set_time_limit(0); set_time_limit(0);
use CpChart\Classes\pCache as pCache;
use CpChart\Classes\pData as pData; use CpChart\Classes\pData as pData;
use CpChart\Classes\pImage as pImage; use CpChart\Classes\pImage as pImage;
use CpChart\Classes\pCache as pCache;
/** /**
* Class FlatViewTable * Class FlatViewTable
@ -395,12 +395,43 @@ class FlatViewTable extends SortableTable
// step 1: generate columns: evaluations and links // step 1: generate columns: evaluations and links
$header_names = $this->datagen->get_header_names($this->offset, $selectlimit); $header_names = $this->datagen->get_header_names($this->offset, $selectlimit);
$this->set_header(0, $header_names[0]); $userRowSpan = false;
$this->set_header(1, $header_names[1]); foreach ($header_names as $item) {
if (is_array($item)) {
$userRowSpan = true;
break;
}
}
$thAttributes = '';
if ($userRowSpan) {
$thAttributes = 'rowspan=2';
}
$this->set_header(0, $header_names[0], true, $thAttributes);
$this->set_header(1, $header_names[1], true, $thAttributes);
$column = 2; $column = 2;
$firstHeader = [];
while ($column < count($header_names)) { while ($column < count($header_names)) {
$this->set_header($column, $header_names[$column], false); $headerData = $header_names[$column];
if (is_array($headerData)) {
$countItems = count($headerData['items']);
$this->set_header(
$column,
$headerData['header'],
false,
'colspan="'.$countItems.'"'
);
foreach ($headerData['items'] as $item) {
$firstHeader[] = '<center>'.$item.'</center>';
}
} else {
$this->set_header($column, $headerData, false, $thAttributes);
}
$column++; $column++;
} }
@ -413,6 +444,11 @@ class FlatViewTable extends SortableTable
); );
$table_data = array(); $table_data = array();
if (!empty($firstHeader)) {
$table_data[] = $firstHeader;
}
foreach ($data_array as $user_row) { foreach ($data_array as $user_row) {
$user_id = $user_row[0]; $user_id = $user_row[0];
unset($user_row[0]); unset($user_row[0]);

@ -65,9 +65,9 @@ class FlatViewDataGenerator
} }
/** /**
* Get total number of evaluations/links (columns) (the 2 users columns not included) * Get total number of evaluations/links (columns) (the 2 users columns not included)
* @return int * @return int
*/ */
public function get_total_items_count() public function get_total_items_count()
{ {
return count($this->evals_links); return count($this->evals_links);
@ -164,7 +164,14 @@ class FlatViewDataGenerator
// Means there are any subcategory // Means there are any subcategory
foreach ($allcat as $sub_cat) { foreach ($allcat as $sub_cat) {
$extra = '';
$sub_cat_weight = round(100 * $sub_cat->get_weight() / $main_weight, 1);
$add_weight = " $sub_cat_weight %";
$mainHeader = Display::url(
$sub_cat->get_name(),
api_get_self().'?selectcat='.$sub_cat->get_id().'&'.api_get_cidreq()
).$add_weight;
if (api_get_configuration_value('gradebook_detailed_admin_view') == true) { if (api_get_configuration_value('gradebook_detailed_admin_view') == true) {
@ -183,20 +190,18 @@ class FlatViewDataGenerator
} }
$finalList = array_merge($linkNameList, $evalNameList); $finalList = array_merge($linkNameList, $evalNameList);
$extra = '';
if (!empty($finalList)) { if (!empty($finalList)) {
$finalList[] = get_lang('Average'); $finalList[] = get_lang('Average');
$extra = '<br />'.implode(' / ', $finalList);
} }
}
$sub_cat_weight = round(100 * $sub_cat->get_weight() / $main_weight, 1); $list = [];
$add_weight = " $sub_cat_weight %"; $list['items'] = $finalList;
$headers[] = Display::url( $list['header'] = $mainHeader;
$sub_cat->get_name(), $headers[]= $list;
api_get_self().'?selectcat='.$sub_cat->get_id().'&'.api_get_cidreq() } else {
).$add_weight.$extra; $headers[] = $mainHeader;
}
} }
} else { } else {
if (!isset($this->params['only_total_category']) || if (!isset($this->params['only_total_category']) ||
@ -462,7 +467,6 @@ class FlatViewDataGenerator
} }
$real_score = $score; $real_score = $score;
$divide = $score[1] == 0 ? 1 : $score[1]; $divide = $score[1] == 0 ? 1 : $score[1];
$sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()]; $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()];
@ -479,7 +483,6 @@ class FlatViewDataGenerator
} }
*/ */
if (api_get_setting('gradebook_show_percentage_in_reports') == 'false') { if (api_get_setting('gradebook_show_percentage_in_reports') == 'false') {
//if (true)
$real_score = $scoredisplay->display_score($real_score, SCORE_SIMPLE); $real_score = $scoredisplay->display_score($real_score, SCORE_SIMPLE);
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM); $temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM);
$temp_score = Display::tip($real_score, $temp_score); $temp_score = Display::tip($real_score, $temp_score);
@ -491,15 +494,16 @@ class FlatViewDataGenerator
if (!isset($this->params['only_total_category']) || if (!isset($this->params['only_total_category']) ||
(isset($this->params['only_total_category']) && (isset($this->params['only_total_category']) &&
$this->params['only_total_category'] == false) $this->params['only_total_category'] == false)
) { ) {
if (!$show_all) { if (!$show_all) {
if (api_get_configuration_value('gradebook_detailed_admin_view')) { if (api_get_configuration_value('gradebook_detailed_admin_view')) {
$finalList = array_merge($linkScoreList, $evalScoreList); $finalList = array_merge($linkScoreList, $evalScoreList);
$average = array_sum($finalList) / count($finalList); $average = array_sum($finalList) / count($finalList);
$finalList[] = round($average, 2); $finalList[] = round($average, 2);
$extra = implode(' / ', $finalList); foreach ($finalList as $finalValue) {
$row[] = $extra; $row[] = '<center>'.$finalValue.'</center>';
}
} else { } else {
$row[] = $temp_score.' '; $row[] = $temp_score.' ';
} }
@ -507,7 +511,7 @@ class FlatViewDataGenerator
$row[] = $temp_score; $row[] = $temp_score;
} }
} }
$item_value_total +=$item_value; $item_value_total += $item_value;
} }
if ($convert_using_the_global_weight) { if ($convert_using_the_global_weight) {
//$item_total = $main_weight; //$item_total = $main_weight;
@ -652,14 +656,14 @@ class FlatViewDataGenerator
) { ) {
if (!$show_all) { if (!$show_all) {
if (in_array($item->get_type(), array( if (in_array($item->get_type(), array(
LINK_EXERCISE, LINK_EXERCISE,
LINK_DROPBOX, LINK_DROPBOX,
LINK_STUDENTPUBLICATION, LINK_STUDENTPUBLICATION,
LINK_LEARNPATH, LINK_LEARNPATH,
LINK_FORUM_THREAD, LINK_FORUM_THREAD,
LINK_ATTENDANCE, LINK_ATTENDANCE,
LINK_SURVEY, LINK_SURVEY,
LINK_HOTPOTATOES) LINK_HOTPOTATOES)
) )
) { ) {
if (!empty($score[0])) { if (!empty($score[0])) {
@ -689,7 +693,7 @@ class FlatViewDataGenerator
* @param int $session_id * @param int $session_id
* @return array * @return array
*/ */
public function get_evaluation_sumary_results ($session_id = null) public function get_evaluation_sumary_results($session_id = null)
{ {
$usertable = array(); $usertable = array();
foreach ($this->users as $user) { foreach ($this->users as $user) {

@ -1015,6 +1015,7 @@ class HTML_Table extends HTML_Common {
} }
} else { } else {
for ($i = 0; $i < $this->_tbodyCount; $i++) { for ($i = 0; $i < $this->_tbodyCount; $i++) {
$this->_tbodies[$i]->setAutoFill($this->_autoFill);
$strHtml .= $this->_tbodies[$i]->toHtml($tabs, $tab); $strHtml .= $this->_tbodies[$i]->toHtml($tabs, $tab);
} }
} }

@ -290,8 +290,8 @@ class HTML_Table_Storage extends HTML_Common {
{ {
if ( isset($this->_structure[$row][$col]) if ( isset($this->_structure[$row][$col])
&& $this->_structure[$row][$col] == '__SPANNED__' && $this->_structure[$row][$col] == '__SPANNED__'
) { ) {
return; return;
} }
$attributes = $this->_parseAttributes($attributes); $attributes = $this->_parseAttributes($attributes);
$err = $this->_adjustEnds($row, $col, 'setCellAttributes', $attributes); $err = $this->_adjustEnds($row, $col, 'setCellAttributes', $attributes);
@ -299,7 +299,8 @@ class HTML_Table_Storage extends HTML_Common {
return $err; return $err;
} }
$this->_structure[$row][$col]['attr'] = $attributes; $this->_structure[$row][$col]['attr'] = $attributes;
$this->_updateSpanGrid($row, $col); // Fix use of rowspan/colspan
//$this->_updateSpanGrid($row, $col);
} }
/** /**
@ -315,7 +316,7 @@ class HTML_Table_Storage extends HTML_Common {
{ {
if ( isset($this->_structure[$row][$col]) if ( isset($this->_structure[$row][$col])
&& $this->_structure[$row][$col] == '__SPANNED__' && $this->_structure[$row][$col] == '__SPANNED__'
) { ) {
return; return;
} }
$attributes = $this->_parseAttributes($attributes); $attributes = $this->_parseAttributes($attributes);
@ -324,7 +325,7 @@ class HTML_Table_Storage extends HTML_Common {
return $err; return $err;
} }
$this->_updateAttrArray($this->_structure[$row][$col]['attr'], $attributes); $this->_updateAttrArray($this->_structure[$row][$col]['attr'], $attributes);
$this->_updateSpanGrid($row, $col); //$this->_updateSpanGrid($row, $col);
} }
/** /**
@ -338,7 +339,7 @@ class HTML_Table_Storage extends HTML_Common {
{ {
if ( isset($this->_structure[$row][$col]) if ( isset($this->_structure[$row][$col])
&& $this->_structure[$row][$col] != '__SPANNED__' && $this->_structure[$row][$col] != '__SPANNED__'
) { ) {
return $this->_structure[$row][$col]['attr']; return $this->_structure[$row][$col]['attr'];
} elseif (!isset($this->_structure[$row][$col])) { } elseif (!isset($this->_structure[$row][$col])) {
return PEAR::raiseError('Invalid table cell reference[' . return PEAR::raiseError('Invalid table cell reference[' .
@ -370,7 +371,7 @@ class HTML_Table_Storage extends HTML_Common {
if (is_array($contents)) { if (is_array($contents)) {
foreach ($contents as $singleContent) { foreach ($contents as $singleContent) {
$ret = $this->_setSingleCellContents($row, $col, $singleContent, $ret = $this->_setSingleCellContents($row, $col, $singleContent,
$type); $type);
if (PEAR::isError($ret)) { if (PEAR::isError($ret)) {
return $ret; return $ret;
} }
@ -406,7 +407,7 @@ class HTML_Table_Storage extends HTML_Common {
{ {
if ( isset($this->_structure[$row][$col]) if ( isset($this->_structure[$row][$col])
&& $this->_structure[$row][$col] == '__SPANNED__' && $this->_structure[$row][$col] == '__SPANNED__'
) { ) {
return; return;
} }
$err = $this->_adjustEnds($row, $col, 'setCellContents'); $err = $this->_adjustEnds($row, $col, 'setCellContents');
@ -428,7 +429,7 @@ class HTML_Table_Storage extends HTML_Common {
{ {
if ( isset($this->_structure[$row][$col]) if ( isset($this->_structure[$row][$col])
&& $this->_structure[$row][$col] == '__SPANNED__' && $this->_structure[$row][$col] == '__SPANNED__'
) { ) {
return; return;
} }
if (!isset($this->_structure[$row][$col])) { if (!isset($this->_structure[$row][$col])) {
@ -477,10 +478,10 @@ class HTML_Table_Storage extends HTML_Common {
{ {
if (isset($contents) && !is_array($contents)) { if (isset($contents) && !is_array($contents)) {
return PEAR::raiseError('First parameter to HTML_Table::addRow ' . return PEAR::raiseError('First parameter to HTML_Table::addRow ' .
'must be an array'); 'must be an array');
} }
if (is_null($contents)) { if (is_null($contents)) {
$contents = array(); $contents = array();
} }
$type = strtolower($type); $type = strtolower($type);
@ -620,10 +621,10 @@ class HTML_Table_Storage extends HTML_Common {
{ {
if (isset($contents) && !is_array($contents)) { if (isset($contents) && !is_array($contents)) {
return PEAR::raiseError('First parameter to HTML_Table::addCol ' . return PEAR::raiseError('First parameter to HTML_Table::addCol ' .
'must be an array'); 'must be an array');
} }
if (is_null($contents)) { if (is_null($contents)) {
$contents = array(); $contents = array();
} }
$type = strtolower($type); $type = strtolower($type);
@ -748,7 +749,7 @@ class HTML_Table_Storage extends HTML_Common {
if (isset($this->_structure[$i][$j]['contents'])) { if (isset($this->_structure[$i][$j]['contents'])) {
$contents = $this->_structure[$i][$j]['contents']; $contents = $this->_structure[$i][$j]['contents'];
} }
$strHtml .= $tabs . $tab . $tab . $extraTab . "<$type" . $this->_getAttrString($attr) . '>';
if (is_object($contents)) { if (is_object($contents)) {
// changes indent and line end settings on nested tables // changes indent and line end settings on nested tables
if (is_subclass_of($contents, 'html_common')) { if (is_subclass_of($contents, 'html_common')) {
@ -766,11 +767,22 @@ class HTML_Table_Storage extends HTML_Common {
if (is_array($contents)) { if (is_array($contents)) {
$contents = implode(', ', $contents); $contents = implode(', ', $contents);
} }
if (isset($this->_autoFill) && $contents === '') {
$contents = $this->_autoFill; $typeContent = $tabs . $tab . $tab . $extraTab . "<$type" . $this->_getAttrString($attr) . '>';
if (empty($contents)) {
if (isset($this->_autoFill) && $this->_autoFill) {
$contents = $this->_autoFill;
}
} else {
$typeContent .= $contents;
}
$typeContent .= "</$type>" . $lnEnd;
if (!empty($contents)) {
$strHtml .= $typeContent;
} }
$strHtml .= $contents;
$strHtml .= "</$type>" . $lnEnd;
} }
$strHtml .= $tabs . $tab . $extraTab . '</tr>' . $lnEnd; $strHtml .= $tabs . $tab . $extraTab . '</tr>' . $lnEnd;
} }
@ -816,16 +828,16 @@ class HTML_Table_Storage extends HTML_Common {
} }
/** /**
* Adjusts ends (total number of rows and columns) * Adjusts ends (total number of rows and columns)
* @param int $row Row index * @param int $row Row index
* @param int $col Column index * @param int $col Column index
* @param string $method Method name of caller * @param string $method Method name of caller
* Used to populate PEAR_Error if thrown. * Used to populate PEAR_Error if thrown.
* @param array $attributes Assoc array of attributes * @param array $attributes Assoc array of attributes
* Default is an empty array. * Default is an empty array.
* @access private * @access private
* @throws PEAR_Error * @throws PEAR_Error
*/ */
function _adjustEnds($row, $col, $method, $attributes = array()) function _adjustEnds($row, $col, $method, $attributes = array())
{ {
$colspan = isset($attributes['colspan']) ? $attributes['colspan'] : 1; $colspan = isset($attributes['colspan']) ? $attributes['colspan'] : 1;
@ -833,9 +845,10 @@ class HTML_Table_Storage extends HTML_Common {
if (($row + $rowspan - 1) >= $this->_rows) { if (($row + $rowspan - 1) >= $this->_rows) {
if ($this->_autoGrow) { if ($this->_autoGrow) {
$this->_rows = $row + $rowspan; $this->_rows = $row + $rowspan;
} else { } else {
return PEAR::raiseError('Invalid table row reference[' . /*return PEAR::raiseError('Invalid table row reference[' .
$row . '] in HTML_Table::' . $method); $row . '] in HTML_Table::' . $method);*/
} }
} }
@ -843,18 +856,18 @@ class HTML_Table_Storage extends HTML_Common {
if ($this->_autoGrow) { if ($this->_autoGrow) {
$this->_cols = $col + $colspan; $this->_cols = $col + $colspan;
} else { } else {
return PEAR::raiseError('Invalid table column reference[' . /*return PEAR::raiseError('Invalid table column reference[' .
$col . '] in HTML_Table::' . $method); $col . '] in HTML_Table::' . $method);*/
} }
} }
} }
/** /**
* Tells if the parameter is an array of attribute arrays/strings * Tells if the parameter is an array of attribute arrays/strings
* @param mixed $attributes Variable to test * @param mixed $attributes Variable to test
* @access private * @access private
* @return bool * @return bool
*/ */
function _isAttributesArray($attributes) function _isAttributesArray($attributes)
{ {
if (is_array($attributes) && isset($attributes[0])) { if (is_array($attributes) && isset($attributes[0])) {

Loading…
Cancel
Save