123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- <?php
- require_once dirname(__FILE__).'/../../../inc/global.inc.php';
- require_once dirname(__FILE__).'/../be.inc.php';
- set_time_limit(0);
- class FlatViewTable extends SortableTable
- {
- private $selectcat;
- public $datagen;
- private $limit_enabled;
- private $offset;
-
- 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);
- $this->selectcat = $selectcat;
- $this->datagen = new FlatViewDataGenerator($users, $evals, $links, array('only_subcat'=>$this->selectcat->get_id()));
-
- $this->limit_enabled = $limit_enabled;
- $this->offset = $offset;
- if (isset ($addparams)) {
- $this->set_additional_parameters($addparams);
- }
-
-
- $this->datagen->category = $this->selectcat;
- }
-
- function display_graph() {
- 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/pCache.class.php';
- $header_name = $this->datagen->get_header_names();
- $total_users = $this->datagen->get_total_users_count();
-
- $img_file = '';
-
- if ($this->datagen->get_total_items_count()>0 && $total_users > 0 ) {
-
- array_shift($header_name);
- array_shift($header_name);
- array_pop($header_name);
-
- $user_results = $this->datagen->get_data_to_graph();
-
- $pre_result = $new_result = array();
- $DataSet = new pData();
-
-
-
- foreach($user_results as $result) {
- for($i=0; $i < count($header_name); $i++) {
- $pre_result[$i+3]+= $result[$i+1];
- }
- }
- $i = 1;
- $show_draw = false;
- if ($total_users >0 ) {
- foreach($pre_result as $res) {
- $total = $res / ($total_users);
- if ($total != 0) {
- $show_draw = true;
- }
- $DataSet->AddPoint($total, "Serie".$i);
- $DataSet->SetSerieName(strip_tags($header_name[$i-1]),"Serie".$i);
-
-
- $DataSet->AddAllSeries();
- $DataSet->SetAbsciseLabelSerie();
- $i++;
- }
- }
-
- $Cache = new pCache();
-
- $gradebook_id = intval($_GET['selectcat']);
- $graph_id = api_get_user_id().'AverageResultsVsResource'.$gradebook_id.api_get_course_id();
- $data = $DataSet->GetData();
-
- if ($show_draw) {
- if ($Cache->IsInCache($graph_id, $DataSet->GetData())) {
-
-
-
- $img_file = $Cache->GetHash($graph_id,$DataSet->GetData());
- } else {
-
-
- $Test = new pChart(760, 360);
-
- $quant_resources = count($data[0])-1;
-
- if ($quant_resources < 8) {
- $Test->loadColorPalette(api_get_path(LIBRARY_PATH)."pchart/palette/reduced.txt");
- } else {
- $Test->loadColorPalette(api_get_path(LIBRARY_PATH)."pchart/palette/default.txt");
- }
-
- $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",8);
- $Test->setGraphArea(50,30,610,300);
- $Test->drawFilledRoundedRectangle(7,7,780,330,5,240,240,240);
-
-
- $Test->drawGraphArea(255,255,255,TRUE);
- $Test->drawScale($DataSet->GetData(), $DataSet->GetDataDescription(), SCALE_START0 ,150,150,150,TRUE,0,1, FALSE);
-
-
- $Test->drawGrid(4,TRUE,230,230,230,50);
-
-
-
-
- $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);
-
- $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",9);
- $Test->drawLegend(620, 70,$DataSet->GetDataDescription(),255,255,255);
-
- $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",10);
- $Test->drawTitle(50,22,get_lang('AverageResultsVsResource'),50,50,80,620);
-
-
- $Cache->WriteToCache($graph_id,$DataSet->GetData(),$Test);
- ob_start();
- $Test->Stroke();
- ob_end_clean();
- $img_file = $Cache->GetHash($graph_id,$DataSet->GetData());
- }
- }
- }
- return api_get_path(WEB_ARCHIVE_PATH).$img_file;
- }
- function display_graph_by_resource() {
- 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/pCache.class.php';
- $header_name = $this->datagen->get_header_names();
- $total_users = $this->datagen->get_total_users_count();
- $img_file = '';
- if ($this->datagen->get_total_items_count() > 0 && $total_users > 0 ) {
-
- array_shift($header_name);
-
- array_shift($header_name);
-
- $displayscore = ScoreDisplay :: instance();
- $customdisplays = $displayscore->get_custom_score_display_settings();
-
- if (is_array($customdisplays) && count(($customdisplays))) {
-
- $user_results = $this->datagen->get_data_to_graph2();
- $pre_result = $new_result = array();
- $DataSet = new pData();
-
- foreach ($user_results as $result) {
-
- for($i=0; $i< count($header_name); $i++) {
- $pre_result[$i+3][]= $result[$i+1];
- }
- }
-
- $i=0;
- $show_draw = false;
- $resource_list = array();
- $pre_result2 = array();
- foreach($pre_result as $key=>$res_array) {
- rsort($res_array);
- $pre_result2[] = $res_array;
- }
-
-
-
- rsort($customdisplays);
-
- if ($total_users > 0) {
- foreach($pre_result2 as $key=>$res_array) {
- $key_list = array();
- foreach($res_array as $user_result) {
- $resource_list[$key][$user_result[1]] += 1;
- $key_list[] = $user_result[1];
- }
-
- foreach ($customdisplays as $display) {
- if (!in_array($display['display'], $key_list))
- $resource_list[$key][$display['display']] = 0;
- }
- $i++;
- }
- }
-
-
- $max = 0;
- $new_list = array();
- foreach($resource_list as $key=>$value) {
- $new_value = array();
-
- foreach($customdisplays as $item) {
- if ($value[$item['display']] > $max) {
- $max = $value[$item['display']];
- }
- $new_value[$item['display']] = strip_tags($value[$item['display']]);
- }
- $new_list[] = $new_value;
- }
- $resource_list = $new_list;
-
- $i = 1;
- $j = 0;
- foreach($resource_list as $key=>$resource) {
- $new_resource_list = $new_resource_list_name = array();
- $DataSet = new pData();
- foreach ($resource as $name=>$cant) {
- $DataSet->AddPoint($cant,"Serie".$j);
- $DataSet->SetSerieName(strip_tags($name),"Serie".$j);
- $j++;
- }
-
-
- $DataSet->AddAllSeries();
- $DataSet->SetAbsciseLabelSerie('');
- $DataSet->SetXAxisName(get_lang('GradebookSkillsRanking'));
- $DataSet->SetYAxisName(get_lang('Students'));
- $show_draw = true;
-
- $Cache = new pCache();
-
- $gradebook_id = intval($_GET['selectcat']);
- $graph_id = api_get_user_id().'ByResource'.$gradebook_id.api_get_course_id().api_get_session_id();
- if ($show_draw) {
-
- if (0) {
-
-
- $img_file = $Cache->GetHash($graph_id,$DataSet->GetData());
- } else {
-
-
- $chart_size_w= 480;
- $chart_size_h= 250;
- $Test = new pChart($chart_size_w, $chart_size_h);
-
- $Test->loadColorPalette(api_get_path(LIBRARY_PATH)."pchart/palette/pastel.txt");
-
- $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",8);
- $area_graph_w = $chart_size_w-130;
- $Test->setGraphArea(50,30,$area_graph_w ,$chart_size_h-50);
- $Test->drawFilledRoundedRectangle(5,5,$chart_size_w-1,$chart_size_h-20,5,240,240,240);
-
-
- $Test->drawGraphArea(255,255,255,TRUE);
-
-
- if (!empty($max)) {
- $Test->setFixedScale(0, $max);
- }
-
- $Test->drawScale($DataSet->GetData(),$DataSet->GetDataDescription(), SCALE_ADDALLSTART0, 150,150,150, TRUE, 0, 0, FALSE);
-
- $Test->drawGrid(4, TRUE,230,230,230,50);
-
-
-
-
- $Test->drawBarGraph($DataSet->GetData(),$DataSet->GetDataDescription(),TRUE);
-
- $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",9);
- $Test->drawLegend($area_graph_w+10, 50,$DataSet->GetDataDescription(),255,255,255);
-
- $Test->setFontProperties(api_get_path(LIBRARY_PATH)."pchart/fonts/tahoma.ttf",10);
- $Test->drawTitle(50,22, strip_tags($header_name[$i-1]),50,50,80,$chart_size_w-50);
-
-
- $Cache->WriteToCache($graph_id,$DataSet->GetData(),$Test);
- ob_start();
- $Test->Stroke();
- ob_end_clean();
- $img_file = $Cache->GetHash($graph_id,$DataSet->GetData());
- }
- echo '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'" >';
- if ($i % 2 == 0 && $i!=0) {
- echo '<br />';
- }
- $i++;
- }
- }
- } else {
- echo get_lang('ToViewGraphScoreRuleMustBeEnabled');
- }
-
-
- }
- }
-
- function get_total_number_of_items() {
- return $this->datagen->get_total_users_count();
- }
-
- function get_table_data ($from = 1, $per_page = null, $column = null, $direction = null, $sort = null) {
- $is_western_name_order = api_is_western_name_order();
-
- $totalitems = $this->datagen->get_total_items_count();
- if ($this->limit_enabled && $totalitems > LIMIT) {
- $selectlimit = LIMIT;
- } else {
- $selectlimit = $totalitems;
- }
- 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">'
- .'<tbody>'
- .'<tr>';
-
- $header .= '<td style="width:100%;">';
- if ($this->offset >= LIMIT) {
- $header .= '<a href="'.api_get_self()
- .'?selectcat='.Security::remove_XSS($_GET['selectcat'])
- .'&offset='.(($this->offset)-LIMIT)
- .(isset($_GET['search'])?'&search='.Security::remove_XSS($_GET['search']):'').'">'
- .Display::return_icon('action_prev.png', get_lang('PreviousPage'), array(), 32)
- .'</a>';
- } else {
- $header .= Display::return_icon('action_prev_na.png', get_lang('PreviousPage'), array(), 32);
- }
- $header .= ' ';
-
- $calcnext = (($this->offset+(2*LIMIT)) > $totalitems) ?
- ($totalitems-(LIMIT+$this->offset)) : LIMIT;
-
- if ($calcnext > 0) {
- $header .= '<a href="'.api_get_self()
- .'?selectcat='.Security::remove_XSS($_GET['selectcat'])
- .'&offset='.($this->offset+LIMIT)
- .(isset($_GET['search'])?'&search='.Security::remove_XSS($_GET['search']):'').'">'
- .Display::return_icon('action_next.png', get_lang('NextPage'), array(), 32)
- .'</a>';
- } else {
- $header .= Display::return_icon('action_next_na.png', get_lang('NextPage'), array(), 32);
- }
- $header .= '</td>';
- $header .= '</tbody></table>';
- echo $header;
- }
-
- if ($is_western_name_order) {
- $users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME : FlatViewDataGenerator :: FVDG_SORT_LASTNAME);
- } else {
- $users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_LASTNAME : FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME);
- }
- if ($this->direction == 'DESC') {
- $users_sorting |= FlatViewDataGenerator :: FVDG_SORT_DESC;
- } else {
- $users_sorting |= FlatViewDataGenerator :: FVDG_SORT_ASC;
- }
-
- $header_names = $this->datagen->get_header_names($this->offset, $selectlimit);
- $column = 0;
-
- if ($is_western_name_order) {
- $this->set_header($column++, $header_names[1]);
- $this->set_header($column++, $header_names[0]);
- } else {
- $this->set_header($column++, $header_names[0]);
- $this->set_header($column++, $header_names[1]);
- }
- while ($column < count($header_names)) {
- $this->set_header($column, $header_names[$column], false);
- $column++;
- }
- $data_array = $this->datagen->get_data($users_sorting, $from, $this->per_page, $this->offset, $selectlimit);
- $table_data = array();
- foreach ($data_array as $user_row) {
- $table_row = array ();
- $count = 0;
- $user_id = $user_row[$count++];
- $lastname = $user_row[$count++];
- $firstname = $user_row[$count++];
- if ($is_western_name_order) {
- $table_row[] = $this->build_name_link($user_id, $firstname);
- $table_row[] = $this->build_name_link($user_id, $lastname);
- } else {
- $table_row[] = $this->build_name_link($user_id, $lastname);
- $table_row[] = $this->build_name_link($user_id, $firstname);
- }
- while ($count < count($user_row)) {
- $table_row[] = $user_row[$count++];
- }
- $table_data[]= $table_row;
- }
- return $table_data;
- }
-
- private function build_name_link ($user_id, $name) {
- return '<a href="user_stats.php?userid='.$user_id.'&selectcat='.$this->selectcat->get_id().'">'.$name.'</a>';
- }
- }
|