skala
cfasanando 15 years ago
parent dc90dfcb76
commit e339267a23
  1. 4
      main/gradebook/lib/be/category.class.php
  2. 103
      main/gradebook/lib/flatview_data_generator.class.php
  3. 24
      main/gradebook/lib/gradebook_functions.inc.php
  4. 102
      main/inc/lib/pchart/pChart.class.php
  5. 40
      main/inc/lib/pchart/pData.class.php
  6. 0
      plugin/dashboard/block_course/css/default.css
  7. 0
      plugin/dashboard/block_course/css/index.html
  8. 0
      plugin/dashboard/block_course/index.html
  9. 0
      plugin/dashboard/block_session/css/default.css
  10. 0
      plugin/dashboard/block_session/css/index.html
  11. 0
      plugin/dashboard/block_session/index.html
  12. 0
      plugin/dashboard/block_student/css/default.css
  13. 0
      plugin/dashboard/block_student/css/index.html
  14. 0
      plugin/dashboard/block_student/index.html
  15. 87
      plugin/dashboard/block_student_graph/block_student_graph.class.php
  16. 0
      plugin/dashboard/block_teacher/css/default.css
  17. 0
      plugin/dashboard/block_teacher/css/index.html
  18. 0
      plugin/dashboard/block_teacher/index.html
  19. 0
      plugin/dashboard/index.html

@ -1035,7 +1035,7 @@ class Category implements GradebookItem
}
} else {// all students
// course admin
if (api_is_allowed_to_create_course() && !api_is_platform_admin()) {
if ((api_is_allowed_to_create_course() || api_is_drh()) && !api_is_platform_admin()) {
// root
if ($this->id == 0) {
$evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null);
@ -1093,7 +1093,7 @@ class Category implements GradebookItem
api_is_allowed_to_create_course() ? null : 1);
}
// all students -> only for course/platform admin
elseif (api_is_allowed_to_create_course()) {
elseif (api_is_allowed_to_create_course() || api_is_drh()) {
$links = LinkFactory::load(null,null,null,null,empty($this->course_code)?null:$this->course_code,$this->id, null);
}

@ -86,6 +86,24 @@ class FlatViewDataGenerator
$headers[] = get_lang('GradebookQualificationTotal');
return $headers;
}
/**
* Get array containing evaluation items
*/
public function get_evaluation_items($items_start = 0, $items_count = null) {
$headers = array();
if (!isset($items_count)) {
$items_count = count($this->evals_links) - $items_start;
}
for ($count=0;
($count < $items_count ) && ($items_start + $count < count($this->evals_links));
$count++) {
$item = $this->evals_links [$count + $items_start];
$headers[] = $item->get_name();
}
return $headers;
}
/**
* Get actual array data
@ -167,6 +185,91 @@ class FlatViewDataGenerator
return $data;
}
/**
* Get actual array data evaluation/link scores
*/
public function get_evaluation_sumary_results ($users_sorting = 0,
$users_start = 0, $users_count = null,
$items_start = 0, $items_count = null,
$ignore_score_color = false) {
// do some checks on users/items counts, redefine if invalid values
if (!isset($users_count)) {
$users_count = count ($this->users) - $users_start;
}
if ($users_count < 0) {
$users_count = 0;
}
if (!isset($items_count)) {
$items_count = count ($this->evals) + count ($this->links) - $items_start;
}
if ($items_count < 0) {
$items_count = 0;
}
// copy users to a new array that we will sort
// TODO - needed ?
$usertable = array ();
foreach ($this->users as $user) {
$usertable[] = $user;
}
// sort users array
if ($users_sorting & self :: FVDG_SORT_LASTNAME) {
usort($usertable, array ('FlatViewDataGenerator','sort_by_last_name'));
} elseif ($users_sorting & self :: FVDG_SORT_FIRSTNAME) {
usort($usertable, array ('FlatViewDataGenerator','sort_by_first_name'));
}
if ($users_sorting & self :: FVDG_SORT_DESC) {
$usertable = array_reverse($usertable);
}
// select the requested users
$selected_users = array_slice($usertable, $users_start, $users_count);
// generate actual data array
$scoredisplay = ScoreDisplay :: instance();
$data= array ();
$displaytype = SCORE_DIV;
if ($ignore_score_color) {
$displaytype |= SCORE_IGNORE_SPLIT;
}
foreach ($selected_users as $user) {
$row = array ();
$item_value=0;
$item_total=0;
for ($count=0;($count < $items_count ) && ($items_start + $count < count($this->evals_links));$count++) {
$item = $this->evals_links [$count + $items_start];
$score = $item->calc_score($user[0]);
$porcent_score = $score[1] ?round(($score[0]*100)/$score[1]):0;
$row[$item->get_name()] = $porcent_score;
}
unset($score);
$data[$user[0]] = $row;
}
$data_by_item = array();
foreach ($data as $key => $value) {
$tmp = array();
foreach ($value as $item => $val) {
$tmp[] = $item;
if (in_array($item,$tmp)) {
$data_by_item[$item][] = $val;
}
}
}
var_dump($data_by_item);
return $data;
}
public function get_data_to_graph () {
// do some checks on users/items counts, redefine if invalid values

@ -339,6 +339,30 @@ function get_printable_data($users,$alleval, $alllinks) {
return array ($header_names, $newarray);
}
function get_evaluation_sumary_result($users,$alleval, $alllinks) {
$datagen = new FlatViewDataGenerator ($users, $alleval, $alllinks);
$offset = isset($_GET['offset']) ? $_GET['offset'] : '0';
$count = (($offset + 10) > $datagen->get_total_items_count()) ? ($datagen->get_total_items_count() - $offset) : 10;
$header_names = $datagen->get_evaluation_items($offset, $count);
$data_array = $datagen->get_evaluation_sumary_results(FlatViewDataGenerator :: FVDG_SORT_LASTNAME, 0, null, $offset, $count, true);
$newarray = array();
foreach ($data_array as $data) {
$newarray[] = array_slice($data, 1);
}
return array ($header_names, $newarray);
}
/**
* XML-parser: handle character data
*/

@ -196,15 +196,15 @@
/* This function create the background picture */
function pChart($XSize,$YSize)
{
$this->XSize = $XSize;
$this->YSize = $YSize;
$this->YSize = $YSize;
$this->Picture = imagecreatetruecolor($XSize,$YSize);
$C_White =$this->AllocateColor($this->Picture,255,255,255);
imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White);
$C_White = $this->AllocateColor($this->Picture,255,255,255);
imagefilledrectangle($this->Picture,0,0,$XSize,$YSize,$C_White);
imagecolortransparent($this->Picture,$C_White);
$this->setFontProperties("tahoma.ttf",8);
}
/* Set if warnings should be reported */
@ -1913,6 +1913,68 @@
}
}
/* This function draw a bar graph */
function drawHorizontalBarGraph($Data,$DataDescription,$Shadow=FALSE,$Alpha=100)
{
/* Validate the Data and DataDescription array */
$this->validateDataDescription("drawHorizontalBarGraph",$DataDescription);
$this->validateData("drawHorizontalBarGraph",$Data);
$GraphID = 0;
$Series = count($DataDescription["Values"]);
$SeriesWidth = $this->DivisionWidth / ($Series+1);
$SerieXOffset = $this->DivisionWidth / 2 - $SeriesWidth / 2;
$YZero = $this->GArea_Y2 - ((0-$this->VMin) * $this->DivisionRatio);
if ( $YZero > $this->GArea_Y2 ) { $YZero = $this->GArea_Y2; }
$SerieID = 0;
foreach ( $DataDescription["Values"] as $Key2 => $ColName )
{
$ID = 0;
foreach ( $DataDescription["Description"] as $keyI => $ValueI )
{ if ( $keyI == $ColName ) { $ColorID = $ID; }; $ID++; }
$XPos = $this->GArea_X1 + $this->GAreaXOffset - $SerieXOffset + $SeriesWidth * $SerieID;
$XLast = -1;
foreach ( $Data as $Key => $Values )
{
if ( isset($Data[$Key][$ColName]))
{
if ( is_numeric($Data[$Key][$ColName]) )
{
$Value = $Data[$Key][$ColName];
$YPos = $this->GArea_Y2 - (($Value-$this->VMin) * $this->DivisionRatio);
/* Save point into the image map if option activated */
if ( $this->BuildMap )
{
$this->addToImageMap($XPos+1,min($YZero,$YPos),$XPos+$SeriesWidth-1,max($YZero,$YPos),$DataDescription["Description"][$ColName],$Data[$Key][$ColName].$DataDescription["Unit"]["Y"],"Bar");
}
if ( $Shadow && $Alpha == 100 )
$X1 = $YZero;
$Y1 = $XPos+1;
$X2 = $YPos;
$Y2 = $XPos+$SeriesWidth-1;
$this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha);
$this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
//$this->drawRectangle($X1,$Y1,$X2,$Y2,$YPos,25,25,25,TRUE,$Alpha);
//$this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
}
}
$XPos = $XPos + $this->DivisionWidth;
}
$SerieID++;
}
}
/* This function draw a bar graph */
function drawBarGraph($Data,$DataDescription,$Shadow=FALSE,$Alpha=100)
{
@ -1953,9 +2015,18 @@
}
if ( $Shadow && $Alpha == 100 )
$this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha);
$this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
$X1 = $YZero;
$Y1 = $XPos+1;
$X2 = $YPos;
$Y2 = $XPos+$SeriesWidth-1;
//$this->drawRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,25,25,25,TRUE,$Alpha);
//$this->drawFilledRectangle($XPos+1,$YZero,$XPos+$SeriesWidth-1,$YPos,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
$this->drawRectangle($X1,$Y1,$X2,$Y2,$YPos,25,25,25,TRUE,$Alpha);
$this->drawFilledRectangle($X1,$Y1,$X2,$Y2,$this->Palette[$ColorID]["R"],$this->Palette[$ColorID]["G"],$this->Palette[$ColorID]["B"],TRUE,$Alpha);
}
}
$XPos = $XPos + $this->DivisionWidth;
@ -1964,6 +2035,9 @@
}
}
/* This function draw a stacked bar graph */
function drawStackedBarGraph($Data,$DataDescription,$Alpha=50,$Contiguous=FALSE)
{
@ -2024,6 +2098,8 @@
}
}
/* This function draw a limits bar graphs */
function drawLimitsGraph($Data,$DataDescription,$R=0,$G=0,$B=0)
{
@ -2808,10 +2884,13 @@
$X1=$X1-.2;$Y1=$Y1-.2;
$X2=$X2+.2;$Y2=$Y2+.2;
$this->drawLine($X1,$Y1,$X2,$Y1,$R,$G,$B);
$this->drawLine($X2,$Y1,$X2,$Y2,$R,$G,$B);
$this->drawLine($X2,$Y2,$X1,$Y2,$R,$G,$B);
$this->drawLine($X1,$Y2,$X1,$Y1,$R,$G,$B);
}
/* This function create a filled rectangle with antialias */
@ -2914,8 +2993,11 @@
if ( $G < 0 ) { $G = 0; } if ( $G > 255 ) { $G = 255; }
if ( $B < 0 ) { $B = 0; } if ( $B > 255 ) { $B = 255; }
$C_Rectangle = $this->AllocateColor($this->Picture,$R,$G,$B);
$Step = 90 / ((3.1418 * $Radius)/2);
for($i=0;$i<=90;$i=$i+$Step)
@ -2953,6 +3035,10 @@
$this->drawLine($X2-$Radius,$Y2,$X1+$Radius,$Y2,$R,$G,$B);
$this->drawLine($X1,$Y2-$Radius,$X1,$Y1+$Radius,$R,$G,$B);
}
/* This function create a circle with antialias */
function drawCircle($Xc,$Yc,$Height,$R,$G,$B,$Width=0)

@ -117,35 +117,35 @@
}
}
function AddPoint($Value,$Serie="Serie1",$Description="")
{
function AddPoint($Value,$Serie="Serie1",$Description="") {
if (is_array($Value) && count($Value) == 1)
$Value = $Value[0];
$ID = 0;
for($i=0;$i<=count($this->Data);$i++)
{ if(isset($this->Data[$i][$Serie])) { $ID = $i+1; } }
if ( count($Value) == 1 )
{
$ID = 0;
for ($i=0;$i<=count($this->Data);$i++) {
if(isset($this->Data[$i][$Serie])) { $ID = $i+1; }
}
if ( count($Value) == 1 ) {
$this->Data[$ID][$Serie] = $Value;
if ( $Description != "" )
$this->Data[$ID]["Name"] = $Description;
elseif (!isset($this->Data[$ID]["Name"]))
$this->Data[$ID]["Name"] = $ID;
}
else
{
foreach($Value as $key => $Val)
{
if ( $Description != "" ) $this->Data[$ID]["Name"] = $Description;
elseif (!isset($this->Data[$ID]["Name"])) $this->Data[$ID]["Name"] = $ID;
} else {
foreach ($Value as $key => $Val) {
$this->Data[$ID][$Serie] = $Val;
if (!isset($this->Data[$ID]["Name"]))
$this->Data[$ID]["Name"] = $ID;
$ID++;
}
}
}
function AddSerie($SerieName="Serie1")
{
if ( !isset($this->DataDescription["Values"]) )
@ -164,9 +164,8 @@
}
function AddAllSeries()
{
{
unset($this->DataDescription["Values"]);
if ( isset($this->Data[0]) )
{
foreach($this->Data[0] as $Key => $Value)
@ -175,8 +174,11 @@
$this->DataDescription["Values"][] = $Key;
}
}
}
function RemoveSerie($SerieName="Serie1")
{
if ( !isset($this->DataDescription["Values"]) )

@ -62,7 +62,7 @@ class BlockStudentGraph extends Block {
if (api_is_platform_admin()) {
$student_content_html = $this->get_students_content_html_for_platform_admin();
} else if (api_is_drh()) {*/
$students_evaluation_graph = $this->get_students_evaluation_graph();
$students_attendance_graph = $this->get_students_attendance_graph();
//}
$html = '
@ -72,7 +72,7 @@ class BlockStudentGraph extends Block {
<div class="widget-actions"><a onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;" href="index.php?action=disable_block&path='.$this->path.'">'.Display::return_icon('close.gif',get_lang('Close')).'</a></div>
</div>
<div class="widget-content" align="center">
'.$students_evaluation_graph.'
'.$students_attendance_graph.'
</div>
</li>
';
@ -88,7 +88,7 @@ class BlockStudentGraph extends Block {
* This method return a graph containing informations about students evaluation, it's used inside get_block method for showing it inside dashboard interface
* @return string img html
*/
public function get_students_evaluation_graph() {
public function get_students_attendance_graph() {
$students = $this->students;
$attendance = new Attendance();
@ -123,44 +123,85 @@ class BlockStudentGraph extends Block {
$img_file = '';
if (is_array($usernames) && count($usernames) > 0) {
// Defining data
// Defining data
$data_set = new pData;
$data_set->AddPoint($usernames,"Usuario");
$data_set->AddPoint($faults,"Promedio");
$data_set->AddAllSeries();
$data_set->SetXAxisName(get_lang('UserName'));
$data_set->SetYAxisName(get_lang('AttendancesFaults'));
$data_set->SetAbsciseLabelSerie("Usuario");
$graph_id = $this->user_id.'StudentEvaluationGraph';
$cache = new pCache();
// the graph id
$data = $data_set->GetData();
$data_set->AddPoint($faults,"Promedio"); // $this->Data = array(0=>array('Promedio'=>57,'Name'=>0), 1=>array('Promedio'=>43,'Name'=>1), 2=>array('Promedio'=>29,'Name'=>2))
$data_set->AddPoint($usernames,"Usuario"); // $this->Data = array(0=>array('Usuario'=>'alumno3','Name'=>0), 1=>array('Usuario'=>'alumno1','Name'=>1), 2=>array('Usuario'=>'alumno2','Name'=>2))
$data_set->AddAllSeries(); // $this->DataDescription = array('Position'=>'Name', 'Format'=>array('X'=>'number','Y'=>'number'), 'Unit'=>array('X'=>null,'Y'=null),'Values'=>array(0=>'Promedio',1=>'Usuario'))
$data_set->SetXAxisName(get_lang('UserName')); // $this->DataDescription["Axis"]["X"] = 'UserName';
$data_set->SetYAxisName(get_lang('AttendancesFaults')); // $this->DataDescription["Axis"]["Y"] = 'AttendancesFaults';
$data_set->SetAbsciseLabelSerie("Usuario"); // $this->DataDescription["Position"] = "Usuario";
// prepare cache for saving image
$graph_id = $this->user_id.'StudentEvaluationGraph'; // the graph id
$cache = new pCache();
$data = $data_set->GetData(); // return $this->DataDescription
if ($cache->IsInCache($graph_id, $data_set->GetData())) {
//if we already created the img
$img_file = $cache->GetHash($graph_id, $data_set->GetData());
$img_file = $cache->GetHash($graph_id, $data_set->GetData()); // image file with hash
} else {
// Initializing the graph
$test = new pChart(365,250);
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
$test->setGraphArea(50,30,345,200);
$test = new pChart(365,300); // Create transparent image 365x300
// $this->FontName = api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf'
// $this->FontSize = 8
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',8);
$X1 = 50;
$Y1 = 30;
$X2 = 345;
$Y2 = 200;
//$this->GArea_X1 = $X1;$this->GArea_Y1 = $Y1;$this->GArea_X2 = $X2;$this->GArea_Y2 = $Y2;
$test->setGraphArea($X1,$Y1,$X2,$Y2);
$test->drawFilledRoundedRectangle(7,7,371,240,5,240,240,240);
$test->drawRoundedRectangle(5,5,373,225,5,230,230,230);
$test->drawGraphArea(255,255,255,TRUE);
$test->setFixedScale(0,100,5);
$test->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,10,TRUE);
$test->drawScale($data_set->GetData(),$data_set->GetDataDescription(),SCALE_NORMAL,150,150,150,TRUE,0,10,TRUE);
$test->drawGrid(4,TRUE,230,230,230,50);
// Drawing bars
$test->drawBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE);
//$test->drawBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE);
//$test->drawLimitsGraph($data_set->GetData(),$data_set->GetDataDescription(),240,240,240);
//$test->drawOverlayBarGraph($data_set->GetData(),$data_set->GetDataDescription());
$test->drawHorizontalBarGraph($data_set->GetData(),$data_set->GetDataDescription(),TRUE);
// Drawing title
$test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf',10);
$test->drawTitle(50,22,get_lang('AttendancesFaults'),50,50,50,385);
$test->writeValues($data_set->GetData(),$data_set->GetDataDescription(),"Promedio");
$cache->WriteToCache($graph_id, $data_set->GetData(), $test);
ob_start();

Loading…
Cancel
Save