diff --git a/main/gradebook/index.php b/main/gradebook/index.php
index 8065d58ec0..e3ac940868 100755
--- a/main/gradebook/index.php
+++ b/main/gradebook/index.php
@@ -874,6 +874,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
}
$gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, $addparams);
$gradebooktable->display();
+ echo $gradebooktable->getGraph();
}
}
}
diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php
index abd74a6d2d..e1ea27a7c4 100755
--- a/main/gradebook/lib/fe/gradebooktable.class.php
+++ b/main/gradebook/lib/fe/gradebooktable.class.php
@@ -1,6 +1,10 @@
build_type_column($item);
+ $this->dataForGraph['categories'][] = $item->get_name();
+
// Name.
if (get_class($item) == 'Category') {
$row[] = $invisibility_span_open.'
'.$item->get_name().'
'.$invisibility_span_close;
@@ -291,6 +298,9 @@ class GradebookTable extends SortableTable
$totalAverage[1] + $data['average_score'][1],
];
+ $this->dataForGraph['my_result'][] = (float) $scoredisplay->display_score($totalResult, SCORE_AVERAGE);
+ $this->dataForGraph['average'][] = (float) $scoredisplay->display_score($totalAverage, SCORE_AVERAGE);
+
// Student result
$row[] = $value_data;
// Ranking
@@ -612,6 +622,101 @@ class GradebookTable extends SortableTable
return $sortable_data;
}
+
+ /**
+ * @return array
+ */
+ private function getDataForGraph()
+ {
+ return $this->dataForGraph;
+ }
+
+ /**
+ * @return string
+ */
+ public function getGraph()
+ {
+ $data = $this->getDataForGraph();
+ if (!empty($data) && isset($data['my_result'])) {
+ $dataSet = new pData();
+ $dataSet->addPoints($data['my_result'], get_lang('Me'));
+ // In order to generate random values
+ // $data['average'] = array(rand(0,50), rand(0,50));
+ $dataSet->addPoints($data['average'], get_lang('Average'));
+
+ $dataSet->addPoints($data['categories'], 'categories');
+
+ $dataSet->setAbscissa("categories");
+ $xSize = 600;
+ $ySize = 400;
+ $pChart = new pImage($xSize, $ySize, $dataSet);
+ /* Turn of Antialiasing */
+ $pChart->Antialias = FALSE;
+
+ /* Add a border to the picture */
+ $pChart->drawRectangle(0,0,$xSize-10,$ySize-10,array("R"=>0,"G"=>0,"B"=>0));
+
+ $pChart->drawText(10,16,get_lang('Results'),array("FontSize"=>11,"Align"=>TEXT_ALIGN_BOTTOMLEFT));
+
+ $pChart->setGraphArea(50, 30, $xSize-50, $ySize-50);
+
+ $pChart->setFontProperties(
+ array(
+ 'FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf',
+ 'FontSize' => 10
+ )
+ );
+
+ /* Draw the scale */
+ $scaleSettings = array(
+ "XMargin" => 10,
+ "YMargin" => 10,
+ "Floating" => true,
+ "GridR" => 200,
+ "GridG" => 200,
+ "GridB" => 200,
+ "DrawSubTicks" => true,
+ "CycleBackground" => true,
+ );
+ $pChart->drawScale($scaleSettings);
+
+ /* Draw the line chart */
+ $pChart->drawLineChart();
+ $pChart->drawPlotChart(array("DisplayValues"=>TRUE,"PlotBorder"=>TRUE,"BorderSize"=>2,"Surrounding"=>-60,"BorderAlpha"=>80));
+
+ /* Write the chart legend */
+ $pChart->drawLegend(
+ $xSize-180,
+ 9,
+ array(
+ "Style" => LEGEND_NOBORDER,
+ "Mode" => LEGEND_HORIZONTAL,
+ "FontR" => 0,
+ "FontG" => 0,
+ "FontB" => 0,
+ )
+ );
+
+ $cachePath = api_get_path(SYS_ARCHIVE_PATH);
+ $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)));
+ $chartHash = $myCache->getHash($dataSet);
+
+ $myCache->writeToCache($chartHash, $pChart);
+ $imgSysPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
+ $myCache->saveFromCache($chartHash, $imgSysPath);
+ $imgWebPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
+
+ if (file_exists($imgSysPath)) {
+ $result = '';
+ $result .= '

';
+ $result .= '
';
+ return $result;
+ }
+ }
+
+ return '';
+ }
+
/**
* @param $item
* @return mixed
diff --git a/main/inc/lib/sortable_table.class.php b/main/inc/lib/sortable_table.class.php
index ea96b6c927..3241c19a16 100755
--- a/main/inc/lib/sortable_table.class.php
+++ b/main/inc/lib/sortable_table.class.php
@@ -950,6 +950,8 @@ class SortableTable extends HTML_Table
}
return array();
}
+
+
}
/**