/** * Display gradebook graphs */ public function display_graph_by_resource() { $headerName = $this->datagen->get_header_names(); $total_users = $this->datagen->get_total_users_count(); $displayscore = ScoreDisplay::instance(); $customdisplays = $displayscore->get_custom_score_display_settings(); if (empty($customdisplays)) { echo get_lang('ToViewGraphScoreRuleMustBeEnabled'); return ''; } $user_results = $this->datagen->get_data_to_graph2(false); //if (empty($this->datagen->get_total_items_count()) || empty($total_users)) { if (empty($user_results) || empty($total_users)) { echo get_lang('NoResults'); return ''; } // Removing first name array_shift($headerName); // Removing last name array_shift($headerName); $pre_result = $new_result = array(); foreach ($user_results as $result) { for ($i = 0; $i < count($headerName); $i++) { if (isset($result[$i + 1])) { $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; } //@todo when a display custom does not exist the order of the color does not match //filling all the answer that are not responded with 0 rsort($customdisplays); if ($total_users > 0) { foreach ($pre_result2 as $key => $res_array) { $key_list = array(); foreach ($res_array as $user_result) { $userResult = isset($user_result[1]) ? $user_result[1] : null; if (!isset($resource_list[$key][$userResult])) { $resource_list[$key][$userResult] = 0; } $resource_list[$key][$userResult] += 1; $key_list[] = $userResult; } foreach ($customdisplays as $display) { if (!in_array($display['display'], $key_list)) { $resource_list[$key][$display['display']] = 0; } } $i++; } } //fixing $resource_list $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; foreach ($resource_list as $key => $resource) { // Reverse array, otherwise we get highest values first $resource = array_reverse($resource, true); $dataSet = new pData(); $dataSet->addPoints($resource, 'Serie'); $dataSet->addPoints(array_keys($resource), 'Labels'); $dataSet->setSerieDescription('Labels', strip_tags($headerName[$i - 1])); $dataSet->setAbscissa('Labels'); $dataSet->setAbscissaName(get_lang('GradebookSkillsRanking')); $dataSet->setAxisName(0, get_lang('Students')); $palette = array('0' => array('R' => 186, 'G' => 206, 'B' => 151, 'Alpha' => 100), '1' => array('R' => 210, 'G' => 148, 'B' => 147, 'Alpha' => 100), '2' => array('R' => 148, 'G' => 170, 'B' => 208, 'Alpha' => 100), '3' => array('R' => 221, 'G' => 133, 'B' => 61, 'Alpha' => 100), '4' => array('R' => 65, 'G' => 153, 'B' => 176, 'Alpha' => 100), '5' => array('R' => 114, 'G' => 88, 'B' => 144, 'Alpha' => 100), '6' => array('R' => 138, 'G' => 166, 'B' => 78, 'Alpha' => 100), '7' => array('R' => 171, 'G' => 70, 'B' => 67, 'Alpha' => 100), '8' => array('R' => 69, 'G' => 115, 'B' => 168, 'Alpha' => 100)); // Cache definition $cachePath = api_get_path(SYS_ARCHIVE_PATH); $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $chartHash = $myCache->getHash($dataSet); if ($myCache->isInCache($chartHash)) { $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } else { /* Create the pChart object */ $widthSize = 480; $heightSize = 250; $myPicture = new pImage($widthSize, $heightSize, $dataSet); /* Turn of Antialiasing */ $myPicture->Antialias = false; /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0)); /* Set the default font */ $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10)); /* Write the chart title */ $myPicture->drawText(250, 30, strip_tags($headerName[$i - 1]), array('FontSize' => 12, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE)); /* Define the chart area */ $myPicture->setGraphArea(50, 40, $widthSize - 20, $heightSize - 50); /* Draw the scale */ $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_START0); $myPicture->drawScale($scaleSettings); /* Turn on shadow computing */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); /* Draw the chart */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); $settings = array('OverrideColors' => $palette, 'Gradient' => false, 'GradientMode' => GRADIENT_SIMPLE, 'DisplayPos' => LABEL_POS_TOP, 'DisplayValues' => true, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayShadow' => true, 'Surrounding' => 10); $myPicture->drawBarChart($settings); /* Render the picture (choose the best way) */ $myCache->writeToCache($chartHash, $myPicture); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } echo '<img src="' . $imgPath . '" >'; if ($i % 2 == 0 && $i != 0) { echo '<br /><br />'; } else { echo ' '; } $i++; } }
/** * Generates a big graph with the number of best results * @param array */ static function generate_exercise_result_graph($attempts) { $exercise_title = strip_tags($attempts['title']); $attempts = $attempts['data']; $my_exercise_result_array = $exercise_result = array(); if (empty($attempts)) { return null; } foreach ($attempts as $attempt) { if (api_get_user_id() == $attempt['exe_user_id']) { if ($attempt['exe_weighting'] != 0) { $my_exercise_result_array[] = $attempt['exe_result'] / $attempt['exe_weighting']; } } else { if ($attempt['exe_weighting'] != 0) { $exercise_result[] = $attempt['exe_result'] / $attempt['exe_weighting']; } } } //Getting best result rsort($my_exercise_result_array); $my_exercise_result = 0; if (isset($my_exercise_result_array[0])) { $my_exercise_result = $my_exercise_result_array[0] * 100; } $max = 100; $pieces = 5; $part = round($max / $pieces); $x_axis = array(); $final_array = array(); $my_final_array = array(); for ($i = 1; $i <= $pieces; $i++) { $sum = 1; if ($i == 1) { $sum = 0; } $min = ($i - 1) * $part + $sum; $max = $i * $part; $x_axis[] = $min . " - " . $max; $count = 0; foreach ($exercise_result as $result) { $percentage = $result * 100; if ($percentage >= $min && $percentage <= $max) { $count++; } } $final_array[] = $count; if ($my_exercise_result >= $min && $my_exercise_result <= $max) { $my_final_array[] = 1; } else { $my_final_array[] = 0; } } //Fix to remove the data of the user with my data for ($i = 0; $i <= count($my_final_array); $i++) { if (!empty($my_final_array[$i])) { $my_final_array[$i] = $final_array[$i] + 1; //Add my result $final_array[$i] = 0; } } // Dataset definition $dataSet = new pData(); $dataSet->addPoints($final_array, 'Serie1'); $dataSet->addPoints($my_final_array, 'Serie2'); $dataSet->addPoints($x_axis, 'Serie3'); $dataSet->setSerieDescription('Serie1', get_lang('Score')); $dataSet->setSerieDescription('Serie2', get_lang('MyResults')); $dataSet->setAbscissa('Serie3'); $dataSet->setXAxisName(get_lang('Score')); $dataSet->normalize(100, "%"); $dataSet->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true); // Cache definition $cachePath = api_get_path(SYS_ARCHIVE_PATH); $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $chartHash = $myCache->getHash($dataSet); if ($myCache->isInCache($chartHash)) { $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } else { /* Create the pChart object */ $widthSize = 480; $heightSize = 250; $fontSize = 8; $myPicture = new pImage($widthSize, $heightSize, $dataSet); /* Turn of Antialiasing */ $myPicture->Antialias = false; /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0)); /* Set the default font */ $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10)); /* Write the chart title */ $myPicture->drawText(250, 20, $exercise_title, array('FontSize' => 12, 'Align' => TEXT_ALIGN_BOTTOMMIDDLE)); /* Define the chart area */ $myPicture->setGraphArea(50, 50, $widthSize - 20, $heightSize - 30); /* Draw the scale */ $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_MANUAL, 'ManualScale' => array('0' => array('Min' => 0, 'Max' => 100))); $myPicture->drawScale($scaleSettings); /* Turn on shadow computing */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); /* Draw the chart */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); $settings = array('DisplayValues' => true, 'DisplaySize' => $fontSize, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayOrientation' => ORIENTATION_HORIZONTAL, 'Gradient' => false, 'Surrounding' => 30, 'InnerSurrounding' => 25); $myPicture->drawStackedBarChart($settings); $legendSettings = array('Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER); $myPicture->drawLegend($widthSize / 2, 30, $legendSettings); /* Write and save into cache */ $myCache->writeToCache($chartHash, $myPicture); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } return $imgPath; }
/** * This method return a graph containing information about evaluations * inside courses in sessions, it's used inside get_block method for * showing it inside dashboard interface * @return string img html */ public function get_evaluations_courses_in_sessions_graph() { $graphs = array(); if (!empty($this->sessions)) { $session_ids = array_keys($this->sessions); foreach ($session_ids as $session_id) { $courses_code = array_keys(Tracking::get_courses_list_from_session($session_id)); $courses_graph = array(); foreach ($courses_code as $course_code) { $cats = Category::load(null, null, $course_code, null, null, $session_id); if (isset($cats) && isset($cats[0])) { $alleval = $cats[0]->get_evaluations(null, true, $course_code); $alllinks = $cats[0]->get_links(null, true); $users = GradebookUtils::get_all_users($alleval, $alllinks); $datagen = new FlatViewDataGenerator($users, $alleval, $alllinks); $evaluation_sumary = $datagen->get_evaluation_sumary_results(); if (!empty($evaluation_sumary)) { $items = array_keys($evaluation_sumary); $max = $min = $avg = array(); foreach ($evaluation_sumary as $evaluation) { $max[] = $evaluation['max']; $min[] = $evaluation['min']; $avg[] = $evaluation['avg']; } // Dataset definition $dataSet = new pData(); $dataSet->addPoints($min, 'Serie3'); $dataSet->addPoints($avg, 'Serie2'); $dataSet->addPoints($max, 'Serie1'); $dataSet->addPoints($items, 'Labels'); $dataSet->setSerieDescription('Serie1', get_lang('Max')); $dataSet->setSerieDescription('Serie2', get_lang('Avg')); $dataSet->setSerieDescription('Serie3', get_lang('Min')); $dataSet->setAbscissa('Labels'); $dataSet->setAbscissaName(get_lang('EvaluationName')); $dataSet->normalize(100, '%'); $dataSet->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true); // Cache definition $cachePath = api_get_path(SYS_ARCHIVE_PATH); $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $chartHash = $myCache->getHash($dataSet); if ($myCache->isInCache($chartHash)) { $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } else { /* Create the pChart object */ $widthSize = $this->bg_width; $heightSize = $this->bg_height; $fontSize = 8; $angle = 50; $myPicture = new pImage($widthSize, $heightSize, $dataSet); /* Turn of Antialiasing */ $myPicture->Antialias = false; /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0)); /* Set the default font */ $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10)); /* Do NOT Write the chart title */ /* Define the chart area */ $myPicture->setGraphArea(50, 30, $widthSize - 20, $heightSize - 100); /* Draw the scale */ $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_MANUAL, 'ManualScale' => array('0' => array('Min' => 0, 'Max' => 100)), 'LabelRotation' => $angle); $myPicture->drawScale($scaleSettings); /* Turn on shadow computing */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); /* Draw the chart */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); $settings = array('DisplayValues' => true, 'DisplaySize' => $fontSize, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayOrientation' => ORIENTATION_HORIZONTAL, 'Gradient' => false, 'Surrounding' => 30, 'InnerSurrounding' => 25); $myPicture->drawStackedBarChart($settings); $legendSettings = array('Mode' => LEGEND_HORIZONTAL, 'Style' => LEGEND_NOBORDER); $myPicture->drawLegend($widthSize / 2, 15, $legendSettings); /* Write and save into cache */ $myCache->writeToCache($chartHash, $myPicture); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } if (!empty($imgPath)) { $courses_graph[$course_code] = '<img src="' . $imgPath . '">'; } } } } if (!empty($courses_graph)) { $graphs[$session_id] = $courses_graph; } } } return $graphs; }
/** * This function draw the graphic to be displayed on the user view as an image * * @param array $sql_result * @param string $start_date * @param string $end_date * @param string $type * @author Jorge Frisancho Jibaja * @version OCT-22- 2010 * @return string */ function grapher($sql_result, $start_date, $end_date, $type = "") { if (empty($start_date)) { $start_date = ""; } if (empty($end_date)) { $end_date = ""; } if ($type == "") { $type = 'day'; } $main_year = $main_month_year = $main_day = array(); // get last 8 days/months $last_days = 5; $last_months = 3; for ($i = $last_days; $i >= 0; $i--) { $main_day[date('d-m-Y', mktime() - $i * 3600 * 24)] = 0; } for ($i = $last_months; $i >= 0; $i--) { $main_month_year[date('m-Y', mktime() - $i * 30 * 3600 * 24)] = 0; } $i = 0; if (is_array($sql_result) && count($sql_result) > 0) { foreach ($sql_result as $key => $data) { //creating the main array $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0); $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0); if ($i > 500) { break; } $i++; } switch ($type) { case 'day': $main_date = $main_day; break; case 'month': $main_date = $main_month_year; break; case 'year': $main_date = $main_year; break; } // the nice graphics :D $labels = array_keys($main_date); if (count($main_date) == 1) { $labels = $labels[0]; $main_date = $main_date[$labels]; } /* Create and populate the pData object */ $myData = new pData(); $myData->addPoints($main_date, 'Serie1'); if (count($main_date) != 1) { $myData->addPoints($labels, 'Labels'); $myData->setSerieDescription('Labels', 'Months'); $myData->setAbscissa('Labels'); } $myData->setSerieWeight('Serie1', 1); $myData->setSerieDescription('Serie1', get_lang('MyResults')); $myData->setAxisName(0, get_lang('Minutes')); $myData->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true); // Cache definition $cachePath = api_get_path(SYS_ARCHIVE_PATH); $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $chartHash = $myCache->getHash($myData); if ($myCache->isInCache($chartHash)) { //if we already created the img $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } else { /* Define width, height and angle */ $mainWidth = 760; $mainHeight = 230; $angle = 50; /* Create the pChart object */ $myPicture = new pImage($mainWidth, $mainHeight, $myData); /* Turn of Antialiasing */ $myPicture->Antialias = false; /* Draw the background */ $settings = array("R" => 255, "G" => 255, "B" => 255); $myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $settings); /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $mainWidth - 1, $mainHeight - 1, array("R" => 0, "G" => 0, "B" => 0)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', "FontSize" => 10)); /* Write the chart title */ $myPicture->drawText($mainWidth / 2, 30, get_lang('ExercisesInTimeProgressChart'), array("FontSize" => 12, "Align" => TEXT_ALIGN_BOTTOMMIDDLE)); /* Set the default font */ $myPicture->setFontProperties(array("FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', "FontSize" => 8)); /* Define the chart area */ $myPicture->setGraphArea(50, 40, $mainWidth - 40, $mainHeight - 80); /* Draw the scale */ $scaleSettings = array('XMargin' => 10, 'YMargin' => 10, 'Floating' => true, 'GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'LabelRotation' => $angle, 'Mode' => SCALE_MODE_ADDALL_START0); $myPicture->drawScale($scaleSettings); /* Turn on Antialiasing */ $myPicture->Antialias = true; /* Enable shadow computing */ $myPicture->setShadow(true, array("X" => 1, "Y" => 1, "R" => 0, "G" => 0, "B" => 0, "Alpha" => 10)); /* Draw the line chart */ $myPicture->setFontProperties(array("FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', "FontSize" => 10)); $myPicture->drawSplineChart(); $myPicture->drawPlotChart(array("DisplayValues" => true, "PlotBorder" => true, "BorderSize" => 1, "Surrounding" => -60, "BorderAlpha" => 80)); /* Do NOT Write the chart legend */ /* Write and save into cache */ $myCache->writeToCache($chartHash, $myPicture); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } $html = '<img src="' . $imgPath . '">'; return $html; } else { $foo_img = api_convert_encoding('<div id="messages" class="warning-message">' . get_lang('GraphicNotAvailable') . '</div>', 'UTF-8'); return $foo_img; } }
/** * @return string */ public function getGraph() { $data = $this->getDataForGraph(); if (!empty($data) && isset($data['categories']) && isset($data['my_result']) && isset($data['average'])) { $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 = '<div id="contentArea" style="text-align: center;" >'; $result .= '<img src="' . $imgWebPath . '" >'; $result .= '</div>'; return $result; } } return ''; }
/** * This method return a graph containing information about students evaluation, * it's used inside get_block method for showing it inside dashboard interface * @return string img html */ public function get_students_attendance_graph() { $students = $this->students; $attendance = new Attendance(); // get data $attendances_faults_avg = array(); if (is_array($students) && count($students) > 0) { foreach ($students as $student) { $student_id = $student['user_id']; //$student_info = api_get_user_info($student_id); // get average of faults in attendances by student $results_faults_avg = $attendance->get_faults_average_inside_courses($student_id); if (!empty($results_faults_avg)) { $attendances_faults_avg[$student['lastname']] = $results_faults_avg['porcent']; } else { $attendances_faults_avg[$student['lastname']] = 0; } } } arsort($attendances_faults_avg); $usernames = array_keys($attendances_faults_avg); $faults = array(); foreach ($usernames as $username) { $faults[] = $attendances_faults_avg[$username]; } $graph = ''; $img_file = ''; if (is_array($usernames) && count($usernames) > 0) { // Defining data $dataSet = new pData(); $dataSet->addPoints($faults, 'Serie1'); $dataSet->addPoints($usernames, 'Labels'); $dataSet->setSerieDescription('Series1', get_lang('Average')); $dataSet->setSerieDescription('Labels', get_lang('User')); $dataSet->setAbscissa('Labels'); $dataSet->setAbscissaName(get_lang('User')); $dataSet->setAxisName(0, get_lang('Attendance')); $palette = array('0' => array('R' => 186, 'G' => 206, 'B' => 151, 'Alpha' => 100), '1' => array('R' => 210, 'G' => 148, 'B' => 147, 'Alpha' => 100), '2' => array('R' => 148, 'G' => 170, 'B' => 208, 'Alpha' => 100), '3' => array('R' => 221, 'G' => 133, 'B' => 61, 'Alpha' => 100), '4' => array('R' => 65, 'G' => 153, 'B' => 176, 'Alpha' => 100), '5' => array('R' => 114, 'G' => 88, 'B' => 144, 'Alpha' => 100), '6' => array('R' => 138, 'G' => 166, 'B' => 78, 'Alpha' => 100), '7' => array('R' => 171, 'G' => 70, 'B' => 67, 'Alpha' => 100), '8' => array('R' => 69, 'G' => 115, 'B' => 168, 'Alpha' => 100)); // Cache definition $cachePath = api_get_path(SYS_ARCHIVE_PATH); $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $chartHash = $myCache->getHash($dataSet); if ($myCache->isInCache($chartHash)) { $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } else { $maxCounts = max(count($usernames), count($faults)); if ($maxCounts < 5) { $heightSize = 200; } else { $heightSize = $maxCounts * 40; } /* Create the pChart object */ $widthSize = 480; $angle = 40; $myPicture = new pImage($widthSize, $heightSize, $dataSet); /* Turn of Antialiasing */ $myPicture->Antialias = false; /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0)); /* Set the default font */ $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10)); /* Do NOT Write the chart title */ /* Define the chart area */ $myPicture->setGraphArea(80, 40, $widthSize - 20, $heightSize - 40); /* Draw the scale */ $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_ADDALL_START0, 'Pos' => SCALE_POS_TOPBOTTOM, 'DrawXLines' => false, 'LabelRotation' => $angle); $myPicture->drawScale($scaleSettings); /* Turn on shadow computing */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); /* Draw the chart */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); $settings = array('OverrideColors' => $palette, 'Gradient' => false, 'GradientMode' => GRADIENT_SIMPLE, 'DisplayPos' => LABEL_POS_TOP, 'DisplayValues' => true, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0, 'DisplayShadow' => true, 'Surrounding' => 10); $myPicture->drawBarChart($settings); /* Write and save into cache */ $myCache->writeToCache($chartHash, $myPicture); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } $graph = '<img src="' . $imgPath . '" >'; } else { $graph = '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>'; } return $graph; }
/** * This method return a content html, it's used inside get_block method for showing it inside dashboard interface * @return string content html */ public function get_teachers_information_graph() { $teachers = $this->teachers; $graph = ''; $user_ids = array_keys($teachers); $a_last_week = get_last_week(); if (is_array($user_ids) && count($user_ids) > 0) { $dataSet = new pData(); foreach ($user_ids as $user_id) { $teacher_info = api_get_user_info($user_id); $username = $teacher_info['username']; $time_by_days = array(); foreach ($a_last_week as $day) { // day is received as y-m-d 12:00:00 $start_date = api_get_utc_datetime($day); $end_date = api_get_utc_datetime($day + (3600 * 24 - 1)); $time_on_platform_by_day = Tracking::get_time_spent_on_the_platform($user_id, 'custom', $start_date, $end_date); $hours = floor($time_on_platform_by_day / 3600); $min = floor(($time_on_platform_by_day - $hours * 3600) / 60); $time_by_days[] = $min; } $dataSet->addPoints($time_by_days, $username); } $last_week = date('Y-m-d', $a_last_week[0]) . ' ' . get_lang('To') . ' ' . date('Y-m-d', $a_last_week[6]); $days_on_week = array(); foreach ($a_last_week as $weekday) { $days_on_week[] = date('d/m', $weekday); } $dataSet->addPoints($days_on_week, 'Days'); $dataSet->setAbscissaName($last_week); $dataSet->setAxisName(0, get_lang('Minutes')); $dataSet->setAbscissa('Days'); $dataSet->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true); // Cache definition $cachePath = api_get_path(SYS_ARCHIVE_PATH); $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1))); $chartHash = $myCache->getHash($dataSet); if ($myCache->isInCache($chartHash)) { $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } else { /* Create the pChart object */ $widthSize = 440; $heightSize = 350; $angle = 50; $myPicture = new pImage($widthSize, $heightSize, $dataSet); /* Turn of Antialiasing */ $myPicture->Antialias = false; /* Add a border to the picture */ $myPicture->drawRectangle(0, 0, $widthSize - 1, $heightSize - 1, array('R' => 0, 'G' => 0, 'B' => 0)); /* Set the default font */ $myPicture->setFontProperties(array('FontName' => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf', 'FontSize' => 10)); /* Do NOT Write the chart title */ /* Define the chart area */ $myPicture->setGraphArea(40, 40, $widthSize - 20, $heightSize - 80); /* Draw the scale */ $scaleSettings = array('GridR' => 200, 'GridG' => 200, 'GridB' => 200, 'DrawSubTicks' => true, 'CycleBackground' => true, 'Mode' => SCALE_MODE_ADDALL_START0, 'LabelRotation' => $angle); $myPicture->drawScale($scaleSettings); /* Turn on shadow computing */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); /* Draw the chart */ $myPicture->setShadow(true, array('X' => 1, 'Y' => 1, 'R' => 0, 'G' => 0, 'B' => 0, 'Alpha' => 10)); $settings = array('DisplayValues' => true, 'DisplayR' => 0, 'DisplayG' => 0, 'DisplayB' => 0); $myPicture->drawFilledSplineChart($settings); $myPicture->drawLegend(40, 20, array('Mode' => LEGEND_HORIZONTAL)); /* Write and save into cache */ $myCache->writeToCache($chartHash, $myPicture); $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash; $myCache->saveFromCache($chartHash, $imgPath); $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash; } $graph = '<img src="' . $imgPath . '" >'; } else { $graph = '<p>' . api_convert_encoding(get_lang('GraphicNotAvailable'), 'UTF-8') . '</p>'; } return $graph; }