Minor - format code.

1.9.x
Julio Montoya 12 years ago
parent e875077906
commit c0e4a054ec
  1. 116
      main/gradebook/gradebook_flatview.php
  2. 47
      main/gradebook/lib/fe/flatviewtable.class.php
  3. 96
      main/gradebook/lib/flatview_data_generator.class.php

@ -4,9 +4,6 @@
* Script * Script
* @package chamilo.gradebook * @package chamilo.gradebook
*/ */
/**
* Init
*/
$language_file = 'gradebook'; $language_file = 'gradebook';
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
@ -97,11 +94,11 @@ $offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
$flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams); $flatviewtable = new FlatViewTable($cat[0], $users, $alleval, $alllinks, true, $offset, $addparams);
$parameters=array('selectcat'=>intval($_GET['selectcat'])); $parameters = array('selectcat' => intval($_GET['selectcat']));
$flatviewtable->set_additional_parameters($parameters); $flatviewtable->set_additional_parameters($parameters);
$params = array();
if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') { if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
$params = array();
$params['only_total_category'] = true; $params['only_total_category'] = true;
$params['join_firstname_lastname'] = true; $params['join_firstname_lastname'] = true;
$params['show_official_code'] = true; $params['show_official_code'] = true;
@ -118,10 +115,16 @@ if (isset($_GET['exportpdf'])) {
'name' => get_lang('FlatView') 'name' => get_lang('FlatView')
); );
$export_pdf_form = new DataForm(DataForm::TYPE_EXPORT_PDF, 'export_pdf_form', null, api_get_self().'?exportpdf=&offset='.intval($_GET['offset']).'&selectcat='.intval($_GET['selectcat']), '_blank', ''); $export_pdf_form = new DataForm(
DataForm::TYPE_EXPORT_PDF,
'export_pdf_form',
null,
api_get_self() . '?exportpdf=&offset=' . intval($_GET['offset']) . '&selectcat=' . intval($_GET['selectcat']),
'_blank',
''
);
if ($export_pdf_form->validate()) { if ($export_pdf_form->validate()) {
$params = array();
$params = $export_pdf_form->exportValues(); $params = $export_pdf_form->exportValues();
Display :: set_header(null, false, false); Display :: set_header(null, false, false);
$params['join_firstname_lastname'] = true; $params['join_firstname_lastname'] = true;
@ -135,78 +138,77 @@ if (isset($_GET['exportpdf'])) {
} }
if (isset ($_GET['print'])) { if (isset ($_GET['print'])) {
$printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks); $printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks, $params);
echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name()); echo print_table($printable_data[1],$printable_data[0], get_lang('FlatView'), $cat[0]->get_name());
exit; exit;
} }
if (!empty($_GET['export_report']) && $_GET['export_report'] == 'export_report') { if (!empty($_GET['export_report']) && $_GET['export_report'] == 'export_report') {
if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) { if (api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) {
$user_id = null; $user_id = null;
if (empty($_SESSION['export_user_fields'])) { if (empty($_SESSION['export_user_fields'])) {
$_SESSION['export_user_fields'] = false; $_SESSION['export_user_fields'] = false;
} }
if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) { if (!api_is_allowed_to_edit(false, false) and !api_is_course_tutor()) {
$user_id = api_get_user_id(); $user_id = api_get_user_id();
} }
require_once 'gradebook_result.class.php'; require_once 'gradebook_result.class.php';
$printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks); $printable_data = get_printable_data($cat[0], $users, $alleval, $alllinks, $params);
switch($_GET['export_format']) { switch ($_GET['export_format']) {
case 'xls': case 'xls':
$export = new GradeBookResult(); $export = new GradeBookResult();
$export->exportCompleteReportXLS($printable_data); $export->exportCompleteReportXLS($printable_data);
break; break;
case 'doc': case 'doc':
$export = new GradeBookResult(); $export = new GradeBookResult();
$export->exportCompleteReportDOC($printable_data); $export->exportCompleteReportDOC($printable_data);
exit; exit;
break; break;
case 'csv': case 'csv':
default: default:
$export = new GradeBookResult(); $export = new GradeBookResult();
$export->exportCompleteReportCSV($printable_data); $export->exportCompleteReportCSV($printable_data);
exit; exit;
break; break;
} }
} else { } else {
api_not_allowed(true); api_not_allowed(true);
} }
} }
$addparams = array ('selectcat' => $cat[0]->get_id()); $addparams = array ('selectcat' => $cat[0]->get_id());
if (isset($_GET['search'])) { if (isset($_GET['search'])) {
$addparams['search'] = $keyword; $addparams['search'] = $keyword;
} }
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
if (isset($_GET['exportpdf'])) { if (isset($_GET['exportpdf'])) {
$export_pdf_form->display(); $export_pdf_form->display();
} else { } else {
Display :: display_header(get_lang('FlatView')); Display :: display_header(get_lang('FlatView'));
} }
if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') { if (isset($_GET['isStudentView']) && $_GET['isStudentView'] == 'false') {
DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form); DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
$flatviewtable->display(); $flatviewtable->display();
} elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) { } elseif (isset($_GET['selectcat']) && ($_SESSION['studentview'] == 'teacherview')) {
DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form); DisplayGradebook :: display_header_reduce_flatview($cat[0], $showeval, $showlink, $simple_search_form);
// main graph // main graph
$flatviewtable->display(); $flatviewtable->display();
// @todo this needs a fix // @todo this needs a fix
//$image_file = $flatviewtable->display_graph(); //$image_file = $flatviewtable->display_graph();
//@todo load images with jquery //@todo load images with jquery
echo '<div id="contentArea" style="text-align: center;" >'; echo '<div id="contentArea" style="text-align: center;" >';
if (!empty($image_file)) { if (!empty($image_file)) {
echo '<img src="'.$image_file.'">'; echo '<img src="'.$image_file.'">';
} }
$flatviewtable->display_graph_by_resource(); $flatviewtable->display_graph_by_resource();
echo '</div>'; echo '</div>';
} }
Display :: display_footer(); Display :: display_footer();

@ -1,18 +1,12 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/**
* Script
* @package chamilo.gradebook
*/
/**
* Init
*/
require_once dirname(__FILE__) . '/../../../inc/global.inc.php'; require_once dirname(__FILE__) . '/../../../inc/global.inc.php';
require_once dirname(__FILE__) . '/../be.inc.php'; require_once dirname(__FILE__) . '/../be.inc.php';
set_time_limit(0); set_time_limit(0);
/** /**
* Class FlatViewTable
* Table to display flat view (all evaluations and links for all students) * Table to display flat view (all evaluations and links for all students)
* @author Stijn Konings * @author Stijn Konings
* @author Bert Steppé - (refactored, optimised) * @author Bert Steppé - (refactored, optimised)
@ -21,7 +15,6 @@ set_time_limit(0);
*/ */
class FlatViewTable extends SortableTable class FlatViewTable extends SortableTable
{ {
private $selectcat; private $selectcat;
public $datagen; public $datagen;
private $limit_enabled; private $limit_enabled;
@ -30,8 +23,15 @@ class FlatViewTable extends SortableTable
/** /**
* Constructor * Constructor
*/ */
function FlatViewTable($selectcat, $users = array(), $evals = array(), $links = array(), $limit_enabled = false, $offset = 0, $addparams = null) public function FlatViewTable(
{ $selectcat,
$users = array(),
$evals = array(),
$links = array(),
$limit_enabled = false,
$offset = 0,
$addparams = null
) {
parent :: __construct('flatviewlist', null, null, (api_is_western_name_order() xor api_sort_by_first_name()) ? 1 : 0); parent :: __construct('flatviewlist', null, null, (api_is_western_name_order() xor api_sort_by_first_name()) ? 1 : 0);
$this->selectcat = $selectcat; $this->selectcat = $selectcat;
$this->datagen = new FlatViewDataGenerator($users, $evals, $links, array('only_subcat' => $this->selectcat->get_id())); $this->datagen = new FlatViewDataGenerator($users, $evals, $links, array('only_subcat' => $this->selectcat->get_id()));
@ -47,9 +47,9 @@ class FlatViewTable extends SortableTable
} }
/** /**
* Display the graph of the total results of all students * Display the graph of the total results of all students
* */ * */
function display_graph() public function display_graph()
{ {
include_once api_get_path(LIBRARY_PATH) . 'pchart/pData.class.php'; include_once api_get_path(LIBRARY_PATH) . 'pchart/pData.class.php';
include_once api_get_path(LIBRARY_PATH) . 'pchart/pChart.class.php'; include_once api_get_path(LIBRARY_PATH) . 'pchart/pChart.class.php';
@ -163,7 +163,10 @@ class FlatViewTable extends SortableTable
return api_get_path(WEB_ARCHIVE_PATH) . $img_file; return api_get_path(WEB_ARCHIVE_PATH) . $img_file;
} }
function display_graph_by_resource() /**
*
*/
public function display_graph_by_resource()
{ {
require_once api_get_path(LIBRARY_PATH) . 'pchart/pData.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pchart/pData.class.php';
require_once api_get_path(LIBRARY_PATH) . 'pchart/pChart.class.php'; require_once api_get_path(LIBRARY_PATH) . 'pchart/pChart.class.php';
@ -411,7 +414,7 @@ class FlatViewTable extends SortableTable
/** /**
* Function used by SortableTable to get total number of items in the table * Function used by SortableTable to get total number of items in the table
*/ */
function get_total_number_of_items() public function get_total_number_of_items()
{ {
return $this->datagen->get_total_users_count(); return $this->datagen->get_total_users_count();
} }
@ -419,7 +422,7 @@ class FlatViewTable extends SortableTable
/** /**
* Function used by SortableTable to generate the data to display * Function used by SortableTable to generate the data to display
*/ */
function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = null)
{ {
$is_western_name_order = api_is_western_name_order(); $is_western_name_order = api_is_western_name_order();
@ -430,8 +433,8 @@ class FlatViewTable extends SortableTable
} else { } else {
$selectlimit = $totalitems; $selectlimit = $totalitems;
} }
$header = null;
if ($this->limit_enabled && $totalitems > LIMIT) { if ($this->limit_enabled && $totalitems > LIMIT) {
$calcprevious = LIMIT;
$header .= '<table style="width: 100%; text-align: right; margin-left: auto; margin-right: auto;" border="0" cellpadding="2">' $header .= '<table style="width: 100%; text-align: right; margin-left: auto; margin-right: auto;" border="0" cellpadding="2">'
. '<tbody>' . '<tbody>'
. '<tr>'; . '<tr>';
@ -522,11 +525,13 @@ class FlatViewTable extends SortableTable
return $table_data; return $table_data;
} }
// Other functions /**
* @param $user_id
* @param $name
* @return string
*/
private function build_name_link($user_id, $name) private function build_name_link($user_id, $name)
{ {
return '<a href="user_stats.php?userid=' . $user_id . '&selectcat=' . $this->selectcat->get_id() . '">' . $name . '</a>'; return '<a href="user_stats.php?userid=' . $user_id . '&selectcat=' . $this->selectcat->get_id() . '">' . $name . '</a>';
} }
} }

@ -1,13 +1,12 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* Class FlatViewDataGenerator
* Class to select, sort and transform object data into array data, * Class to select, sort and transform object data into array data,
* used for the teacher's flat view * used for the teacher's flat view
* @author Bert Steppé * @author Bert Steppé
* @package chamilo.gradebook *
*/
/**
* Class
* @package chamilo.gradebook * @package chamilo.gradebook
*/ */
class FlatViewDataGenerator class FlatViewDataGenerator
@ -28,7 +27,8 @@ class FlatViewDataGenerator
/** /**
* Constructor * Constructor
*/ */
public function FlatViewDataGenerator ($users = array(), $evals = array(), $links = array(), $params = array()) { public function FlatViewDataGenerator ($users = array(), $evals = array(), $links = array(), $params = array())
{
$this->users = (isset($users) ? $users : array()); $this->users = (isset($users) ? $users : array());
$this->evals = (isset($evals) ? $evals : array()); $this->evals = (isset($evals) ? $evals : array());
$this->links = (isset($links) ? $links : array()); $this->links = (isset($links) ? $links : array());
@ -39,25 +39,28 @@ class FlatViewDataGenerator
/** /**
* Get total number of users (rows) * Get total number of users (rows)
*/ */
public function get_total_users_count() { public function get_total_users_count()
{
return count($this->users); return count($this->users);
} }
/** /**
* 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)
*/ */
public function get_total_items_count() { public function get_total_items_count()
{
return count($this->evals_links); return count($this->evals_links);
} }
/** /**
* Get array containing column header names (incl user columns) * Get array containing column header names (incl user columns)
* @param int Start item offset * @param int $items_start Start item offset
* @param int Number of items to get * @param int $items_count Number of items to get
* @param bool whether to show the details or not * @param bool $show_detail whether to show the details or not
* @return array List of headers * @return array List of headers
*/ */
public function get_header_names($items_start = 0, $items_count = null , $show_detail = false) { public function get_header_names($items_start = 0, $items_count = null, $show_detail = false)
{
$headers = array(); $headers = array();
if (isset($this->params['show_official_code']) && $this->params['show_official_code']) { if (isset($this->params['show_official_code']) && $this->params['show_official_code']) {
@ -78,6 +81,7 @@ class FlatViewDataGenerator
$headers[] = get_lang('FirstName'); $headers[] = get_lang('FirstName');
} }
} }
if (!isset($items_count)) { if (!isset($items_count)) {
$items_count = count($this->evals_links) - $items_start; $items_count = count($this->evals_links) - $items_start;
} }
@ -100,7 +104,9 @@ class FlatViewDataGenerator
//@todo move these in a function //@todo move these in a function
$sum_categories_weight_array = array(); $sum_categories_weight_array = array();
$mainCategoryId = null;
if (isset($this->category) && !empty($this->category)) { if (isset($this->category) && !empty($this->category)) {
$mainCategoryId = $this->category->get_id();
$categories = Category::load(null, null, null, $this->category->get_id()); $categories = Category::load(null, null, null, $this->category->get_id());
if (!empty($categories)) { if (!empty($categories)) {
foreach ($categories as $category) { foreach ($categories as $category) {
@ -111,16 +117,15 @@ class FlatViewDataGenerator
} }
} }
//No category was added // No category was added
$course_code = api_get_course_id(); $course_code = api_get_course_id();
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id'); $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id');
if ($parent_id == 0 && !empty($allcat)) { if ($parent_id == 0 && !empty($allcat)) {
// Means there are any subcategory
//Means there are any subcategory
foreach ($allcat as $sub_cat) { foreach ($allcat as $sub_cat) {
$sub_cat_weight = round(100*$sub_cat->get_weight()/$main_weight,1); $sub_cat_weight = round(100*$sub_cat->get_weight()/$main_weight,1);
$add_weight = " $sub_cat_weight %"; $add_weight = " $sub_cat_weight %";
@ -130,19 +135,25 @@ class FlatViewDataGenerator
$headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).$add_weight; $headers[] = Display::url($sub_cat->get_name(), api_get_self().'?selectcat='.$sub_cat->get_id()).$add_weight;
} }
} else { } else {
if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) { if (!isset($this->params['only_total_category']) ||
(isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)
) {
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) { for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$item = $this->evals_links[$count + $items_start]; $item = $this->evals_links[$count + $items_start];
var_dump($item);
$weight = round(100*$item->get_weight()/$main_weight,1); $weight = round(100*$item->get_weight()/$main_weight,1);
$headers[] = $item->get_name().' '.$weight.' % '; $headers[] = $item->get_name().' '.$weight.' % ';
} }
} }
} }
$headers[] = api_strtoupper(get_lang('GradebookQualificationTotal')); $headers[] = api_strtoupper(get_lang('GradebookQualificationTotal'));
return $headers; return $headers;
} }
function get_max_result_by_link($id) { public function get_max_result_by_link($id)
{
$max = 0; $max = 0;
foreach ($this->users as $user) { foreach ($this->users as $user) {
$item = $this->evals_links [$id]; $item = $this->evals_links [$id];
@ -157,7 +168,8 @@ class FlatViewDataGenerator
/** /**
* Get array containing evaluation items * Get array containing evaluation items
*/ */
public function get_evaluation_items($items_start = 0, $items_count = null) { public function get_evaluation_items($items_start = 0, $items_count = null)
{
$headers = array(); $headers = array();
if (!isset($items_count)) { if (!isset($items_count)) {
$items_count = count($this->evals_links) - $items_start; $items_count = count($this->evals_links) - $items_start;
@ -177,10 +189,15 @@ class FlatViewDataGenerator
* 2: user firstname * 2: user firstname
* 3+: evaluation/link scores * 3+: evaluation/link scores
*/ */
public function get_data ($users_sorting = 0, $users_start = 0, $users_count = null, public function get_data(
$items_start = 0, $items_count = null, $users_sorting = 0,
$ignore_score_color = false, $show_all = false) { $users_start = 0,
$users_count = null,
$items_start = 0,
$items_count = null,
$ignore_score_color = false,
$show_all = false
) {
// do some checks on users/items counts, redefine if invalid values // do some checks on users/items counts, redefine if invalid values
if (!isset($users_count)) { if (!isset($users_count)) {
$users_count = count ($this->users) - $users_start; $users_count = count ($this->users) - $users_start;
@ -437,9 +454,9 @@ class FlatViewDataGenerator
/** /**
* Get actual array data evaluation/link scores * Get actual array data evaluation/link scores
*/ */
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) { $usertable[] = $user; } foreach ($this->users as $user) { $usertable[] = $user; }
$selected_users = $usertable; $selected_users = $usertable;
@ -484,7 +501,11 @@ class FlatViewDataGenerator
return $result; return $result;
} }
public function get_data_to_graph () { /**
* @return array
*/
public function get_data_to_graph()
{
// do some checks on users/items counts, redefine if invalid values // do some checks on users/items counts, redefine if invalid values
$usertable = array (); $usertable = array ();
foreach ($this->users as $user) { foreach ($this->users as $user) {
@ -526,10 +547,11 @@ class FlatViewDataGenerator
/** /**
* This is a function to show the generated data * This is a function to show the generated data
* @param type $displayWarning * @param bool $displayWarning
* @return array * @return array
*/ */
public function get_data_to_graph2 ($displayWarning = true) { public function get_data_to_graph2($displayWarning = true)
{
// do some checks on users/items counts, redefine if invalid values // do some checks on users/items counts, redefine if invalid values
$usertable = array (); $usertable = array ();
foreach ($this->users as $user) { foreach ($this->users as $user) {
@ -549,10 +571,7 @@ class FlatViewDataGenerator
$item_value = 0; $item_value = 0;
$item_total = 0; $item_total = 0;
$final_score = 0; $final_score = 0;
$item_value_total = 0; $item_value_total = 0;
$convert_using_the_global_weight = true; $convert_using_the_global_weight = true;
$course_code = api_get_course_id(); $course_code = api_get_course_id();
@ -572,8 +591,6 @@ class FlatViewDataGenerator
$item_total += $sub_cat->get_weight(); $item_total += $sub_cat->get_weight();
$row[] = array ($item_value, trim($scoredisplay->display_score($real_score, SCORE_CUSTOM,null, true))); $row[] = array ($item_value, trim($scoredisplay->display_score($real_score, SCORE_CUSTOM,null, true)));
$item_value_total += $item_value; $item_value_total += $item_value;
$final_score += $score[0]; $final_score += $score[0];
//$final_score = ($final_score / $item_total) * 100; //$final_score = ($final_score / $item_total) * 100;
@ -581,10 +598,7 @@ class FlatViewDataGenerator
} }
$total_score = array($final_score, $item_total); $total_score = array($final_score, $item_total);
$row[] = array ($final_score, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); $row[] = array ($final_score, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)));
} else { } else {
for ($count=0;$count < count($this->evals_links); $count++) { for ($count=0;$count < count($this->evals_links); $count++) {
$item = $this->evals_links [$count]; $item = $this->evals_links [$count];
$score = $item->calc_score($user[0]); $score = $item->calc_score($user[0]);
@ -602,20 +616,20 @@ class FlatViewDataGenerator
Display::display_warning_message( Display::display_warning_message($total_score[1])); Display::display_warning_message( Display::display_warning_message($total_score[1]));
} }
$row[] =array ($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true))); $row[] =array ($score_final, trim($scoredisplay->display_score($total_score, SCORE_CUSTOM, null, true)));
} }
$data[] = $row; $data[] = $row;
} }
return $data; return $data;
} }
// Sort functions - used internally
function sort_by_last_name($item1, $item2) { public function sort_by_last_name($item1, $item2)
{
return api_strcmp($item1[2], $item2[2]); return api_strcmp($item1[2], $item2[2]);
} }
function sort_by_first_name($item1, $item2) { public function sort_by_first_name($item1, $item2)
{
return api_strcmp($item1[3], $item2[3]); return api_strcmp($item1[3], $item2[3]);
} }
} }

Loading…
Cancel
Save